dispatch-trace: move dispatch trace pcap code to plugin

Type: refactor
Change-Id: I02a527f57853ebff797f0d85761b71127916d6ce
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2021-03-05 14:41:25 +01:00
parent 46353f0693
commit 25ab6c5410
10 changed files with 614 additions and 573 deletions

View File

@ -394,6 +394,11 @@ I: avf
M: Damjan Marion <damarion@cisco.com>
F: src/plugins/avf/
Plugin - Dispatch Trace PCAP
I: dispatch-trace
M: Dave Barach <vpp@barachs.net>
F: src/plugins/dispatch-trace
Plugin - DPDK
I: dpdk
M: Damjan Marion <damarion@cisco.com>

View File

@ -0,0 +1,17 @@
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_vpp_plugin(dispatch_trace
SOURCES
main.c
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,6 @@
#include <vppinfra/pool.h>
#include <vppinfra/random_buffer.h>
#include <vppinfra/time.h>
#include <vppinfra/pcap.h>
#include <pthread.h>
@ -180,13 +179,6 @@ typedef struct vlib_main_t
/* Packet trace buffer. */
vlib_trace_main_t trace_main;
/* Pcap dispatch trace main */
pcap_main_t dispatch_pcap_main;
uword dispatch_pcap_enable;
uword dispatch_pcap_postmortem;
u32 *dispatch_buffer_trace_nodes;
u8 *pcap_buffer;
/* Packet trace capture filter */
vlib_trace_filter_t trace_filter;
@ -259,8 +251,8 @@ typedef struct vlib_main_t
/* debugging */
volatile int parked_at_barrier;
/* Attempt to do a post-mortem elog dump */
int elog_post_mortem_dump;
/* post-mortem callbacks */
void (**post_mortem_callbacks) (void);
/*
* Need to call vlib_worker_thread_node_runtime_update before
@ -459,22 +451,8 @@ extern u8 **vlib_thread_stacks;
u32 vlib_app_num_thread_stacks_needed (void) __attribute__ ((weak));
extern void vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n);
void vlib_add_del_post_mortem_callback (void *cb, int is_add);
#define VLIB_PCAP_MAJOR_VERSION 1
#define VLIB_PCAP_MINOR_VERSION 0
typedef struct
{
u8 *filename;
int enable;
int status;
int post_mortem;
u32 packets_to_capture;
u32 buffer_trace_node_index;
u32 buffer_traces_to_capture;
} vlib_pcap_dispatch_trace_args_t;
int vlib_pcap_dispatch_trace_configure (vlib_pcap_dispatch_trace_args_t *);
vlib_main_t *vlib_get_main_not_inline (void);
elog_main_t *vlib_get_elog_main_not_inline ();

View File

@ -76,7 +76,6 @@ typedef u32 vlib_log_class_t;
#include <vlib/trace_funcs.h>
#include <vlib/global_funcs.h>
#include <vlib/buffer_node.h>
#include <vppinfra/pcap_funcs.h>
#endif /* included_vlib_h */

View File

@ -520,6 +520,9 @@ STATIC_ASSERT (sizeof (vnet_buffer_opaque2_t) <=
format_function_t format_vnet_buffer;
format_function_t format_vnet_buffer_offload;
format_function_t format_vnet_buffer_flags;
format_function_t format_vnet_buffer_opaque;
format_function_t format_vnet_buffer_opaque2;
static_always_inline void
vnet_buffer_offload_flags_set (vlib_buffer_t *b, u32 oflags)

View File

@ -510,6 +510,43 @@ u8 *format_vnet_interface_output_trace (u8 * s, va_list * va);
serialize_function_t serialize_vnet_interface_state,
unserialize_vnet_interface_state;
/**
* @brief Add buffer (vlib_buffer_t) to the trace
*
* @param *pm - pcap_main_t
* @param *vm - vlib_main_t
* @param buffer_index - u32
* @param n_bytes_in_trace - u32
*
*/
static inline void
pcap_add_buffer (pcap_main_t *pm, struct vlib_main_t *vm, u32 buffer_index,
u32 n_bytes_in_trace)
{
vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index);
u32 n = vlib_buffer_length_in_chain (vm, b);
i32 n_left = clib_min (n_bytes_in_trace, n);
f64 time_now = vlib_time_now (vm);
void *d;
if (PREDICT_TRUE (pm->n_packets_captured < pm->n_packets_to_capture))
{
clib_spinlock_lock_if_init (&pm->lock);
d = pcap_add_packet (pm, time_now, n_left, n);
while (1)
{
u32 copy_length = clib_min ((u32) n_left, b->current_length);
clib_memcpy_fast (d, b->data + b->current_data, copy_length);
n_left -= b->current_length;
if (n_left <= 0)
break;
d += b->current_length;
ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
b = vlib_get_buffer (vm, b->next_buffer);
}
clib_spinlock_unlock_if_init (&pm->lock);
}
}
#endif /* included_vnet_interface_funcs_h */
/*

View File

@ -112,6 +112,7 @@ typedef struct vnet_main_t
extern vnet_main_t vnet_main;
#include <vppinfra/pcap_funcs.h>
#include <vnet/interface_funcs.h>
#include <vnet/global_funcs.h>

View File

@ -54,45 +54,6 @@ pcap_add_packet (pcap_main_t * pm,
return h->data;
}
/**
* @brief Add buffer (vlib_buffer_t) to the trace
*
* @param *pm - pcap_main_t
* @param *vm - vlib_main_t
* @param buffer_index - u32
* @param n_bytes_in_trace - u32
*
*/
static inline void
pcap_add_buffer (pcap_main_t * pm,
struct vlib_main_t *vm, u32 buffer_index,
u32 n_bytes_in_trace)
{
vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index);
u32 n = vlib_buffer_length_in_chain (vm, b);
i32 n_left = clib_min (n_bytes_in_trace, n);
f64 time_now = vlib_time_now (vm);
void *d;
if (PREDICT_TRUE (pm->n_packets_captured < pm->n_packets_to_capture))
{
clib_spinlock_lock_if_init (&pm->lock);
d = pcap_add_packet (pm, time_now, n_left, n);
while (1)
{
u32 copy_length = clib_min ((u32) n_left, b->current_length);
clib_memcpy_fast (d, b->data + b->current_data, copy_length);
n_left -= b->current_length;
if (n_left <= 0)
break;
d += b->current_length;
ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT);
b = vlib_get_buffer (vm, b->next_buffer);
}
clib_spinlock_unlock_if_init (&pm->lock);
}
}
#endif /* included_vppinfra_pcap_funcs_h */
/*