Improve XDP samples usability and output
Subsystems (4)
Kumar Kartikeya Dwivedi
maintainerv4 cover Improve XDP samples usability and output
This set revamps XDP samples related to redirection to show better output and implement missing features consolidating all their differences and giving them a consistent look and feel, by implementing common features and command line options. Some of the TODO items like reporting redirect error numbers (ENETDOWN, EINVAL, ENOSPC, etc.) have also been implemented.
Some of the features are:
* Received packet statistics
* xdp_redirect/xdp_redirect_map tracepoint statistics
* xdp_redirect_err/xdp_redirect_map_err tracepoint statistics (with support for showing exact errno)
* xdp_cpumap_enqueue/xdp_cpumap_kthread tracepoint statistics
* xdp_devmap_xmit tracepoint statistics
* xdp_exception tracepoint statistics
* Per ifindex pair devmap_xmit stats shown dynamically (for xdp_monitor) to decompose the total.
* Use of BPF skeleton and BPF static linking to share BPF programs.
* Use of vmlinux.h and tp_btf for raw_tracepoint support.
* Removal of redundant -N/--native-mode option (enforced by default now)
* ... and massive cleanups all over the place.
All tracepoints also use raw_tp now, and tracepoints like xdp_redirect are only enabled when requested explicitly to capture successful redirection statistics.
The set of programs converted as part of this series are:
* xdp_redirect_cpu
* xdp_redirect_map_multi
* xdp_redirect_map
* xdp_redirect
* xdp_monitor
Explanation of the output:
There is now a concise output mode by default that shows primarily four fields:
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
Some examples:
; sudo ./xdp_redirect_map veth0 veth1 -s
Redirecting from veth0 (ifindex 15; driver veth) to veth1 (ifindex 14; driver veth)veth0->veth1 0 rx/s 0 redir/s 0 err,drop/s 0 xmit/sveth0->veth1 9,998,660 rx/s 9,998,658 redir/s 0 err,drop/s 9,998,654 xmit/s
...
There is also a verbose mode, that can also be enabled by default using -v (--verbose). The output mode can be switched dynamically at runtime using Ctrl + \ (SIGQUIT).
To make the concise output more useful, the errors that occur are expanded inline (as if verbose mode was enabled) to let the user pin down the source of the problem without having to clutter output (or possibly miss it) or always use verbose mode.
For instance, let's consider a case where the output device link state is set to down while redirection is happening:
[...]
veth0->veth1 24,503,376 rx/s 0 err,drop/s 24,503,372 xmit/s veth0->veth1 25,044,775 rx/s 0 err,drop/s 25,044,783 xmit/s veth0->veth1 25,263,046 rx/s 4 err,drop/s 25,263,028 xmit/s
redirect_err 4 error/s
ENETDOWN 4 error/s
[...]
The same holds for xdp_exception actions.
An example of how a complete xdp_redirect_map session would look:
; sudo ./xdp_redirect_map veth0 veth1
Redirecting from veth0 (ifindex 5; driver veth) to veth1 (ifindex 4; driver veth)
veth0->veth1 7,411,506 rx/s 0 err,drop/s 7,411,470 xmit/s
veth0->veth1 8,931,770 rx/s 0 err,drop/s 8,931,771 xmit/s
^\
veth0->veth1 8,787,295 rx/s 0 err,drop/s 8,787,325 xmit/s
receive total 8,787,295 pkt/s 0 drop/s 0 error/s
cpu:7 8,787,295 pkt/s 0 drop/s 0 error/s
redirect_err 0 error/s
xdp_exception 0 hit/s
xmit veth0->veth1 8,787,325 xmit/s 0 drop/s 0 drv_err/s 2.00 bulk-avg
cpu:7 8,787,325 xmit/s 0 drop/s 0 drv_err/s 2.00 bulk-avgveth0->veth1 8,842,610 rx/s 0 err,drop/s 8,842,606 xmit/s
receive total 8,842,610 pkt/s 0 drop/s 0 error/s
cpu:7 8,842,610 pkt/s 0 drop/s 0 error/s
redirect_err 0 error/s
xdp_exception 0 hit/s
xmit veth0->veth1 8,842,606 xmit/s 0 drop/s 0 drv_err/s 2.00 bulk-avg
cpu:7 8,842,606 xmit/s 0 drop/s 0 drv_err/s 2.00 bulk-avg^C
Packets received : 33,973,181
Average packets/s : 4,246,648
Packets transmitted : 33,973,172
Average transmit/s : 4,246,647
The xdp_redirect tracepoint (for success stats) needs to be enabled explicitly using --stats/-s. Documentation for entire output and options is provided when user specifies --help/-h with a sample.
Changelog:
----------
v3 -> v4:
v3: https://lore.kernel.org/bpf/[email protected]
* Address all feedback from Daniel
* Use READ_ONCE/WRITE_ONCE from linux/compiler.h (cannot directly include due to conflicts with vmlinux.h)
* Fix MAX_CPUS hardcoding by switching to mmapable array maps, that are resized based on the value of libbpf_num_possible_cpus
* s/ELEMENTS_OF/ARRAY_SIZE/g
* Use tools/include/linux/hashtable.h
* Coding style fixes
* Remove hyperlinks for tracepoints
* Split into smaller reviewable changes
* Restore support for specifying custom xdp_redirect_cpu cpumap prog with some enhancements, including built-in programs for common actions (pass, drop, redirect). By default, cpumap prog is now disabled.
* Misc bug fixes all over the place
The printing stuff is a lot more basic without hyperlink support, hence it has not been exported into a more general facility.
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]
* Address all feedback from Andrii
* Replace usage of libbpf hashmap (internal API) with custom one
* Rename ATOMIC_* macros to NO_TEAR_* to better reflect their use
* Use size_t as a portable word sized data type
* Set libbpf_set_strict_mode
* Invert conditions in BPF programs to exit early and reduce nesting
* Use canonical SEC("xdp") naming for all XDP BPF progams
* Add missing help description for cpumap enqueue and kthread tracepoints
* Move private struct declarations from xdp_sample_user.h to .c file
* Improve help output for cpumap enqueue and cpumap kthread tracepoints
* Fix a bug where keys array for BPF_MAP_LOOKUP_BATCH is overallocated
* Fix some conditions for printing stats (earlier only checked pps, now pps, drop, err and print if any is greater than zero)
* Fix alloc_stats_record to properly return and cleanup allocated memory on allocation failure instead of calling exit(3)
* Bump bpf_map_lookup_batch count to 32 to reduce lookup time with multiple devices in map
* Fix a bug where devmap_xmit_multi stats are not printed when previous record is missing (i.e. when the first time stats are printed), by simply using a dummy record that is zeroed out
* Also print per-CPU counts for devmap_xmit_multi which we collect already
* Change mac_map to be BPF_MAP_TYPE_HASH instead of array to prevent resizing to a large size when max_ifindex is high, in xdp_redirect_map_multi
* Fix instance of strerror(errno) in sample_install_xdp to use saved errno
* Provide a usage function from samples helper
* Provide a fix where incorrect stats are shown for parallel sessions of xdp_redirect_* samples by introducing matching support for input device(s), output device(s) and cpumap map id for enqueue and kthread stats. Only xdp_monitor doesn't filter stats, all others do.
RFC (v1) -> v2
RFC (v1): https://lore.kernel.org/bpf/[email protected]
* Address all feedback from Andrii
* Use BPF static linking
* Use vmlinux.h
* Use BPF_PROG macro
* Use global variables instead of maps
* Use of tp_btf for raw_tracepoint progs
* Switch to timerfd for polling
* Use libbpf hashmap for maintaing device sets for per ifindex pair devmap_xmit stats
* Fix Makefile to specify object dependencies properly
* Use in-tree bpftool
* ... misc fixes and cleanups all over the place
Kumar Kartikeya Dwivedi (22):
samples: bpf: fix a couple of warnings
tools: include: add ethtool_drvinfo definition to UAPI header
samples: bpf: Add basic infrastructure for XDP samples
samples: bpf: Add BPF support for redirect tracepoint
samples: bpf: Add redirect tracepoint statistics support
samples: bpf: Add BPF support for xdp_exception tracepoint
samples: bpf: Add xdp_exception tracepoint statistics support
samples: bpf: Add BPF support for cpumap tracepoints
samples: bpf: Add cpumap tracepoint statistics support
samples: bpf: Add BPF support for devmap_xmit tracepoint
samples: bpf: Add devmap_xmit tracepoint statistics support
samples: bpf: add vmlinux.h generation support
samples: bpf: Convert xdp_monitor_kern.o to XDP samples helper
samples: bpf: Convert xdp_monitor to XDP samples helper
samples: bpf: Convert xdp_redirect_kern.o to XDP samples helper
samples: bpf: Convert xdp_redirect to XDP samples helper
samples: bpf: Convert xdp_redirect_cpu_kern.o to XDP samples helper
samples: bpf: Convert xdp_redirect_cpu to XDP samples helper
samples: bpf: Convert xdp_redirect_map_kern.o to XDP samples helper
samples: bpf: Convert xdp_redirect_map to XDP samples helper
samples: bpf: Convert xdp_redirect_map_multi_kern.o to XDP samples
helper
samples: bpf: Convert xdp_redirect_map_multi to XDP samples helper
samples/bpf/Makefile | 109 +-
samples/bpf/Makefile.target | 11 +
samples/bpf/cookie_uid_helper_example.c | 11 +-
samples/bpf/tracex4_user.c | 2 +-
samples/bpf/xdp_monitor.bpf.c | 8 +
samples/bpf/xdp_monitor_kern.c | 257 ---
samples/bpf/xdp_monitor_user.c | 798 +-------
samples/bpf/xdp_redirect.bpf.c | 49 +
...rect_cpu_kern.c => xdp_redirect_cpu.bpf.c} | 393 +---
samples/bpf/xdp_redirect_cpu_user.c | 1105 ++++-------
samples/bpf/xdp_redirect_kern.c | 90 -
...rect_map_kern.c => xdp_redirect_map.bpf.c} | 89 +-
...ti_kern.c => xdp_redirect_map_multi.bpf.c} | 50 +-
samples/bpf/xdp_redirect_map_multi_user.c | 345 ++--
samples/bpf/xdp_redirect_map_user.c | 385 ++--
samples/bpf/xdp_redirect_user.c | 270 ++-
samples/bpf/xdp_sample.bpf.c | 266 +++
samples/bpf/xdp_sample.bpf.h | 141 ++
samples/bpf/xdp_sample_shared.h | 17 +
samples/bpf/xdp_sample_user.c | 1673 +++++++++++++++++
samples/bpf/xdp_sample_user.h | 108 ++
tools/include/uapi/linux/ethtool.h | 53 +
22 files changed, 3388 insertions(+), 2842 deletions(-)
create mode 100644 samples/bpf/xdp_monitor.bpf.c
delete mode 100644 samples/bpf/xdp_monitor_kern.c
create mode 100644 samples/bpf/xdp_redirect.bpf.c
rename samples/bpf/{xdp_redirect_cpu_kern.c => xdp_redirect_cpu.bpf.c} (52%)
delete mode 100644 samples/bpf/xdp_redirect_kern.c
rename samples/bpf/{xdp_redirect_map_kern.c => xdp_redirect_map.bpf.c} (57%)
rename samples/bpf/{xdp_redirect_map_multi_kern.c => xdp_redirect_map_multi.bpf.c} (64%)
create mode 100644 samples/bpf/xdp_sample.bpf.c
create mode 100644 samples/bpf/xdp_sample.bpf.h
create mode 100644 samples/bpf/xdp_sample_shared.h
create mode 100644 samples/bpf/xdp_sample_user.c
create mode 100644 samples/bpf/xdp_sample_user.hSignature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 1/22 samples: bpf: fix a couple of warnings
cookie_uid_helper_example.c: In function ‘main’:
cookie_uid_helper_example.c:178:69: warning: ‘ -j ACCEPT’ directive
writing 10 bytes into a region of size between 8 and 58 [-Wformat-overflow=]
178 | sprintf(rules, "iptables -A OUTPUT -m bpf --object-pinned %s -j ACCEPT",
| ^~~~~~~~~~
/home/kkd/src/linux/samples/bpf/cookie_uid_helper_example.c:178:9: note:
‘sprintf’ output between 53 and 103 bytes into a destination of size 100
178 | sprintf(rules, "iptables -A OUTPUT -m bpf --object-pinned %s -j ACCEPT",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
179 | file);
| ~~~~~Fix by using snprintf and a sufficiently sized buffer.
tracex4_user.c:35:15: warning: ‘write’ reading 12 bytes from a region of
size 11 [-Wstringop-overread]
35 | key = write(1, "\e[1;1H\e[2J", 12); /* clear screen */
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use size as 11.
--- samples/bpf/cookie_uid_helper_example.c | 11 ++++++++--- samples/bpf/tracex4_user.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
samples/bpf/cookie_uid_helper_example.c +8 -3
@@ -167,7 +167,7 @@ static void prog_load(void)static void prog_attach_iptables (char *file) {int ret; -char rules[100 ]; +char rules[256 ];if (bpf_obj_pin (prog_fd, file))error (1 , errno,"bpf_obj_pin" );
@@ -175,8 +175,13 @@ static void prog_attach_iptables(char *file)printf ("file path too long: %s\n" , file);exit (1 ); } -sprintf (rules,"iptables -A OUTPUT -m bpf --object-pinned %s -j ACCEPT" , - file); + ret =snprintf (rules,sizeof (rules), +"iptables -A OUTPUT -m bpf --object-pinned %s -j ACCEPT" , + file); +if (ret <0 || ret >=sizeof (rules)) { +printf ("error constructing iptables command\n" ); +exit (1 ); + } ret =system (rules);if (ret <0 ) {printf ("iptables rule update failed: %d/n" ,WEXITSTATUS (ret));
samples/bpf/tracex4_user.c +1 -1
@@ -32,7 +32,7 @@ static void print_old_objects(int fd)__u64 key, next_key;struct pair v; - key =write (1 ,"\e[1;1H\e[2J" ,12 );/* clear screen */ + key =write (1 ,"\e[1;1H\e[2J" ,11 );/* clear screen */ key =-1 ;while (bpf_map_get_next_key (fd, &key, &next_key) ==0 ) {
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 2/22 tools: include: add ethtool_drvinfo definition to UAPI header
In reply to Kumar Kartikeya DwivediInstead of copying the whole header in, just add the struct definitions we need for now. In the future it can be synced as a copy of in-tree header if required.
--- tools/include/uapi/linux/ethtool.h | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
tools/include/uapi/linux/ethtool.h +53 -0
@@ -48,4 +48,57 @@ struct ethtool_channels { __u32 combined_count; }; +#define ETHTOOL_FWVERS_LEN 32 +#define ETHTOOL_BUSINFO_LEN 32 +#define ETHTOOL_EROMVERS_LEN 32 + +/** +* struct ethtool_drvinfo - general driver and device information +* @cmd: Command number = %ETHTOOL_GDRVINFO +* @driver: Driver short name. This should normally match the name +* in its bus driver structure (e.g. pci_driver::name). Must +* not be an empty string. +* @version: Driver version string; may be an empty string +* @fw_version: Firmware version string; may be an empty string +* @erom_version: Expansion ROM version string; may be an empty string +* @bus_info: Device bus address. This should match the dev_name() +* string for the underlying bus device, if there is one. May be +* an empty string. +* @reserved2: Reserved for future use; see the note on reserved space. +* @n_priv_flags: Number of flags valid for %ETHTOOL_GPFLAGS and +* %ETHTOOL_SPFLAGS commands; also the number of strings in the +* %ETH_SS_PRIV_FLAGS set +* @n_stats: Number of u64 statistics returned by the %ETHTOOL_GSTATS +* command; also the number of strings in the %ETH_SS_STATS set +* @testinfo_len: Number of results returned by the %ETHTOOL_TEST +* command; also the number of strings in the %ETH_SS_TEST set +* @eedump_len: Size of EEPROM accessible through the %ETHTOOL_GEEPROM +* and %ETHTOOL_SEEPROM commands, in bytes +* @regdump_len: Size of register dump returned by the %ETHTOOL_GREGS +* command, in bytes +* +* Users can use the %ETHTOOL_GSSET_INFO command to get the number of +* strings in any string set (from Linux 2.6.34). +* +* Drivers should set at most @driver, @version, @fw_version and +* @bus_info in their get_drvinfo() implementation. The ethtool +* core fills in the other fields using other driver operations. +*/ +struct ethtool_drvinfo { +__u32 cmd; +char driver[32 ]; +char version[32 ]; +char fw_version[ETHTOOL_FWVERS_LEN ]; +char bus_info[ETHTOOL_BUSINFO_LEN ]; +char erom_version[ETHTOOL_EROMVERS_LEN ]; +char reserved2[12 ]; +__u32 n_priv_flags; +__u32 n_stats; +__u32 testinfo_len; +__u32 eedump_len; +__u32 regdump_len; +}; + +#define ETHTOOL_GDRVINFO 0x00000003 +#endif /* _UAPI_LINUX_ETHTOOL_H */
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 3/22 samples: bpf: Add basic infrastructure for XDP samples
In reply to Kumar Kartikeya DwivediThis file implements some common helpers to consolidate differences in features and functionality between the various XDP samples and give them a consistent look, feel, and reporting capabilities.
This commit only adds support for receive statistics, which does not rely on any tracepoint, but on the XDP program installed on the device by each XDP redirect sample.
Some of the key features are:
* A concise output format accompanied by helpful text explaining its fields.
* An elaborate output format building upon the concise one, and folding out details in case of errors and staying out of view otherwise.
* Printing driver names for devices redirecting packets.
* Getting mac address for interface.
* Printing summarized total statistics for the entire session.
* Ability to dynamically switch between concise and verbose mode, using SIGQUIT (Ctrl + \).
In later patches, the support will be extended for each tracepoint with its own custom output in concise and verbose mode.
--- samples/bpf/xdp_sample_shared.h | 17 + samples/bpf/xdp_sample_user.c | 838 ++++++++++++++++++++++++++++++++ samples/bpf/xdp_sample_user.h | 60 +++ 3 files changed, 915 insertions(+) create mode 100644 samples/bpf/xdp_sample_shared.h create mode 100644 samples/bpf/xdp_sample_user.c create mode 100644 samples/bpf/xdp_sample_user.h
samples/bpf/xdp_sample_shared.h new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-only +#ifndef _XDP_SAMPLE_SHARED_H +#define _XDP_SAMPLE_SHARED_H + +struct datarec { +size_t processed; +size_t dropped; +size_t issue; +union { +size_t xdp_pass; +size_t info; + }; +size_t xdp_drop; +size_t xdp_redirect; +} __attribute__((aligned (64 ))); + +#endif
samples/bpf/xdp_sample_user.c new file +838 -0
838 lines not on this page · raw message
samples/bpf/xdp_sample_user.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 4/22 samples: bpf: Add BPF support for redirect tracepoint
In reply to Kumar Kartikeya DwivediThis adds the shared BPF file that will be used going forward for sharing tracepoint programs among XDP redirect samples.
Since vmlinux.h conflicts with tools/include for READ_ONCE/WRITE_ONCE and ARRAY_SIZE, they are copied in to xdp_sample.bpf.h along with other helpers that will be required.
--- samples/bpf/xdp_sample.bpf.c | 112 ++++++++++++++++++++++++++++ samples/bpf/xdp_sample.bpf.h | 141 +++++++++++++++++++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 samples/bpf/xdp_sample.bpf.c create mode 100644 samples/bpf/xdp_sample.bpf.h
samples/bpf/xdp_sample.bpf.c new file +112 -0
@@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* GPLv2, Copyright(c) 2017 Jesper Dangaard Brouer, Red Hat, Inc. */ +#include "xdp_sample.bpf.h" + +#include <bpf/bpf_tracing.h> +#include <bpf/bpf_core_read.h> +#include <bpf/bpf_helpers.h> + +array_map rx_cnt SEC(".maps"); +array_map redir_err_cnt SEC(".maps"); + +const volatile int nr_cpus =0 ; + +/* These can be set before loading so that redundant comparisons can be DCE'd by +* the verifier, and only actual matches are tried after loading tp_btf program. +* This allows sample to filter tracepoint stats based on net_device. +*/ +const volatile int from_match[32 ] = {}; +const volatile int to_match[32 ] = {}; + +/* Find if b is part of set a, but if a is empty set then evaluate to true */ +#define IN_SET (a, b) \ + ({ \ + bool __res = !(a)[0]; \ + for (int i = 0; i < ARRAY_SIZE(a) && (a)[i]; i++) { \ + __res = (a)[i] == (b); \ + if (__res) \ + break; \ + } \ + __res; \ + }) + +static __always_inline __u32 xdp_get_err_key(int err) +{ +switch (err) { +case 0 : +return 0 ; +case -EINVAL : +return 2 ; +case -ENETDOWN : +return 3 ; +case -EMSGSIZE : +return 4 ; +case -EOPNOTSUPP : +return 5 ; +case -ENOSPC : +return 6 ; +default : +return 1 ; + } +} + +static __always_inline int xdp_redirect_collect_stat(int from, int err) +{ +u32 cpu =bpf_get_smp_processor_id (); +u32 key =XDP_REDIRECT_ERROR ; +struct datarec *rec; +u32 idx; + +if (!IN_SET (from_match, from)) +return 0 ; + + key =xdp_get_err_key (err); + + idx = key * nr_cpus + cpu; + rec =bpf_map_lookup_elem (&redir_err_cnt, &idx); +if (!rec) +return 0 ; +if (key) +NO_TEAR_INC (rec->dropped); +else +NO_TEAR_INC (rec->processed); +return 0 ;/* Indicate event was filtered (no further processing)*/ +/* +* Returning 1 here would allow e.g. a perf-record tracepoint +* to see and record these events, but it doesn't work well +* in-practice as stopping perf-record also unload this +* bpf_prog. Plus, there is additional overhead of doing so. +*/ +} + +SEC("tp_btf/xdp_redirect_err") +int BPF_PROG (tp_xdp_redirect_err ,const struct net_device *dev, +const struct bpf_prog *xdp,const void *tgt,int err, +const struct bpf_map *map,u32 index) +{ +return xdp_redirect_collect_stat (dev->ifindex, err); +} + +SEC("tp_btf/xdp_redirect_map_err") +int BPF_PROG (tp_xdp_redirect_map_err ,const struct net_device *dev, +const struct bpf_prog *xdp,const void *tgt,int err, +const struct bpf_map *map,u32 index) +{ +return xdp_redirect_collect_stat (dev->ifindex, err); +} + +SEC("tp_btf/xdp_redirect") +int BPF_PROG (tp_xdp_redirect ,const struct net_device *dev, +const struct bpf_prog *xdp,const void *tgt,int err, +const struct bpf_map *map,u32 index) +{ +return xdp_redirect_collect_stat (dev->ifindex, err); +} + +SEC("tp_btf/xdp_redirect_map") +int BPF_PROG (tp_xdp_redirect_map ,const struct net_device *dev, +const struct bpf_prog *xdp,const void *tgt,int err, +const struct bpf_map *map,u32 index) +{ +return xdp_redirect_collect_stat (dev->ifindex, err); +}
samples/bpf/xdp_sample.bpf.h new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 5/22 samples: bpf: Add redirect tracepoint statistics support
In reply to Kumar Kartikeya DwivediThis implements per-errno reporting (for the ones we explicitly recognize), adds some help output, and implements the stats retrieval and printing functions.
--- samples/bpf/xdp_sample_user.c | 194 ++++++++++++++++++++++++++++++++++ samples/bpf/xdp_sample_user.h | 21 ++++ 2 files changed, 215 insertions(+)
samples/bpf/xdp_sample_user.c +194 -0
@@ -73,6 +73,7 @@enum map_type {MAP_RX , +MAP_REDIRECT_ERR ,NUM_MAP , };
@@ -96,17 +97,24 @@ struct map_entry {struct stats_record {struct record rx_cnt; +struct record redir_err[XDP_REDIRECT_ERR_MAX ]; };struct sample_output {struct {__u64 rx; +__u64 redir; +__u64 err; } totals;struct {__u64 pps;__u64 drop;__u64 err; } rx_cnt; +struct { +__u64 suc; +__u64 err; + } redir_cnt; };struct xdp_desc {
@@ -127,6 +135,27 @@ int sample_n_cpus;int sample_sig_fd;int sample_mask; +static const char *xdp_redirect_err_names[XDP_REDIRECT_ERR_MAX ] = { +/* Key=1 keeps unknown errors */ +"Success" , +"Unknown" , +"EINVAL" , +"ENETDOWN" , +"EMSGSIZE" , +"EOPNOTSUPP" , +"ENOSPC" , +}; + +/* Keyed from Unknown */ +static const char *xdp_redirect_err_help[XDP_REDIRECT_ERR_MAX -1 ] = { +"Unknown error" , +"Invalid redirection" , +"Device being redirected to is down" , +"Packet length too large for device" , +"Operation not supported" , +"No space in ptr_ring of cpumap kthread" , +}; +static __u64 gettime (void ) {struct timespec t;
@@ -162,6 +191,21 @@ static void sample_print_help(int mask)" \t\t\t\tdrop/s - Packets dropped per second\n" " \t\t\t\terror/s - Errors encountered per second\n\n"); } +if (mask & (SAMPLE_REDIRECT_CNT |SAMPLE_REDIRECT_ERR_CNT )) { +printf (" redirect\t\tDisplays the number of packets successfully redirected\n" +" \t\t\tErrors encountered are expanded under redirect_err field\n" +" \t\t\tNote that passing -s to enable it has a per packet overhead\n" +" \t\t\t\tredir/s - Packets redirected successfully per second\n\n" +" redirect_err\t\tDisplays the number of packets that failed redirection\n" +" \t\t\tThe errno is expanded under this field with per CPU count\n" +" \t\t\tThe recognized errors are:\n" ); + +for (int i =2 ; i <XDP_REDIRECT_ERR_MAX ; i++) +printf ("\t\t\t %s: %s\n" , xdp_redirect_err_names[i], + xdp_redirect_err_help[i -1 ]); + +printf (" \n\t\t\t\terror/s - Packets that failed redirection per second\n\n" ); + } } void sample_usage(char *argv[], const struct option *long_options,
@@ -269,8 +313,25 @@ static struct stats_record *alloc_stats_record(void) goto end_rec; } } +if (sample_mask & (SAMPLE_REDIRECT_CNT |SAMPLE_REDIRECT_ERR_CNT )) { +for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++) { + rec->redir_err[i].cpu =alloc_record_per_cpu (); +if (!rec->redir_err[i].cpu) { +fprintf (stderr, +"Failed to allocate redir_err per-CPU array for " +"\"%s\" case\n" , + xdp_redirect_err_names[i]); +while (i--) +free (rec->redir_err[i].cpu); + goto end_rx_cnt; + } + } + }return rec; + +end_rx_cnt: +free (rec->rx_cnt.cpu); end_rec:free (rec);return NULL ;
@@ -282,6 +343,8 @@ static void free_stats_record(struct stats_record *r)struct map_entry *e;int i; +for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++) +free (r->redir_err[i].cpu);free (r->rx_cnt.cpu);free (r); }
@@ -407,6 +470,87 @@ static void stats_get_rx_cnt(struct stats_record *stats_rec, } } +static void stats_get_redirect_cnt (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus, +struct sample_output *out) +{ +struct record *rec, *prev; +double t, pps; +int i; + + rec = &stats_rec->redir_err[0 ]; + prev = &stats_prev->redir_err[0 ]; + t =calc_period (rec, prev); +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; + + pps =calc_pps (r, p, t); +if (!pps) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); +print_default (" %-18s " FMT_COLUMNf"\n" , str,REDIR (pps)); + } + +if (out) { + pps =calc_pps (&rec->total, &prev->total, t); + out->redir_cnt.suc = pps; + out->totals.redir += pps; + } +} + +static void stats_get_redirect_err_cnt (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus, +struct sample_output *out) +{ +struct record *rec, *prev; +double t, drop, sum =0 ; +int rec_i, i; + +for (rec_i =1 ; rec_i <XDP_REDIRECT_ERR_MAX ; rec_i++) { +char str[64 ]; + + rec = &stats_rec->redir_err[rec_i]; + prev = &stats_prev->redir_err[rec_i]; + t =calc_period (rec, prev); + + drop =calc_drop_pps (&rec->total, &prev->total, t); +if (drop >0 && !out) { +snprintf (str,sizeof (str), + sample_log_level &LL_DEFAULT ?"%s total" : +"%s" , + xdp_redirect_err_names[rec_i]); +print_err (drop," %-18s " FMT_COLUMNf"\n" , str, +ERR (drop)); + } + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +double drop; + + drop =calc_drop_pps (r, p, t); +if (!drop) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); +print_default (" %-16s" FMT_COLUMNf"\n" , str, +ERR (drop)); + } + + sum += drop; + } + +if (out) { + out->redir_cnt.err = sum; + out->totals.err += sum; + } +} +static void stats_print (const char *prefix,int mask,struct stats_record *r,struct stats_record *p,struct sample_output *out)
@@ -417,6 +561,8 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,print_always ("%-23s" , prefix ?:"Summary" );if (mask &SAMPLE_RX_CNT )print_always (FMT_COLUMNl,RX (out->totals.rx)); +if (mask &SAMPLE_REDIRECT_CNT ) +print_always (FMT_COLUMNl,REDIR (out->totals.redir));printf ("\n" );if (mask &SAMPLE_RX_CNT ) {
@@ -431,6 +577,24 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,stats_get_rx_cnt (r, p, nr_cpus,NULL ); } +if (mask &SAMPLE_REDIRECT_CNT ) { + str = out->redir_cnt.suc ?"redirect total" :"redirect" ; +print_default (" %-20s " FMT_COLUMNl"\n" , str, +REDIR (out->redir_cnt.suc)); + +stats_get_redirect_cnt (r, p, nr_cpus,NULL ); + } + +if (mask &SAMPLE_REDIRECT_ERR_CNT ) { + str = (sample_log_level &LL_DEFAULT ) && out->redir_cnt.err ? +"redirect_err total" : +"redirect_err" ; +print_err (out->redir_cnt.err," %-20s " FMT_COLUMNl"\n" , str, +ERR (out->redir_cnt.err)); + +stats_get_redirect_err_cnt (r, p, nr_cpus,NULL ); + } +if (sample_log_level &LL_DEFAULT || ((sample_log_level &LL_SIMPLE ) && sample_err_exp)) { sample_err_exp = false;
@@ -449,6 +613,10 @@ int sample_setup_maps(struct bpf_map **maps)case MAP_RX : sample_map_count[i] = sample_n_cpus;break ; +case MAP_REDIRECT_ERR : + sample_map_count[i] = +XDP_REDIRECT_ERR_MAX * sample_n_cpus; +break ;default :return -EINVAL ; }
@@ -568,6 +736,17 @@ static void sample_summary_print(void)print_always (" Average packets/s : %'-10.0f\n" ,sample_round (pkts / period)); } +if (sample_out.totals.redir) { +double pkts = sample_out.totals.redir; + +print_always (" Packets redirected : %'-10llu\n" , + sample_out.totals.redir); +print_always (" Average redir/s : %'-10.0f\n" , +sample_round (pkts / period)); + } +if (sample_out.totals.err) +print_always (" Errors recorded : %'-10llu\n" , + sample_out.totals.err); }void sample_exit (int status)
@@ -600,12 +779,23 @@ static int sample_stats_collect(struct stats_record *rec)if (sample_mask &SAMPLE_RX_CNT )map_collect_percpu (sample_mmap[MAP_RX ], &rec->rx_cnt); +if (sample_mask &SAMPLE_REDIRECT_CNT ) +map_collect_percpu (sample_mmap[MAP_REDIRECT_ERR ], &rec->redir_err[0 ]); + +if (sample_mask &SAMPLE_REDIRECT_ERR_CNT ) { +for (i =1 ; i <XDP_REDIRECT_ERR_MAX ; i++) +map_collect_percpu (&sample_mmap[MAP_REDIRECT_ERR ][i * sample_n_cpus], + &rec->redir_err[i]); + } +return 0 ; }static void sample_summary_update (struct sample_output *out,int interval) { sample_out.totals.rx += out->totals.rx; + sample_out.totals.redir += out->totals.redir; + sample_out.totals.err += out->totals.err; sample_out.rx_cnt.pps += interval; }
@@ -617,6 +807,10 @@ static void sample_stats_print(int mask, struct stats_record *cur,if (mask &SAMPLE_RX_CNT )stats_get_rx_cnt (cur, prev,0 , &out); +if (mask &SAMPLE_REDIRECT_CNT ) +stats_get_redirect_cnt (cur, prev,0 , &out); +if (mask &SAMPLE_REDIRECT_ERR_CNT ) +stats_get_redirect_err_cnt (cur, prev,0 , &out);sample_summary_update (&out, interval);stats_print (prog_name, mask, cur, prev, &out);
samples/bpf/xdp_sample_user.h +21 -0
@@ -10,6 +10,10 @@enum stats_mask { _SAMPLE_REDIRECT_MAP =1U <<0 ,SAMPLE_RX_CNT =1U <<1 , +SAMPLE_REDIRECT_ERR_CNT =1U <<2 , +SAMPLE_REDIRECT_CNT =1U <<7 , +SAMPLE_REDIRECT_MAP_CNT =SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP, +SAMPLE_REDIRECT_ERR_MAP_CNT =SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP, };/* Exit return codes */
@@ -47,6 +51,15 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size) }#pragma GCC diagnostic pop +#define __attach_tp (name) \ + ({ \ + if (!bpf_program__is_tracing(skel->progs.name)) \ + return -EINVAL; \ + skel->links.name = bpf_program__attach(skel->progs.name); \ + if (!skel->links.name) \ + return -errno; \ + }) +#define DEFINE_SAMPLE_INIT (name) \ static int sample_init(struct name *skel, int mask) \ { \
@@ -54,6 +67,14 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size) ret =__sample_init (mask); \if (ret <0 ) \return ret; \ +if (mask &SAMPLE_REDIRECT_MAP_CNT ) \ +__attach_tp (tp_xdp_redirect_map); \ +if (mask &SAMPLE_REDIRECT_CNT ) \ +__attach_tp (tp_xdp_redirect); \ +if (mask &SAMPLE_REDIRECT_ERR_MAP_CNT ) \ +__attach_tp (tp_xdp_redirect_map_err); \ +if (mask &SAMPLE_REDIRECT_ERR_CNT ) \ +__attach_tp (tp_xdp_redirect_err); \return 0 ; \ }
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 6/22 samples: bpf: Add BPF support for xdp_exception tracepoint
In reply to Kumar Kartikeya DwivediThis would allow us to store stats for each XDP action, including their per-CPU counts. Consolidating this here allows all redirect samples to detect xdp_exception events.
--- samples/bpf/xdp_sample.bpf.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
samples/bpf/xdp_sample.bpf.c +27 -0
@@ -8,6 +8,7 @@ array_map rx_cnt SEC(".maps"); array_map redir_err_cnt SEC(".maps"); +array_map exception_cnt SEC(".maps");const volatile int nr_cpus =0 ;
@@ -110,3 +111,29 @@ int BPF_PROG(tp_xdp_redirect_map, const struct net_device *dev, {return xdp_redirect_collect_stat (dev->ifindex, err); } + +SEC("tp_btf/xdp_exception") +int BPF_PROG (tp_xdp_exception ,const struct net_device *dev, +const struct bpf_prog *xdp,u32 act) +{ +u32 cpu =bpf_get_smp_processor_id (); +struct datarec *rec; +u32 key = act, idx; + +if (!IN_SET (from_match, dev->ifindex)) +return 0 ; +if (!IN_SET (to_match, dev->ifindex)) +return 0 ; + +if (key >XDP_REDIRECT ) + key =XDP_REDIRECT +1 ; + + idx = key * nr_cpus + cpu; + rec =bpf_map_lookup_elem (&exception_cnt, &idx); +if (!rec) +return 0 ; +NO_TEAR_INC (rec->dropped); + +return 0 ; +} +
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 7/22 samples: bpf: Add xdp_exception tracepoint statistics support
In reply to Kumar Kartikeya DwivediThis implements the retrieval and printing, as well the help output.
--- samples/bpf/xdp_sample_user.c | 113 ++++++++++++++++++++++++++++++++++ samples/bpf/xdp_sample_user.h | 3 + 2 files changed, 116 insertions(+)
samples/bpf/xdp_sample_user.c +113 -0
@@ -74,6 +74,7 @@enum map_type {MAP_RX ,MAP_REDIRECT_ERR , +MAP_EXCEPTION ,NUM_MAP , };
@@ -98,6 +99,7 @@ struct map_entry {struct stats_record {struct record rx_cnt;struct record redir_err[XDP_REDIRECT_ERR_MAX ]; +struct record exception[XDP_ACTION_MAX ]; };struct sample_output {
@@ -115,6 +117,9 @@ struct sample_output {__u64 suc;__u64 err; } redir_cnt; +struct { +__u64 hits; + } except_cnt; };struct xdp_desc {
@@ -156,6 +161,15 @@ static const char *xdp_redirect_err_help[XDP_REDIRECT_ERR_MAX - 1] = { "No space in ptr_ring of cpumap kthread", }; +static const char *xdp_action_names[XDP_ACTION_MAX ] = { + [XDP_ABORTED ] ="XDP_ABORTED" , + [XDP_DROP ] ="XDP_DROP" , + [XDP_PASS ] ="XDP_PASS" , + [XDP_TX ] ="XDP_TX" , + [XDP_REDIRECT ] ="XDP_REDIRECT" , + [XDP_UNKNOWN ] ="XDP_UNKNOWN" , +}; +static __u64 gettime (void ) {struct timespec t;
@@ -169,6 +183,13 @@ static __u64 gettime(void)return (__u64 )t.tv_sec *NANOSEC_PER_SEC + t.tv_nsec; } +static const char *action2str (int action) +{ +if (action <XDP_ACTION_MAX ) +return xdp_action_names[action]; +return NULL ; +} +static void sample_print_help (int mask) { printf("Output format description\n\n"
@@ -206,6 +227,15 @@ static void sample_print_help(int mask)printf (" \n\t\t\t\terror/s - Packets that failed redirection per second\n\n" ); } + +if (mask &SAMPLE_EXCEPTION_CNT ) { +printf (" xdp_exception\t\tDisplays xdp_exception tracepoint events\n" +" \t\t\tThis can occur due to internal driver errors, unrecognized\n" +" \t\t\tXDP actions and due to explicit user trigger by use of XDP_ABORTED\n" +" \t\t\tEach action is expanded below this field with its count\n" +" \t\t\t\thit/s - Number of times the tracepoint was hit per second\n\n" ); + } + } void sample_usage(char *argv[], const struct option *long_options,
@@ -327,9 +357,26 @@ static struct stats_record *alloc_stats_record(void) } } } +if (sample_mask &SAMPLE_EXCEPTION_CNT ) { +for (i =0 ; i <XDP_ACTION_MAX ; i++) { + rec->exception[i].cpu =alloc_record_per_cpu (); +if (!rec->exception[i].cpu) { +fprintf (stderr, +"Failed to allocate exception per-CPU array for " +"\"%s\" case\n" , +action2str (i)); +while (i--) +free (rec->exception[i].cpu); + goto end_redir; + } + } + }return rec; +end_redir: +for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++) +free (rec->redir_err[i].cpu); end_rx_cnt:free (rec->rx_cnt.cpu); end_rec:
@@ -343,6 +390,8 @@ static void free_stats_record(struct stats_record *r)struct map_entry *e;int i; +for (i =0 ; i <XDP_ACTION_MAX ; i++) +free (r->exception[i].cpu);for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++)free (r->redir_err[i].cpu);free (r->rx_cnt.cpu);
@@ -551,6 +600,50 @@ static void stats_get_redirect_err_cnt(struct stats_record *stats_rec, } } +static void stats_get_exception_cnt (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus, +struct sample_output *out) +{ +double t, drop, sum =0 ; +struct record *rec, *prev; +int rec_i, i; + +for (rec_i =0 ; rec_i <XDP_ACTION_MAX ; rec_i++) { + rec = &stats_rec->exception[rec_i]; + prev = &stats_prev->exception[rec_i]; + t =calc_period (rec, prev); + + drop =calc_drop_pps (&rec->total, &prev->total, t); +/* Fold out errors after heading */ + sum += drop; + +if (drop >0 && !out) { +print_always (" %-18s " FMT_COLUMNf"\n" , +action2str (rec_i),ERR (drop)); + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; +double drop; + + drop =calc_drop_pps (r, p, t); +if (!drop) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); +print_default (" %-16s" FMT_COLUMNf"\n" , + str,ERR (drop)); + } + } + } + +if (out) { + out->except_cnt.hits = sum; + out->totals.err += sum; + } +}static void stats_print (const char *prefix,int mask,struct stats_record *r,struct stats_record *p,struct sample_output *out)
@@ -595,6 +688,16 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,stats_get_redirect_err_cnt (r, p, nr_cpus,NULL ); } +if (mask &SAMPLE_EXCEPTION_CNT ) { + str = out->except_cnt.hits ?"xdp_exception total" : +"xdp_exception" ; + +print_err (out->except_cnt.hits," %-20s " FMT_COLUMNl"\n" , str, +HITS (out->except_cnt.hits)); + +stats_get_exception_cnt (r, p, nr_cpus,NULL ); + } +if (sample_log_level &LL_DEFAULT || ((sample_log_level &LL_SIMPLE ) && sample_err_exp)) { sample_err_exp = false;
@@ -617,6 +720,9 @@ int sample_setup_maps(struct bpf_map **maps) sample_map_count[i] =XDP_REDIRECT_ERR_MAX * sample_n_cpus;break ; +case MAP_EXCEPTION : + sample_map_count[i] =XDP_ACTION_MAX * sample_n_cpus; +break ;default :return -EINVAL ; }
@@ -788,6 +894,11 @@ static int sample_stats_collect(struct stats_record *rec) &rec->redir_err[i]); } +if (sample_mask &SAMPLE_EXCEPTION_CNT ) +for (i =0 ; i <XDP_ACTION_MAX ; i++) +map_collect_percpu (&sample_mmap[MAP_EXCEPTION ][i * sample_n_cpus], + &rec->exception[i]); +return 0 ; }
@@ -811,6 +922,8 @@ static void sample_stats_print(int mask, struct stats_record *cur,stats_get_redirect_cnt (cur, prev,0 , &out);if (mask &SAMPLE_REDIRECT_ERR_CNT )stats_get_redirect_err_cnt (cur, prev,0 , &out); +if (mask &SAMPLE_EXCEPTION_CNT ) +stats_get_exception_cnt (cur, prev,0 , &out);sample_summary_update (&out, interval);stats_print (prog_name, mask, cur, prev, &out);
samples/bpf/xdp_sample_user.h +3 -0
@@ -11,6 +11,7 @@ enum stats_mask { _SAMPLE_REDIRECT_MAP =1U <<0 ,SAMPLE_RX_CNT =1U <<1 ,SAMPLE_REDIRECT_ERR_CNT =1U <<2 , +SAMPLE_EXCEPTION_CNT =1U <<5 ,SAMPLE_REDIRECT_CNT =1U <<7 ,SAMPLE_REDIRECT_MAP_CNT =SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP, SAMPLE_REDIRECT_ERR_MAP_CNT = SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP,
@@ -75,6 +76,8 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)__attach_tp (tp_xdp_redirect_map_err); \if (mask &SAMPLE_REDIRECT_ERR_CNT ) \__attach_tp (tp_xdp_redirect_err); \ +if (mask &SAMPLE_EXCEPTION_CNT ) \ +__attach_tp (tp_xdp_exception); \return 0 ; \ }
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 8/22 samples: bpf: Add BPF support for cpumap tracepoints
In reply to Kumar Kartikeya DwivediThese are invoked in two places, when the XDP frame or SKB (for generic XDP) enqueued to the ptr_ring (cpumap_enqueue) and when kthread processes the frame after invoking the CPUMAP program for it (returning stats for the batch).
We use cpumap_map_id to filter on the map_id as a way to avoid printing incorrect stats for parallel sessions of xdp_redirect_cpu.
--- samples/bpf/xdp_sample.bpf.c | 58 +++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-)
samples/bpf/xdp_sample.bpf.c +57 -1
@@ -8,6 +8,8 @@ array_map rx_cnt SEC(".maps"); array_map redir_err_cnt SEC(".maps"); +array_map cpumap_enqueue_cnt SEC(".maps"); +array_map cpumap_kthread_cnt SEC(".maps"); array_map exception_cnt SEC(".maps");const volatile int nr_cpus =0 ;
@@ -19,6 +21,8 @@ const volatile int nr_cpus = 0;const volatile int from_match[32 ] = {};const volatile int to_match[32 ] = {}; +int cpumap_map_id =0 ; +/* Find if b is part of set a, but if a is empty set then evaluate to true */ #define IN_SET (a, b) \ ({ \
@@ -112,6 +116,59 @@ int BPF_PROG(tp_xdp_redirect_map, const struct net_device *dev,return xdp_redirect_collect_stat (dev->ifindex, err); } +SEC("tp_btf/xdp_cpumap_enqueue") +int BPF_PROG (tp_xdp_cpumap_enqueue ,int map_id,unsigned int processed, +unsigned int drops,int to_cpu) +{ +u32 cpu =bpf_get_smp_processor_id (); +struct datarec *rec; +u32 idx; + +if (cpumap_map_id && cpumap_map_id != map_id) +return 0 ; + + idx = to_cpu * nr_cpus + cpu; + rec =bpf_map_lookup_elem (&cpumap_enqueue_cnt, &idx); +if (!rec) +return 0 ; +NO_TEAR_ADD (rec->processed, processed); +NO_TEAR_ADD (rec->dropped, drops); +/* Record bulk events, then userspace can calc average bulk size */ +if (processed >0 ) +NO_TEAR_INC (rec->issue); +/* Inception: It's possible to detect overload situations, via +* this tracepoint. This can be used for creating a feedback +* loop to XDP, which can take appropriate actions to mitigate +* this overload situation. +*/ +return 0 ; +} + +SEC("tp_btf/xdp_cpumap_kthread") +int BPF_PROG (tp_xdp_cpumap_kthread ,int map_id,unsigned int processed, +unsigned int drops,int sched,struct xdp_cpumap_stats *xdp_stats) +{ +struct datarec *rec; +u32 cpu; + +if (cpumap_map_id && cpumap_map_id != map_id) +return 0 ; + + cpu =bpf_get_smp_processor_id (); + rec =bpf_map_lookup_elem (&cpumap_kthread_cnt, &cpu); +if (!rec) +return 0 ; +NO_TEAR_ADD (rec->processed, processed); +NO_TEAR_ADD (rec->dropped, drops); +NO_TEAR_ADD (rec->xdp_pass, xdp_stats->pass); +NO_TEAR_ADD (rec->xdp_drop, xdp_stats->drop); +NO_TEAR_ADD (rec->xdp_redirect, xdp_stats->redirect); +/* Count times kthread yielded CPU via schedule call */ +if (sched) +NO_TEAR_INC (rec->issue); +return 0 ; +} + SEC("tp_btf/xdp_exception")int BPF_PROG (tp_xdp_exception ,const struct net_device *dev,const struct bpf_prog *xdp,u32 act)
@@ -136,4 +193,3 @@ int BPF_PROG(tp_xdp_exception, const struct net_device *dev,return 0 ; } -
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 9/22 samples: bpf: Add cpumap tracepoint statistics support
In reply to Kumar Kartikeya DwivediThis consolidates retrieval and printing into the XDP sample helper. For the kthread stats, it expands xdp_stats separately with its own per-CPU stats. For cpumap enqueue, we display FROM->TO stats also with its per-CPU stats.
The help out explains in detail the various aspects of the output.
--- samples/bpf/xdp_sample_user.c | 219 +++++++++++++++++++++++++++++++++- samples/bpf/xdp_sample_user.h | 6 + 2 files changed, 224 insertions(+), 1 deletion(-)
samples/bpf/xdp_sample_user.c +218 -1
@@ -74,6 +74,8 @@enum map_type {MAP_RX ,MAP_REDIRECT_ERR , +MAP_CPUMAP_ENQUEUE , +MAP_CPUMAP_KTHREAD ,MAP_EXCEPTION ,NUM_MAP , };
@@ -99,13 +101,16 @@ struct map_entry {struct stats_record {struct record rx_cnt;struct record redir_err[XDP_REDIRECT_ERR_MAX ]; +struct record kthread;struct record exception[XDP_ACTION_MAX ]; +struct record enq[]; };struct sample_output {struct {__u64 rx;__u64 redir; +__u64 drop;__u64 err; } totals;struct {
@@ -228,6 +233,30 @@ static void sample_print_help(int mask)printf (" \n\t\t\t\terror/s - Packets that failed redirection per second\n\n" ); } +if (mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) { +printf (" enqueue to cpu N\tDisplays the number of packets enqueued to bulk queue of CPU N\n" +" \t\t\tExpands to cpu:FROM->N to display enqueue stats for each CPU enqueuing to CPU N\n" +" \t\t\tReceived packets can be associated with the CPU redirect program is enqueuing \n" +" \t\t\tpackets to.\n" +" \t\t\t\tpkt/s - Packets enqueued per second from other CPU to CPU N\n" +" \t\t\t\tdrop/s - Packets dropped when trying to enqueue to CPU N\n" +" \t\t\t\tbulk-avg - Average number of packets processed for each event\n\n" ); + } + +if (mask &SAMPLE_CPUMAP_KTHREAD_CNT ) { +printf (" kthread\t\tDisplays the number of packets processed in CPUMAP kthread for each CPU\n" +" \t\t\tPackets consumed from ptr_ring in kthread, and its xdp_stats (after calling \n" +" \t\t\tCPUMAP bpf prog) are expanded below this. xdp_stats are expanded as a total and\n" +" \t\t\tthen per-CPU to associate it to each CPU's pinned CPUMAP kthread.\n" +" \t\t\t\tpkt/s - Packets consumed per second from ptr_ring\n" +" \t\t\t\tdrop/s - Packets dropped per second in kthread\n" +" \t\t\t\tsched - Number of times kthread called schedule()\n\n" +" \t\t\txdp_stats (also expands to per-CPU counts)\n" +" \t\t\t\tpass/s - XDP_PASS count for CPUMAP program execution\n" +" \t\t\t\tdrop/s - XDP_DROP count for CPUMAP program execution\n" +" \t\t\t\tredir/s - XDP_REDIRECT count for CPUMAP program execution\n\n" ); + } +if (mask &SAMPLE_EXCEPTION_CNT ) {printf (" xdp_exception\t\tDisplays xdp_exception tracepoint events\n" " \t\t\tThis can occur due to internal driver errors, unrecognized\n"
@@ -357,6 +386,14 @@ static struct stats_record *alloc_stats_record(void) } } } +if (sample_mask &SAMPLE_CPUMAP_KTHREAD_CNT ) { + rec->kthread.cpu =alloc_record_per_cpu (); +if (!rec->kthread.cpu) { +fprintf (stderr, +"Failed to allocate kthread per-CPU array\n" ); + goto end_redir; + } + }if (sample_mask &SAMPLE_EXCEPTION_CNT ) {for (i =0 ; i <XDP_ACTION_MAX ; i++) { rec->exception[i].cpu =alloc_record_per_cpu ();
@@ -367,13 +404,32 @@ static struct stats_record *alloc_stats_record(void) action2str(i));while (i--)free (rec->exception[i].cpu); - goto end_redir; + goto end_kthread; + } + } + } +if (sample_mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) { +for (i =0 ; i < sample_n_cpus; i++) { + rec->enq[i].cpu =alloc_record_per_cpu (); +if (!rec->enq[i].cpu) { +fprintf (stderr, +"Failed to allocate enqueue per-CPU array for " +"CPU %d\n" , + i); +while (i--) +free (rec->enq[i].cpu); + goto end_exception; } } }return rec; +end_exception: +for (i =0 ; i <XDP_ACTION_MAX ; i++) +free (rec->exception[i].cpu); +end_kthread: +free (rec->kthread.cpu); end_redir:for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++)free (rec->redir_err[i].cpu);
@@ -390,8 +446,11 @@ static void free_stats_record(struct stats_record *r)struct map_entry *e;int i; +for (i =0 ; i < sample_n_cpus; i++) +free (r->enq[i].cpu);for (i =0 ; i <XDP_ACTION_MAX ; i++)free (r->exception[i].cpu); +free (r->kthread.cpu);for (i =0 ; i <XDP_REDIRECT_ERR_MAX ; i++)free (r->redir_err[i].cpu);free (r->rx_cnt.cpu);
@@ -519,6 +578,137 @@ static void stats_get_rx_cnt(struct stats_record *stats_rec, } } +static void stats_get_cpumap_enqueue (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus) +{ +struct record *rec, *prev; +double t, pps, drop, err; +int i, to_cpu; + +/* cpumap enqueue stats */ +for (to_cpu =0 ; to_cpu < sample_n_cpus; to_cpu++) { + rec = &stats_rec->enq[to_cpu]; + prev = &stats_prev->enq[to_cpu]; + t =calc_period (rec, prev); + + pps =calc_pps (&rec->total, &prev->total, t); + drop =calc_drop_pps (&rec->total, &prev->total, t); + err =calc_errs_pps (&rec->total, &prev->total, t); + +if (pps >0 || drop >0 ) { +char str[64 ]; + +snprintf (str,sizeof (str),"enqueue to cpu %d" , to_cpu); + +if (err >0 ) + err = pps / err;/* calc average bulk size */ + +print_err (drop, + " %-20s " FMT_COLUMNf FMT_COLUMNf __COLUMN( + ".2f") "\n", + str,PPS (pps),DROP (drop), err,"bulk-avg" ); + } + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; + + pps =calc_pps (r, p, t); + drop =calc_drop_pps (r, p, t); + err =calc_errs_pps (r, p, t); +if (!pps && !drop && !err) +continue ; + +snprintf (str,sizeof (str),"cpu:%d->%d" , i, to_cpu); +if (err >0 ) + err = pps / err;/* calc average bulk size */ +print_default ( + " %-18s " FMT_COLUMNf FMT_COLUMNf __COLUMN( + ".2f") "\n", + str,PPS (pps),DROP (drop), err,"bulk-avg" ); + } + } +} + +static void stats_get_cpumap_remote (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus) +{ +double xdp_pass, xdp_drop, xdp_redirect; +struct record *rec, *prev; +double t; +int i; + + rec = &stats_rec->kthread; + prev = &stats_prev->kthread; + t =calc_period (rec, prev); + +calc_xdp_pps (&rec->total, &prev->total, &xdp_pass, &xdp_drop, + &xdp_redirect, t); +if (xdp_pass || xdp_drop || xdp_redirect) { +print_err (xdp_drop, +" %-18s " FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf"\n" , +"xdp_stats" ,PASS (xdp_pass),DROP (xdp_drop), +REDIR (xdp_redirect)); + } + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; + +calc_xdp_pps (r, p, &xdp_pass, &xdp_drop, &xdp_redirect, t); +if (!xdp_pass && !xdp_drop && !xdp_redirect) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); +print_default (" %-16s " FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf +"\n" , + str,PASS (xdp_pass),DROP (xdp_drop), +REDIR (xdp_redirect)); + } +} + +static void stats_get_cpumap_kthread (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus) +{ +struct record *rec, *prev; +double t, pps, drop, err; +int i; + + rec = &stats_rec->kthread; + prev = &stats_prev->kthread; + t =calc_period (rec, prev); + + pps =calc_pps (&rec->total, &prev->total, t); + drop =calc_drop_pps (&rec->total, &prev->total, t); + err =calc_errs_pps (&rec->total, &prev->total, t); + +print_err (drop," %-20s " FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf"\n" , + pps ?"kthread total" :"kthread" ,PPS (pps),DROP (drop), err, +"sched" ); + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; + + pps =calc_pps (r, p, t); + drop =calc_drop_pps (r, p, t); + err =calc_errs_pps (r, p, t); +if (!pps && !drop && !err) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); +print_default (" %-18s " FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf +"\n" , + str,PPS (pps),DROP (drop), err,"sched" ); + } +} + static void stats_get_redirect_cnt(struct stats_record *stats_rec, struct stats_record *stats_prev, unsigned int nr_cpus,
@@ -656,6 +846,9 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,print_always (FMT_COLUMNl,RX (out->totals.rx));if (mask &SAMPLE_REDIRECT_CNT )print_always (FMT_COLUMNl,REDIR (out->totals.redir)); +printf (FMT_COLUMNl, + out->totals.err + out->totals.drop + out->totals.drop_xmit, +"err,drop/s" );printf ("\n" );if (mask &SAMPLE_RX_CNT ) {
@@ -670,6 +863,14 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,stats_get_rx_cnt (r, p, nr_cpus,NULL ); } +if (mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) +stats_get_cpumap_enqueue (r, p, nr_cpus); + +if (mask &SAMPLE_CPUMAP_KTHREAD_CNT ) { +stats_get_cpumap_kthread (r, p, nr_cpus); +stats_get_cpumap_remote (r, p, nr_cpus); + } +if (mask &SAMPLE_REDIRECT_CNT ) { str = out->redir_cnt.suc ?"redirect total" :"redirect" ; print_default(" %-20s " FMT_COLUMNl "\n", str,
@@ -714,6 +915,7 @@ int sample_setup_maps(struct bpf_map **maps)switch (i) {case MAP_RX : +case MAP_CPUMAP_KTHREAD : sample_map_count[i] = sample_n_cpus;break ;case MAP_REDIRECT_ERR :
@@ -722,6 +924,8 @@ int sample_setup_maps(struct bpf_map **maps)break ;case MAP_EXCEPTION : sample_map_count[i] =XDP_ACTION_MAX * sample_n_cpus; +case MAP_CPUMAP_ENQUEUE : + sample_map_count[i] = sample_n_cpus * sample_n_cpus;break ;default :return -EINVAL ;
@@ -850,6 +1054,9 @@ static void sample_summary_print(void)print_always (" Average redir/s : %'-10.0f\n" ,sample_round (pkts / period)); } +if (sample_out.totals.drop) +print_always (" Rx dropped : %'-10llu\n" , + sample_out.totals.drop);if (sample_out.totals.err)print_always (" Errors recorded : %'-10llu\n" , sample_out.totals.err);
@@ -894,6 +1101,15 @@ static int sample_stats_collect(struct stats_record *rec) &rec->redir_err[i]); } +if (sample_mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) +for (i =0 ; i < sample_n_cpus; i++) +map_collect_percpu (&sample_mmap[MAP_CPUMAP_ENQUEUE ][i * sample_n_cpus], + &rec->enq[i]); + +if (sample_mask &SAMPLE_CPUMAP_KTHREAD_CNT ) +map_collect_percpu (sample_mmap[MAP_CPUMAP_KTHREAD ], + &rec->kthread); +if (sample_mask &SAMPLE_EXCEPTION_CNT )for (i =0 ; i <XDP_ACTION_MAX ; i++) map_collect_percpu(&sample_mmap[MAP_EXCEPTION][i * sample_n_cpus],
@@ -906,6 +1122,7 @@ static void sample_summary_update(struct sample_output *out, int interval) { sample_out.totals.rx += out->totals.rx; sample_out.totals.redir += out->totals.redir; + sample_out.totals.drop += out->totals.drop; sample_out.totals.err += out->totals.err; sample_out.rx_cnt.pps += interval; }
samples/bpf/xdp_sample_user.h +6 -0
@@ -11,6 +11,8 @@ enum stats_mask { _SAMPLE_REDIRECT_MAP =1U <<0 ,SAMPLE_RX_CNT =1U <<1 ,SAMPLE_REDIRECT_ERR_CNT =1U <<2 , +SAMPLE_CPUMAP_ENQUEUE_CNT =1U <<3 , +SAMPLE_CPUMAP_KTHREAD_CNT =1U <<4 ,SAMPLE_EXCEPTION_CNT =1U <<5 ,SAMPLE_REDIRECT_CNT =1U <<7 , SAMPLE_REDIRECT_MAP_CNT = SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP,
@@ -76,6 +78,10 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)__attach_tp (tp_xdp_redirect_map_err); \if (mask &SAMPLE_REDIRECT_ERR_CNT ) \__attach_tp (tp_xdp_redirect_err); \ +if (mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) \ +__attach_tp (tp_xdp_cpumap_enqueue); \ +if (mask &SAMPLE_CPUMAP_KTHREAD_CNT ) \ +__attach_tp (tp_xdp_cpumap_kthread); \if (mask &SAMPLE_EXCEPTION_CNT ) \__attach_tp (tp_xdp_exception); \return 0 ; \
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 10/22 samples: bpf: Add BPF support for devmap_xmit tracepoint
In reply to Kumar Kartikeya DwivediThis adds support for the devmap_xmit tracepoint, and its multi device variant that can be used to obtain streams for each individual net_device to net_device redirection. This is useful for decomposing total xmit stats in xdp_monitor.
--- samples/bpf/xdp_sample.bpf.c | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
samples/bpf/xdp_sample.bpf.c +71 -0
@@ -11,6 +11,14 @@ array_map redir_err_cnt SEC(".maps"); array_map cpumap_enqueue_cnt SEC(".maps"); array_map cpumap_kthread_cnt SEC(".maps"); array_map exception_cnt SEC(".maps"); +array_map devmap_xmit_cnt SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_HASH); + __uint(max_entries, 32 * 32); + __type(key, u64); + __type(value, struct datarec); +} devmap_xmit_cnt_multi SEC(".maps");const volatile int nr_cpus =0 ;
@@ -193,3 +201,66 @@ int BPF_PROG(tp_xdp_exception, const struct net_device *dev,return 0 ; } + +SEC("tp_btf/xdp_devmap_xmit") +int BPF_PROG (tp_xdp_devmap_xmit ,const struct net_device *from_dev, +const struct net_device *to_dev,int sent,int drops,int err) +{ +struct datarec *rec; +int idx_in, idx_out; +u32 cpu; + + idx_in = from_dev->ifindex; + idx_out = to_dev->ifindex; + +if (!IN_SET (from_match, idx_in)) +return 0 ; +if (!IN_SET (to_match, idx_out)) +return 0 ; + + cpu =bpf_get_smp_processor_id (); + rec =bpf_map_lookup_elem (&devmap_xmit_cnt, &cpu); +if (!rec) +return 0 ; +NO_TEAR_ADD (rec->processed, sent); +NO_TEAR_ADD (rec->dropped, drops); +/* Record bulk events, then userspace can calc average bulk size */ +NO_TEAR_INC (rec->info); +/* Record error cases, where no frame were sent */ +/* Catch API error of drv ndo_xdp_xmit sent more than count */ +if (err || drops <0 ) +NO_TEAR_INC (rec->issue); +return 0 ; +} + +SEC("tp_btf/xdp_devmap_xmit") +int BPF_PROG (tp_xdp_devmap_xmit_multi ,const struct net_device *from_dev, +const struct net_device *to_dev,int sent,int drops,int err) +{ +struct datarec empty = {}; +struct datarec *rec; +int idx_in, idx_out; +u64 idx; + + idx_in = from_dev->ifindex; + idx_out = to_dev->ifindex; + idx = idx_in; + idx = idx <<32 | idx_out; + +if (!IN_SET (from_match, idx_in)) +return 0 ; +if (!IN_SET (to_match, idx_out)) +return 0 ; + +bpf_map_update_elem (&devmap_xmit_cnt_multi, &idx, &empty,BPF_NOEXIST ); + rec =bpf_map_lookup_elem (&devmap_xmit_cnt_multi, &idx); +if (!rec) +return 0 ; + +NO_TEAR_ADD (rec->processed, sent); +NO_TEAR_ADD (rec->dropped, drops); +NO_TEAR_INC (rec->info); +if (err || drops <0 ) +NO_TEAR_INC (rec->issue); +return 0 ; +}
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 11/22 samples: bpf: Add devmap_xmit tracepoint statistics support
In reply to Kumar Kartikeya DwivediThis adds support for retrieval and printing for devmap_xmit total and mutli mode tracepoint. For multi mode, we keep a hash map entry for each redirection stream, such that we can dynamically add and remove entries on output.
The from_match and to_match will be set by individual samples when setting up the XDP program on these devices.
The multi mode tracepoint is also handy for xdp_redirect_map_multi, where up to 32 devices can be specified.
Also add samples_init_pre_load macro to finally set up the resized maps and mmap them in place for low overhead stats retrieval.
--- samples/bpf/xdp_sample_user.c | 317 +++++++++++++++++++++++++++++++++- samples/bpf/xdp_sample_user.h | 17 ++ 2 files changed, 331 insertions(+), 3 deletions(-)
samples/bpf/xdp_sample_user.c +314 -3
@@ -77,6 +77,8 @@ enum map_type {MAP_CPUMAP_ENQUEUE ,MAP_CPUMAP_KTHREAD ,MAP_EXCEPTION , +MAP_DEVMAP_XMIT , +MAP_DEVMAP_XMIT_MULTI , NUM_MAP, };
@@ -103,6 +105,8 @@ struct stats_record {struct record redir_err[XDP_REDIRECT_ERR_MAX ];struct record kthread;struct record exception[XDP_ACTION_MAX ]; +struct record devmap_xmit; +DECLARE_HASHTABLE (xmit_map,5 );struct record enq[]; };
@@ -111,7 +115,9 @@ struct sample_output {__u64 rx;__u64 redir;__u64 drop; +__u64 drop_xmit;__u64 err; +__u64 xmit; } totals;struct {__u64 pps;
@@ -125,6 +131,12 @@ struct sample_output {struct {__u64 hits; } except_cnt; +struct { +__u64 pps; +__u64 drop; +__u64 err; +double bavg; + } xmit_cnt; };struct xdp_desc {
@@ -265,6 +277,16 @@ static void sample_print_help(int mask) " \t\t\t\thit/s - Number of times the tracepoint was hit per second\n\n"); } +if (mask &SAMPLE_DEVMAP_XMIT_CNT ) { +printf (" devmap_xmit\t\tDisplays devmap_xmit tracepoint events\n" +" \t\t\tThis tracepoint is invoked for successful transmissions on output\n" +" \t\t\tdevice but these statistics are not available for generic XDP mode,\n" +" \t\t\thence they will be omitted from the output when using SKB mode\n" +" \t\t\t\txmit/s - Number of packets that were transmitted per second\n" +" \t\t\t\tdrop/s - Number of packets that failed transmissions per second\n" +" \t\t\t\tdrv_err/s - Number of internal driver errors per second\n" +" \t\t\t\tbulk-avg - Average number of packets processed for each event\n\n" ); + } } void sample_usage(char *argv[], const struct option *long_options,
@@ -353,6 +375,74 @@ static void map_collect_percpu(struct datarec *values, struct record *rec) rec->total.xdp_redirect = sum_xdp_redirect; } +static int map_collect_percpu_devmap (int map_fd,struct stats_record *rec) +{ +unsigned int nr_cpus =bpf_num_possible_cpus (); +__u32 batch, count =32 ; +struct datarec *values; +bool init = false; +__u64 *keys; +int i, ret; + + keys =calloc (count,sizeof (__u64)); +if (!keys) +return -ENOMEM ; + values =calloc (count * nr_cpus,sizeof (struct datarec )); +if (!values) { +free (keys); +return -ENOMEM ; + } + +for (;;) { +bool exit = false; + + ret =bpf_map_lookup_batch (map_fd, init ? &batch :NULL , &batch, + keys, values, &count,NULL ); +if (ret <0 && errno !=ENOENT ) +break ; +if (errno ==ENOENT ) + exit = true; + + init = true; +for (i =0 ; i < count; i++) { +struct map_entry *e, *x =NULL ; +__u64 pair = keys[i]; +struct datarec *arr; + + arr = &values[i * nr_cpus]; +hash_for_each_possible (rec->xmit_map, e, node, pair) { +if (e->pair == pair) { + x = e; +break ; + } + } +if (!x) { + x =calloc (1 ,sizeof (*x)); +if (!x) + goto cleanup; +if (map_entry_init (x, pair) <0 ) { +free (x); + goto cleanup; + } +hash_add (rec->xmit_map, &x->node, pair); + } +map_collect_percpu (arr, &x->val); + } + +if (exit) +break ; + count =32 ; + } + +free (values); +free (keys); +return 0 ; +cleanup: +free (values); +free (keys); +return -ENOMEM ; +} +static struct stats_record *alloc_stats_record (void ) {struct stats_record *rec;
@@ -408,6 +498,16 @@ static struct stats_record *alloc_stats_record(void) } } } +if (sample_mask &SAMPLE_DEVMAP_XMIT_CNT ) { + rec->devmap_xmit.cpu =alloc_record_per_cpu (); +if (!rec->devmap_xmit.cpu) { +fprintf (stderr, +"Failed to allocate devmap_xmit per-CPU array\n" ); + goto end_exception; + } + } +if (sample_mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) +hash_init (rec->xmit_map);if (sample_mask &SAMPLE_CPUMAP_ENQUEUE_CNT ) {for (i =0 ; i < sample_n_cpus; i++) { rec->enq[i].cpu =alloc_record_per_cpu ();
@@ -418,13 +518,15 @@ static struct stats_record *alloc_stats_record(void) i);while (i--)free (rec->enq[i].cpu); - goto end_exception; + goto end_devmap_xmit; } } }return rec; +end_devmap_xmit: +free (rec->devmap_xmit.cpu); end_exception:for (i =0 ; i <XDP_ACTION_MAX ; i++)free (rec->exception[i].cpu);
@@ -448,6 +550,12 @@ static void free_stats_record(struct stats_record *r)for (i =0 ; i < sample_n_cpus; i++)free (r->enq[i].cpu); +hash_for_each_safe (r->xmit_map, i, tmp, e, node) { +hash_del (&e->node); +free (e->val.cpu); +free (e); + } +free (r->devmap_xmit.cpu);for (i =0 ; i <XDP_ACTION_MAX ; i++)free (r->exception[i].cpu);free (r->kthread.cpu);
@@ -835,6 +943,160 @@ static void stats_get_exception_cnt(struct stats_record *stats_rec, } } +static void stats_get_devmap_xmit (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus, +struct sample_output *out) +{ +double pps, drop, info, err; +struct record *rec, *prev; +double t; +int i; + + rec = &stats_rec->devmap_xmit; + prev = &stats_prev->devmap_xmit; + t =calc_period (rec, prev); +for (i =0 ; i < nr_cpus; i++) { +struct datarec *r = &rec->cpu[i]; +struct datarec *p = &prev->cpu[i]; +char str[64 ]; + + pps =calc_pps (r, p, t); + drop =calc_drop_pps (r, p, t); + err =calc_errs_pps (r, p, t); + +if (!pps && !drop && !err) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); + info =calc_info_pps (r, p, t); +if (info >0 ) + info = (pps + drop) / info;/* calc avg bulk */ + print_default(" %-18s" FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf + __COLUMN(".2f") "\n", + str,XMIT (pps),DROP (drop), err,"drv_err/s" , + info,"bulk-avg" ); + } +if (out) { + pps =calc_pps (&rec->total, &prev->total, t); + drop =calc_drop_pps (&rec->total, &prev->total, t); + info =calc_info_pps (&rec->total, &prev->total, t); +if (info >0 ) + info = (pps + drop) / info;/* calc avg bulk */ + err =calc_errs_pps (&rec->total, &prev->total, t); + + out->xmit_cnt.pps = pps; + out->xmit_cnt.drop = drop; + out->xmit_cnt.bavg = info; + out->xmit_cnt.err = err; + out->totals.xmit += pps; + out->totals.drop_xmit += drop; + out->totals.err += err; + } +} + +static void stats_get_devmap_xmit_multi (struct stats_record *stats_rec, +struct stats_record *stats_prev, +unsigned int nr_cpus, +struct sample_output *out, +bool xmit_total) +{ +double pps, drop, info, err; +struct map_entry *entry; +struct record *r, *p; +double t; +int bkt; + +hash_for_each (stats_rec->xmit_map, bkt, entry, node) { +struct map_entry *e, *x =NULL ; +char ifname_from[IFNAMSIZ ]; +char ifname_to[IFNAMSIZ ]; +const char *fstr, *tstr; +unsigned long prev_time; +struct record beg = {}; +__u32 from_idx, to_idx; +char str[128 ]; +__u64 pair; +int i; + + prev_time = sample_interval *NANOSEC_PER_SEC ; + + pair = entry->pair; + from_idx = pair >>32 ; + to_idx = pair &0xFFFFFFFF ; + + r = &entry->val; + beg.timestamp = r->timestamp - prev_time; + +/* Find matching entry from stats_prev map */ +hash_for_each_possible (stats_prev->xmit_map, e, node, pair) { +if (e->pair == pair) { + x = e; +break ; + } + } +if (x) + p = &x->val; +else + p = &beg; + t =calc_period (r, p); + pps =calc_pps (&r->total, &p->total, t); + drop =calc_drop_pps (&r->total, &p->total, t); + info =calc_info_pps (&r->total, &p->total, t); +if (info >0 ) + info = (pps + drop) / info;/* calc avg bulk */ + err =calc_errs_pps (&r->total, &p->total, t); + +if (out) { +/* We are responsible for filling out totals */ + out->totals.xmit += pps; + out->totals.drop_xmit += drop; + out->totals.err += err; +continue ; + } + + fstr = tstr =NULL ; +if (if_indextoname (from_idx, ifname_from)) + fstr = ifname_from; +if (if_indextoname (to_idx, ifname_to)) + tstr = ifname_to; + +snprintf (str,sizeof (str),"xmit %s->%s" , fstr ?:"?" , + tstr ?:"?" ); +/* Skip idle streams of redirection */ +if (pps || drop || err) { +print_err (drop, + " %-20s " FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf + __COLUMN(".2f") "\n", str, XMIT(pps), DROP(drop), + err,"drv_err/s" , info,"bulk-avg" ); + } + +for (i =0 ; i < nr_cpus; i++) { +struct datarec *rc = &r->cpu[i]; +struct datarec *pc, p_beg = {}; +char str[64 ]; + + pc = p == &beg ? &p_beg : &p->cpu[i]; + + pps =calc_pps (rc, pc, t); + drop =calc_drop_pps (rc, pc, t); + err =calc_errs_pps (rc, pc, t); + +if (!pps && !drop && !err) +continue ; + +snprintf (str,sizeof (str),"cpu:%d" , i); + info =calc_info_pps (rc, pc, t); +if (info >0 ) + info = (pps + drop) / info;/* calc avg bulk */ + + print_default(" %-18s" FMT_COLUMNf FMT_COLUMNf FMT_COLUMNf + __COLUMN(".2f") "\n", str, XMIT(pps), +DROP (drop), err,"drv_err/s" , info,"bulk-avg" ); + } + } +} +static void stats_print (const char *prefix,int mask,struct stats_record *r,struct stats_record *p,struct sample_output *out) {
@@ -849,6 +1111,9 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,printf (FMT_COLUMNl, out->totals.err + out->totals.drop + out->totals.drop_xmit,"err,drop/s" ); +if (mask &SAMPLE_DEVMAP_XMIT_CNT || + mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) +printf (FMT_COLUMNl,XMIT (out->totals.xmit));printf ("\n" );if (mask &SAMPLE_RX_CNT ) {
@@ -899,6 +1164,25 @@ static void stats_print(const char *prefix, int mask, struct stats_record *r,stats_get_exception_cnt (r, p, nr_cpus,NULL ); } +if (mask &SAMPLE_DEVMAP_XMIT_CNT ) { + str = (sample_log_level &LL_DEFAULT ) && out->xmit_cnt.pps ? +"devmap_xmit total" : +"devmap_xmit" ; + +print_err (out->xmit_cnt.err || out->xmit_cnt.drop, + " %-20s " FMT_COLUMNl FMT_COLUMNl FMT_COLUMNl + __COLUMN(".2f") "\n", + str,XMIT (out->xmit_cnt.pps), +DROP (out->xmit_cnt.drop), out->xmit_cnt.err, +"drv_err/s" , out->xmit_cnt.bavg,"bulk-avg" ); + +stats_get_devmap_xmit (r, p, nr_cpus,NULL ); + } + +if (mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) +stats_get_devmap_xmit_multi (r, p, nr_cpus,NULL , + mask &SAMPLE_DEVMAP_XMIT_CNT ); +if (sample_log_level &LL_DEFAULT || ((sample_log_level &LL_SIMPLE ) && sample_err_exp)) { sample_err_exp = false;
@@ -910,12 +1194,13 @@ int sample_setup_maps(struct bpf_map **maps) { sample_n_cpus =libbpf_num_possible_cpus (); -for (int i =0 ; i <NUM_MAP ; i++) { +for (int i =0 ; i <MAP_DEVMAP_XMIT_MULTI ; i++) { sample_map[i] = maps[i];switch (i) {case MAP_RX :case MAP_CPUMAP_KTHREAD : +case MAP_DEVMAP_XMIT : sample_map_count[i] = sample_n_cpus;break ;case MAP_REDIRECT_ERR :
@@ -933,12 +1218,13 @@ int sample_setup_maps(struct bpf_map **maps)if (bpf_map__resize (sample_map[i], sample_map_count[i]) <0 )return -errno; } + sample_map[MAP_DEVMAP_XMIT_MULTI ] = maps[MAP_DEVMAP_XMIT_MULTI ];return 0 ; }static int sample_setup_maps_mappings (void ) { -for (int i =0 ; i <NUM_MAP ; i++) { +for (int i =0 ; i <MAP_DEVMAP_XMIT_MULTI ; i++) {size_t size = sample_map_count[i] *sizeof (struct datarec ); sample_mmap[i] = mmap(NULL, size, PROT_READ | PROT_WRITE,
@@ -1057,9 +1343,20 @@ static void sample_summary_print(void)if (sample_out.totals.drop)print_always (" Rx dropped : %'-10llu\n" , sample_out.totals.drop); +if (sample_out.totals.drop_xmit) +print_always (" Tx dropped : %'-10llu\n" , + sample_out.totals.drop_xmit);if (sample_out.totals.err)print_always (" Errors recorded : %'-10llu\n" , sample_out.totals.err); +if (sample_out.totals.xmit) { +double pkts = sample_out.totals.xmit; + +print_always (" Packets transmitted : %'-10llu\n" , + sample_out.totals.xmit); +print_always (" Average transmit/s : %'-10.0f\n" , +sample_round (pkts / period)); + } }void sample_exit (int status)
@@ -1115,6 +1412,13 @@ static int sample_stats_collect(struct stats_record *rec)map_collect_percpu (&sample_mmap[MAP_EXCEPTION ][i * sample_n_cpus], &rec->exception[i]); +if (sample_mask &SAMPLE_DEVMAP_XMIT_CNT ) +map_collect_percpu (sample_mmap[MAP_DEVMAP_XMIT ], &rec->devmap_xmit); + +if (sample_mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) { +if (map_collect_percpu_devmap (bpf_map__fd (sample_map[MAP_DEVMAP_XMIT_MULTI ]), rec) <0 ) +return -EINVAL ; + }return 0 ; }
@@ -1123,7 +1427,9 @@ static void sample_summary_update(struct sample_output *out, int interval) sample_out.totals.rx += out->totals.rx; sample_out.totals.redir += out->totals.redir; sample_out.totals.drop += out->totals.drop; + sample_out.totals.drop_xmit += out->totals.drop_xmit; sample_out.totals.err += out->totals.err; + sample_out.totals.xmit += out->totals.xmit; sample_out.rx_cnt.pps += interval; }
@@ -1141,6 +1447,11 @@ static void sample_stats_print(int mask, struct stats_record *cur,stats_get_redirect_err_cnt (cur, prev,0 , &out);if (mask &SAMPLE_EXCEPTION_CNT )stats_get_exception_cnt (cur, prev,0 , &out); +if (mask &SAMPLE_DEVMAP_XMIT_CNT ) +stats_get_devmap_xmit (cur, prev,0 , &out); +else if (mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) +stats_get_devmap_xmit_multi (cur, prev,0 , &out, + mask &SAMPLE_DEVMAP_XMIT_CNT );sample_summary_update (&out, interval);stats_print (prog_name, mask, cur, prev, &out);
samples/bpf/xdp_sample_user.h +17 -0
@@ -14,9 +14,11 @@ enum stats_mask {SAMPLE_CPUMAP_ENQUEUE_CNT =1U <<3 ,SAMPLE_CPUMAP_KTHREAD_CNT =1U <<4 ,SAMPLE_EXCEPTION_CNT =1U <<5 , +SAMPLE_DEVMAP_XMIT_CNT =1U <<6 ,SAMPLE_REDIRECT_CNT =1U <<7 ,SAMPLE_REDIRECT_MAP_CNT =SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP,SAMPLE_REDIRECT_ERR_MAP_CNT =SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP, + SAMPLE_DEVMAP_XMIT_CNT_MULTI = 1U << 8, };/* Exit return codes */
@@ -63,6 +65,17 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)return -errno; \ }) +#define sample_init_pre_load (skel) \ + ({ \ + skel->rodata->nr_cpus = libbpf_num_possible_cpus(); \ + sample_setup_maps((struct bpf_map *[]){ \ + skel->maps.rx_cnt, skel->maps.redir_err_cnt, \ + skel->maps.cpumap_enqueue_cnt, \ + skel->maps.cpumap_kthread_cnt, \ + skel->maps.exception_cnt, skel->maps.devmap_xmit_cnt, \ + skel->maps.devmap_xmit_cnt_multi }); \ + }) +#define DEFINE_SAMPLE_INIT (name) \ static int sample_init(struct name *skel, int mask) \ { \
@@ -84,6 +97,10 @@ static inline char *safe_strncpy(char *dst, const char *src, size_t size)__attach_tp (tp_xdp_cpumap_kthread); \if (mask &SAMPLE_EXCEPTION_CNT ) \__attach_tp (tp_xdp_exception); \ +if (mask &SAMPLE_DEVMAP_XMIT_CNT ) \ +__attach_tp (tp_xdp_devmap_xmit); \ +if (mask &SAMPLE_DEVMAP_XMIT_CNT_MULTI ) \ +__attach_tp (tp_xdp_devmap_xmit_multi); \return 0 ; \ }
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 12/22 samples: bpf: add vmlinux.h generation support
In reply to Kumar Kartikeya DwivediAlso, take this opportunity to depend on in-tree bpftool, so that we can use static linking support in subsequent commits for XDP samples BPF helper object.
--- samples/bpf/Makefile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
samples/bpf/Makefile +25 -0
@@ -276,6 +276,11 @@ $(LIBBPF): FORCE $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \ LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O= +BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool +BPFTOOL := $(BPFTOOLDIR)/bpftool +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) + $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ + $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE $(call filechk,offsets,__SYSCALL_NRS_H__)
@@ -313,6 +318,26 @@ $(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h -include $(BPF_SAMPLES_PATH)/Makefile.target +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux \ + /sys/kernel/btf/vmlinux \ + /boot/vmlinux-$(shell uname -r) +VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) + +ifeq ($(VMLINUX_BTF),) +$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") +endif + +$(obj)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) +ifeq ($(VMLINUX_H),) + $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ +else + $(Q)cp "$(VMLINUX_H)" $@ +endif + +clean-files += vmlinux.h + # asm/sysreg.h - inline assembly used by it is incompatible with llvm. # But, there is no easy way to fix it, so just exclude it since it is # useless for BPF samples.
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 13/22 samples: bpf: Convert xdp_monitor_kern.o to XDP samples helper
In reply to Kumar Kartikeya DwivediWe already moved all the functionality it provided in XDP samples helper userspace and kernel BPF object, so just delete the unneeded code.
We also add generation of BPF skeleton and compilation using clang -target bpf for files ending with .bpf.c suffix (to denote that they use vmlinux.h).
--- samples/bpf/Makefile | 42 +++++- samples/bpf/xdp_monitor.bpf.c | 8 + samples/bpf/xdp_monitor_kern.c | 257 --------------------------------- 3 files changed, 49 insertions(+), 258 deletions(-) create mode 100644 samples/bpf/xdp_monitor.bpf.c delete mode 100644 samples/bpf/xdp_monitor_kern.c
samples/bpf/Makefile +41 -1
@@ -164,7 +164,6 @@ always-y += xdp_redirect_kern.o always-y += xdp_redirect_map_kern.o always-y += xdp_redirect_map_multi_kern.o always-y += xdp_redirect_cpu_kern.o -always-y += xdp_monitor_kern.o always-y += xdp_rxq_info_kern.o always-y += xdp2skb_meta_kern.o always-y += syscall_tp_kern.o
@@ -338,6 +337,47 @@ endif clean-files += vmlinux.h +# Get Clang's default includes on this system, as opposed to those seen by +# '-target bpf'. This fixes "missing" files on some architectures/distros, +# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. +# +# Use '-idirafter': Don't interfere with include mechanics except where the +# build would have failed anyways. +define get_sys_includes +$(shell $(1) -v -E - </dev/null 2>&1 \ + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ +$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/') +endef + +CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) + +$(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o + +$(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h + @echo " CLANG-BPF " $@ + $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(SRCARCH) \ + -Wno-compare-distinct-pointer-types -I$(srctree)/include \ + -I$(srctree)/samples/bpf -I$(srctree)/tools/include \ + -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \ + -c $(filter %.bpf.c,$^) -o $@ + +LINKED_SKELS := xdp_monitor.skel.h +clean-files += $(LINKED_SKELS) + +xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o + +LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps))) + +BPF_SRCS_LINKED := $(notdir $(wildcard $(src)/*.bpf.c)) +BPF_OBJS_LINKED := $(patsubst %.bpf.c,$(obj)/%.bpf.o, $(BPF_SRCS_LINKED)) +BPF_SKELS_LINKED := $(addprefix $(obj)/,$(LINKED_SKELS)) + +$(BPF_SKELS_LINKED): $(BPF_OBJS_LINKED) $(BPFTOOL) + @echo " BPF GEN-OBJ " $(@:.skel.h=) + $(Q)$(BPFTOOL) gen object $(@:.skel.h=.lbpf.o) $(addprefix $(obj)/,$($(@F)-deps)) + @echo " BPF GEN-SKEL" $(@:.skel.h=) + $(Q)$(BPFTOOL) gen skeleton $(@:.skel.h=.lbpf.o) name $(notdir $(@:.skel.h=)) > $@ + # asm/sysreg.h - inline assembly used by it is incompatible with llvm. # But, there is no easy way to fix it, so just exclude it since it is # useless for BPF samples.
samples/bpf/xdp_monitor.bpf.c new file +8 -0
@@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2017-2018 Jesper Dangaard Brouer, Red Hat Inc. +* +* XDP monitor tool, based on tracepoints +*/ +#include "xdp_sample.bpf.h" + +char _license[] SEC("license") = "GPL";
samples/bpf/xdp_monitor_kern.c deleted +0 -257
257 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 14/22 samples: bpf: Convert xdp_monitor to XDP samples helper
In reply to Kumar Kartikeya DwivediUse the libbpf skeleton facility and other utilities provided by XDP samples helper.
A lot of the code in xdp_monitor and xdp_redirect_cpu has been moved to the xdp_sample_user.o helper, so we remove the duplicate functions here that are no longer needed.
Thanks to BPF skeleton, we no longer depend on order of tracepoints to uninstall them on startup. Instead, the sample mask is used to install the needed tracepoints.
--- samples/bpf/Makefile | 9 +- samples/bpf/Makefile.target | 11 + samples/bpf/xdp_monitor_user.c | 798 +++------------------------------ 3 files changed, 83 insertions(+), 735 deletions(-)
samples/bpf/Makefile +7 -2
@@ -43,7 +43,6 @@ tprogs-y += xdp_redirect tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect_map_multi tprogs-y += xdp_redirect_cpu -tprogs-y += xdp_monitor tprogs-y += xdp_rxq_info tprogs-y += syscall_tp tprogs-y += cpustat
@@ -57,11 +56,14 @@ tprogs-y += xdp_sample_pkts tprogs-y += ibumad tprogs-y += hbm +tprogs-y += xdp_monitor + # Libbpf dependencies LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o +XDP_SAMPLE := xdp_sample_user.o fds_example-objs := fds_example.o sockex1-objs := sockex1_user.o
@@ -102,7 +104,6 @@ xdp_redirect-objs := xdp_redirect_user.o xdp_redirect_map-objs := xdp_redirect_map_user.o xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o -xdp_monitor-objs := xdp_monitor_user.o xdp_rxq_info-objs := xdp_rxq_info_user.o syscall_tp-objs := syscall_tp_user.o cpustat-objs := cpustat_user.o
@@ -116,6 +117,8 @@ xdp_sample_pkts-objs := xdp_sample_pkts_user.o ibumad-objs := ibumad_user.o hbm-objs := hbm.o $(CGROUP_HELPERS) +xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE) + # Tell kbuild to always build the programs always-y := $(tprogs-y) always-y += sockex1_kern.o
@@ -310,6 +313,8 @@ verify_target_bpf: verify_cmds $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) $(src)/*.c: verify_target_bpf $(LIBBPF) +$(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h + $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h $(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h $(obj)/hbm.o: $(src)/hbm.h
samples/bpf/Makefile.target +11 -0
@@ -73,3 +73,14 @@ quiet_cmd_tprog-cobjs = CC $@ cmd_tprog-cobjs = $(CC) $(tprogc_flags) -c -o $@ $< $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE $(call if_changed_dep,tprog-cobjs) + +# Override includes for xdp_sample_user.o because $(srctree)/usr/include in +# TPROGS_CFLAGS causes conflicts +XDP_SAMPLE_CFLAGS += -Wall -O2 -lm \ + -I./tools/include \ + -I./tools/include/uapi \ + -I./tools/lib \ + -I./tools/testing/selftests/bpf +$(obj)/xdp_sample_user.o: $(src)/xdp_sample_user.c \ + $(src)/xdp_sample_user.h $(src)/xdp_sample_shared.h + $(CC) $(XDP_SAMPLE_CFLAGS) -c -o $@ $<
samples/bpf/xdp_monitor_user.c +65 -733
848 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 15/22 samples: bpf: Convert xdp_redirect_kern.o to XDP samples helper
In reply to Kumar Kartikeya DwivediWe moved swap_src_dst_mac to xdp_sample.bpf.h to be shared with other potential users, so drop it while moving code to the new file. Also, consistently use SEC("xdp") naming instead.
--- samples/bpf/Makefile | 5 +- samples/bpf/xdp_redirect.bpf.c | 49 ++++++++++++++++++ samples/bpf/xdp_redirect_kern.c | 90 --------------------------------- 3 files changed, 52 insertions(+), 92 deletions(-) create mode 100644 samples/bpf/xdp_redirect.bpf.c delete mode 100644 samples/bpf/xdp_redirect_kern.c
samples/bpf/Makefile +3 -2
@@ -163,7 +163,6 @@ always-y += tcp_clamp_kern.o always-y += tcp_basertt_kern.o always-y += tcp_tos_reflect_kern.o always-y += tcp_dumpstats_kern.o -always-y += xdp_redirect_kern.o always-y += xdp_redirect_map_kern.o always-y += xdp_redirect_map_multi_kern.o always-y += xdp_redirect_cpu_kern.o
@@ -356,6 +355,7 @@ endef CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) +$(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
@@ -366,9 +366,10 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \ -c $(filter %.bpf.c,$^) -o $@ -LINKED_SKELS := xdp_monitor.skel.h +LINKED_SKELS := xdp_redirect.skel.h xdp_monitor.skel.h clean-files += $(LINKED_SKELS) +xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
samples/bpf/xdp_redirect.bpf.c new file +49 -0
49 lines not on this page · raw message
samples/bpf/xdp_redirect_kern.c deleted +0 -90
90 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 16/22 samples: bpf: Convert xdp_redirect to XDP samples helper
In reply to Kumar Kartikeya DwivediUse the libbpf skeleton facility and other utilities provided by XDP samples helper.
One important note:
The XDP samples helper handles ownership of installed XDP programs on devices, including responding to SIGINT and SIGTERM, so drop the code here and use the helpers we provide going forward for all xdp_redirect* conversions.
--- samples/bpf/Makefile | 5 +- samples/bpf/xdp_redirect_user.c | 270 +++++++++++++------------------- 2 files changed, 116 insertions(+), 159 deletions(-)
samples/bpf/Makefile +3 -2
@@ -39,7 +39,6 @@ tprogs-y += lwt_len_hist tprogs-y += xdp_tx_iptunnel tprogs-y += test_map_in_map tprogs-y += per_socket_stats_example -tprogs-y += xdp_redirect tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect_map_multi tprogs-y += xdp_redirect_cpu
@@ -56,6 +55,7 @@ tprogs-y += xdp_sample_pkts tprogs-y += ibumad tprogs-y += hbm +tprogs-y += xdp_redirect tprogs-y += xdp_monitor # Libbpf dependencies
@@ -100,7 +100,6 @@ lwt_len_hist-objs := lwt_len_hist_user.o xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o test_map_in_map-objs := test_map_in_map_user.o per_socket_stats_example-objs := cookie_uid_helper_example.o -xdp_redirect-objs := xdp_redirect_user.o xdp_redirect_map-objs := xdp_redirect_map_user.o xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o
@@ -117,6 +116,7 @@ xdp_sample_pkts-objs := xdp_sample_pkts_user.o ibumad-objs := ibumad_user.o hbm-objs := hbm.o $(CGROUP_HELPERS) +xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE) xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE) # Tell kbuild to always build the programs
@@ -312,6 +312,7 @@ verify_target_bpf: verify_cmds $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) $(src)/*.c: verify_target_bpf $(LIBBPF) +$(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
samples/bpf/xdp_redirect_user.c +113 -157
320 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 17/22 samples: bpf: Convert xdp_redirect_cpu_kern.o to XDP samples helper
In reply to Kumar Kartikeya DwivediSimilar to xdp_monitor_kern, a lot of these BPF programs have been reimplemented properly consolidating missing features from other XDP samples. Hence, drop the unneeded code and rename to .bpf.c suffix.
---
samples/bpf/Makefile | 5 +-
...rect_cpu_kern.c => xdp_redirect_cpu.bpf.c} | 393 +++++-------------
2 files changed, 105 insertions(+), 293 deletions(-)
rename samples/bpf/{xdp_redirect_cpu_kern.c => xdp_redirect_cpu.bpf.c} (52%)samples/bpf/Makefile +3 -2
@@ -165,7 +165,6 @@ always-y += tcp_tos_reflect_kern.o always-y += tcp_dumpstats_kern.o always-y += xdp_redirect_map_kern.o always-y += xdp_redirect_map_multi_kern.o -always-y += xdp_redirect_cpu_kern.o always-y += xdp_rxq_info_kern.o always-y += xdp2skb_meta_kern.o always-y += syscall_tp_kern.o
@@ -356,6 +355,7 @@ endef CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) +$(obj)/xdp_redirect_cpu.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o
@@ -367,9 +367,10 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \ -c $(filter %.bpf.c,$^) -o $@ -LINKED_SKELS := xdp_redirect.skel.h xdp_monitor.skel.h +LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect.skel.h xdp_monitor.skel.h clean-files += $(LINKED_SKELS) +xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o
samples/bpf/xdp_redirect_cpu.bpf.c renamed from samples/bpf/xdp_redirect_cpu_kern.c +102 -291
637 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 18/22 samples: bpf: Convert xdp_redirect_cpu to XDP samples helper
In reply to Kumar Kartikeya DwivediUse the libbpf skeleton facility and other utilities provided by XDP samples helper.
Similar to xdp_monitor, xdp_redirect_cpu was quite featureful except a few minor omissions (e.g. redirect errno reporting). All of these have been moved to XDP samples helper, hence drop the unneeded code and convert to usage of helpers provided by it.
One of the important changes here is dropping of mprog-disable option, as we make that the default. Also, we support built-in programs for some common actions on the packet when it reaches kthread (pass, drop, redirect to device). If the user still needs to install a custom program, they can still supply a BPF object, however the program should be suitably tagged with SEC("xdp_cpumap") annotation so that the expected attach type is correct when updating our cpumap map element.
--- samples/bpf/Makefile | 5 +- samples/bpf/xdp_redirect_cpu_user.c | 1105 +++++++++------------------ 2 files changed, 343 insertions(+), 767 deletions(-)
samples/bpf/Makefile +3 -2
@@ -41,7 +41,6 @@ tprogs-y += test_map_in_map tprogs-y += per_socket_stats_example tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect_map_multi -tprogs-y += xdp_redirect_cpu tprogs-y += xdp_rxq_info tprogs-y += syscall_tp tprogs-y += cpustat
@@ -55,6 +54,7 @@ tprogs-y += xdp_sample_pkts tprogs-y += ibumad tprogs-y += hbm +tprogs-y += xdp_redirect_cpu tprogs-y += xdp_redirect tprogs-y += xdp_monitor
@@ -102,7 +102,6 @@ test_map_in_map-objs := test_map_in_map_user.o per_socket_stats_example-objs := cookie_uid_helper_example.o xdp_redirect_map-objs := xdp_redirect_map_user.o xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o -xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o xdp_rxq_info-objs := xdp_rxq_info_user.o syscall_tp-objs := syscall_tp_user.o cpustat-objs := cpustat_user.o
@@ -116,6 +115,7 @@ xdp_sample_pkts-objs := xdp_sample_pkts_user.o ibumad-objs := ibumad_user.o hbm-objs := hbm.o $(CGROUP_HELPERS) +xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE) xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE) xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE)
@@ -311,6 +311,7 @@ verify_target_bpf: verify_cmds $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) $(src)/*.c: verify_target_bpf $(LIBBPF) +$(obj)/xdp_redirect_cpu_user.o: $(obj)/xdp_redirect_cpu.skel.h $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h
samples/bpf/xdp_redirect_cpu_user.c +340 -765
1,282 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 19/22 samples: bpf: Convert xdp_redirect_map_kern.o to XDP samples helper
In reply to Kumar Kartikeya DwivediAlso update it to use consistent SEC("xdp") and SEC("xdp_devmap") naming, and use global variable instead of BPF map for copying the mac address.
---
samples/bpf/Makefile | 6 +-
...rect_map_kern.c => xdp_redirect_map.bpf.c} | 89 +++++--------------
2 files changed, 25 insertions(+), 70 deletions(-)
rename samples/bpf/{xdp_redirect_map_kern.c => xdp_redirect_map.bpf.c} (57%)samples/bpf/Makefile +4 -2
@@ -163,7 +163,6 @@ always-y += tcp_clamp_kern.o always-y += tcp_basertt_kern.o always-y += tcp_tos_reflect_kern.o always-y += tcp_dumpstats_kern.o -always-y += xdp_redirect_map_kern.o always-y += xdp_redirect_map_multi_kern.o always-y += xdp_rxq_info_kern.o always-y += xdp2skb_meta_kern.o
@@ -357,6 +356,7 @@ endef CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) $(obj)/xdp_redirect_cpu.bpf.o: $(obj)/xdp_sample.bpf.o +$(obj)/xdp_redirect_map.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o
@@ -368,10 +368,12 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \ -c $(filter %.bpf.c,$^) -o $@ -LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect.skel.h xdp_monitor.skel.h +LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map.skel.h \ + xdp_redirect.skel.h xdp_monitor.skel.h clean-files += $(LINKED_SKELS) xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o +xdp_redirect_map.skel.h-deps := xdp_redirect_map.bpf.o xdp_sample.bpf.o xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o
samples/bpf/xdp_redirect_map.bpf.c renamed from samples/bpf/xdp_redirect_map_kern.c +21 -68
149 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 20/22 samples: bpf: Convert xdp_redirect_map to XDP samples helper
In reply to Kumar Kartikeya DwivediUse the libbpf skeleton facility and other utilities provided by XDP samples helper.
Since get_mac_addr is already provided by XDP samples helper, we drop it. Also convert to XDP samples helper similar to prior samples to minimize duplication of code.
--- samples/bpf/Makefile | 5 +- samples/bpf/xdp_redirect_map_user.c | 385 ++++++++++++---------------- 2 files changed, 161 insertions(+), 229 deletions(-)
samples/bpf/Makefile +3 -2
@@ -39,7 +39,6 @@ tprogs-y += lwt_len_hist tprogs-y += xdp_tx_iptunnel tprogs-y += test_map_in_map tprogs-y += per_socket_stats_example -tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect_map_multi tprogs-y += xdp_rxq_info tprogs-y += syscall_tp
@@ -55,6 +54,7 @@ tprogs-y += ibumad tprogs-y += hbm tprogs-y += xdp_redirect_cpu +tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect tprogs-y += xdp_monitor
@@ -100,7 +100,6 @@ lwt_len_hist-objs := lwt_len_hist_user.o xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o test_map_in_map-objs := test_map_in_map_user.o per_socket_stats_example-objs := cookie_uid_helper_example.o -xdp_redirect_map-objs := xdp_redirect_map_user.o xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o xdp_rxq_info-objs := xdp_rxq_info_user.o syscall_tp-objs := syscall_tp_user.o
@@ -116,6 +115,7 @@ ibumad-objs := ibumad_user.o hbm-objs := hbm.o $(CGROUP_HELPERS) xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE) +xdp_redirect_map-objs := xdp_redirect_map_user.o $(XDP_SAMPLE) xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE) xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE)
@@ -311,6 +311,7 @@ $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) $(src)/*.c: verify_target_bpf $(LIBBPF) $(obj)/xdp_redirect_cpu_user.o: $(obj)/xdp_redirect_cpu.skel.h +$(obj)/xdp_redirect_map_user.o: $(obj)/xdp_redirect_map.skel.h $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h
samples/bpf/xdp_redirect_map_user.c +158 -227
436 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 21/22 samples: bpf: Convert xdp_redirect_map_multi_kern.o to XDP samples helper
In reply to Kumar Kartikeya DwivediOne of the notable changes is using a BPF_MAP_TYPE_HASH instead of array map to store mac addresses of devices, as the resizing behavior was based on max_ifindex, which unecessarily maximized the capacity of map beyond what was needed.
---
samples/bpf/Makefile | 7 +--
...ti_kern.c => xdp_redirect_map_multi.bpf.c} | 50 ++++++++-----------
2 files changed, 26 insertions(+), 31 deletions(-)
rename samples/bpf/{xdp_redirect_map_multi_kern.c => xdp_redirect_map_multi.bpf.c} (64%)samples/bpf/Makefile +4 -3
@@ -163,7 +163,6 @@ always-y += tcp_clamp_kern.o always-y += tcp_basertt_kern.o always-y += tcp_tos_reflect_kern.o always-y += tcp_dumpstats_kern.o -always-y += xdp_redirect_map_multi_kern.o always-y += xdp_rxq_info_kern.o always-y += xdp2skb_meta_kern.o always-y += syscall_tp_kern.o
@@ -357,6 +356,7 @@ endef CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) $(obj)/xdp_redirect_cpu.bpf.o: $(obj)/xdp_sample.bpf.o +$(obj)/xdp_redirect_map_multi.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_redirect_map.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o
@@ -369,11 +369,12 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \ -c $(filter %.bpf.c,$^) -o $@ -LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map.skel.h \ - xdp_redirect.skel.h xdp_monitor.skel.h +LINKED_SKELS := xdp_redirect_cpu.skel.h xdp_redirect_map_multi.skel.h \ + xdp_redirect_map.skel.h xdp_redirect.skel.h xdp_monitor.skel.h clean-files += $(LINKED_SKELS) xdp_redirect_cpu.skel.h-deps := xdp_redirect_cpu.bpf.o xdp_sample.bpf.o +xdp_redirect_map_multi.skel.h-deps := xdp_redirect_map_multi.bpf.o xdp_sample.bpf.o xdp_redirect_map.skel.h-deps := xdp_redirect_map.bpf.o xdp_sample.bpf.o xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o
samples/bpf/xdp_redirect_map_multi.bpf.c renamed from samples/bpf/xdp_redirect_map_multi_kern.c +22 -28
83 lines not on this page · raw message
Signature · 1 line
2.33.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 22/22 samples: bpf: Convert xdp_redirect_map_multi to XDP samples helper
In reply to Kumar Kartikeya DwivediUse the libbpf skeleton facility and other utilities provided by XDP samples helper. Also adapt to change of type of mac address map, so that no resizing is required.
Add a new flag for sample mask that skips priting the from_device->to_device heading for each line, as xdp_redirect_map_multi may have two devices but the flow of data may be bidirectional, so the output would be confusing.
--- samples/bpf/Makefile | 5 +- samples/bpf/xdp_redirect_map_multi_user.c | 345 +++++++++------------- samples/bpf/xdp_sample_user.c | 2 +- samples/bpf/xdp_sample_user.h | 21 +- 4 files changed, 153 insertions(+), 220 deletions(-)
samples/bpf/Makefile +3 -2
@@ -39,7 +39,6 @@ tprogs-y += lwt_len_hist tprogs-y += xdp_tx_iptunnel tprogs-y += test_map_in_map tprogs-y += per_socket_stats_example -tprogs-y += xdp_redirect_map_multi tprogs-y += xdp_rxq_info tprogs-y += syscall_tp tprogs-y += cpustat
@@ -54,6 +53,7 @@ tprogs-y += ibumad tprogs-y += hbm tprogs-y += xdp_redirect_cpu +tprogs-y += xdp_redirect_map_multi tprogs-y += xdp_redirect_map tprogs-y += xdp_redirect tprogs-y += xdp_monitor
@@ -100,7 +100,6 @@ lwt_len_hist-objs := lwt_len_hist_user.o xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o test_map_in_map-objs := test_map_in_map_user.o per_socket_stats_example-objs := cookie_uid_helper_example.o -xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o xdp_rxq_info-objs := xdp_rxq_info_user.o syscall_tp-objs := syscall_tp_user.o cpustat-objs := cpustat_user.o
@@ -114,6 +113,7 @@ xdp_sample_pkts-objs := xdp_sample_pkts_user.o ibumad-objs := ibumad_user.o hbm-objs := hbm.o $(CGROUP_HELPERS) +xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o $(XDP_SAMPLE) xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o $(XDP_SAMPLE) xdp_redirect_map-objs := xdp_redirect_map_user.o $(XDP_SAMPLE) xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE)
@@ -310,6 +310,7 @@ $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) $(src)/*.c: verify_target_bpf $(LIBBPF) $(obj)/xdp_redirect_cpu_user.o: $(obj)/xdp_redirect_cpu.skel.h +$(obj)/xdp_redirect_map_multi_user.o: $(obj)/xdp_redirect_map_multi.skel.h $(obj)/xdp_redirect_map_user.o: $(obj)/xdp_redirect_map.skel.h $(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h
samples/bpf/xdp_redirect_map_multi_user.c +138 -207
432 lines not on this page · raw message
samples/bpf/xdp_sample_user.c +1 -1
@@ -1510,7 +1510,7 @@ static int sample_timer_cb(int timerfd, struct stats_record **rec,if (ret <0 )return ret; -if (sample_xdp_cnt ==2 ) { +if (sample_xdp_cnt ==2 && !(sample_mask &SAMPLE_SKIP_HEADING )) {char fi[IFNAMSIZ ];char to[IFNAMSIZ ];const char *f, *t;
samples/bpf/xdp_sample_user.h +11 -10
@@ -8,17 +8,18 @@#include "xdp_sample_shared.h" enum stats_mask { - _SAMPLE_REDIRECT_MAP =1U <<0 , -SAMPLE_RX_CNT =1U <<1 , -SAMPLE_REDIRECT_ERR_CNT =1U <<2 , -SAMPLE_CPUMAP_ENQUEUE_CNT =1U <<3 , -SAMPLE_CPUMAP_KTHREAD_CNT =1U <<4 , -SAMPLE_EXCEPTION_CNT =1U <<5 , -SAMPLE_DEVMAP_XMIT_CNT =1U <<6 , -SAMPLE_REDIRECT_CNT =1U <<7 , -SAMPLE_REDIRECT_MAP_CNT =SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP, -SAMPLE_REDIRECT_ERR_MAP_CNT =SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP, + _SAMPLE_REDIRECT_MAP =1U <<0 , +SAMPLE_RX_CNT =1U <<1 , +SAMPLE_REDIRECT_ERR_CNT =1U <<2 , +SAMPLE_CPUMAP_ENQUEUE_CNT =1U <<3 , +SAMPLE_CPUMAP_KTHREAD_CNT =1U <<4 , +SAMPLE_EXCEPTION_CNT =1U <<5 , +SAMPLE_DEVMAP_XMIT_CNT =1U <<6 , +SAMPLE_REDIRECT_CNT =1U <<7 , +SAMPLE_REDIRECT_MAP_CNT =SAMPLE_REDIRECT_CNT | _SAMPLE_REDIRECT_MAP, +SAMPLE_REDIRECT_ERR_MAP_CNT =SAMPLE_REDIRECT_ERR_CNT | _SAMPLE_REDIRECT_MAP,SAMPLE_DEVMAP_XMIT_CNT_MULTI =1U <<8 , +SAMPLE_SKIP_HEADING =1U <<9 , };/* Exit return codes */
Signature · 1 line
2.33.0