Move bpf_printk to bpf_helpers.h
Subsystems (6)
v2 cover Move bpf_printk to bpf_helpers.h
This series of patches move the commonly used bpf_printk macro to bpf_helpers.h which is already included in all BPF programs which defined that macro on their own.
v1->v2:
- If HBM_DEBUG is not defined in hbm sample, undefine bpf_printk and set an empty macro for it.
Michal Rostecki (2):
selftests: bpf: Move bpf_printk to bpf_helpers.h
samples: bpf: Do not define bpf_printk macro
samples/bpf/hbm_kern.h | 11 ++--------- samples/bpf/tcp_basertt_kern.c | 7 ------- samples/bpf/tcp_bufs_kern.c | 7 ------- samples/bpf/tcp_clamp_kern.c | 7 ------- samples/bpf/tcp_cong_kern.c | 7 ------- samples/bpf/tcp_iw_kern.c | 7 ------- samples/bpf/tcp_rwnd_kern.c | 7 ------- samples/bpf/tcp_synrto_kern.c | 7 ------- samples/bpf/tcp_tos_reflect_kern.c | 7 ------- samples/bpf/xdp_sample_pkts_kern.c | 7 ------- tools/testing/selftests/bpf/bpf_helpers.h | 8 ++++++++ .../testing/selftests/bpf/progs/sockmap_parse_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_tcp_msg_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_verdict_prog.c | 7 ------- .../testing/selftests/bpf/progs/test_lwt_seg6local.c | 7 ------- tools/testing/selftests/bpf/progs/test_xdp_noinline.c | 7 ------- tools/testing/selftests/bpf/test_sockmap_kern.h | 7 ------- 17 files changed, 10 insertions(+), 114 deletions(-)
Signature · 1 line
2.21.0
PATCH RESEND v2 1/2 selftests: bpf: Move bpf_printk to bpf_helpers.h
bpf_printk is a macro which is commonly used to print out debug messages in BPF programs and it was copied in many selftests and samples. Since all of them include bpf_helpers.h, this change moves the macro there.
--- tools/testing/selftests/bpf/bpf_helpers.h | 8 ++++++++ tools/testing/selftests/bpf/progs/sockmap_parse_prog.c | 7 ------- tools/testing/selftests/bpf/progs/sockmap_tcp_msg_prog.c | 7 ------- tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c | 7 ------- tools/testing/selftests/bpf/progs/test_lwt_seg6local.c | 7 ------- tools/testing/selftests/bpf/progs/test_xdp_noinline.c | 7 ------- tools/testing/selftests/bpf/test_sockmap_kern.h | 7 ------- 7 files changed, 8 insertions(+), 42 deletions(-)
tools/testing/selftests/bpf/bpf_helpers.h +8 -0
@@ -8,6 +8,14 @@*/ #define SEC (NAME ) __attribute__((section(NAME), used)) +/* helper macro to print out debug messages */ +#define bpf_printk (fmt, ...) \ +({ \ + char ____fmt[] = fmt; \ + bpf_trace_printk(____fmt, sizeof(____fmt), \ + ##__VA_ARGS__); \ +}) +/* helper functions called from eBPF programs written in C */ static void *(*bpf_map_lookup_elem)(void *map,const void *key) = (void *) BPF_FUNC_map_lookup_elem;
tools/testing/selftests/bpf/progs/sockmap_parse_prog.c +0 -7
@@ -5,13 +5,6 @@ int _version SEC("version") = 1; -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sk_skb1")int bpf_prog1 (struct __sk_buff *skb) {
tools/testing/selftests/bpf/progs/sockmap_tcp_msg_prog.c +0 -7
@@ -5,13 +5,6 @@ int _version SEC("version") = 1; -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sk_msg1")int bpf_prog1 (struct sk_msg_md *msg) {
tools/testing/selftests/bpf/progs/sockmap_verdict_prog.c +0 -7
@@ -5,13 +5,6 @@ int _version SEC("version") = 1; -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - struct bpf_map_def SEC("maps") sock_map_rx = { .type = BPF_MAP_TYPE_SOCKMAP, .key_size = sizeof(int),
tools/testing/selftests/bpf/progs/test_lwt_seg6local.c +0 -7
@@ -6,13 +6,6 @@#include "bpf_helpers.h" #include "bpf_endian.h" -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) -/* Packet parsing state machine helpers. */ #define cursor_advance (_cursor, _len) \ ({ void *_tmp = _cursor; _cursor += _len; _tmp; })
tools/testing/selftests/bpf/progs/test_xdp_noinline.c +0 -7
@@ -15,13 +15,6 @@#include <linux/udp.h> #include "bpf_helpers.h" -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) -static __u32 rol32 (__u32 word,unsigned int shift) {return (word << shift) | (word >> ((-shift) &31 ));
tools/testing/selftests/bpf/test_sockmap_kern.h +0 -7
@@ -28,13 +28,6 @@* are established and verdicts are decided. */ -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - struct bpf_map_def SEC("maps") sock_map = { .type = TEST_MAP_TYPE, .key_size = sizeof(int),
Signature · 1 line
2.21.0
PATCH RESEND v2 2/2 samples: bpf: Do not define bpf_printk macro
In reply to Michal RosteckiThe bpf_printk macro was moved to bpf_helpers.h which is included in all example programs.
--- samples/bpf/hbm_kern.h | 11 ++--------- samples/bpf/tcp_basertt_kern.c | 7 ------- samples/bpf/tcp_bufs_kern.c | 7 ------- samples/bpf/tcp_clamp_kern.c | 7 ------- samples/bpf/tcp_cong_kern.c | 7 ------- samples/bpf/tcp_iw_kern.c | 7 ------- samples/bpf/tcp_rwnd_kern.c | 7 ------- samples/bpf/tcp_synrto_kern.c | 7 ------- samples/bpf/tcp_tos_reflect_kern.c | 7 ------- samples/bpf/xdp_sample_pkts_kern.c | 7 ------- 10 files changed, 2 insertions(+), 72 deletions(-)
samples/bpf/hbm_kern.h +2 -9
@@ -30,15 +30,8 @@#define ALLOW_PKT 1#define TCP_ECN_OK 1 -#define HBM_DEBUG 0 // Set to 1 to enable debugging -#if HBM_DEBUG -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) -#else +#ifndef HBM_DEBUG // Define HBM_DEBUG to enable debugging +#undef bpf_printk#define bpf_printk (fmt, ...)#endif
samples/bpf/tcp_basertt_kern.c +0 -7
@@ -21,13 +21,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_basertt (struct bpf_sock_ops *skops) {
samples/bpf/tcp_bufs_kern.c +0 -7
@@ -22,13 +22,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_bufs (struct bpf_sock_ops *skops) {
samples/bpf/tcp_clamp_kern.c +0 -7
@@ -22,13 +22,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_clamp (struct bpf_sock_ops *skops) {
samples/bpf/tcp_cong_kern.c +0 -7
@@ -21,13 +21,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_cong (struct bpf_sock_ops *skops) {
samples/bpf/tcp_iw_kern.c +0 -7
@@ -22,13 +22,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_iw (struct bpf_sock_ops *skops) {
samples/bpf/tcp_rwnd_kern.c +0 -7
@@ -21,13 +21,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_rwnd (struct bpf_sock_ops *skops) {
samples/bpf/tcp_synrto_kern.c +0 -7
@@ -21,13 +21,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_synrto (struct bpf_sock_ops *skops) {
samples/bpf/tcp_tos_reflect_kern.c +0 -7
@@ -20,13 +20,6 @@#define DEBUG 1 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - SEC("sockops")int bpf_basertt (struct bpf_sock_ops *skops) {
samples/bpf/xdp_sample_pkts_kern.c +0 -7
@@ -7,13 +7,6 @@#define SAMPLE_SIZE 64ul#define MAX_CPUS 128 -#define bpf_printk (fmt, ...) \ -({ \ - char ____fmt[] = fmt; \ - bpf_trace_printk(____fmt, sizeof(____fmt), \ - ##__VA_ARGS__); \ -}) - struct bpf_map_def SEC("maps") my_map = { .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, .key_size = sizeof(int),
Signature · 1 line
2.21.0
Quoted 22 lines · Michal Rostecki
This series of patches move the commonly used
bpf_printkmacro tobpf_helpers.hwhich is already included in all BPF programs which defined that macro on their own.
v1->v2:
- IfHBM_DEBUGis not defined in hbm sample, undefinebpf_printkand set an empty macro for it.Michal Rostecki (2):
selftests: bpf: Movebpf_printktobpf_helpers.h
samples: bpf: Do not definebpf_printkmacrosamples/bpf/hbm_kern.h | 11 ++--------- samples/bpf/tcp_basertt_kern.c | 7 ------- samples/bpf/tcp_bufs_kern.c | 7 ------- samples/bpf/tcp_clamp_kern.c | 7 ------- samples/bpf/tcp_cong_kern.c | 7 ------- samples/bpf/tcp_iw_kern.c | 7 ------- samples/bpf/tcp_rwnd_kern.c | 7 ------- samples/bpf/tcp_synrto_kern.c | 7 ------- samples/bpf/tcp_tos_reflect_kern.c | 7 ------- samples/bpf/xdp_sample_pkts_kern.c | 7 -------
Quoted 8 lines
tools/testing/selftests/bpf/bpf_helpers.h | 8 ++++++++ .../testing/selftests/bpf/progs/sockmap_parse_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_tcp_msg_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_verdict_prog.c | 7 ------- .../testing/selftests/bpf/progs/test_lwt_seg6local.c | 7 ------- tools/testing/selftests/bpf/progs/test_xdp_noinline.c | 7 ------- tools/testing/selftests/bpf/test_sockmap_kern.h | 7 ------- 17 files changed, 10 insertions(+), 114 deletions(-)
Ack for the whole series.
Acked-by: Yonghong Song <yhs at fb.com>
Alexei Starovoitov
AppliedQuoted 35 lines · Yonghong Song
Quoted 22 lines · Michal Rostecki
This series of patches move the commonly used
bpf_printkmacro tobpf_helpers.hwhich is already included in all BPF programs which defined that macro on their own.
v1->v2:
- IfHBM_DEBUGis not defined in hbm sample, undefinebpf_printkand set an empty macro for it.Michal Rostecki (2):
selftests: bpf: Movebpf_printktobpf_helpers.h
samples: bpf: Do not definebpf_printkmacrosamples/bpf/hbm_kern.h | 11 ++--------- samples/bpf/tcp_basertt_kern.c | 7 ------- samples/bpf/tcp_bufs_kern.c | 7 ------- samples/bpf/tcp_clamp_kern.c | 7 ------- samples/bpf/tcp_cong_kern.c | 7 ------- samples/bpf/tcp_iw_kern.c | 7 ------- samples/bpf/tcp_rwnd_kern.c | 7 ------- samples/bpf/tcp_synrto_kern.c | 7 ------- samples/bpf/tcp_tos_reflect_kern.c | 7 ------- samples/bpf/xdp_sample_pkts_kern.c | 7 -------Quoted 8 lines
tools/testing/selftests/bpf/bpf_helpers.h | 8 ++++++++ .../testing/selftests/bpf/progs/sockmap_parse_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_tcp_msg_prog.c | 7 ------- .../selftests/bpf/progs/sockmap_verdict_prog.c | 7 ------- .../testing/selftests/bpf/progs/test_lwt_seg6local.c | 7 ------- tools/testing/selftests/bpf/progs/test_xdp_noinline.c | 7 ------- tools/testing/selftests/bpf/test_sockmap_kern.h | 7 ------- 17 files changed, 10 insertions(+), 114 deletions(-)
Quoted 2 lines
Ack for the whole series.
Acked-by: Yonghong Song <yhs at fb.com>
Applied. Thanks