Skip to content

Commit 6d499a6

Browse files
namhyungacmel
authored andcommitted
perf lock: Print the number of lost entries for BPF
Like the normal 'perf lock contention' output, it'd print the number of lost entries for BPF if exists or -v option is passed. Currently it uses BROKEN_CONTENDED stat for the lost count (due to full stack maps). $ sudo perf lock con -a -b --map-nr-entries 128 sleep 5 ... === output for debug=== bad: 43, total: 14903 bad rate: 0.29 % histogram of events caused bad sequence acquire: 0 acquired: 0 contended: 43 release: 0 Signed-off-by: Namhyung Kim <[email protected]> Cc: Blake Jones <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Waiman Long <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ceb13bf commit 6d499a6

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

tools/perf/builtin-lock.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,11 @@ static void print_contention_result(void)
14721472
pr_info(" %10s %s\n\n", "type", "caller");
14731473

14741474
bad = total = 0;
1475+
if (use_bpf)
1476+
bad = bad_hist[BROKEN_CONTENDED];
1477+
14751478
while ((st = pop_from_result())) {
1476-
total++;
1479+
total += use_bpf ? st->nr_contended : 1;
14771480
if (st->broken)
14781481
bad++;
14791482

@@ -1687,6 +1690,9 @@ static int __cmd_contention(int argc, const char **argv)
16871690

16881691
lock_contention_stop();
16891692
lock_contention_read(&con);
1693+
1694+
/* abuse bad hist stats for lost entries */
1695+
bad_hist[BROKEN_CONTENDED] = con.lost;
16901696
} else {
16911697
err = perf_session__process_events(session);
16921698
if (err)

tools/perf/util/bpf_lock_contention.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static struct lock_contention_bpf *skel;
1616

1717
/* should be same as bpf_skel/lock_contention.bpf.c */
1818
struct lock_contention_key {
19-
u32 stack_id;
19+
s32 stack_id;
2020
};
2121

2222
struct lock_contention_data {
@@ -110,7 +110,7 @@ int lock_contention_stop(void)
110110
int lock_contention_read(struct lock_contention *con)
111111
{
112112
int fd, stack;
113-
u32 prev_key, key;
113+
s32 prev_key, key;
114114
struct lock_contention_data data;
115115
struct lock_stat *st;
116116
struct machine *machine = con->machine;
@@ -119,6 +119,8 @@ int lock_contention_read(struct lock_contention *con)
119119
fd = bpf_map__fd(skel->maps.lock_stat);
120120
stack = bpf_map__fd(skel->maps.stacks);
121121

122+
con->lost = skel->bss->lost;
123+
122124
prev_key = 0;
123125
while (!bpf_map_get_next_key(fd, &prev_key, &key)) {
124126
struct map *kmap;

tools/perf/util/bpf_skel/lock_contention.bpf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define MAX_ENTRIES 10240
1313

1414
struct contention_key {
15-
__u32 stack_id;
15+
__s32 stack_id;
1616
};
1717

1818
struct contention_data {
@@ -27,7 +27,7 @@ struct tstamp_data {
2727
__u64 timestamp;
2828
__u64 lock;
2929
__u32 flags;
30-
__u32 stack_id;
30+
__s32 stack_id;
3131
};
3232

3333
/* callstack storage */
@@ -73,6 +73,9 @@ int enabled;
7373
int has_cpu;
7474
int has_task;
7575

76+
/* error stat */
77+
unsigned long lost;
78+
7679
static inline int can_record(void)
7780
{
7881
if (has_cpu) {
@@ -116,6 +119,8 @@ int contention_begin(u64 *ctx)
116119
pelem->flags = (__u32)ctx[1];
117120
pelem->stack_id = bpf_get_stackid(ctx, &stacks, BPF_F_FAST_STACK_CMP);
118121

122+
if (pelem->stack_id < 0)
123+
lost++;
119124
return 0;
120125
}
121126

tools/perf/util/lock-contention.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct lock_contention {
113113
struct machine *machine;
114114
struct hlist_head *result;
115115
unsigned long map_nr_entries;
116+
unsigned long lost;
116117
};
117118

118119
#ifdef HAVE_BPF_SKEL

0 commit comments

Comments
 (0)