Skip to content

Commit

Permalink
perf lock contention: Handle error in a single place
Browse files Browse the repository at this point in the history
It has some duplicate codes to do the same job.  Let's add a label and
goto there to handle errors in a single place.

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-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
namhyung authored and acmel committed Aug 30, 2024
1 parent ccb9004 commit 10d6c57
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions tools/perf/util/bpf_skel/lock_contention.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,8 @@ int contention_end(u64 *ctx)

duration = bpf_ktime_get_ns() - pelem->timestamp;
if ((__s64)duration < 0) {
pelem->lock = 0;
if (need_delete)
bpf_map_delete_elem(&tstamp, &pid);
__sync_fetch_and_add(&time_fail, 1);
return 0;
goto out;
}

switch (aggr_mode) {
Expand Down Expand Up @@ -477,11 +474,8 @@ int contention_end(u64 *ctx)
data = bpf_map_lookup_elem(&lock_stat, &key);
if (!data) {
if (data_map_full) {
pelem->lock = 0;
if (need_delete)
bpf_map_delete_elem(&tstamp, &pid);
__sync_fetch_and_add(&data_fail, 1);
return 0;
goto out;
}

struct contention_data first = {
Expand All @@ -502,10 +496,7 @@ int contention_end(u64 *ctx)
data_map_full = 1;
__sync_fetch_and_add(&data_fail, 1);
}
pelem->lock = 0;
if (need_delete)
bpf_map_delete_elem(&tstamp, &pid);
return 0;
goto out;
}

__sync_fetch_and_add(&data->total_time, duration);
Expand All @@ -517,6 +508,7 @@ int contention_end(u64 *ctx)
if (data->min_time > duration)
data->min_time = duration;

out:
pelem->lock = 0;
if (need_delete)
bpf_map_delete_elem(&tstamp, &pid);
Expand Down

0 comments on commit 10d6c57

Please sign in to comment.