diff options
Diffstat (limited to 'xdp-monitor')
-rw-r--r-- | xdp-monitor/.gitignore | 1 | ||||
-rw-r--r-- | xdp-monitor/Makefile | 16 | ||||
-rw-r--r-- | xdp-monitor/README.org | 151 | ||||
-rw-r--r-- | xdp-monitor/tests/test-xdp-monitor.sh | 11 | ||||
-rw-r--r-- | xdp-monitor/xdp-monitor.8 | 169 | ||||
-rw-r--r-- | xdp-monitor/xdp-monitor.c | 125 | ||||
-rw-r--r-- | xdp-monitor/xdp_monitor.bpf.c | 9 |
7 files changed, 482 insertions, 0 deletions
diff --git a/xdp-monitor/.gitignore b/xdp-monitor/.gitignore new file mode 100644 index 0000000..506a4f8 --- /dev/null +++ b/xdp-monitor/.gitignore @@ -0,0 +1 @@ +xdp-monitor diff --git a/xdp-monitor/Makefile b/xdp-monitor/Makefile new file mode 100644 index 0000000..5b646fa --- /dev/null +++ b/xdp-monitor/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) + +XDP_TARGETS := xdp_monitor.bpf +BPF_SKEL_TARGETS := $(XDP_TARGETS) + +# Don't install skeleton object files +XDP_OBJ_INSTALL := + +TOOL_NAME := xdp-monitor +MAN_PAGE := xdp-monitor.8 +TEST_FILE := tests/test-xdp-monitor.sh +USER_TARGETS := xdp-monitor +LIB_DIR = ../lib + +include $(LIB_DIR)/common.mk + diff --git a/xdp-monitor/README.org b/xdp-monitor/README.org new file mode 100644 index 0000000..4458762 --- /dev/null +++ b/xdp-monitor/README.org @@ -0,0 +1,151 @@ +#+EXPORT_FILE_NAME: xdp-monitor +#+TITLE: xdp-monitor +#+MAN_CLASS_OPTIONS: :section-id "8\" \"DATE\" \"VERSION\" \"A simple XDP monitoring tool" +# This file serves both as a README on github, and as the source for the man +# page; the latter through the org-mode man page export support. +# . +# To export the man page, simply use the org-mode exporter; (require 'ox-man) if +# it's not available. There's also a Makefile rule to export it. + +* XDP-monitor - a simple BPF-powered XDP monitoring tool + +XDP-monitor is a tool that monitors various XDP related statistics and events using +BPF tracepoints infrastructure, trying to be as low overhead as possible. + +Note that by default, statistics for successful XDP redirect events is disabled, +as that leads to a per-packet BPF tracing overhead, which while being low +overhead, can lead to packet processing degradation. + +This tool relies on the BPF raw tracepoints infrastructure in the kernel. + +There is more information on the meaning of the output in both default (terse) +and verbose output mode, in the =Output Format Description= section. + +** Running xdp-monitor +The syntax for running xdp-monitor is: + +#+begin_src sh +xdp-monitor [options] +#+end_src + +The supported options are: + +** -i, --interval <SECONDS> +Set the polling interval for collecting all statistics and displaying them to +the output. The unit of interval is in seconds. + +** -s, --stats +Enable statistics for successful redirection. This option comes with a per +packet tracing overhead, for recording all successful redirections. + +** -e, --extended +Start xdp-bench in "extended" output mode. If not set, xdp-bench will start in +"terse" mode. The output mode can be switched by hitting C-\ while the program +is running. See also the *Output Format Description* section below. + +** -v, --verbose +Enable verbose logging. Supply twice to enable verbose logging from the +underlying =libxdp= and =libbpf= libraries. + +** --version +Show the application version and exit. + +** -h, --help +Display a summary of the available options + +* Output Format Description + +By default, redirect success statistics are disabled, use =--stats= to enable. +The terse output mode is default, extended output mode can be activated using +the =--extended= command line option. + +SIGQUIT (Ctrl + \\) can be used to switch the mode dynamically at runtime. + +Terse mode displays at most the following fields: +#+begin_src sh + rx/s Number of packets received per second + redir/s Number of packets successfully redirected per second + err,drop/s Aggregated count of errors per second (including dropped packets) + xmit/s Number of packets transmitted on the output device per second +#+end_src + +Verbose output mode displays at most the following fields: +#+begin_src sh + FIELD DESCRIPTION + receive Displays the number of packets received and errors encountered + + Whenever an error or packet drop occurs, details of per CPU error + and drop statistics will be expanded inline in terse mode. + pkt/s - Packets received per second + drop/s - Packets dropped per second + error/s - Errors encountered per second + redirect - Displays the number of packets successfully redirected + Errors encountered are expanded under redirect_err field + Note that passing -s to enable it has a per packet overhead + redir/s - Packets redirected successfully per second + + + redirect_err Displays the number of packets that failed redirection + + The errno is expanded under this field with per CPU count + The recognized errors are: + EINVAL: Invalid redirection + ENETDOWN: Device being redirected to is down + EMSGSIZE: Packet length too large for device + EOPNOTSUPP: Operation not supported + ENOSPC: No space in ptr_ring of cpumap kthread + + error/s - Packets that failed redirection per second + + + enqueue to cpu N Displays the number of packets enqueued to bulk queue of CPU N + Expands to cpu:FROM->N to display enqueue stats for each CPU enqueuing to CPU N + Received packets can be associated with the CPU redirect program is enqueuing + packets to. + pkt/s - Packets enqueued per second from other CPU to CPU N + drop/s - Packets dropped when trying to enqueue to CPU N + bulk-avg - Average number of packets processed for each event + + + kthread Displays the number of packets processed in CPUMAP kthread for each CPU + Packets consumed from ptr_ring in kthread, and its xdp_stats (after calling + CPUMAP bpf prog) are expanded below this. xdp_stats are expanded as a total and + then per-CPU to associate it to each CPU's pinned CPUMAP kthread. + pkt/s - Packets consumed per second from ptr_ring + drop/s - Packets dropped per second in kthread + sched - Number of times kthread called schedule() + + xdp_stats (also expands to per-CPU counts) + pass/s - XDP_PASS count for CPUMAP program execution + drop/s - XDP_DROP count for CPUMAP program execution + redir/s - XDP_REDIRECT count for CPUMAP program execution + + + xdp_exception Displays xdp_exception tracepoint events + + This can occur due to internal driver errors, unrecognized + XDP actions and due to explicit user trigger by use of XDP_ABORTED + Each action is expanded below this field with its count + hit/s - Number of times the tracepoint was hit per second + + + devmap_xmit Displays devmap_xmit tracepoint events + + This tracepoint is invoked for successful transmissions on output + device but these statistics are not available for generic XDP mode, + hence they will be omitted from the output when using SKB mode + xmit/s - Number of packets that were transmitted per second + drop/s - Number of packets that failed transmissions per second + drv_err/s - Number of internal driver errors per second + bulk-avg - Average number of packets processed for each event +#+end_src + +* BUGS + +Please report any bugs on Github: https://github.com/xdp-project/xdp-tools/issues + +* AUTHOR + +The original xdp-monitor tool was written by Jesper Dangaard Brouer. It was then +rewritten to support more features by Kumar Kartikeya Dwivedi. This man page was +written by Kumar Kartikeya Dwivedi. diff --git a/xdp-monitor/tests/test-xdp-monitor.sh b/xdp-monitor/tests/test-xdp-monitor.sh new file mode 100644 index 0000000..b85c7c9 --- /dev/null +++ b/xdp-monitor/tests/test-xdp-monitor.sh @@ -0,0 +1,11 @@ +XDP_LOADER=${XDP_LOADER:-./xdp-loader} +XDP_MONITOR=${XDP_MONITOR:-./xdp-monitor} +ALL_TESTS="test_monitor" + +test_monitor() +{ + export XDP_SAMPLE_IMMEDIATE_EXIT=1 + check_run $XDP_MONITOR -vv + check_run $XDP_MONITOR -s -vv + check_run $XDP_MONITOR -e -vv +} diff --git a/xdp-monitor/xdp-monitor.8 b/xdp-monitor/xdp-monitor.8 new file mode 100644 index 0000000..167e4f4 --- /dev/null +++ b/xdp-monitor/xdp-monitor.8 @@ -0,0 +1,169 @@ +.TH "xdp-monitor" "8" "DECEMBER 12, 2022" "V1.3.1" "A simple XDP monitoring tool" + +.SH "NAME" +XDP-monitor \- a simple BPF-powered XDP monitoring tool +.SH "SYNOPSIS" +.PP +XDP-monitor is a tool that monitors various XDP related statistics and events using +BPF tracepoints infrastructure, trying to be as low overhead as possible. + +.PP +Note that by default, statistics for successful XDP redirect events is disabled, +as that leads to a per-packet BPF tracing overhead, which while being low +overhead, can lead to packet processing degradation. + +.PP +This tool relies on the BPF raw tracepoints infrastructure in the kernel. + +.PP +There is more information on the meaning of the output in both default (terse) +and verbose output mode, in the \fIOutput Format Description\fP section. + +.SS "Running xdp-monitor" +.PP +The syntax for running xdp-monitor is: + +.RS +.nf +\fCxdp-monitor [options] +\fP +.fi +.RE + +.PP +The supported options are: + +.SS "-i, --interval <SECONDS>" +.PP +Set the polling interval for collecting all statistics and displaying them to +the output. The unit of interval is in seconds. + +.SS "-s, --stats" +.PP +Enable statistics for successful redirection. This option comes with a per +packet tracing overhead, for recording all successful redirections. + +.SS "-e, --extended" +.PP +Start xdp-bench in "extended" output mode. If not set, xdp-bench will start in +"terse" mode. The output mode can be switched by hitting C-$\ while the program +is running. See also the \fBOutput Format Description\fP section below. + +.SS "-v, --verbose" +.PP +Enable verbose logging. Supply twice to enable verbose logging from the +underlying \fIlibxdp\fP and \fIlibbpf\fP libraries. + +.SS "--version" +.PP +Show the application version and exit. + +.SS "-h, --help" +.PP +Display a summary of the available options + +.SH "Output Format Description" +.PP +By default, redirect success statistics are disabled, use \fI\-\-stats\fP to enable. +The terse output mode is default, extended output mode can be activated using +the \fI\-\-extended\fP command line option. + +.PP +SIGQUIT (Ctrl + \\) can be used to switch the mode dynamically at runtime. + +.PP +Terse mode displays at most the following fields: +.RS +.nf +\fCrx/s Number of packets received per second +redir/s Number of packets successfully redirected per second +err,drop/s Aggregated count of errors per second (including dropped packets) +xmit/s Number of packets transmitted on the output device per second +\fP +.fi +.RE + +.PP +Verbose output mode displays at most the following fields: +.RS +.nf +\fCFIELD DESCRIPTION +receive Displays the number of packets received and errors encountered + + Whenever an error or packet drop occurs, details of per CPU error + and drop statistics will be expanded inline in terse mode. + pkt/s - Packets received per second + drop/s - Packets dropped per second + error/s - Errors encountered per second + redirect - Displays the number of packets successfully redirected + Errors encountered are expanded under redirect_err field + Note that passing -s to enable it has a per packet overhead + redir/s - Packets redirected successfully per second + + +redirect_err Displays the number of packets that failed redirection + + The errno is expanded under this field with per CPU count + The recognized errors are: + EINVAL: Invalid redirection + ENETDOWN: Device being redirected to is down + EMSGSIZE: Packet length too large for device + EOPNOTSUPP: Operation not supported + ENOSPC: No space in ptr_ring of cpumap kthread + + error/s - Packets that failed redirection per second + + +enqueue to cpu N Displays the number of packets enqueued to bulk queue of CPU N + Expands to cpu:FROM->N to display enqueue stats for each CPU enqueuing to CPU N + Received packets can be associated with the CPU redirect program is enqueuing + packets to. + pkt/s - Packets enqueued per second from other CPU to CPU N + drop/s - Packets dropped when trying to enqueue to CPU N + bulk-avg - Average number of packets processed for each event + + +kthread Displays the number of packets processed in CPUMAP kthread for each CPU + Packets consumed from ptr_ring in kthread, and its xdp_stats (after calling + CPUMAP bpf prog) are expanded below this. xdp_stats are expanded as a total and + then per-CPU to associate it to each CPU's pinned CPUMAP kthread. + pkt/s - Packets consumed per second from ptr_ring + drop/s - Packets dropped per second in kthread + sched - Number of times kthread called schedule() + + xdp_stats (also expands to per-CPU counts) + pass/s - XDP_PASS count for CPUMAP program execution + drop/s - XDP_DROP count for CPUMAP program execution + redir/s - XDP_REDIRECT count for CPUMAP program execution + + +xdp_exception Displays xdp_exception tracepoint events + + This can occur due to internal driver errors, unrecognized + XDP actions and due to explicit user trigger by use of XDP_ABORTED + Each action is expanded below this field with its count + hit/s - Number of times the tracepoint was hit per second + + +devmap_xmit Displays devmap_xmit tracepoint events + + This tracepoint is invoked for successful transmissions on output + device but these statistics are not available for generic XDP mode, + hence they will be omitted from the output when using SKB mode + xmit/s - Number of packets that were transmitted per second + drop/s - Number of packets that failed transmissions per second + drv_err/s - Number of internal driver errors per second + bulk-avg - Average number of packets processed for each event +\fP +.fi +.RE + +.SH "BUGS" +.PP +Please report any bugs on Github: \fIhttps://github.com/xdp-project/xdp-tools/issues\fP + +.SH "AUTHOR" +.PP +The original xdp-monitor tool was written by Jesper Dangaard Brouer. It was then +rewritten to support more features by Kumar Kartikeya Dwivedi. This man page was +written by Kumar Kartikeya Dwivedi. diff --git a/xdp-monitor/xdp-monitor.c b/xdp-monitor/xdp-monitor.c new file mode 100644 index 0000000..533475f --- /dev/null +++ b/xdp-monitor/xdp-monitor.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2017 Jesper Dangaard Brouer, Red Hat, Inc. */ +static const char *__doc__= +"XDP monitor tool, based on tracepoints\n"; + +static const char *__doc_err_only__= +"NOTICE: Only tracking XDP redirect errors\n" +" Enable redirect success stats via '-s/--stats'\n" +" (which comes with a per packet processing overhead)\n"; + +#define PROG_NAME "xdp-monitor" + +#include <time.h> +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <getopt.h> +#include <locale.h> +#include <net/if.h> +#include <signal.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <bpf/bpf.h> +#include <stdbool.h> +#include <bpf/libbpf.h> +#include <sys/resource.h> + +#include <xdp_sample.h> +#include "xdp_monitor.skel.h" +#include "params.h" +#include "util.h" +#include "logging.h" + +static int mask = SAMPLE_REDIRECT_ERR_CNT | SAMPLE_CPUMAP_ENQUEUE_CNT | + SAMPLE_CPUMAP_KTHREAD_CNT | SAMPLE_EXCEPTION_CNT | + SAMPLE_DEVMAP_XMIT_CNT | SAMPLE_DEVMAP_XMIT_CNT_MULTI; + +DEFINE_SAMPLE_INIT(xdp_monitor); + +static const struct monitoropt { + bool stats; + bool extended; + __u32 interval; +} defaults_monitoropt = { .stats = false, .interval = 2 }; + +static struct prog_option xdpmonitor_options[] = { + DEFINE_OPTION("interval", OPT_U32, struct monitoropt, interval, + .short_opt = 'i', + .metavar = "<seconds>", + .help = "Polling interval (default 2)"), + DEFINE_OPTION("stats", OPT_BOOL, struct monitoropt, stats, + .short_opt = 's', + .help = "Enable statistics for transmitted packets (not just errors)"), + DEFINE_OPTION("extended", OPT_BOOL, struct monitoropt, extended, + .short_opt = 'e', + .help = "Start running in extended output mode (C^\\ to toggle)"), + END_OPTIONS +}; + +int main(int argc, char **argv) +{ + int ret = EXIT_FAIL_OPTION; + struct monitoropt cfg = {}; + struct xdp_monitor *skel; + + if (parse_cmdline_args(argc, argv, xdpmonitor_options, &cfg, + PROG_NAME, PROG_NAME, __doc__, + &defaults_monitoropt) != 0) + return ret; + + /* If all the options are parsed ok, make sure we are root! */ + if (check_bpf_environ()) + return ret; + + skel = xdp_monitor__open(); + if (!skel) { + pr_warn("Failed to xdp_monitor__open: %s\n", + strerror(errno)); + return EXIT_FAIL_BPF; + } + + ret = sample_init_pre_load(skel, NULL); + if (ret < 0) { + pr_warn("Failed to sample_init_pre_load: %s\n", strerror(-ret)); + ret = EXIT_FAIL_BPF; + goto end_destroy; + } + + ret = xdp_monitor__load(skel); + if (ret < 0) { + pr_warn("Failed to xdp_monitor__load: %s\n", strerror(errno)); + ret = EXIT_FAIL_BPF; + goto end_destroy; + } + + if (cfg.stats) + mask |= SAMPLE_REDIRECT_CNT; + else + printf("%s", __doc_err_only__); + + if (cfg.extended) + sample_switch_mode(); + + ret = sample_init(skel, mask, 0, 0); + if (ret < 0) { + pr_warn("Failed to initialize sample: %s\n", strerror(-ret)); + ret = EXIT_FAIL_BPF; + goto end_destroy; + } + + ret = sample_run(cfg.interval, NULL, NULL); + if (ret < 0) { + pr_warn("Failed during sample run: %s\n", strerror(-ret)); + ret = EXIT_FAIL; + goto end_destroy; + } + ret = EXIT_OK; + +end_destroy: + xdp_monitor__destroy(skel); + sample_teardown(); + return ret; +} diff --git a/xdp-monitor/xdp_monitor.bpf.c b/xdp-monitor/xdp_monitor.bpf.c new file mode 100644 index 0000000..3387261 --- /dev/null +++ b/xdp-monitor/xdp_monitor.bpf.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2017-2018 Jesper Dangaard Brouer, Red Hat Inc. + * + * XDP monitor tool, based on tracepoints + */ +#include <xdp/xdp_sample.bpf.h> +#include <xdp/xdp_sample_common.bpf.h> + +char _license[] SEC("license") = "GPL"; |