Commit 0d5bcea9 authored by Joanne Hugé's avatar Joanne Hugé

Add tracemark options to server

parent bba18f1b
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <unistd.h> #include <unistd.h>
#include "common.h" #include "common.h"
#include "tracer.h"
#ifdef WITH_XDP #ifdef WITH_XDP
#include <bpf/bpf.h> #include <bpf/bpf.h>
...@@ -56,7 +57,9 @@ static ingress_stat_t *stats; ...@@ -56,7 +57,9 @@ static ingress_stat_t *stats;
static uint64_t *kernel_latency_hist; static uint64_t *kernel_latency_hist;
static int use_histogram; static int use_histogram;
uint64_t post_kernel_timestamp; static uint64_t post_kernel_timestamp;
static char ts_tracemark_buf[64];
// Sets the interface // Sets the interface
static int set_if(void) { static int set_if(void) {
...@@ -176,27 +179,34 @@ void recv_udp_packet() { ...@@ -176,27 +179,34 @@ void recv_udp_packet() {
struct timespec *stamp = struct timespec *stamp =
(struct timespec *)CMSG_DATA(cmsg); (struct timespec *)CMSG_DATA(cmsg);
uint64_t kernel_latency = if(params->enable_ts_tracemark) {
post_kernel_timestamp - ts_to_uint(*stamp); sprintf(ts_tracemark_buf, "%" PRIu64, ts_to_uint(*stamp));
kernel_latency /= 1000u; tracemark(ts_tracemark_buf);
}
stats->min_kernel_latency = _min_( else {
kernel_latency, stats->min_kernel_latency);
stats->max_kernel_latency = _max_( uint64_t kernel_latency =
kernel_latency, stats->max_kernel_latency); post_kernel_timestamp - ts_to_uint(*stamp);
stats->avg_kernel_latency = kernel_latency /= 1000u;
(stats->max_kernel_latency *
(stats->packets_received) + stats->min_kernel_latency = _min_(
kernel_latency) / kernel_latency, stats->min_kernel_latency);
(stats->packets_received + 1); stats->max_kernel_latency = _max_(
kernel_latency, stats->max_kernel_latency);
if (use_histogram) { stats->avg_kernel_latency =
if (kernel_latency > MAX_KERNEL_LATENCY) (stats->max_kernel_latency *
stats->high_kernel_latency++; (stats->packets_received) +
else kernel_latency) /
kernel_latency_hist (stats->packets_received + 1);
[kernel_latency]++;
} if (use_histogram) {
if (kernel_latency > MAX_KERNEL_LATENCY)
stats->high_kernel_latency++;
else
kernel_latency_hist
[kernel_latency]++;
}
}
} }
} }
} }
......
...@@ -7,6 +7,7 @@ typedef struct ingress_param { ...@@ -7,6 +7,7 @@ typedef struct ingress_param {
char network_if[16]; char network_if[16];
int use_timestamps; int use_timestamps;
int enable_ts_tracemark;
int xdp_polling_mode; int xdp_polling_mode;
uint64_t interval; uint64_t interval;
......
...@@ -42,6 +42,7 @@ typedef struct thread_param { ...@@ -42,6 +42,7 @@ typedef struct thread_param {
int emit_signal; int emit_signal;
int enable_diff_ts; int enable_diff_ts;
int enable_receive_tracemark;
} thread_param_t; } thread_param_t;
...@@ -80,6 +81,8 @@ static int64_t min_diff_ts = INT_MAX; ...@@ -80,6 +81,8 @@ static int64_t min_diff_ts = INT_MAX;
static int64_t max_diff_ts = 0; static int64_t max_diff_ts = 0;
static int64_t avg_diff_ts = 0; static int64_t avg_diff_ts = 0;
static char ts_tracemark_buf[64];
static void help(char *argv[]) { static void help(char *argv[]) {
printf( printf(
"Usage: %s [-f IF -a CPU -p PRIO -i USEC -r USEC] [-b CLIENT_IP] [-d " "Usage: %s [-f IF -a CPU -p PRIO -i USEC -r USEC] [-b CLIENT_IP] [-d "
...@@ -100,6 +103,8 @@ static void help(char *argv[]) { ...@@ -100,6 +103,8 @@ static void help(char *argv[]) {
" POLL_MODE: 0 for polling, 1 for combination of both\n" " POLL_MODE: 0 for polling, 1 for combination of both\n"
" -X Trace during XDP packet reception\n" " -X Trace during XDP packet reception\n"
" -T THRESHOLD Enable tracing until THRESHOLD is reached\n" " -T THRESHOLD Enable tracing until THRESHOLD is reached\n"
" -M Send tracemark when packet is received\n"
" -S Send tracemark containing RX SO_TIMESTAMP timestamp\n"
" -v Verbose\n" " -v Verbose\n"
"\n", "\n",
argv[0]); argv[0]);
...@@ -174,6 +179,11 @@ static void *tsn_thread(void *p) { ...@@ -174,6 +179,11 @@ static void *tsn_thread(void *p) {
clock_gettime(CLOCK_REALTIME, &current); clock_gettime(CLOCK_REALTIME, &current);
recv_xdp_cleanup(); recv_xdp_cleanup();
if(thread_params.enable_receive_tracemark) {
sprintf(ts_tracemark_buf, "%" PRIu64, ts_to_uint(current));
tracemark(ts_tracemark_buf);
}
if(thread_params.enable_diff_ts) { if(thread_params.enable_diff_ts) {
uint64_t send_ts = decode(ingress_stats.data); uint64_t send_ts = decode(ingress_stats.data);
int64_t diff_us = (((int64_t) ts_to_uint(current)) - ((int64_t)send_ts)) / 1000; int64_t diff_us = (((int64_t) ts_to_uint(current)) - ((int64_t)send_ts)) / 1000;
...@@ -293,6 +303,7 @@ int main(int argc, char *argv[]) { ...@@ -293,6 +303,7 @@ int main(int argc, char *argv[]) {
thread_params.emit_signal = 0; thread_params.emit_signal = 0;
thread_params.affinity_cpu = 0; thread_params.affinity_cpu = 0;
thread_params.enable_diff_ts = 0; thread_params.enable_diff_ts = 0;
thread_params.enable_receive_tracemark = 0;
main_params.refresh_rate = 50000; main_params.refresh_rate = 50000;
main_params.verbose = 0; main_params.verbose = 0;
main_params.enable_tracing = 0; main_params.enable_tracing = 0;
...@@ -300,6 +311,7 @@ int main(int argc, char *argv[]) { ...@@ -300,6 +311,7 @@ int main(int argc, char *argv[]) {
enable_histograms = 0; enable_histograms = 0;
tsn_task = RECV_PACKET_TASK; tsn_task = RECV_PACKET_TASK;
ingress_params.tx_buffer_len = 1024; ingress_params.tx_buffer_len = 1024;
ingress_params.enable_ts_tracemark = 0;
// Process bash options // Process bash options
process_options(argc, argv); process_options(argc, argv);
...@@ -449,7 +461,7 @@ static void process_options(int argc, char *argv[]) { ...@@ -449,7 +461,7 @@ static void process_options(int argc, char *argv[]) {
int network_if_specified = 0; int network_if_specified = 0;
for (;;) { for (;;) {
int c = getopt(argc, argv, "a:b:cCd:f:ghi:p:r:tvx:XT:G"); int c = getopt(argc, argv, "a:b:cCd:f:ghi:p:r:tvx:XT:GMS");
if (c == -1) break; if (c == -1) break;
...@@ -511,6 +523,12 @@ static void process_options(int argc, char *argv[]) { ...@@ -511,6 +523,12 @@ static void process_options(int argc, char *argv[]) {
main_params.enable_tracing = 1; main_params.enable_tracing = 1;
thread_params.latency_threshold = atoi(optarg); thread_params.latency_threshold = atoi(optarg);
break; break;
case 'M':
thread_params.enable_receive_tracemark = 1;
break;
case 'S':
ingress_params.enable_ts_tracemark = 1;
break;
} }
} }
......
...@@ -32,11 +32,14 @@ Usage: $0 [-h] [-I if] [SERVER] | TCPDUMP [TRACE_OPTS] ...@@ -32,11 +32,14 @@ Usage: $0 [-h] [-I if] [SERVER] | TCPDUMP [TRACE_OPTS]
TRACE_OPTS: -T LATENCY_THRESHOLD [-P TRACER -E XDP_EVENTS] TRACE_OPTS: -T LATENCY_THRESHOLD [-P TRACER -E XDP_EVENTS]
Trace until latency threshold is met Trace until latency threshold is met
-T USEC Enable tracing until threshold is met -T USEC Enable tracing until threshold is met
-Q Enable eth0 IRQ tracing only
-P TRACER Which trace to use when tracing: function, function_graph, wakeup etc... -P TRACER Which trace to use when tracing: function, function_graph, wakeup etc...
Default: function Default: function
-E EVENTS Specify which events to trace (e.g: "-E "-e net -e irq") -E EVENTS Specify which events to trace (e.g: "-E "-e net -e irq")
Default: irq, sched, net, napi Default: irq, sched, net, napi
-B SIZE Size of the buffer for each CPU in kilobytes -B SIZE Size of the buffer for each CPU in kilobytes
-M Send tracemark when packet is received\n"
-S Send tracemark containing RX SO_TIMESTAMP timestamp\n"
ENDUSAGE ENDUSAGE
1>&2; 1>&2;
...@@ -53,7 +56,7 @@ tracecmd_events="-e irq -e sched -e net -e napi" ...@@ -53,7 +56,7 @@ tracecmd_events="-e irq -e sched -e net -e napi"
tracecmd_opts="" tracecmd_opts=""
cpu=1 cpu=1
while getopts "a:b:cChtx:X:d:i:g:I:T:E:P:B:" opt; do while getopts "a:b:cChtx:X:d:i:g:I:T:E:P:B:MSQ" opt; do
case "${opt}" in case "${opt}" in
a ) a )
cpu=${OPTARG} cpu=${OPTARG}
...@@ -111,6 +114,18 @@ while getopts "a:b:cChtx:X:d:i:g:I:T:E:P:B:" opt; do ...@@ -111,6 +114,18 @@ while getopts "a:b:cChtx:X:d:i:g:I:T:E:P:B:" opt; do
use_tracer=1 use_tracer=1
server_options+=" -T ${OPTARG}" server_options+=" -T ${OPTARG}"
;; ;;
M )
server_options+=" -M "
;;
S )
server_options+=" -S "
;;
Q )
use_tracer=1
server_options+=" -T 999999"
tracecmd_events=" -e irq_handler_entry "
tracecmd_filter="irq == 56"
;;
* ) * )
usage usage
;; ;;
...@@ -148,8 +163,15 @@ else ...@@ -148,8 +163,15 @@ else
cd $script_dir/../packet-exchange/build;make $make_opts server;cd $script_dir cd $script_dir/../packet-exchange/build;make $make_opts server;cd $script_dir
if [ -n "${use_tracer}" ]; then if [ -n "${use_tracer}" ]; then
echo "trace-cmd record $tracecmd_opts $tracecmd_events $script_dir/../packet-exchange/build/server $server_options";
trace-cmd record $tracecmd_opts $tracecmd_events $script_dir/../packet-exchange/build/server $server_options; if [ -n "${tracecmd_filter}" ]; then
echo "trace-cmd record $tracecmd_opts $tracecmd_events -f \"$tracecmd_filter\" $script_dir/../packet-exchange/build/server $server_options";
trace-cmd record $tracecmd_opts $tracecmd_events -f "$tracecmd_filter" $script_dir/../packet-exchange/build/server $server_options;
else
echo "trace-cmd record $tracecmd_opts $tracecmd_events $script_dir/../packet-exchange/build/server $server_options";
trace-cmd record $tracecmd_opts $tracecmd_events $script_dir/../packet-exchange/build/server $server_options;
fi
elif [ -z "${use_histogram}" ]; then elif [ -z "${use_histogram}" ]; then
echo "server $server_options"; echo "server $server_options";
$script_dir/../packet-exchange/build/server $server_options; $script_dir/../packet-exchange/build/server $server_options;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment