From: Suzuki K Poulose <suzuki.poulose@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, mark.rutland@arm.com,
will.deacon@arm.com, robin.murphy@arm.com,
Suzuki K Poulose <suzuki.poulose@arm.com>
Subject: [PATCH 3/6] arm_pmu: Add support for long event counters
Date: Fri, 18 May 2018 11:22:20 +0100 [thread overview]
Message-ID: <1526638943-2110-4-git-send-email-suzuki.poulose@arm.com> (raw)
In-Reply-To: <1526638943-2110-1-git-send-email-suzuki.poulose@arm.com>
Each PMU has a set of fixed width event counters. But in some
special cases, the events could be counted using a counter which
effectively has twice the normal width of a coutner.
e.g, Arm V8 PMUv3 has a 64 bit cycle counter which can count
only the CPU cylces. Also, the PMU can chain the event counters
to effectively count as a 64bit counter.
Add support for tracking the events that uses double the normal
counter size. This only affects the periods set for each counter.
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
drivers/perf/arm_pmu.c | 25 ++++++++++++++++++++++---
include/linux/perf/arm_pmu.h | 6 ++++++
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index e23e1a1..1adabb5 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -33,6 +33,21 @@ static inline u64 arm_pmu_max_period(struct arm_pmu *pmu)
return (((u64)1) << (pmu->counter_width)) - 1;
}
+static inline u64 arm_pmu_get_event_max_period(struct arm_pmu *pmu,
+ struct perf_event *event)
+{
+ u64 period = arm_pmu_max_period(pmu);
+
+ /*
+ * To prevent shift-counter-overflow warning, create the
+ * mask, by shift + OR sequence.
+ */
+ if (event->hw.flags & ARMPMU_EVT_LONG)
+ period = (period << pmu->counter_width) | period;
+
+ return period;
+}
+
static int
armpmu_map_cache_event(const unsigned (*cache_map)
[PERF_COUNT_HW_CACHE_MAX]
@@ -122,7 +137,7 @@ int armpmu_event_set_period(struct perf_event *event)
u64 max_period;
int ret = 0;
- max_period = arm_pmu_max_period(armpmu);
+ max_period = arm_pmu_get_event_max_period(armpmu, event);
if (unlikely(left <= -period)) {
left = period;
local64_set(&hwc->period_left, left);
@@ -148,7 +163,7 @@ int armpmu_event_set_period(struct perf_event *event)
local64_set(&hwc->prev_count, (u64)-left);
- armpmu->write_counter(event, (u64)(-left) & 0xffffffff);
+ armpmu->write_counter(event, (u64)(-left) & max_period);
perf_event_update_userpage(event);
@@ -160,7 +175,7 @@ u64 armpmu_event_update(struct perf_event *event)
struct arm_pmu *armpmu = to_arm_pmu(event->pmu);
struct hw_perf_event *hwc = &event->hw;
u64 delta, prev_raw_count, new_raw_count;
- u64 max_period = arm_pmu_max_period(armpmu);
+ u64 max_period = arm_pmu_get_event_max_period(armpmu, event);
again:
prev_raw_count = local64_read(&hwc->prev_count);
@@ -368,6 +383,7 @@ __hw_perf_event_init(struct perf_event *event)
struct hw_perf_event *hwc = &event->hw;
int mapping;
+ hwc->flags = 0;
mapping = armpmu->map_event(event);
if (mapping < 0) {
@@ -670,6 +686,9 @@ static void cpu_pm_pmu_setup(struct arm_pmu *armpmu, unsigned long cmd)
continue;
event = hw_events->events[idx];
+ /* Chained events could use multiple counters */
+ if (!event)
+ continue;
switch (cmd) {
case CPU_PM_ENTER:
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index 705e8c3..ed7e3f7 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -25,6 +25,12 @@
*/
#define ARMPMU_MAX_HWEVENTS 32
+/*
+ * ARM PMU hw_event flags
+ */
+/* Event uses a counter with double the normal width */
+#define ARMPMU_EVT_LONG 1
+
#define HW_OP_UNSUPPORTED 0xFFFF
#define C(_x) PERF_COUNT_HW_CACHE_##_x
#define CACHE_OP_UNSUPPORTED 0xFFFF
--
2.7.4
next prev parent reply other threads:[~2018-05-18 10:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-18 10:22 [PATCH 0/6] arm64: perf: Support for chaining event counters Suzuki K Poulose
2018-05-18 10:22 ` [PATCH 1/6] arm_pmu: Refactor maximum period handling Suzuki K Poulose
2018-05-18 13:10 ` Robin Murphy
2018-05-18 10:22 ` [PATCH 2/6] arm_pmu: Change API to support 64bit counter values Suzuki K Poulose
2018-05-21 23:30 ` kbuild test robot
2018-05-22 9:42 ` Suzuki K Poulose
2018-05-18 10:22 ` Suzuki K Poulose [this message]
2018-05-18 13:22 ` [PATCH 3/6] arm_pmu: Add support for long event counters Robin Murphy
2018-05-18 10:22 ` [PATCH 4/6] arm64: perf: Make the cycle counter 64bit by default Suzuki K Poulose
2018-05-18 10:22 ` [PATCH 5/6] arm_pmu: Tidy up clear_event_idx call backs Suzuki K Poulose
2018-05-18 10:22 ` [PATCH 6/6] arm64: perf: Add support for chaining counters Suzuki K Poulose
2018-05-18 13:49 ` Robin Murphy
2018-05-18 15:57 ` Suzuki K Poulose
2018-05-21 13:42 ` Suzuki K Poulose
2018-05-21 14:00 ` Robin Murphy
2018-05-21 14:41 ` Suzuki K Poulose
2018-05-21 15:29 ` Robin Murphy
2018-05-18 14:57 ` Robin Murphy
2018-05-21 10:49 ` Suzuki K Poulose
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=1526638943-2110-4-git-send-email-suzuki.poulose@arm.com \
--to=suzuki.poulose@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=robin.murphy@arm.com \
--cc=will.deacon@arm.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 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).