Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf lock contention: Add lock_data.h for common data

Accessing BPF maps should use the same data types. Add bpf_skel/lock_data.h
to define the common data structures. No functional changes.

Committer notes:

Fixed contention_key.stack_id missing rename to contention_key.stack_or_task_id.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Blake Jones <blakejones@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20221209190727.759804-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
fd507d3e 3cad53a6

+39 -29
+6 -13
tools/perf/util/bpf_lock_contention.c
··· 12 12 #include <bpf/bpf.h> 13 13 14 14 #include "bpf_skel/lock_contention.skel.h" 15 + #include "bpf_skel/lock_data.h" 15 16 16 17 static struct lock_contention_bpf *skel; 17 - 18 - struct lock_contention_data { 19 - u64 total_time; 20 - u64 min_time; 21 - u64 max_time; 22 - u32 count; 23 - u32 flags; 24 - }; 25 18 26 19 int lock_contention_prepare(struct lock_contention *con) 27 20 { ··· 103 110 int lock_contention_read(struct lock_contention *con) 104 111 { 105 112 int fd, stack, err = 0; 106 - s32 prev_key, key; 107 - struct lock_contention_data data = {}; 113 + struct contention_key *prev_key, key; 114 + struct contention_data data = {}; 108 115 struct lock_stat *st = NULL; 109 116 struct machine *machine = con->machine; 110 117 u64 *stack_trace; ··· 119 126 if (stack_trace == NULL) 120 127 return -1; 121 128 122 - prev_key = 0; 123 - while (!bpf_map_get_next_key(fd, &prev_key, &key)) { 129 + prev_key = NULL; 130 + while (!bpf_map_get_next_key(fd, prev_key, &key)) { 124 131 struct map *kmap; 125 132 struct symbol *sym; 126 133 int idx = 0; ··· 177 184 } 178 185 179 186 hlist_add_head(&st->hash_entry, con->result); 180 - prev_key = key; 187 + prev_key = &key; 181 188 182 189 /* we're fine now, reset the values */ 183 190 st = NULL;
+3 -16
tools/perf/util/bpf_skel/lock_contention.bpf.c
··· 5 5 #include <bpf/bpf_tracing.h> 6 6 #include <bpf/bpf_core_read.h> 7 7 8 - /* maximum stack trace depth */ 9 - #define MAX_STACKS 8 8 + #include "lock_data.h" 10 9 11 10 /* default buffer size */ 12 11 #define MAX_ENTRIES 10240 13 - 14 - struct contention_key { 15 - __s32 stack_id; 16 - }; 17 - 18 - struct contention_data { 19 - __u64 total_time; 20 - __u64 min_time; 21 - __u64 max_time; 22 - __u32 count; 23 - __u32 flags; 24 - }; 25 12 26 13 struct tstamp_data { 27 14 __u64 timestamp; ··· 21 34 struct { 22 35 __uint(type, BPF_MAP_TYPE_STACK_TRACE); 23 36 __uint(key_size, sizeof(__u32)); 24 - __uint(value_size, MAX_STACKS * sizeof(__u64)); 37 + __uint(value_size, sizeof(__u64)); 25 38 __uint(max_entries, MAX_ENTRIES); 26 39 } stacks SEC(".maps"); 27 40 ··· 141 154 142 155 duration = bpf_ktime_get_ns() - pelem->timestamp; 143 156 144 - key.stack_id = pelem->stack_id; 157 + key.stack_or_task_id = pelem->stack_id; 145 158 data = bpf_map_lookup_elem(&lock_stat, &key); 146 159 if (!data) { 147 160 struct contention_data first = {
+30
tools/perf/util/bpf_skel/lock_data.h
··· 1 + // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + /* Data structures shared between BPF and tools. */ 3 + #ifndef UTIL_BPF_SKEL_LOCK_DATA_H 4 + #define UTIL_BPF_SKEL_LOCK_DATA_H 5 + 6 + struct contention_key { 7 + s32 stack_or_task_id; 8 + }; 9 + 10 + #define TASK_COMM_LEN 16 11 + 12 + struct contention_task_data { 13 + char comm[TASK_COMM_LEN]; 14 + }; 15 + 16 + struct contention_data { 17 + u64 total_time; 18 + u64 min_time; 19 + u64 max_time; 20 + u32 count; 21 + u32 flags; 22 + }; 23 + 24 + enum lock_aggr_mode { 25 + LOCK_AGGR_ADDR = 0, 26 + LOCK_AGGR_TASK, 27 + LOCK_AGGR_CALLER, 28 + }; 29 + 30 + #endif /* UTIL_BPF_SKEL_LOCK_DATA_H */