From: Yeoreum Yun <yeoreum.yun@arm.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
amhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, james.clark@linaro.org
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
nd@arm.com, Yeoreum Yun <yeoreum.yun@arm.com>
Subject: [PATCH 1/1] events/core: fix error run/enable ratio display
Date: Wed, 18 Dec 2024 08:46:56 +0000 [thread overview]
Message-ID: <20241218084656.609764-1-yeoreum.yun@arm.com> (raw)
when runs below command (with core pmu) sometime perf prints error
ratio for each perf.
sudo ./perf stat -vvv -e armv8_pmuv3_0/event=0x08/ -e armv8_pmuv3_1/event=0x08/ -- stress-ng --pthread=2 -t 2s
...
armv8_pmuv3_0/event=0x08/: -1: 1081702126 2289429840 2174835740
armv8_pmuv3_1/event=0x08/: -1: 794080238 1950025700 847648440
armv8_pmuv3_0/event=0x08/: 1138698008 2289429840 2174835740
armv8_pmuv3_1/event=0x08/: 1826791390 1950025700 847648440
Performance counter stats for 'stress-ng --pthread=2 -t 2s':
1,138,698,008 armv8_pmuv3_0/event=0x08/ (94.99%)
1,826,791,390 armv8_pmuv3_1/event=0x08/ (43.47%)
This happens because of missing total_enable_time of inactivate event.
it's enabled time doesn't update at the event_sched_out() because state
isn't PERF_EVENT_STATE_ACTIVE but PERF_EVENT_STATE_INACTIVE.
For example, Suppose there're two events:
e0: with pmu0 which supports only cpu0
e1: with pmu1 which supports only cpu1.
then
CPU0 CPU1 CPU0
| in | out | | in | out | | in | out (exit) |
------------------------------------------------------------------------------
ctx->time | 0 | t1 | | t1 | t1 + t2 | | t1 + t2 | t1 + t2 + t3 |
------------------------------------------------------------------------------
e0->ena | 0 | t1 | | t1 | t1 | | t1 + t2 | t1 + t2 + t3 |
------------------------------------------------------------------------------
e0->run | 0 | t1 | | t1 | t1 + t2 | | t1 + t2 | t1 + t3 |
------------------------------------------------------------------------------
e1->ena | 0 | 0 | | t1 | t1 + t2 | | t1 + t2 | t1 + t2 |
------------------------------------------------------------------------------
e1->run | 0 | 0 | | 0 | t2 | | t1 + t2 | t2 |
------------------------------------------------------------------------------
at the CPU0, state of e1 is PERF_EVENT_STATE_INACTIVE since it doesn't
support on CPU0. So when event_sched_out() it failed to update its
total_enable_time and it makes error print of run/ena ratio.
To address this, update total_enable_time in event_sched_out() when event state
is PERF_EVENT_STATE_INACTIVE.
After this patch, this problem is gone like:
sudo ./perf stat -vvv -e armv8_pmuv3_0/event=0x08/ -e armv8_pmuv3_1/event=0x08/ -- stress-ng --pthread=2 -t 2s
...
armv8_pmuv3_0/event=0x08/: -1: 10484528214 32157963940 21898169000
armv8_pmuv3_1/event=0x08/: -1: 7155819373 32157963940 10259794940
armv8_pmuv3_0/event=0x08/: 15396770398 32157963940 21898169000
armv8_pmuv3_1/event=0x08/: 22428964974 32157963940 10259794940
Performance counter stats for 'stress-ng --pthread=2 -t 10s':
15,396,770,398 armv8_pmuv3_0/event=0x08/ (68.10%)
22,428,964,974 armv8_pmuv3_1/event=0x08/ (31.90%)
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
kernel/events/core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 065f9188b44a..f40cca02636d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2311,6 +2311,11 @@ event_sched_out(struct perf_event *event, struct perf_event_context *ctx)
WARN_ON_ONCE(event->ctx != ctx);
lockdep_assert_held(&ctx->lock);
+ if (event->state == PERF_EVENT_STATE_INACTIVE) {
+ perf_event_update_time(event);
+ return ;
+ }
+
if (event->state != PERF_EVENT_STATE_ACTIVE)
return;
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
next reply other threads:[~2024-12-18 8:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 8:46 Yeoreum Yun [this message]
2024-12-18 10:42 ` Peter Zijlstra
2024-12-18 11:25 ` Yeoreum Yun
2024-12-18 11:33 ` Mark Rutland
2024-12-18 11:52 ` Yeoreum Yun
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=20241218084656.609764-1-yeoreum.yun@arm.com \
--to=yeoreum.yun@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=amhyung@kernel.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=nd@arm.com \
--cc=peterz@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
all inboxes | Powered by JetHome®