Loading samples/bpf/tracex2_kern.c +1 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ struct hist_key { }; struct bpf_map_def SEC("maps") my_hist_map = { .type = BPF_MAP_TYPE_HASH, .type = BPF_MAP_TYPE_PERCPU_HASH, .key_size = sizeof(struct hist_key), .value_size = sizeof(long), .max_entries = 1024, Loading samples/bpf/tracex2_user.c +6 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ struct hist_key { static void print_hist_for_pid(int fd, void *task) { struct hist_key key = {}, next_key; unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); long values[nr_cpus]; char starstr[MAX_STARS]; long value; long data[MAX_INDEX] = {}; Loading @@ -49,7 +51,10 @@ static void print_hist_for_pid(int fd, void *task) key = next_key; continue; } bpf_lookup_elem(fd, &next_key, &value); bpf_lookup_elem(fd, &next_key, values); value = 0; for (i = 0; i < nr_cpus; i++) value += values[i]; ind = next_key.index; data[ind] = value; if (value && ind > max_ind) Loading samples/bpf/tracex3_kern.c +4 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ struct bpf_map_def SEC("maps") my_map = { /* kprobe is NOT a stable ABI. If kernel internals change this bpf+kprobe * example will no longer be meaningful */ SEC("kprobe/blk_mq_start_request") SEC("kprobe/blk_start_request") int bpf_prog1(struct pt_regs *ctx) { long rq = PT_REGS_PARM1(ctx); Loading @@ -42,13 +42,13 @@ static unsigned int log2l(unsigned long long n) #define SLOTS 100 struct bpf_map_def SEC("maps") lat_map = { .type = BPF_MAP_TYPE_ARRAY, .type = BPF_MAP_TYPE_PERCPU_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(u64), .max_entries = SLOTS, }; SEC("kprobe/blk_update_request") SEC("kprobe/blk_account_io_completion") int bpf_prog2(struct pt_regs *ctx) { long rq = PT_REGS_PARM1(ctx); Loading Loading @@ -81,7 +81,7 @@ int bpf_prog2(struct pt_regs *ctx) value = bpf_map_lookup_elem(&lat_map, &index); if (value) __sync_fetch_and_add((long *)value, 1); *value += 1; return 0; } Loading samples/bpf/tracex3_user.c +14 −7 Original line number Diff line number Diff line Loading @@ -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[] = { Loading Loading @@ -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) Loading Loading
samples/bpf/tracex2_kern.c +1 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ struct hist_key { }; struct bpf_map_def SEC("maps") my_hist_map = { .type = BPF_MAP_TYPE_HASH, .type = BPF_MAP_TYPE_PERCPU_HASH, .key_size = sizeof(struct hist_key), .value_size = sizeof(long), .max_entries = 1024, Loading
samples/bpf/tracex2_user.c +6 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,8 @@ struct hist_key { static void print_hist_for_pid(int fd, void *task) { struct hist_key key = {}, next_key; unsigned int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); long values[nr_cpus]; char starstr[MAX_STARS]; long value; long data[MAX_INDEX] = {}; Loading @@ -49,7 +51,10 @@ static void print_hist_for_pid(int fd, void *task) key = next_key; continue; } bpf_lookup_elem(fd, &next_key, &value); bpf_lookup_elem(fd, &next_key, values); value = 0; for (i = 0; i < nr_cpus; i++) value += values[i]; ind = next_key.index; data[ind] = value; if (value && ind > max_ind) Loading
samples/bpf/tracex3_kern.c +4 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ struct bpf_map_def SEC("maps") my_map = { /* kprobe is NOT a stable ABI. If kernel internals change this bpf+kprobe * example will no longer be meaningful */ SEC("kprobe/blk_mq_start_request") SEC("kprobe/blk_start_request") int bpf_prog1(struct pt_regs *ctx) { long rq = PT_REGS_PARM1(ctx); Loading @@ -42,13 +42,13 @@ static unsigned int log2l(unsigned long long n) #define SLOTS 100 struct bpf_map_def SEC("maps") lat_map = { .type = BPF_MAP_TYPE_ARRAY, .type = BPF_MAP_TYPE_PERCPU_ARRAY, .key_size = sizeof(u32), .value_size = sizeof(u64), .max_entries = SLOTS, }; SEC("kprobe/blk_update_request") SEC("kprobe/blk_account_io_completion") int bpf_prog2(struct pt_regs *ctx) { long rq = PT_REGS_PARM1(ctx); Loading Loading @@ -81,7 +81,7 @@ int bpf_prog2(struct pt_regs *ctx) value = bpf_map_lookup_elem(&lat_map, &index); if (value) __sync_fetch_and_add((long *)value, 1); *value += 1; return 0; } Loading
samples/bpf/tracex3_user.c +14 −7 Original line number Diff line number Diff line Loading @@ -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[] = { Loading Loading @@ -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) Loading