Skip to content

Commit 89fb1ca

Browse files
namhyungacmel
authored andcommitted
perf tools: Allow creation of cgroup without open
This is a preparation for a test case of expanding events for multiple cgroups. Instead of using real system cgroup, the test will use fake cgroups so it needs a way to have them without a open file descriptor. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20200924124455.336326-5-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent b214ba8 commit 89fb1ca

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎tools/perf/builtin-stat.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ int cmd_stat(int argc, const char **argv)
22352235
}
22362236

22372237
if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list,
2238-
&stat_config.metric_events) < 0)
2238+
&stat_config.metric_events, true) < 0)
22392239
goto out;
22402240
}
22412241

‎tools/perf/util/cgroup.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static struct cgroup *evlist__find_cgroup(struct evlist *evlist, const char *str
5151
return NULL;
5252
}
5353

54-
static struct cgroup *cgroup__new(const char *name)
54+
static struct cgroup *cgroup__new(const char *name, bool do_open)
5555
{
5656
struct cgroup *cgroup = zalloc(sizeof(*cgroup));
5757

@@ -61,9 +61,14 @@ static struct cgroup *cgroup__new(const char *name)
6161
cgroup->name = strdup(name);
6262
if (!cgroup->name)
6363
goto out_err;
64-
cgroup->fd = open_cgroup(name);
65-
if (cgroup->fd == -1)
66-
goto out_free_name;
64+
65+
if (do_open) {
66+
cgroup->fd = open_cgroup(name);
67+
if (cgroup->fd == -1)
68+
goto out_free_name;
69+
} else {
70+
cgroup->fd = -1;
71+
}
6772
}
6873

6974
return cgroup;
@@ -79,7 +84,7 @@ struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name)
7984
{
8085
struct cgroup *cgroup = evlist__find_cgroup(evlist, name);
8186

82-
return cgroup ?: cgroup__new(name);
87+
return cgroup ?: cgroup__new(name, true);
8388
}
8489

8590
static int add_cgroup(struct evlist *evlist, const char *str)
@@ -197,7 +202,7 @@ int parse_cgroups(const struct option *opt, const char *str,
197202
}
198203

199204
int evlist__expand_cgroup(struct evlist *evlist, const char *str,
200-
struct rblist *metric_events)
205+
struct rblist *metric_events, bool open_cgroup)
201206
{
202207
struct evlist *orig_list, *tmp_list;
203208
struct evsel *pos, *evsel, *leader;
@@ -240,7 +245,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str,
240245
if (!name)
241246
goto out_err;
242247

243-
cgrp = cgroup__new(name);
248+
cgrp = cgroup__new(name, open_cgroup);
244249
free(name);
245250
if (cgrp == NULL)
246251
goto out_err;

‎tools/perf/util/cgroup.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct rblist;
2626

2727
struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name);
2828
int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups,
29-
struct rblist *metric_events);
29+
struct rblist *metric_events, bool open_cgroup);
3030

3131
void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup);
3232

0 commit comments

Comments
 (0)