summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorryo <ryo@NetBSD.org>2022-12-01 00:29:10 +0000
committerryo <ryo@NetBSD.org>2022-12-01 00:29:10 +0000
commite099aa8bcf42bf42a4df482b920d77092ec3f58c (patch)
tree547620590bac3919161360b971e0f94fb0b0d5ee /sys/dev
parent496cc17fa789c491a616c3fc0e2e456170fca3c4 (diff)
PMCR.E should not be disabled from tprof.
PMCR.E controls not only performance event counters but also the cycle counter operation, and the cycle counter may be used for cpu_counter. Similarly, the 31st bit in PMINTENCLR and PMCNTENCLR controls the cycle counter, not performance event counters, and should not be modified.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/tprof/tprof_armv7.c22
-rw-r--r--sys/dev/tprof/tprof_armv8.c9
2 files changed, 13 insertions, 18 deletions
diff --git a/sys/dev/tprof/tprof_armv7.c b/sys/dev/tprof/tprof_armv7.c
index 29267ac10f6..d80acbe0cb5 100644
--- a/sys/dev/tprof/tprof_armv7.c
+++ b/sys/dev/tprof/tprof_armv7.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv7.c,v 1.7 2022/11/01 11:03:01 jmcneill Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.8 2022/12/01 00:29:10 ryo Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.7 2022/11/01 11:03:01 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.8 2022/12/01 00:29:10 ryo Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -45,6 +45,11 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.7 2022/11/01 11:03:01 jmcneill Exp
#define PMCR_D __BIT(3)
#define PMCR_E __BIT(0)
+#define PMINTEN_C __BIT(31)
+#define PMINTEN_P __BITS(30,0)
+#define PMCNTEN_C __BIT(31)
+#define PMCNTEN_P __BITS(30,0)
+
#define PMEVTYPER_P __BIT(31)
#define PMEVTYPER_U __BIT(30)
#define PMEVTYPER_EVTCOUNT __BITS(7,0)
@@ -161,18 +166,12 @@ static void
armv7_pmu_stop_cpu(void *arg1, void *arg2)
{
const uint32_t counter_mask = __BIT(armv7_pmu_counter);
- uint32_t pmcr;
/* Disable overflow interrupts */
armreg_pmintenclr_write(counter_mask);
/* Disable event counter */
armreg_pmcntenclr_write(counter_mask);
-
- /* Disable performance monitor */
- pmcr = armreg_pmcr_read();
- pmcr &= ~PMCR_E;
- armreg_pmcr_write(pmcr);
}
static uint64_t
@@ -266,13 +265,10 @@ armv7_pmu_init(void)
armreg_pmuserenr_write(0);
/* Disable interrupts */
- armreg_pmintenclr_write(~0U);
+ armreg_pmintenclr_write(PMINTEN_P);
/* Disable counters */
- armreg_pmcntenclr_write(~0U);
-
- /* Disable performance monitor */
- armreg_pmcr_write(0);
+ armreg_pmcntenclr_write(PMCNTEN_P);
return tprof_backend_register("tprof_armv7", &tprof_armv7_pmu_ops,
TPROF_BACKEND_VERSION);
diff --git a/sys/dev/tprof/tprof_armv8.c b/sys/dev/tprof/tprof_armv8.c
index 9f7be0b330b..f79ee00dde8 100644
--- a/sys/dev/tprof/tprof_armv8.c
+++ b/sys/dev/tprof/tprof_armv8.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tprof_armv8.c,v 1.16 2022/11/10 07:54:20 ryo Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.17 2022/12/01 00:29:10 ryo Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.16 2022/11/10 07:54:20 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.17 2022/12/01 00:29:10 ryo Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -112,7 +112,7 @@ armv8_pmu_start_cpu(void *arg1, void *arg2)
/* Enable event counter */
reg_pmcntenset_el0_write(counter_mask);
- reg_pmcr_el0_write(PMCR_E);
+ reg_pmcr_el0_write(reg_pmcr_el0_read() | PMCR_E);
}
static void
@@ -125,7 +125,6 @@ armv8_pmu_stop_cpu(void *arg1, void *arg2)
/* Disable event counter */
reg_pmcntenclr_el0_write(counter_mask);
- reg_pmcr_el0_write(0);
}
static uint64_t
@@ -214,7 +213,7 @@ armv8_pmu_init_cpu(void *arg1, void *arg2)
reg_pmuserenr_el0_write(0);
/* Disable interrupts */
- reg_pmintenclr_el1_write(~0U);
+ reg_pmintenclr_el1_write(PMINTEN_P);
/* Disable event counters */
reg_pmcntenclr_el0_write(PMCNTEN_P);