Thread (5 messages) 5 messages, 3 authors, 2019-10-20

Re: [PATCH bpf v2] xsk: improve documentation for AF_XDP

From: Magnus Karlsson <hidden>
Date: 2019-10-20 08:14:03
Also in: bpf, linux-doc

On Sat, Oct 19, 2019 at 11:48 AM Alexei Starovoitov
[off-list ref] wrote:
On Fri, Oct 18, 2019 at 11:33:40AM +0200, Magnus Karlsson wrote:
quoted
+
+   #include <linux/bpf.h>
+   #include "bpf_helpers.h"
+
+   #define MAX_SOCKS 16
+
+   struct {
+        __uint(type, BPF_MAP_TYPE_XSKMAP);
+        __uint(max_entries, MAX_SOCKS);
+        __uint(key_size, sizeof(int));
+        __uint(value_size, sizeof(int));
+   } xsks_map SEC(".maps");
+
+   struct {
+        __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+        __uint(max_entries, 1);
+        __type(key, int);
+        __type(value, unsigned int);
+   } rr_map SEC(".maps");
hmm. does xsks_map compile?
Yes. Actually, I wrote a new sample to demonstrate this feature and to
test the code above. I will send that patch set (contains some small
additions to libbpf also to be able to support this) to bpf-next.
Though, if I used the __type declarations of the rr_map PERCPU_ARRAY I
got this warning: "pr_warning("Error in
bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n")", so I had
to change it to the type above that is also used for SOCKMAP. Some
enablement that is missing for XSKMAP? Have not dug into it.
quoted
+
+   SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
+   {
+     int key = 0, idx;
+     unsigned int *rr;
+
+     rr = bpf_map_lookup_elem(&rr_map, &key);
+     if (!rr)
+        return XDP_ABORTED;
could you please use global data and avoid lookup?
The run-time will be much faster.
Good idea. Will do and change the new sample app too.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help