Skip to contentSkip to conversation

drivers/perf: hisi: Enable HiSilicon Erratum 162700402 quirk for UC PMU

PATCH Superseded Junhao He 2 participants 3 messages Feb 7, 2024 – Feb 23, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Junhao He

author
#0 lore raw

PATCH 1/1 drivers/perf: hisi: Enable HiSilicon Erratum 162700402 quirk for UC PMU

HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU counter cannot be set due to the lack of clock under power saving mode. This will lead to error or inaccurate counts. The clock can be enabled by the PMU global enabling control.

This patch tries to fix this by set the UC PMU enable before set event period to turn on the clock, and then restore the UC PMU configuration. The counter register can hold its value without a clock.

---
 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 40 ++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +39 -1
index 636fb79647c8..8e7a9e1f419a 100644
@@ -287,10 +287,48 @@ static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu,
 	return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
 }
 
-static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+static bool hisi_uc_pmu_get_glb_en_state(struct hisi_pmu *uc_pmu)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	return !!FIELD_GET(HISI_UC_EVENT_GLB_EN, val);
+}
+
+static void hisi_uc_pmu_write_counter_quirk_hip09(struct hisi_pmu *uc_pmu,
 				      struct hw_perf_event *hwc, u64 val)
 {
+	bool enable = hisi_uc_pmu_get_glb_en_state(uc_pmu);
+
+	/* Set the UC PMU enable to turn on the clock. */
+	if (!enable)
+		hisi_uc_pmu_start_counters(uc_pmu);
+
 	writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
+
+	/*
+	 * The counter register can hold its value without a clock. We need
+	 * restore the UC PMU configuration. The irq handler will also call
+	 * the function to set period. At this time, PMU is still enabled and
+	 * we cannot directly disable the PMU.
+	 */
+	if (!enable)
+		hisi_uc_pmu_stop_counters(uc_pmu);
+}
+
+static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+				      struct hw_perf_event *hwc, u64 val)
+{
+	/*
+	 * HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU
+	 * counter cannot be set due to the lack of clock under power saving
+	 * mode. This will lead to error or inaccurate counts. The clock can
+	 * be enabled by the PMU global enabling control.
+	 */
+	if (uc_pmu->identifier == HISI_PMU_V2)
+		hisi_uc_pmu_write_counter_quirk_hip09(uc_pmu, hwc, val);
+	else
+		writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
 }
 
 static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu,
Signature · 1 line
2.33.0
#1 lore raw
Quoted 10 lines · On Wed, 7 Feb 2024 17:42:45 +0800 Junhao He <[email protected]> wrote:

HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU counter cannot be set due to the lack of clock under power saving mode. This will lead to error or inaccurate counts. The clock can be enabled by the PMU global enabling control.

This patch tries to fix this by set the UC PMU enable before set event period to turn on the clock, and then restore the UC PMU configuration. The counter register can hold its value without a clock.

Hi.

Some very minor comments about the comments inline.

Jonathan

Quoted 17 lines
---
 drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 40 ++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +4 -1
index 636fb79647c8..8e7a9e1f419a 100644
@@ -287,10 +287,48 @@ static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu,
 	return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
 }
 
-static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+static bool hisi_uc_pmu_get_glb_en_state(struct hisi_pmu *uc_pmu)
+{
+	u32 val;
+

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 303

Quoted 10 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +8 -0
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	return !!FIELD_GET(HISI_UC_EVENT_GLB_EN, val);
+}
+
+static void hisi_uc_pmu_write_counter_quirk_hip09(struct hisi_pmu *uc_pmu,
 				      struct hw_perf_event *hwc, u64 val)
 {
+	bool enable = hisi_uc_pmu_get_glb_en_state(uc_pmu);
+
+	/* Set the UC PMU enable to turn on the clock. */

Comment from below here but adjusted to say which path has the device already enabled.

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 313

Quoted 10 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +9 -0
+	if (!enable)
+		hisi_uc_pmu_start_counters(uc_pmu);
+
 	writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
+
+	/*
+	 * The counter register can hold its value without a clock. We need
+	 * restore the UC PMU configuration. The irq handler will also call
+	 * the function to set period. At this time, PMU is still enabled and
+	 * we cannot directly disable the PMU.

I think the comment is more relevant above...

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 326

Quoted 13 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +13 -0
+	 */
+	if (!enable)
+		hisi_uc_pmu_stop_counters(uc_pmu);
+}
+
+static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+				      struct hw_perf_event *hwc, u64 val)
+{
+	/*
+	 * HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU
+	 * counter cannot be set due to the lack of clock under power saving
+	 * mode. This will lead to error or inaccurate counts. The clock can
+	 * be enabled by the PMU global enabling control.

I'd move the comment to next to the quirk function so that people can immediately see what is being done. Down here we just need to know there is a quirk.

Quoted 8 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +5 -0
+	 */
+	if (uc_pmu->identifier == HISI_PMU_V2)
+		hisi_uc_pmu_write_counter_quirk_hip09(uc_pmu, hwc, val);
+	else
+		writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
 }
 
 static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu,
author
#2 lore raw
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Wed, 7 Feb 2024 17:42:45 +0800 Junhao He <[email protected]> wrote:

HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU counter cannot be set due to the lack of clock under power saving mode. This will lead to error or inaccurate counts. The clock can be enabled by the PMU global enabling control.

Quoted 8 lines
Quoted 5 lines

This patch tries to fix this by set the UC PMU enable before set event period to turn on the clock, and then restore the UC PMU configuration. The counter register can hold its value without a clock.

Hi.

Some very minor comments about the comments inline.

Hi, Jonathan

Thanks for the comments.

Quoted 24 lines

Jonathan

Quoted 21 lines
---
  drivers/perf/hisilicon/hisi_uncore_uc_pmu.c | 40 ++++++++++++++++++++-
  1 file changed, 39 insertions(+), 1 deletion(-)
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +8 -1
index 636fb79647c8..8e7a9e1f419a 100644
@@ -287,10 +287,48 @@ static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu,
  	return readq(uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
  }
 
-static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+static bool hisi_uc_pmu_get_glb_en_state(struct hisi_pmu *uc_pmu)
+{
+	u32 val;
+
+	val = readl(uc_pmu->base + HISI_UC_EVENT_CTRL_REG);
+	return !!FIELD_GET(HISI_UC_EVENT_GLB_EN, val);
+}
+
Quoted 8 lines

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 303

Quoted 6 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +4 -0
+static void hisi_uc_pmu_write_counter_quirk_hip09(struct hisi_pmu *uc_pmu,
  				      struct hw_perf_event *hwc, u64 val)
  {
+	bool enable = hisi_uc_pmu_get_glb_en_state(uc_pmu);
+
+	/* Set the UC PMU enable to turn on the clock. */

Comment from below here but adjusted to say which path has the device already enabled.

This quirk function is simple. I'm going to consolidate all the comments to annotate the quirk function.

Best regards,
Junhao.

Quoted 11 lines

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 313

Quoted 10 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +9 -0
+	if (!enable)
+		hisi_uc_pmu_start_counters(uc_pmu);
+
  	writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
+
+	/*
+	 * The counter register can hold its value without a clock. We need
+	 * restore the UC PMU configuration. The irq handler will also call
+	 * the function to set period. At this time, PMU is still enabled and
+	 * we cannot directly disable the PMU.

I think the comment is more relevant above...

Okay, I'm going to replace the comment with the following

/*
* Restore PMU enable status, the counter can hold its value
* without a clock.
*/

Quoted 7 lines
Quoted 7 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +7 -0
+	 */
+	if (!enable)
+		hisi_uc_pmu_stop_counters(uc_pmu);
+}
+
+static void hisi_uc_pmu_write_counter(struct hisi_pmu *uc_pmu,
+				      struct hw_perf_event *hwc, u64 val)
Quoted 8 lines

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c static u64 hisi_uc_pmu_read_counter(struct hisi_pmu *uc_pmu, · line 326

Quoted 6 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +6 -0
+{
+	/*
+	 * HiSilicon UC PMU v2 suffers the erratum 162700402 that the PMU
+	 * counter cannot be set due to the lack of clock under power saving
+	 * mode. This will lead to error or inaccurate counts. The clock can
+	 * be enabled by the PMU global enabling control.

I'd move the comment to next to the quirk function so that people can immediately see what is being done. Down here we just need to know there is a quirk.

I'd comment the quirk function.

Quoted 10 lines
Quoted 9 lines
drivers/perf/hisilicon/hisi_uncore_uc_pmu.c +5 -0
+	 */
+	if (uc_pmu->identifier == HISI_PMU_V2)
+		hisi_uc_pmu_write_counter_quirk_hip09(uc_pmu, hwc, val);
+	else
+		writeq(val, uc_pmu->base + HISI_UC_CNTR_REGn(hwc->idx));
  }
 
  static void hisi_uc_pmu_enable_counter_int(struct hisi_pmu *uc_pmu,