From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: perf: remove erroneous check on active_events
Date: Thu, 28 Apr 2011 16:41:08 +0100 [thread overview]
Message-ID: <20110428154108.GV17290@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1303898236-14263-1-git-send-email-mark.rutland@arm.com>
On Wed, Apr 27, 2011 at 10:57:16AM +0100, Mark Rutland wrote:
> diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c
> index fd6403c..29a0cf8 100644
> --- a/arch/arm/kernel/perf_event.c
> +++ b/arch/arm/kernel/perf_event.c
> @@ -560,11 +560,6 @@ static int armpmu_event_init(struct perf_event *event)
> event->destroy = hw_perf_event_destroy;
>
> if (!atomic_inc_not_zero(&active_events)) {
> - if (atomic_read(&active_events) > armpmu->num_events) {
> - atomic_dec(&active_events);
Yuck. This is a good example of atomic_* abuse. The above does nothing
to deal with the situation where two threads are running thusly:
CPU0 CPU1
atomic_inc_not_zero(&active_events)
atomic_inc_not_zero(&active_events)
atomic_read(&active_events)
atomic_read(&active_events)
atomic_dec(&active_events)
atomic_dec(&active_events)
return -ENOSPC
return -ENOSPC
when one of those two should have succeeded. I do wish people would
get out of the habbit of using atomic variables - they seem to be ripe
for this kind of abuse.
The only time that atomic variables are atomic is for each individual
_operation_ on the type, not across several operations, and certainly
not atomic_read() or atomic_set().
What it really wants to be is a spinlock or mutex so that it can do
something like this:
int err = 0;
mutex_lock(&active_events_lock);
if (++active_events > armpmu->num_events) {
active_events--;
err = -ENOSPC;
}
mutex_unlock(&active_events);
if (err)
return err;
which gives well defined semantics, and ensures that when two CPUs are
racing, one will at least succeed.
next prev parent reply other threads:[~2011-04-28 15:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 9:57 [PATCH] ARM: perf: remove erroneous check on active_events Mark Rutland
[not found] ` <BANLkTi=J=4R2v5P2iOsf4M5_FMwWJ=JrZw@mail.gmail.com>
2011-04-28 15:21 ` Ashwin Chaugule
2011-04-28 15:41 ` Russell King - ARM Linux [this message]
2011-04-28 16:12 ` Jamie Iles
2011-04-28 17:25 ` Will Deacon
2011-05-16 9:27 ` Mark Rutland
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=20110428154108.GV17290@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.org \
/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 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).