* [tip:perf/core] perf cgroup: Introduce cgroup__new() out of open coded equivalent
@ 2018-03-09 8:36 tip-bot for Arnaldo Carvalho de Melo
0 siblings, 0 replies; only message in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2018-03-09 8:36 UTC (permalink / raw)
To: linux-tip-commits
Cc: jolsa, mingo, linux-kernel, acme, dsahern, adrian.hunter,
wangnan0, hpa, tglx, eranian, namhyung
Commit-ID: 923a0fb332f8ee49b063df07129b2686f78ec9c3
Gitweb: https://git.kernel.org/tip/923a0fb332f8ee49b063df07129b2686f78ec9c3
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Tue, 6 Mar 2018 10:33:04 -0300
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 7 Mar 2018 10:22:25 -0300
perf cgroup: Introduce cgroup__new() out of open coded equivalent
To follow the namespacing convention in tools/perf.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-jaalyl6bkvvji4r5u8wqw4n4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/cgroup.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 84dfc34a6d0f..26a837037797 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -109,6 +109,25 @@ static struct cgroup *evlist__find_cgroup(struct perf_evlist *evlist, char *str)
return cgrp;
}
+static struct cgroup *cgroup__new(char *name)
+{
+ struct cgroup *cgroup = zalloc(sizeof(*cgroup));
+
+ if (cgroup != NULL) {
+ cgroup->name = name;
+ refcount_set(&cgroup->refcnt, 1);
+
+ cgroup->fd = open_cgroup(name);
+ if (cgroup->fd == -1)
+ goto out_err;
+ }
+
+ return cgroup;
+out_err:
+ free(cgroup);
+ return NULL;
+}
+
static int add_cgroup(struct perf_evlist *evlist, char *str)
{
struct perf_evsel *counter;
@@ -116,18 +135,9 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
int n;
if (!cgrp) {
- cgrp = zalloc(sizeof(*cgrp));
+ cgrp = cgroup__new(str);
if (!cgrp)
return -1;
-
- cgrp->name = str;
- refcount_set(&cgrp->refcnt, 1);
-
- cgrp->fd = open_cgroup(str);
- if (cgrp->fd == -1) {
- free(cgrp);
- return -1;
- }
}
/*
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-03-09 8:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-09 8:36 [tip:perf/core] perf cgroup: Introduce cgroup__new() out of open coded equivalent tip-bot for Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).