[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-t3v2uma5digcj2tpkrs3m84u@git.kernel.org>
Date: Wed, 20 May 2015 05:22:30 -0700
From: tip-bot for Arnaldo Carvalho de Melo <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: hpa@...or.com, eranian@...gle.com, bp@...e.de, fweisbec@...il.com,
dzickus@...hat.com, linux-kernel@...r.kernel.org,
namhyung@...nel.org, adrian.hunter@...el.com, acme@...hat.com,
dsahern@...il.com, tglx@...utronix.de, jolsa@...hat.com,
mingo@...nel.org
Subject: [tip:perf/core] perf cgroup: Use atomic.h for refcounting
Commit-ID: f812d3045c2385ac16237e68b156859c4005526e
Gitweb: http://git.kernel.org/tip/f812d3045c2385ac16237e68b156859c4005526e
Author: Arnaldo Carvalho de Melo <acme@...hat.com>
AuthorDate: Fri, 15 May 2015 16:12:20 -0300
Committer: Arnaldo Carvalho de Melo <acme@...hat.com>
CommitDate: Fri, 15 May 2015 16:12:20 -0300
perf cgroup: Use atomic.h for refcounting
Now that we have atomic.h, we should convert all of the existing
refcounts to use it.
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: David Ahern <dsahern@...il.com>
Cc: Don Zickus <dzickus@...hat.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Stephane Eranian <eranian@...gle.com>
Link: http://lkml.kernel.org/n/tip-t3v2uma5digcj2tpkrs3m84u@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/util/cgroup.c | 10 +++-------
tools/perf/util/cgroup.h | 4 +++-
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 88f7be3..32e12ec 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -115,23 +115,19 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
goto found;
n++;
}
- if (cgrp->refcnt == 0)
+ if (atomic_read(&cgrp->refcnt) == 0)
free(cgrp);
return -1;
found:
- cgrp->refcnt++;
+ atomic_inc(&cgrp->refcnt);
counter->cgrp = cgrp;
return 0;
}
void close_cgroup(struct cgroup_sel *cgrp)
{
- if (!cgrp)
- return;
-
- /* XXX: not reentrant */
- if (--cgrp->refcnt == 0) {
+ if (cgrp && atomic_dec_and_test(&cgrp->refcnt)) {
close(cgrp->fd);
zfree(&cgrp->name);
free(cgrp);
diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h
index 89acd6d..b4b8cb4 100644
--- a/tools/perf/util/cgroup.h
+++ b/tools/perf/util/cgroup.h
@@ -1,12 +1,14 @@
#ifndef __CGROUP_H__
#define __CGROUP_H__
+#include <linux/atomic.h>
+
struct option;
struct cgroup_sel {
char *name;
int fd;
- int refcnt;
+ atomic_t refcnt;
};
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists