Commit 89fb1ca2 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b214ba8c
...@@ -2235,7 +2235,7 @@ int cmd_stat(int argc, const char **argv) ...@@ -2235,7 +2235,7 @@ int cmd_stat(int argc, const char **argv)
} }
if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list, if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list,
&stat_config.metric_events) < 0) &stat_config.metric_events, true) < 0)
goto out; goto out;
} }
......
...@@ -51,7 +51,7 @@ static struct cgroup *evlist__find_cgroup(struct evlist *evlist, const char *str ...@@ -51,7 +51,7 @@ static struct cgroup *evlist__find_cgroup(struct evlist *evlist, const char *str
return NULL; return NULL;
} }
static struct cgroup *cgroup__new(const char *name) static struct cgroup *cgroup__new(const char *name, bool do_open)
{ {
struct cgroup *cgroup = zalloc(sizeof(*cgroup)); struct cgroup *cgroup = zalloc(sizeof(*cgroup));
...@@ -61,9 +61,14 @@ static struct cgroup *cgroup__new(const char *name) ...@@ -61,9 +61,14 @@ static struct cgroup *cgroup__new(const char *name)
cgroup->name = strdup(name); cgroup->name = strdup(name);
if (!cgroup->name) if (!cgroup->name)
goto out_err; goto out_err;
cgroup->fd = open_cgroup(name);
if (cgroup->fd == -1) if (do_open) {
goto out_free_name; cgroup->fd = open_cgroup(name);
if (cgroup->fd == -1)
goto out_free_name;
} else {
cgroup->fd = -1;
}
} }
return cgroup; return cgroup;
...@@ -79,7 +84,7 @@ struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name) ...@@ -79,7 +84,7 @@ struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name)
{ {
struct cgroup *cgroup = evlist__find_cgroup(evlist, name); struct cgroup *cgroup = evlist__find_cgroup(evlist, name);
return cgroup ?: cgroup__new(name); return cgroup ?: cgroup__new(name, true);
} }
static int add_cgroup(struct evlist *evlist, const char *str) static int add_cgroup(struct evlist *evlist, const char *str)
...@@ -197,7 +202,7 @@ int parse_cgroups(const struct option *opt, const char *str, ...@@ -197,7 +202,7 @@ int parse_cgroups(const struct option *opt, const char *str,
} }
int evlist__expand_cgroup(struct evlist *evlist, const char *str, int evlist__expand_cgroup(struct evlist *evlist, const char *str,
struct rblist *metric_events) struct rblist *metric_events, bool open_cgroup)
{ {
struct evlist *orig_list, *tmp_list; struct evlist *orig_list, *tmp_list;
struct evsel *pos, *evsel, *leader; struct evsel *pos, *evsel, *leader;
...@@ -240,7 +245,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str, ...@@ -240,7 +245,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const char *str,
if (!name) if (!name)
goto out_err; goto out_err;
cgrp = cgroup__new(name); cgrp = cgroup__new(name, open_cgroup);
free(name); free(name);
if (cgrp == NULL) if (cgrp == NULL)
goto out_err; goto out_err;
......
...@@ -26,7 +26,7 @@ struct rblist; ...@@ -26,7 +26,7 @@ struct rblist;
struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name); struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *name);
int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups, int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups,
struct rblist *metric_events); struct rblist *metric_events, bool open_cgroup);
void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup); void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgroup);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment