perf: arm_cspmu: Separate Arm and vendor module
Subsystems (2)
PATCH v4 1/1 perf: arm_cspmu: Separate Arm and vendor module
Arm Coresight PMU driver consists of main standard code and vendor backend code. Both are currently built as a single module. This patch adds vendor registration API to separate the two to keep things modular. The main driver requests each known backend module during initialization and defer device binding process. The backend module then registers an init callback to the main driver and continue the device driver binding process.
---
Changes from v3:
* Move impl registration module back to main driver module.
* Rebase from will (for-next/perf)
Thanks to Robin for the feedback.
v3: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
Changes from v2:
* Move sysfs_event/format_show definition to arm_cspmu.h and move impl registration API definition to a separate module so main driver and vendor module are independent.
* The registration API now just sets the impl_init_ops callback, no reprobe.
* Add PMIIDR table that maps to the vendor module name. During device probe, main driver requests the vendor module if PMIIDR is matching.
* Keeping the name of the main driver module as arm_cspmu_module.
Thanks to Robin and Suzuki for the feedback.
v2: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
Changes from v1:
* Added separate Kconfig entry for nvidia backend
* Added lock to protect accesses to the lists
* Added support for matching subset devices from a vendor
* Added state tracking to avoid reprobe when a device is in use
Thanks to Suzuki for the feedback.
v1: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#u
--- drivers/perf/arm_cspmu/Kconfig | 9 +- drivers/perf/arm_cspmu/Makefile | 6 +- drivers/perf/arm_cspmu/arm_cspmu.c | 166 +++++++++++++++++++++----- drivers/perf/arm_cspmu/arm_cspmu.h | 24 +++- drivers/perf/arm_cspmu/nvidia_cspmu.c | 34 +++++- drivers/perf/arm_cspmu/nvidia_cspmu.h | 17 --- 6 files changed, 199 insertions(+), 57 deletions(-) delete mode 100644 drivers/perf/arm_cspmu/nvidia_cspmu.h
drivers/perf/arm_cspmu/Kconfig +8 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # -# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. config ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU tristate "ARM Coresight Architecture PMU"
@@ -10,3 +10,10 @@ config ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU based on ARM CoreSight PMU architecture. Note that this PMU architecture does not have relationship with the ARM CoreSight Self-Hosted Tracing. + +config NVIDIA_CORESIGHT_PMU_ARCH_SYSTEM_PMU + tristate "NVIDIA Coresight Architecture PMU" + depends on ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU + help + Provides NVIDIA specific attributes for performance monitoring unit + (PMU) devices based on ARM CoreSight PMU architecture.
drivers/perf/arm_cspmu/Makefile +4 -2
@@ -1,6 +1,8 @@ -# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ARM_CORESIGHT_PMU_ARCH_SYSTEM_PMU) += arm_cspmu_module.o -arm_cspmu_module-y := arm_cspmu.o nvidia_cspmu.o +arm_cspmu_module-y := arm_cspmu.o + +obj-$(CONFIG_NVIDIA_CORESIGHT_PMU_ARCH_SYSTEM_PMU) += nvidia_cspmu.o
drivers/perf/arm_cspmu/arm_cspmu.c +134 -32
242 lines not on this page · raw message
drivers/perf/arm_cspmu/arm_cspmu.h +23 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 * * ARM CoreSight Architecture PMU driver. -* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * */
@@ -69,6 +69,9 @@#define ARM_CSPMU_PMIIDR_IMPLEMENTER GENMASK(11, 0)#define ARM_CSPMU_PMIIDR_PRODUCTID GENMASK(31, 20) +/* JEDEC-assigned JEP106 identification code */ +#define ARM_CSPMU_IMPL_ID_NVIDIA 0x36B +struct arm_cspmu ;/* This tracks the events assigned to each counter in the PMU. */
@@ -106,9 +109,22 @@ struct arm_cspmu_impl_ops { struct attribute *attr, int unused); }; +/* Vendor/implementer registration parameter. */ +struct arm_cspmu_impl_match { +/* Backend module. */ +struct module *module; +const char *module_name; +/* PMIIDR value/mask. */ +u32 pmiidr_val; +u32 pmiidr_mask; +/* Callback to vendor backend to init arm_cspmu_impl::ops. */ +int (*impl_init_ops)(struct arm_cspmu *cspmu); +}; +/* Vendor/implementer descriptor. */ struct arm_cspmu_impl {u32 pmiidr; +struct arm_cspmu_impl_match *match;struct arm_cspmu_impl_ops ops;void *ctx; };
@@ -147,4 +163,10 @@ ssize_t arm_cspmu_sysfs_format_show(struct device *dev,struct device_attribute *attr, char *buf); +/* Register vendor backend. */ +int arm_cspmu_impl_register (const struct arm_cspmu_impl_match *impl_match); + +/* Unregister vendor backend. */ +void arm_cspmu_impl_unregister (const struct arm_cspmu_impl_match *impl_match); +#endif /* __ARM_CSPMU_H__ */
drivers/perf/arm_cspmu/nvidia_cspmu.c +30 -4
@@ -1,14 +1,15 @@// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +* Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * */ /* Support for NVIDIA specific attributes. */ +#include <linux/module.h> #include <linux/topology.h> -#include "nvidia_cspmu.h" +#include "arm_cspmu.h" #define NV_PCIE_PORT_COUNT 10ULL#define NV_PCIE_FILTER_ID_MASK GENMASK_ULL(NV_PCIE_PORT_COUNT - 1, 0)
@@ -351,7 +352,7 @@ static char *nv_cspmu_format_name(const struct arm_cspmu *cspmu,return name; } -int nv_cspmu_init_ops (struct arm_cspmu *cspmu) +static int nv_cspmu_init_ops (struct arm_cspmu *cspmu) {u32 prodid;struct nv_cspmu_ctx *ctx;
@@ -395,6 +396,31 @@ int nv_cspmu_init_ops(struct arm_cspmu *cspmu)return 0 ; } -EXPORT_SYMBOL_GPL (nv_cspmu_init_ops); + +/* Match all NVIDIA Coresight PMU devices */ +static const struct arm_cspmu_impl_match nv_cspmu_param = { + .pmiidr_val =ARM_CSPMU_IMPL_ID_NVIDIA , + .module =THIS_MODULE , + .impl_init_ops = nv_cspmu_init_ops +}; + +static int __init nvidia_cspmu_init (void ) +{ +int ret; + + ret =arm_cspmu_impl_register (&nv_cspmu_param); +if (ret) +pr_err ("nvidia_cspmu backend registration error: %d\n" , ret); + +return ret; +} + +static void __exit nvidia_cspmu_exit(void) +{ +arm_cspmu_impl_unregister (&nv_cspmu_param); +} + +module_init (nvidia_cspmu_init); +module_exit (nvidia_cspmu_exit);MODULE_LICENSE ("GPL v2" );
drivers/perf/arm_cspmu/nvidia_cspmu.h deleted +0 -17
@@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 -* -* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. -* -*/ - -/* Support for NVIDIA specific attributes. */ - -#ifndef __NVIDIA_CSPMU_H__ -#define __NVIDIA_CSPMU_H__ - -#include "arm_cspmu.h" - -/* Allocate NVIDIA descriptor. */ -int nv_cspmu_init_ops (struct arm_cspmu *cspmu); - -#endif /* __NVIDIA_CSPMU_H__ */
base-commit: ea8d1c062a0e876e999e4f347daeb598d5e677ab
Signature · 1 line
2.17.1
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Besar,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ea8d1c062a0e876e999e4f347daeb598d5e677ab]
url: https://github.com/intel-lab-lkp/linux/commits/Besar-Wicaksono/perf-arm_cspmu-Separate-Arm-and-vendor-module/20230620-121723 base: ea8d1c062a0e876e999e4f347daeb598d5e677ab patch link: https://lore.kernel.org/r/20230620041438.32514-1-bwicaksono%40nvidia.com patch subject: [PATCH v4] perf: arm_cspmu: Separate Arm and vendor module config: arm64-defconfig (https://download.01.org/0day-ci/archive/20230620/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230620/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/perf/arm_cspmu/arm_cspmu.c:386:30: warning: no previous prototype for 'arm_cspmu_impl_match_get' [-Wmissing-prototypes]
386 | struct arm_cspmu_impl_match *arm_cspmu_impl_match_get(u32 pmiidr)
| ^~~~~~~~~~~~~~~~~~~~~~~~
vim +/arm_cspmu_impl_match_get +386 drivers/perf/arm_cspmu/arm_cspmu.c
385
> 386 struct arm_cspmu_impl_match *arm_cspmu_impl_match_get(u32 pmiidr)
387 {
388 struct arm_cspmu_impl_match *match = impl_match;
389
390 for (; match->pmiidr_val; match++) {
391 u32 mask = match->pmiidr_mask;
392
393 if ((match->pmiidr_val & mask) == (pmiidr & mask))
394 break;
395 }
396
397 return match;
398 }
399
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Besar,
kernel test robot noticed the following build warnings:
[auto build test WARNING on ea8d1c062a0e876e999e4f347daeb598d5e677ab]
url: https://github.com/intel-lab-lkp/linux/commits/Besar-Wicaksono/perf-arm_cspmu-Separate-Arm-and-vendor-module/20230620-121723 base: ea8d1c062a0e876e999e4f347daeb598d5e677ab patch link: https://lore.kernel.org/r/20230620041438.32514-1-bwicaksono%40nvidia.com patch subject: [PATCH v4] perf: arm_cspmu: Separate Arm and vendor module config: arm64-randconfig-r011-20230621 (https://download.01.org/0day-ci/archive/20230622/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230622/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/perf/arm_cspmu/arm_cspmu.c:386:30: warning: no previous prototype for function 'arm_cspmu_impl_match_get' [-Wmissing-prototypes]
386 | struct arm_cspmu_impl_match *arm_cspmu_impl_match_get(u32 pmiidr)
| ^
drivers/perf/arm_cspmu/arm_cspmu.c:386:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
386 | struct arm_cspmu_impl_match *arm_cspmu_impl_match_get(u32 pmiidr)
| ^
| static 1 warning generated.
vim +/arm_cspmu_impl_match_get +386 drivers/perf/arm_cspmu/arm_cspmu.c
385
> 386 struct arm_cspmu_impl_match *arm_cspmu_impl_match_get(u32 pmiidr)
387 {
388 struct arm_cspmu_impl_match *match = impl_match;
389
390 for (; match->pmiidr_val; match++) {
391 u32 mask = match->pmiidr_mask;
392
393 if ((match->pmiidr_val & mask) == (pmiidr & mask))
394 break;
395 }
396
397 return match;
398 }
399
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki