]> asedeno.scripts.mit.edu Git - linux.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)
commitf3515b5d0b718cceae9e67802cfa20d5e6f9b567
treef36c473e0e53ef2018334abd8cffcf42b4dd70b6
parent43bcf707ccdc79ee63edb953fcf72e6dc244cfa1
bpf: provide a generic macro for percpu values for selftests

To overcome bugs as described and fixed in 89087c456fb5 ("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