]> git.itanic.dy.fi Git - linux-stable/commit
perf lock contention: Clear lock addr after use
authorNamhyung Kim <namhyung@kernel.org>
Fri, 20 Oct 2023 20:47:39 +0000 (13:47 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 25 Oct 2023 17:02:34 +0000 (10:02 -0700)
commitd99317f214ca3d381f7b17a75c41263885664e06
tree3cbd12b10993be639766354b360519081709388e
parente093a222d7cba1eb6c36887e58ce8a4ff249f1c6
perf lock contention: Clear lock addr after use

It checks the current lock to calculated the delta of contention time.
The address is saved in the tstamp map which is allocated at begining of
contention and released at end of contention.

But it's possible for bpf_map_delete_elem() to fail.  In that case, the
element in the tstamp map kept for the current lock and it makes the
next contention for the same lock tracked incorrectly.  Specificially
the next contention begin will see the existing element for the task and
it'd just return.  Then the next contention end will see the element and
calculate the time using the timestamp for the previous begin.

This can result in a large value for two small contentions happened from
time to time.  Let's clear the lock address so that it can be updated
next time even if the bpf_map_delete_elem() failed.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20231020204741.1869520-1-namhyung@kernel.org
tools/perf/util/bpf_skel/lock_contention.bpf.c