summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorskrll <skrll@NetBSD.org>2021-11-25 09:36:20 +0000
committerskrll <skrll@NetBSD.org>2021-11-25 09:36:20 +0000
commit95efe327804d35acfa487d82522c7039199edad3 (patch)
treee32741431b687e2f807bdd0a5f0c787cc2b2efe4 /sys/dev
parent194412c4f23b2bf1fa562dea9a5b19a5a21e3026 (diff)
Improve error handling.
Hypervisors can return a PMCR.N of 0.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/tprof/tprof_armv7.c10
-rw-r--r--sys/dev/tprof/tprof_armv8.c9
2 files changed, 13 insertions, 6 deletions
diff --git a/sys/dev/tprof/tprof_armv7.c b/sys/dev/tprof/tprof_armv7.c
index 422572ee3d9..e99ee7f6f44 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.4 2020/10/30 18:54:37 skrll Exp $ */
+/* $NetBSD: tprof_armv7.c,v 1.5 2021/11/25 09:36:21 skrll 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.4 2020/10/30 18:54:37 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.5 2021/11/25 09:36:21 skrll Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: tprof_armv7.c,v 1.4 2020/10/30 18:54:37 skrll Exp $"
#include <dev/tprof/tprof_armv7.h>
+#define PMCR_N __BITS(15,11)
#define PMCR_D __BIT(3)
#define PMCR_E __BIT(0)
@@ -170,7 +171,10 @@ armv7_pmu_ident(void)
static int
armv7_pmu_start(const tprof_param_t *param)
{
- uint64_t xc;
+ /* PMCR.N of 0 means that no event counters are available */
+ if (__SHIFTOUT(armreg_pmcr_read(), PMCR_N) == 0) {
+ return EINVAL;
+ }
if (!armv7_pmu_event_implemented(param->p_event)) {
printf("%s: event %#llx not implemented on this CPU\n",
diff --git a/sys/dev/tprof/tprof_armv8.c b/sys/dev/tprof/tprof_armv8.c
index c15c1b041b4..03f21460bf8 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.8 2021/11/01 17:03:53 skrll Exp $ */
+/* $NetBSD: tprof_armv8.c,v 1.9 2021/11/25 09:36:21 skrll 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.8 2021/11/01 17:03:53 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tprof_armv8.c,v 1.9 2021/11/25 09:36:21 skrll Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -149,7 +149,10 @@ armv8_pmu_ident(void)
static int
armv8_pmu_start(const tprof_param_t *param)
{
- uint64_t xc;
+ /* PMCR.N of 0 means that no event counters are available */
+ if (__SHIFTOUT(reg_pmcr_el0_read(), PMCR_N) == 0) {
+ return EINVAL;
+ }
if (!armv8_pmu_event_implemented(param->p_event)) {
printf("%s: event %#" PRIx64 " not implemented on this CPU\n",