Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/tprof Improve error handling.
details: https://anonhg.NetBSD.org/src/rev/dff18330b207
branches: trunk
changeset: 1026448:dff18330b207
user: skrll <skrll%NetBSD.org@localhost>
date: Thu Nov 25 09:36:20 2021 +0000
description:
Improve error handling.
Hypervisors can return a PMCR.N of 0.
diffstat:
sys/arch/arm/acpi/cpu_acpi.c | 11 ++++++++---
sys/arch/arm/fdt/pmu_fdt.c | 11 ++++++++---
sys/dev/tprof/tprof_armv7.c | 10 +++++++---
sys/dev/tprof/tprof_armv8.c | 9 ++++++---
4 files changed, 29 insertions(+), 12 deletions(-)
diffs (132 lines):
diff -r b68a70ffd787 -r dff18330b207 sys/arch/arm/acpi/cpu_acpi.c
--- a/sys/arch/arm/acpi/cpu_acpi.c Thu Nov 25 08:08:28 2021 +0000
+++ b/sys/arch/arm/acpi/cpu_acpi.c Thu Nov 25 09:36:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_acpi.c,v 1.12 2021/11/24 10:01:24 jmcneill Exp $ */
+/* $NetBSD: cpu_acpi.c,v 1.13 2021/11/25 09:36:20 skrll Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#include "opt_multiprocessor.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_acpi.c,v 1.12 2021/11/24 10:01:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_acpi.c,v 1.13 2021/11/25 09:36:20 skrll Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -225,7 +225,12 @@
static void
cpu_acpi_tprof_init(device_t self)
{
- armv8_pmu_init();
+ int err = armv8_pmu_init();
+ if (err) {
+ aprint_error_dev(self,
+ "failed to initialize PMU event counter\n");
+ return;
+ }
if (acpi_madt_map() != AE_OK) {
aprint_error_dev(self,
diff -r b68a70ffd787 -r dff18330b207 sys/arch/arm/fdt/pmu_fdt.c
--- a/sys/arch/arm/fdt/pmu_fdt.c Thu Nov 25 08:08:28 2021 +0000
+++ b/sys/arch/arm/fdt/pmu_fdt.c Thu Nov 25 09:36:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmu_fdt.c,v 1.9 2021/09/27 09:54:52 jmcneill Exp $ */
+/* $NetBSD: pmu_fdt.c,v 1.10 2021/11/25 09:36:20 skrll Exp $ */
/*-
* Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmu_fdt.c,v 1.9 2021/09/27 09:54:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmu_fdt.c,v 1.10 2021/11/25 09:36:20 skrll Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -133,7 +133,12 @@
}
if (pmu_fdt_count == 0) {
- arm_pmu_init();
+ error = arm_pmu_init();
+ if (error) {
+ aprint_error_dev(self,
+ "couldn't initialise PMU event counter");
+ }
+ return;
}
ih = kmem_zalloc(sizeof(void *) * ncpu, KM_SLEEP);
diff -r b68a70ffd787 -r dff18330b207 sys/dev/tprof/tprof_armv7.c
--- a/sys/dev/tprof/tprof_armv7.c Thu Nov 25 08:08:28 2021 +0000
+++ b/sys/dev/tprof/tprof_armv7.c Thu Nov 25 09:36:20 2021 +0000
@@ -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@localhost>
@@ -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 @@
#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 @@
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 -r b68a70ffd787 -r dff18330b207 sys/dev/tprof/tprof_armv8.c
--- a/sys/dev/tprof/tprof_armv8.c Thu Nov 25 08:08:28 2021 +0000
+++ b/sys/dev/tprof/tprof_armv8.c Thu Nov 25 09:36:20 2021 +0000
@@ -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@localhost>
@@ -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 @@
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",
Home |
Main Index |
Thread Index |
Old Index