diff options
author | Alexei Starovoitov <ast@fb.com> | 2016-02-02 07:39:58 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-02-06 09:34:36 +0100 |
commit | 3059303f59cf90a84e7fdef154ff0b215bcfaa97 (patch) | |
tree | bacdf1b8025256fc591b1fd935a99f0b6af7466f /samples/bpf/tracex3_user.c | |
parent | samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_ARRAY (diff) | |
download | linux-3059303f59cf90a84e7fdef154ff0b215bcfaa97.tar.xz linux-3059303f59cf90a84e7fdef154ff0b215bcfaa97.zip |
samples/bpf: update tracex[23] examples to use per-cpu maps
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/tracex3_user.c')
-rw-r--r-- | samples/bpf/tracex3_user.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/samples/bpf/tracex3_user.c b/samples/bpf/tracex3_user.c index 0aaa933ab938..48716f7f0d8b 100644 --- a/samples/bpf/tracex3_user.c +++ b/samples/bpf/tracex3_user.c @@ -20,11 +20,13 @@ static void clear_stats(int fd) { + unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); + __u64 values[nr_cpus]; __u32 key; - __u64 value = 0; + memset(values, 0, sizeof(values)); for (key = 0; key < SLOTS; key++) - bpf_update_elem(fd, &key, &value, BPF_ANY); + bpf_update_elem(fd, &key, values, BPF_ANY); } const char *color[] = { @@ -75,15 +77,20 @@ static void print_banner(void) static void print_hist(int fd) { - __u32 key; - __u64 value; - __u64 cnt[SLOTS]; - __u64 max_cnt = 0; + unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); __u64 total_events = 0; + long values[nr_cpus]; + __u64 max_cnt = 0; + __u64 cnt[SLOTS]; + __u64 value; + __u32 key; + int i; for (key = 0; key < SLOTS; key++) { + bpf_lookup_elem(fd, &key, values); value = 0; - bpf_lookup_elem(fd, &key, &value); + for (i = 0; i < nr_cpus; i++) + value += values[i]; cnt[key] = value; total_events += value; if (value > max_cnt) |