mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
perf lock contention: Do not fail EEXIST for update
When it updates the lock stat for the first time, it needs to create an element in the BPF hash map. But if there's a concurrent thread waiting for the same lock (like for rwsem or rwlock), it might race with the thread and possibly fail to update with -EEXIST. In that case, it can lookup the map again and put the data there instead of failing. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <song@kernel.org> Cc: bpf@vger.kernel.org Link: https://lore.kernel.org/r/20240830065150.1758962-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
05a5dd1dfd
commit
36cddd1056
|
|
@ -491,6 +491,12 @@ int contention_end(u64 *ctx)
|
|||
|
||||
err = bpf_map_update_elem(&lock_stat, &key, &first, BPF_NOEXIST);
|
||||
if (err < 0) {
|
||||
if (err == -EEXIST) {
|
||||
/* it lost the race, try to get it again */
|
||||
data = bpf_map_lookup_elem(&lock_stat, &key);
|
||||
if (data != NULL)
|
||||
goto found;
|
||||
}
|
||||
if (err == -E2BIG)
|
||||
data_map_full = 1;
|
||||
__sync_fetch_and_add(&data_fail, 1);
|
||||
|
|
@ -498,6 +504,7 @@ int contention_end(u64 *ctx)
|
|||
goto out;
|
||||
}
|
||||
|
||||
found:
|
||||
__sync_fetch_and_add(&data->total_time, duration);
|
||||
__sync_fetch_and_add(&data->count, 1);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user