From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: David Carrillo-Cisneros <davidcc@google.com>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
Kees Kook <keescook@chromium.org>,
Sudeep Holla <Sudeep.Holla@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Wang Nan <wangnan0@huawei.com>,
Elena Reshetova <elena.reshetova@intel.com>,
Stephane Eranian <eranian@google.com>,
Paul Turner <pjt@google.com>
Subject: Re: [PATCH 1/4] perf tool cgroup: Initialize cgroup refcnt with refcount_set
Date: Fri, 21 Jul 2017 13:55:35 -0300 [thread overview]
Message-ID: <20170721165535.GK4134@kernel.org> (raw)
In-Reply-To: <20170719011839.99399-2-davidcc@google.com>
Em Tue, Jul 18, 2017 at 06:18:36PM -0700, David Carrillo-Cisneros escreveu:
> Atomic reference counters were replaced by refcount_t in
> commit 79c5fe6db8c7 ("perf/core: Fix error handling in perf_event_alloc()")
>
> In util/cgroup.c atomic_inc was replaced by refcount_inc, but the latter
> is not mean to initiliaze refcounts with zero value. Add a path
> to initialize cgrp->refcnt == 0 using refcount_set.
>
> Before this patch:
>
> $ perf stat -e cycles -C 0 -G /
> perf_before: /usr/local/.../tools/include/linux/refcount.h:108: refcount_inc: Assertion `!(!refcount_inc_not_zero(r))' failed.
> Aborted (core dumped)
>
> After this patch:
>
> $ perf stat -e cycles -C 0 -G /
> Performance counter stats for 'CPU(s) 0':
> 17,516,664 cycles /
Ok, so this one was also reported by Brendan and I came up with an
alternative patch, that follows the usual sequence of steps, see below.
- Arnaldo
commit b13ca9843c4ea07c5a1dbf0295986b5dfeb6ef6f
Author: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
Date: Tue Jul 18 20:20:19 2017 -0300
perf cgroup: Fix refcount usage
When converting from atomic_t to refcount_t we didn't follow the usual
step of initializing it to one before taking any new reference, which
trips over checking if taking a reference for a freed refcount_t, fix
it.
Brendan's report:
---
It's 4.12-rc7, with node v4.4.1. I'm building 4.13-rc1 now, as I hit
what I think is another unrelated perf bug and I'm starting to wonder
what else is broken on that version:
(root) /mnt/src/linux-4.12-rc7/tools/perf # ./perf record -F 99 -a -e
cpu-clock --cgroup=docker/f9e9d5df065b14646e8a11edc837a13877fd90c171137b2ba3feb67a0201cb65
-g
perf: /mnt/src/linux-4.12-rc7/tools/include/linux/refcount.h:108:
refcount_inc: Assertion `!(!refcount_inc_not_zero(r))' failed.
Aborted
that used to work...
---
Testing it:
Before:
# perf stat -e cycles -C 0 --cgroup /
perf: /home/acme/git/linux/tools/include/linux/refcount.h:108: refcount_inc: Assertion `!(!refcount_inc_not_zero(r))' failed.
Aborted (core dumped)
#
After:
# perf stat -e cycles -C 0 --cgroup /
^C
Performance counter stats for 'CPU(s) 0':
132,081,393 cycles /
2.492942763 seconds time elapsed
#
Reported-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Acked-by: Elena Reshetova <elena.reshetova@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: David Carrillo-Cisneros <davidcc@google.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Krister Johansen <kjlx@templeofstupid.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sudeep Holla <Sudeep.Holla@arm.com>
Cc: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Fixes: 79c5fe6db8c7 ("perf cgroup: Convert cgroup_sel.refcnt from atomic_t to refcount_t")
Link: http://lkml.kernel.org/n/tip-l7ovfblq14ip2i08m1g0fkhv@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 03347748f3fa..0e77bc9e5f3c 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -98,8 +98,10 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
cgrp = counter->cgrp;
if (!cgrp)
continue;
- if (!strcmp(cgrp->name, str))
+ if (!strcmp(cgrp->name, str)) {
+ refcount_inc(&cgrp->refcnt);
break;
+ }
cgrp = NULL;
}
@@ -110,6 +112,7 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
return -1;
cgrp->name = str;
+ refcount_set(&cgrp->refcnt, 1);
cgrp->fd = open_cgroup(str);
if (cgrp->fd == -1) {
@@ -128,12 +131,11 @@ static int add_cgroup(struct perf_evlist *evlist, char *str)
goto found;
n++;
}
- if (refcount_read(&cgrp->refcnt) == 0)
+ if (refcount_dec_and_test(&cgrp->refcnt))
free(cgrp);
return -1;
found:
- refcount_inc(&cgrp->refcnt);
counter->cgrp = cgrp;
return 0;
}
next prev parent reply other threads:[~2017-07-21 16:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-19 1:18 [PATCH 0/4] Resubmitted forgotten patches David Carrillo-Cisneros
2017-07-19 1:18 ` [PATCH 1/4] perf tool cgroup: Initialize cgroup refcnt with refcount_set David Carrillo-Cisneros
2017-07-21 16:55 ` Arnaldo Carvalho de Melo [this message]
2017-07-19 1:18 ` [PATCH 2/4] perf tools: Add EXCLUDE_EXTLIBS and EXTRA_PERFLIBS to makefile David Carrillo-Cisneros
2017-07-26 17:22 ` [tip:perf/core] " tip-bot for David Carrillo-Cisneros
2017-07-19 1:18 ` [PATCH 3/4] perf annotate: Process tracing data in pipe mode David Carrillo-Cisneros
2017-07-26 17:22 ` [tip:perf/core] " tip-bot for David Carrillo-Cisneros
2017-07-19 1:18 ` [PATCH 4/4] tools: perf: Fix linker error when libelf config is disabled David Carrillo-Cisneros
2017-07-26 17:23 ` [tip:perf/core] perf jvmti: " tip-bot for Sudeep Holla
2017-07-19 8:45 ` [PATCH 0/4] Resubmitted forgotten patches Jiri Olsa
2017-07-21 17:00 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170721165535.GK4134@kernel.org \
--to=acme@kernel.org \
--cc=Sudeep.Holla@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=davidcc@google.com \
--cc=elena.reshetova@intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pjt@google.com \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.