]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
perf cgroup: Introduce cgroup__get()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 6 Mar 2018 13:18:40 +0000 (10:18 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 7 Mar 2018 13:22:25 +0000 (10:22 -0300)
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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cgroup.c
tools/perf/util/cgroup.h

index b078d54d424557abe83f8eb9a14c9ca29f59a02d..8ea964461eb722d2b9e5db64b717ddb0dfebc899 100644 (file)
@@ -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
         */
        evlist__for_each_entry(evlist, counter) {
-               cgrp = counter->cgrp;
-               if (!cgrp)
+               if (!counter->cgrp)
                        continue;
-               if (!strcmp(cgrp->name, str)) {
-                       refcount_inc(&cgrp->refcnt);
+               if (!strcmp(counter->cgrp->name, str)) {
+                       cgrp = cgroup__get(counter->cgrp);
                        break;
                }
-
-               cgrp = NULL;
        }
 
        if (!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 unset __maybe_unused)
 {
index 69169fbf8d1388668017caf3c7f635a70cb61789..34a6c11543dce91d29db288e7644121732487a04 100644 (file)
@@ -15,6 +15,7 @@ struct cgroup {
 
 extern int nr_cgroups; /* number of explicit cgroups defined */
 
+struct cgroup *cgroup__get(struct cgroup *cgroup);
 void cgroup__put(struct cgroup *cgroup);
 
 int parse_cgroups(const struct option *opt, const char *str, int unset);