Skip to content

Commit

Permalink
perf tools: Ignore deleted cgroups
Browse files Browse the repository at this point in the history
On large systems, cgroups can be created and deleted often.  That means
there's a race between perf tools and cgroups when it gets the cgroup
name and opens the cgroup.

I got a report that 'perf stat' with many cgroups failed quite often due
to the missing cgroups on such a large machine.

I think we can ignore such cgroups when expanding events and use id 0 if
it fails to read the cgroup id.  IIUC 0 is not a vaild cgroup id so it
won't update event counts for the failed cgroups.

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>
Link: https://lore.kernel.org/r/20240509182235.2319599-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 10, 2024
1 parent 5ceb579 commit e2eeef2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions tools/perf/util/bpf_counter_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ static int bperf_load_program(struct evlist *evlist)
cgrp = evsel->cgrp;

if (read_cgroup_id(cgrp) < 0) {
pr_err("Failed to get cgroup id\n");
err = -1;
goto out;
pr_debug("Failed to get cgroup id for %s\n", cgrp->name);
cgrp->id = 0;
}

map_fd = bpf_map__fd(skel->maps.cgrp_idx);
Expand Down
4 changes: 3 additions & 1 deletion tools/perf/util/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str,
name = cn->name + prefix_len;
if (name[0] == '/' && name[1])
name++;

/* the cgroup can go away in the meantime */
cgrp = cgroup__new(name, open_cgroup);
if (cgrp == NULL)
goto out_err;
continue;

leader = NULL;
evlist__for_each_entry(orig_list, pos) {
Expand Down

0 comments on commit e2eeef2

Please sign in to comment.