From: ashwinc@codeaurora.org (Ashwin Chaugule)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: perf: remove erroneous check on active_events
Date: Thu, 28 Apr 2011 11:21:30 -0400 [thread overview]
Message-ID: <4DB985FA.1080508@codeaurora.org> (raw)
In-Reply-To: <BANLkTi=J=4R2v5P2iOsf4M5_FMwWJ=JrZw@mail.gmail.com>
Hi Mark,
> From: Mark Rutland <mark.rutland@arm.com>
>
> When initialising a PMU, there is a check to protect against races with
> other CPUs filling all of the available event slots. Since armpmu_add
> checks that an event can be scheduled, we do not need to do this at
> initialisation time. Furthermore the current code is broken because it
> assumes that atomic_inc_not_zero will unconditionally increment
> active_counts and then tries to decrement it again on failure.
>
> This patch removes the broken, redundant code.
Nice find ! I had a slightly different solution.
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Acked-by: Will Deacon <will.deacon@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Jamie Iles <jamie@jamieiles.com>
> ---
> arch/arm/kernel/perf_event.c | 5 -----
> 1 files changed, 0 insertions(+), 5 deletions(-)
>
> 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);
> - return -ENOSPC;
> - }
> -
> mutex_lock(&pmu_reserve_mutex);
> if (atomic_read(&active_events) == 0) {
> err = armpmu_reserve_hardware();
> --
While its true that we check if we can schedule an event in add(), I think
we should check it here, because, if we don't have space on the PMU,
returning -ENOSPC will not "allocate" a perf_event instance.
Whereas, if we skip this check in the init function, the perf_event
instance will be allocated but may or may not be "armed" on the pmu in
add(). This is fine, except that perf-core code "rotates" the linked list
of active events. When an event is allocated but can't be "armed" on the
PMU, the perf-core normalizes its output. This shows up as (scaled by)
against the output of the event in perf-stat.
In practice, I've seen that when this happens, the output of the event has
anywhere between 50-80% std deviation. Many users seem to not like this.
So I think we should enforce support for only as many events as there are
counters in the init function, and return -ENOSPC otherwise.
If the event allocation fails, it'll show up as <not-counted>, which I
think is better than using an output with very high std dev.
How about something like this:-
if (!atomic_inc_not_zero(&active_events)) {
mutex_lock
err = armpmu_reserve_hardware();
mutex_unlock
if (!err)
atomic_inc(&active_events);
..
} else
if(atomic_read(&active_events) > armpmu->num_events)
atomic_dec(&active_events)
return -ENOSPC;
}
Cheers,
Ashwin
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2011-04-28 15:21 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 [this message]
2011-04-28 15:41 ` Russell King - ARM Linux
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=4DB985FA.1080508@codeaurora.org \
--to=ashwinc@codeaurora.org \
--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).