diff options
author | Alexei Starovoitov <ast@fb.com> | 2016-02-02 01:39:58 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-02-06 03:34:36 -0500 |
commit | 3059303f59cf90a84e7fdef154ff0b215bcfaa97 (patch) | |
tree | bacdf1b8025256fc591b1fd935a99f0b6af7466f /samples/bpf/tracex3_user.c | |
parent | df570f577231407d929bdc6f59ae2f53e0028e8a (diff) |
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 @@ | |||
20 | 20 | ||
21 | static void clear_stats(int fd) | 21 | static void clear_stats(int fd) |
22 | { | 22 | { |
23 | unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); | ||
24 | __u64 values[nr_cpus]; | ||
23 | __u32 key; | 25 | __u32 key; |
24 | __u64 value = 0; | ||
25 | 26 | ||
27 | memset(values, 0, sizeof(values)); | ||
26 | for (key = 0; key < SLOTS; key++) | 28 | for (key = 0; key < SLOTS; key++) |
27 | bpf_update_elem(fd, &key, &value, BPF_ANY); | 29 | bpf_update_elem(fd, &key, values, BPF_ANY); |
28 | } | 30 | } |
29 | 31 | ||
30 | const char *color[] = { | 32 | const char *color[] = { |
@@ -75,15 +77,20 @@ static void print_banner(void) | |||
75 | 77 | ||
76 | static void print_hist(int fd) | 78 | static void print_hist(int fd) |
77 | { | 79 | { |
78 | __u32 key; | 80 | unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); |
79 | __u64 value; | ||
80 | __u64 cnt[SLOTS]; | ||
81 | __u64 max_cnt = 0; | ||
82 | __u64 total_events = 0; | 81 | __u64 total_events = 0; |
82 | long values[nr_cpus]; | ||
83 | __u64 max_cnt = 0; | ||
84 | __u64 cnt[SLOTS]; | ||
85 | __u64 value; | ||
86 | __u32 key; | ||
87 | int i; | ||
83 | 88 | ||
84 | for (key = 0; key < SLOTS; key++) { | 89 | for (key = 0; key < SLOTS; key++) { |
90 | bpf_lookup_elem(fd, &key, values); | ||
85 | value = 0; | 91 | value = 0; |
86 | bpf_lookup_elem(fd, &key, &value); | 92 | for (i = 0; i < nr_cpus; i++) |
93 | value += values[i]; | ||
87 | cnt[key] = value; | 94 | cnt[key] = value; |
88 | total_events += value; | 95 | total_events += value; |
89 | if (value > max_cnt) | 96 | if (value > max_cnt) |