From e72d30978936cd0f133ba1e429c707c61ee0ff90 Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Tue, 1 Feb 2022 11:56:32 +0100 Subject: [PATCH] tc-policy: Monitor TXQ usage with bpftrace script Signed-off-by: Jesper Dangaard Brouer --- tc-policy/README.org | 18 ++++++++++++++++++ tc-policy/monitor_txq_usage.bt | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 tc-policy/monitor_txq_usage.bt diff --git a/tc-policy/README.org b/tc-policy/README.org index 308dbc9..e8aa5a2 100644 --- a/tc-policy/README.org +++ b/tc-policy/README.org @@ -54,3 +54,21 @@ You can now use it in all perf tools, such as: #+end_src Afterwards run =perf script= and see results. + +** bpftrace + +It is also possible to monitor TXQ usage via a =bpftrace= script. + * see [[file:monitor_txq_usage.bt]]. + +The main part of the script is: +#+begin_src sh + tracepoint:net:net_dev_start_xmit { + $qm = args->queue_mapping; + $dev = str(args->name, 15); + + @stat_txq_usage[$dev] = lhist($qm, 0,32,1); + } +#+end_src + +Or as oneliner: + * =bpftrace -e 't:net:net_dev_start_xmit {@txq[str(args->name, 15)]=lhist(args->queue_mapping, 0,32,1)}'= diff --git a/tc-policy/monitor_txq_usage.bt b/tc-policy/monitor_txq_usage.bt new file mode 100755 index 0000000..5192996 --- /dev/null +++ b/tc-policy/monitor_txq_usage.bt @@ -0,0 +1,26 @@ +#!/usr/bin/bpftrace + +//BEGIN { +// printf("Monitor TXQ usage\n"); +// printf(" - Remember: BPF set queue_mapping is one-less here (zero-indexed)\n"); +//} + +tracepoint:net:net_dev_start_xmit { + $qm = args->queue_mapping; + $dev = str(args->name, 15); + + @stat_txq_usage[$dev] = lhist($qm, 0,32,1); +} + +/* Periodically print stats */ +interval:s:3 +{ + printf("\nPeriodic show stats - time: "); + time(); + print(@stat_txq_usage); +} + +/* Default bpftrace will print all remaining maps at END */ +//END { +// printf("END stats:\n"); +//}