perf cgroup: Introduce cgroup__get()

The refcount operation counterpart to cgroup__put(), use it when reusing
a cgroup.

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-14ynvrl7y2cz8gyuy5q5v41g@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 a53b6460
...@@ -99,15 +99,12 @@ static int add_cgroup(struct perf_evlist *evlist, char *str) ...@@ -99,15 +99,12 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
* check if cgrp is already defined, if so we reuse it * check if cgrp is already defined, if so we reuse it
*/ */
evlist__for_each_entry(evlist, counter) { evlist__for_each_entry(evlist, counter) {
cgrp = counter->cgrp; if (!counter->cgrp)
if (!cgrp)
continue; continue;
if (!strcmp(cgrp->name, str)) { if (!strcmp(counter->cgrp->name, str)) {
refcount_inc(&cgrp->refcnt); cgrp = cgroup__get(counter->cgrp);
break; break;
} }
cgrp = NULL;
} }
if (!cgrp) { if (!cgrp) {
...@@ -157,6 +154,13 @@ void cgroup__put(struct cgroup *cgrp) ...@@ -157,6 +154,13 @@ void cgroup__put(struct cgroup *cgrp)
} }
} }
struct cgroup *cgroup__get(struct cgroup *cgroup)
{
if (cgroup)
refcount_inc(&cgroup->refcnt);
return cgroup;
}
int parse_cgroups(const struct option *opt, const char *str, int parse_cgroups(const struct option *opt, const char *str,
int unset __maybe_unused) int unset __maybe_unused)
{ {
......
...@@ -15,6 +15,7 @@ struct cgroup { ...@@ -15,6 +15,7 @@ struct cgroup {
extern int nr_cgroups; /* number of explicit cgroups defined */ extern int nr_cgroups; /* number of explicit cgroups defined */
struct cgroup *cgroup__get(struct cgroup *cgroup);
void cgroup__put(struct cgroup *cgroup); void cgroup__put(struct cgroup *cgroup);
int parse_cgroups(const struct option *opt, const char *str, int unset); int parse_cgroups(const struct option *opt, const char *str, int unset);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册