* [PATCH bpf-next v2 0/2] sample: xdp1 improvements
@ 2018-12-01 0:23 Matteo Croce
2018-12-01 0:23 ` [PATCH bpf-next v2 1/2] samples: bpf: improve xdp1 example Matteo Croce
2018-12-01 6:11 ` [PATCH bpf-next v2 0/2] sample: xdp1 improvements Alexei Starovoitov
0 siblings, 2 replies; 6+ messages in thread
From: Matteo Croce @ 2018-12-01 0:23 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Y Song
Small improvements to improve the readability and easiness
to use of the xdp1 sample.
Matteo Croce (2):
samples: bpf: improve xdp1 example
samples: bpf: get ifindex from ifname
samples/bpf/xdp1_user.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
--
2.19.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf-next v2 1/2] samples: bpf: improve xdp1 example
2018-12-01 0:23 [PATCH bpf-next v2 0/2] sample: xdp1 improvements Matteo Croce
@ 2018-12-01 0:23 ` Matteo Croce
2018-12-01 0:23 ` [PATCH bpf-next v2 2/2] samples: bpf: get ifindex from ifname Matteo Croce
2018-12-01 6:11 ` [PATCH bpf-next v2 0/2] sample: xdp1 improvements Alexei Starovoitov
1 sibling, 1 reply; 6+ messages in thread
From: Matteo Croce @ 2018-12-01 0:23 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Y Song
Store only the total packet count for every protocol, instead of the
whole per-cpu array.
Use bpf_map_get_next_key() to iterate the map, instead of looking up
all the protocols.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
samples/bpf/xdp1_user.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index b02c531510ed..4f3d824fc044 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -34,26 +34,24 @@ static void int_exit(int sig)
static void poll_stats(int map_fd, int interval)
{
unsigned int nr_cpus = bpf_num_possible_cpus();
- const unsigned int nr_keys = 256;
- __u64 values[nr_cpus], prev[nr_keys][nr_cpus];
- __u32 key;
+ __u64 values[nr_cpus], prev[UINT8_MAX] = { 0 };
int i;
- memset(prev, 0, sizeof(prev));
-
while (1) {
+ __u32 key = UINT32_MAX;
+
sleep(interval);
- for (key = 0; key < nr_keys; key++) {
+ while (bpf_map_get_next_key(map_fd, &key, &key) != -1) {
__u64 sum = 0;
assert(bpf_map_lookup_elem(map_fd, &key, values) == 0);
for (i = 0; i < nr_cpus; i++)
- sum += (values[i] - prev[key][i]);
- if (sum)
+ sum += values[i];
+ if (sum > prev[key])
printf("proto %u: %10llu pkt/s\n",
- key, sum / interval);
- memcpy(prev[key], values, sizeof(values));
+ key, (sum - prev[key]) / interval);
+ prev[key] = sum;
}
}
}
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf-next v2 2/2] samples: bpf: get ifindex from ifname
2018-12-01 0:23 ` [PATCH bpf-next v2 1/2] samples: bpf: improve xdp1 example Matteo Croce
@ 2018-12-01 0:23 ` Matteo Croce
0 siblings, 0 replies; 6+ messages in thread
From: Matteo Croce @ 2018-12-01 0:23 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Y Song
Find the ifindex with if_nametoindex() instead of requiring the
numeric ifindex.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
v2: use if_nametoindex() instead of ioctl()
samples/bpf/xdp1_user.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index 4f3d824fc044..0a197f86ac43 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <libgen.h>
#include <sys/resource.h>
+#include <net/if.h>
#include "bpf_util.h"
#include "bpf/bpf.h"
@@ -59,7 +60,7 @@ static void poll_stats(int map_fd, int interval)
static void usage(const char *prog)
{
fprintf(stderr,
- "usage: %s [OPTS] IFINDEX\n\n"
+ "usage: %s [OPTS] IFACE\n\n"
"OPTS:\n"
" -S use skb-mode\n"
" -N enforce native mode\n",
@@ -102,7 +103,11 @@ int main(int argc, char **argv)
return 1;
}
- ifindex = strtoul(argv[optind], NULL, 0);
+ ifindex = if_nametoindex(argv[1]);
+ if (!ifindex) {
+ perror("if_nametoindex");
+ return 1;
+ }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
--
2.19.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v2 0/2] sample: xdp1 improvements
2018-12-01 0:23 [PATCH bpf-next v2 0/2] sample: xdp1 improvements Matteo Croce
2018-12-01 0:23 ` [PATCH bpf-next v2 1/2] samples: bpf: improve xdp1 example Matteo Croce
@ 2018-12-01 6:11 ` Alexei Starovoitov
2018-12-02 2:23 ` Matteo Croce
1 sibling, 1 reply; 6+ messages in thread
From: Alexei Starovoitov @ 2018-12-01 6:11 UTC (permalink / raw)
To: Matteo Croce
Cc: netdev, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Y Song
On Sat, Dec 01, 2018 at 01:23:04AM +0100, Matteo Croce wrote:
> Small improvements to improve the readability and easiness
> to use of the xdp1 sample.
Applied to bpf-next.
I think that sample code could be more useful if it's wrapped with bash
script like selftests/test_xdp* tests do.
At that point it can move to selftests to get 0bot coverage.
Would you be interested in doing that?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v2 0/2] sample: xdp1 improvements
2018-12-01 6:11 ` [PATCH bpf-next v2 0/2] sample: xdp1 improvements Alexei Starovoitov
@ 2018-12-02 2:23 ` Matteo Croce
2018-12-03 23:00 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Matteo Croce @ 2018-12-02 2:23 UTC (permalink / raw)
To: alexei.starovoitov
Cc: netdev, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
Y Song
On Sat, Dec 1, 2018 at 6:11 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Sat, Dec 01, 2018 at 01:23:04AM +0100, Matteo Croce wrote:
> > Small improvements to improve the readability and easiness
> > to use of the xdp1 sample.
>
> Applied to bpf-next.
>
> I think that sample code could be more useful if it's wrapped with bash
> script like selftests/test_xdp* tests do.
> At that point it can move to selftests to get 0bot coverage.
> Would you be interested in doing that?
>
It would be nice, but I think that the samples have more urgent issues
right now.
Many examples doesn't compile on my system (Fedora 29, GCC 8.2.1, Clang 7.0.0),
these are the errors that I encounter:
HOSTCC /home/matteo/src/kernel/linux/samples/bpf/test_lru_dist
/home/matteo/src/kernel/linux/samples/bpf/test_lru_dist.c:39:8: error:
redefinition of ‘struct list_head’
struct list_head {
^~~~~~~~~
HOSTCC /home/matteo/src/kernel/linux/samples/bpf/sock_example
In file included from
/home/matteo/src/kernel/linux/samples/bpf/sock_example.c:27:
/usr/include/linux/ip.h:102:2: error: unknown type name ‘__sum16’
__sum16 check;
^~~~~~~
HOSTCC /home/matteo/src/kernel/linux/samples/bpf/tracex5_user.o
/home/matteo/src/kernel/linux/samples/bpf/tracex5_user.c: In function
‘install_accept_all_seccomp’:
/home/matteo/src/kernel/linux/samples/bpf/tracex5_user.c:17:21: error:
array type has incomplete element type ‘struct sock_filter’
struct sock_filter filter[] = {
^~~~~~
HOSTCC /home/matteo/src/kernel/linux/samples/bpf/test_cgrp2_attach2.o
/home/matteo/src/kernel/linux/samples/bpf/test_cgrp2_attach2.c: In
function ‘prog_load_cnt’:
/home/matteo/src/kernel/linux/samples/bpf/test_cgrp2_attach2.c:229:3:
error: ‘BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE’ undeclared (first use in
this function); did you mean ‘BPF_MAP_TYPE_CGROUP_STORAGE’?
BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HOSTCC /home/matteo/src/kernel/linux/samples/bpf/xdpsock_user.o
/home/matteo/src/kernel/linux/samples/bpf/xdpsock_user.c:59:15: error:
conflicting types for ‘u64’
typedef __u64 u64;
^~~
To be able to compile the samples, I temporarily removed them from the
compilation this way:
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index be0a961450bc..33d7161f2231 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -4,8 +4,6 @@ BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
# List of programs to build
-hostprogs-y := test_lru_dist
-hostprogs-y += sock_example
hostprogs-y += fds_example
hostprogs-y += sockex1
hostprogs-y += sockex2
@@ -14,7 +12,6 @@ hostprogs-y += tracex1
hostprogs-y += tracex2
hostprogs-y += tracex3
hostprogs-y += tracex4
-hostprogs-y += tracex5
hostprogs-y += tracex6
hostprogs-y += tracex7
hostprogs-y += test_probe_write_user
@@ -26,7 +23,6 @@ hostprogs-y += map_perf_test
hostprogs-y += test_overhead
hostprogs-y += test_cgrp2_array_pin
hostprogs-y += test_cgrp2_attach
-hostprogs-y += test_cgrp2_attach2
hostprogs-y += test_cgrp2_sock
hostprogs-y += test_cgrp2_sock2
hostprogs-y += xdp1
@@ -49,7 +45,6 @@ hostprogs-y += xdp_rxq_info
hostprogs-y += syscall_tp
hostprogs-y += cpustat
hostprogs-y += xdp_adjust_tail
-hostprogs-y += xdpsock
hostprogs-y += xdp_fwd
hostprogs-y += task_fd_query
hostprogs-y += xdp_sample_pkts
Regards,
--
Matteo Croce
per aspera ad upstream
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v2 0/2] sample: xdp1 improvements
2018-12-02 2:23 ` Matteo Croce
@ 2018-12-03 23:00 ` Jakub Kicinski
0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2018-12-03 23:00 UTC (permalink / raw)
To: alexei.starovoitov, Daniel Borkmann
Cc: Matteo Croce, netdev, Alexei Starovoitov, John Fastabend, Y Song
On Sun, 2 Dec 2018 02:23:41 +0000, Matteo Croce wrote:
> On Sat, Dec 1, 2018 at 6:11 AM Alexei Starovoitov wrote:
> >
> > On Sat, Dec 01, 2018 at 01:23:04AM +0100, Matteo Croce wrote:
> > > Small improvements to improve the readability and easiness
> > > to use of the xdp1 sample.
> >
> > Applied to bpf-next.
> >
> > I think that sample code could be more useful if it's wrapped with bash
> > script like selftests/test_xdp* tests do.
> > At that point it can move to selftests to get 0bot coverage.
> > Would you be interested in doing that?
> >
>
> It would be nice, but I think that the samples have more urgent issues
> right now.
> Many examples doesn't compile on my system (Fedora 29, GCC 8.2.1, Clang 7.0.0),
> these are the errors that I encounter:
>
> HOSTCC /home/matteo/src/kernel/linux/samples/bpf/test_lru_dist
> /home/matteo/src/kernel/linux/samples/bpf/test_lru_dist.c:39:8: error:
> redefinition of ‘struct list_head’
> struct list_head {
> ^~~~~~~~~
I wonder if there is a way to catch that, and print "run make
headers_install, please" rather than confuse newcomers. Hm..
Like this?
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 35444f4a846b..b1fdea806d4d 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -205,6 +205,15 @@ HOSTCC = $(CROSS_COMPILE)gcc
CLANG_ARCH_ARGS = -target $(ARCH)
endif
+HDR_PROBE := $(shell echo "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
+ gcc $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
+ echo okay)
+
+ifeq ($(HDR_PROBE),)
+$(warning Detected possible issues with include path.)
+$(warning Please install kernel headers locally (make headers_install))
+endif
+
BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-12-03 23:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-01 0:23 [PATCH bpf-next v2 0/2] sample: xdp1 improvements Matteo Croce
2018-12-01 0:23 ` [PATCH bpf-next v2 1/2] samples: bpf: improve xdp1 example Matteo Croce
2018-12-01 0:23 ` [PATCH bpf-next v2 2/2] samples: bpf: get ifindex from ifname Matteo Croce
2018-12-01 6:11 ` [PATCH bpf-next v2 0/2] sample: xdp1 improvements Alexei Starovoitov
2018-12-02 2:23 ` Matteo Croce
2018-12-03 23:00 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).