Module Name: src Committed By: skrll Date: Thu Nov 25 09:36:21 UTC 2021
Modified Files: src/sys/arch/arm/acpi: cpu_acpi.c src/sys/arch/arm/fdt: pmu_fdt.c src/sys/dev/tprof: tprof_armv7.c tprof_armv8.c Log Message: Improve error handling. Hypervisors can return a PMCR.N of 0. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/arch/arm/acpi/cpu_acpi.c cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/fdt/pmu_fdt.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/tprof/tprof_armv7.c cvs rdiff -u -r1.8 -r1.9 src/sys/dev/tprof/tprof_armv8.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/arm/acpi/cpu_acpi.c diff -u src/sys/arch/arm/acpi/cpu_acpi.c:1.12 src/sys/arch/arm/acpi/cpu_acpi.c:1.13 --- src/sys/arch/arm/acpi/cpu_acpi.c:1.12 Wed Nov 24 10:01:24 2021 +++ src/sys/arch/arm/acpi/cpu_acpi.c Thu Nov 25 09:36:20 2021 @@ -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 @@ cpu_acpi_tprof_intr_establish(ACPI_SUBTA 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, Index: src/sys/arch/arm/fdt/pmu_fdt.c diff -u src/sys/arch/arm/fdt/pmu_fdt.c:1.9 src/sys/arch/arm/fdt/pmu_fdt.c:1.10 --- src/sys/arch/arm/fdt/pmu_fdt.c:1.9 Mon Sep 27 09:54:52 2021 +++ src/sys/arch/arm/fdt/pmu_fdt.c Thu Nov 25 09:36:20 2021 @@ -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 <jmcne...@invisible.ca> @@ -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 @@ pmu_fdt_init(device_t self) } 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); Index: src/sys/dev/tprof/tprof_armv7.c diff -u src/sys/dev/tprof/tprof_armv7.c:1.4 src/sys/dev/tprof/tprof_armv7.c:1.5 --- src/sys/dev/tprof/tprof_armv7.c:1.4 Fri Oct 30 18:54:37 2020 +++ src/sys/dev/tprof/tprof_armv7.c Thu Nov 25 09:36:21 2021 @@ -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 <jmcne...@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. #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", Index: src/sys/dev/tprof/tprof_armv8.c diff -u src/sys/dev/tprof/tprof_armv8.c:1.8 src/sys/dev/tprof/tprof_armv8.c:1.9 --- src/sys/dev/tprof/tprof_armv8.c:1.8 Mon Nov 1 17:03:53 2021 +++ src/sys/dev/tprof/tprof_armv8.c Thu Nov 25 09:36:21 2021 @@ -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 <jmcne...@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",