From 79a79e7b9b4a764cb7bf41744cf23962b2dc6bed Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sat, 3 Mar 2018 00:30:32 +0100 Subject: [PATCH] bpf: print numa_node using xlat As the value of -1 has a special meaning. The issue is complicated by the fact that this constant is not exported by UAPI. * xlat/numa_node.in: New file. * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Print numa_node field using printxvals_ex with a special xlat style. --- bpf.c | 19 +++++++++++++++++-- xlat/numa_node.in | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 xlat/numa_node.in diff --git a/bpf.c b/bpf.c index f45973dd..8d694240 100644 --- a/bpf.c +++ b/bpf.c @@ -46,6 +46,7 @@ #include "xlat/bpf_attach_type.h" #include "xlat/bpf_attach_flags.h" #include "xlat/bpf_query_flags.h" +#include "xlat/numa_node.h" /** Storage for all the data that is needed to be stored on entering. */ struct bpf_priv_data { @@ -134,8 +135,22 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE) PRINT_FIELD_U(", ", attr, max_entries); PRINT_FIELD_FLAGS(", ", attr, map_flags, bpf_map_flags, "BPF_F_???"); PRINT_FIELD_FD(", ", attr, inner_map_fd, tcp); - if (attr.map_flags & BPF_F_NUMA_NODE) - PRINT_FIELD_U(", ", attr, numa_node); + if (attr.map_flags & BPF_F_NUMA_NODE) { + /* + * Kernel uses the value of -1 as a designation for "no NUMA + * node specified", and even uses NUMA_NO_NODE constant; + * however, the constant definition is not a part of UAPI + * headers, thus we can't simply print this named constant + * instead of the value. Let's force verbose xlat style instead + * in order to provide the information for the user while + * not hampering the availability to derive the actual value + * without the access to the kernel headers. + */ + tprints(", numa_node="); + printxvals_ex(attr.numa_node, NULL, + XLAT_STYLE_FMT_U | XLAT_STYLE_VERBOSE, + numa_node, NULL); + } } END_BPF_CMD_DECODER(RVAL_DECODED | RVAL_FD) diff --git a/xlat/numa_node.in b/xlat/numa_node.in new file mode 100644 index 00000000..414b35a9 --- /dev/null +++ b/xlat/numa_node.in @@ -0,0 +1 @@ +NUMA_NO_NODE -1U -- 2.40.0