]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: provide a generic macro for percpu values for selftests
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 26 Apr 2017 23:39:35 +0000 (01:39 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Apr 2017 19:48:15 +0000 (15:48 -0400)
commit293baf9fb502698678eea22ded20d19e1f9e9ee7
treef36c473e0e53ef2018334abd8cffcf42b4dd70b6
parentd08550c0e0616d4098ff5b39a4d4d179dfdd3a74
bpf: provide a generic macro for percpu values for selftests

To overcome bugs as described and fixed in c6878714ac1a ("bpf: Fix
values type used in test_maps"), provide a generic BPF_DECLARE_PERCPU()
and bpf_percpu() accessor macro for all percpu map values used in
tests.

Declaring variables works as follows (also works for structs):

  BPF_DECLARE_PERCPU(uint32_t, my_value);

They can then be accessed normally as uint32_t type through:

  bpf_percpu(my_value, <cpu_nr>)

For example:

  bpf_percpu(my_value, 0)++;

Implicitly, we make sure that the passed type is allocated and aligned
by gcc at least on a 8-byte boundary, so that it works together with
the map lookup/update syscall for percpu maps. We use it as a usage
example in test_maps, so that others are free to adapt this into their
code when necessary.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/bpf/bpf_util.h
tools/testing/selftests/bpf/test_maps.c