All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] arm64: Enable perf events based hard lockup detector
@ 2020-05-15  8:49 Sumit Garg
  2020-05-15 14:34 ` kbuild test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sumit Garg @ 2020-05-15  8:49 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: mark.rutland, Sumit Garg, daniel.thompson, peterz,
	catalin.marinas, jolsa, dianders, acme, alexander.shishkin,
	mingo, namhyung, tglx, will, julien.thierry.kdev

With the recent feature added to enable perf events to use pseudo NMIs
as interrupts on platforms which support GICv3 or later, its now been
possible to enable hard lockup detector (or NMI watchdog) on arm64
platforms. So enable corresponding support.

One thing to note here is that normally lockup detector is initialized
just after the early initcalls but PMU on arm64 comes up much later as
device_initcall(). So we need to re-initialize lockup detection once
PMU has been initialized.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---

This patch is dependent on perf NMI patch-set [1].

[1] https://patchwork.kernel.org/cover/11047407/

 arch/arm64/Kconfig             |  2 ++
 arch/arm64/kernel/perf_event.c | 32 ++++++++++++++++++++++++++++++--
 drivers/perf/arm_pmu.c         | 11 +++++++++++
 include/linux/perf/arm_pmu.h   |  2 ++
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 40fb05d..36f75c2 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -160,6 +160,8 @@ config ARM64
 	select HAVE_NMI
 	select HAVE_PATA_PLATFORM
 	select HAVE_PERF_EVENTS
+	select HAVE_PERF_EVENTS_NMI if ARM64_PSEUDO_NMI
+	select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
 	select HAVE_PERF_REGS
 	select HAVE_PERF_USER_STACK_DUMP
 	select HAVE_REGS_AND_STACK_ACCESS_API
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index 3ad5c8f..df57360 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -20,6 +20,8 @@
 #include <linux/perf/arm_pmu.h>
 #include <linux/platform_device.h>
 #include <linux/smp.h>
+#include <linux/nmi.h>
+#include <linux/cpufreq.h>
 
 /* ARMv8 Cortex-A53 specific event types. */
 #define ARMV8_A53_PERFCTR_PREF_LINEFILL				0xC2
@@ -1190,10 +1192,21 @@ static struct platform_driver armv8_pmu_driver = {
 
 static int __init armv8_pmu_driver_init(void)
 {
+	int ret;
+
 	if (acpi_disabled)
-		return platform_driver_register(&armv8_pmu_driver);
+		ret = platform_driver_register(&armv8_pmu_driver);
 	else
-		return arm_pmu_acpi_probe(armv8_pmuv3_init);
+		ret = arm_pmu_acpi_probe(armv8_pmuv3_init);
+
+	/*
+	 * Try to re-initialize lockup detector after PMU init in
+	 * case PMU events are triggered via NMIs.
+	 */
+	if (arm_pmu_irq_is_nmi())
+		lockup_detector_init();
+
+	return ret;
 }
 device_initcall(armv8_pmu_driver_init)
 
@@ -1225,3 +1238,18 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->time_shift = (u16)shift;
 	userpg->time_offset = -now;
 }
+
+#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
+#define SAFE_MAX_CPU_FREQ	4000000000UL // 4 GHz
+u64 hw_nmi_get_sample_period(int watchdog_thresh)
+{
+	unsigned int cpu = smp_processor_id();
+	unsigned int max_cpu_freq;
+
+	max_cpu_freq = cpufreq_get_hw_max_freq(cpu);
+	if (max_cpu_freq)
+		return (u64)max_cpu_freq * 1000 * watchdog_thresh;
+	else
+		return (u64)SAFE_MAX_CPU_FREQ * watchdog_thresh;
+}
+#endif
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index f96cfc4..691dfc9 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -718,6 +718,17 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
 	return per_cpu(hw_events->irq, cpu);
 }
 
+bool arm_pmu_irq_is_nmi(void)
+{
+	const struct pmu_irq_ops *irq_ops;
+
+	irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
+	if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
+		return true;
+	else
+		return false;
+}
+
 /*
  * PMU hardware loses all context when a CPU goes offline.
  * When a CPU is hotplugged back in, since some hardware registers are
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index d9b8b76..a71f029 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -155,6 +155,8 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
 static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
 #endif
 
+bool arm_pmu_irq_is_nmi(void);
+
 /* Internal functions only for core arm_pmu code */
 struct arm_pmu *armpmu_alloc(void);
 struct arm_pmu *armpmu_alloc_atomic(void);
-- 
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-15  8:49 [RFC] arm64: Enable perf events based hard lockup detector Sumit Garg
@ 2020-05-15 14:34 ` kbuild test robot
  2020-05-15 19:51 ` kbuild test robot
  2020-05-18 14:34 ` Mark Rutland
  2 siblings, 0 replies; 8+ messages in thread
From: kbuild test robot @ 2020-05-15 14:34 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4233 bytes --]

Hi Sumit,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on arm-soc/for-next arm/for-next xlnx/master kvmarm/next linus/master v5.7-rc5 next-20200514]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sumit-Garg/arm64-Enable-perf-events-based-hard-lockup-detector/20200515-165226
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: arm-defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

In file included from include/asm-generic/percpu.h:7,
from arch/arm/include/asm/percpu.h:39,
from include/linux/percpu.h:13,
from include/linux/context_tracking_state.h:5,
from include/linux/vtime.h:5,
from include/linux/hardirq.h:8,
from include/linux/interrupt.h:11,
from include/linux/perf/arm_pmu.h:11,
from drivers/perf/arm_pmu.c:20:
drivers/perf/arm_pmu.c: In function 'arm_pmu_irq_is_nmi':
>> drivers/perf/arm_pmu.c:613:20: error: 'cpu_irq_ops' undeclared (first use in this function); did you mean 'pmu_irq_ops'?
613 |  irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
|                    ^~~~~~~~~~~
include/linux/percpu-defs.h:219:47: note: in definition of macro '__verify_pcpu_ptr'
219 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;          |                                               ^~~
include/linux/percpu-defs.h:269:29: note: in expansion of macro 'per_cpu_ptr'
269 | #define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu))
|                             ^~~~~~~~~~~
>> drivers/perf/arm_pmu.c:613:12: note: in expansion of macro 'per_cpu'
613 |  irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
|            ^~~~~~~
drivers/perf/arm_pmu.c:613:20: note: each undeclared identifier is reported only once for each function it appears in
613 |  irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
|                    ^~~~~~~~~~~
include/linux/percpu-defs.h:219:47: note: in definition of macro '__verify_pcpu_ptr'
219 |  const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;          |                                               ^~~
include/linux/percpu-defs.h:269:29: note: in expansion of macro 'per_cpu_ptr'
269 | #define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu))
|                             ^~~~~~~~~~~
>> drivers/perf/arm_pmu.c:613:12: note: in expansion of macro 'per_cpu'
613 |  irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
|            ^~~~~~~
>> drivers/perf/arm_pmu.c:614:18: error: 'pmunmi_ops' undeclared (first use in this function)
614 |  if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
|                  ^~~~~~~~~~
>> drivers/perf/arm_pmu.c:614:44: error: 'percpu_pmunmi_ops' undeclared (first use in this function)
614 |  if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
|                                            ^~~~~~~~~~~~~~~~~
>> drivers/perf/arm_pmu.c:618:1: warning: control reaches end of non-void function [-Wreturn-type]
618 | }
| ^

vim +613 drivers/perf/arm_pmu.c

   608	
   609	bool arm_pmu_irq_is_nmi(void)
   610	{
   611		const struct pmu_irq_ops *irq_ops;
   612	
 > 613		irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
 > 614		if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
   615			return true;
   616		else
   617			return false;
 > 618	}
   619	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 51930 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-15  8:49 [RFC] arm64: Enable perf events based hard lockup detector Sumit Garg
  2020-05-15 14:34 ` kbuild test robot
@ 2020-05-15 19:51 ` kbuild test robot
  2020-05-18  5:55   ` Sumit Garg
  2020-05-18 14:34 ` Mark Rutland
  2 siblings, 1 reply; 8+ messages in thread
From: kbuild test robot @ 2020-05-15 19:51 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6977 bytes --]

Hi Sumit,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on arm-soc/for-next arm/for-next kvmarm/next linus/master v5.7-rc5 next-20200515]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sumit-Garg/arm64-Enable-perf-events-based-hard-lockup-detector/20200515-165226
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: arm64-randconfig-r025-20200515 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 9d4cf5bd421fb6467ff5f00e26a37527246dd4d6)
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>, old ones prefixed by <<):

drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^~~~~~~~~~~
cpu_map_ops
include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
#define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
^
include/linux/percpu-defs.h:235:20: note: expanded from macro 'per_cpu_ptr'
__verify_pcpu_ptr(ptr);                                                                      ^
include/linux/percpu-defs.h:219:47: note: expanded from macro '__verify_pcpu_ptr'
const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;                                                            ^
include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
^
drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^~~~~~~~~~~
cpu_map_ops
include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
#define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
^
include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
^
include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
__ptr = (unsigned long) (ptr);                                                              ^
include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
^
drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^~~~~~~~~~~
cpu_map_ops
include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
#define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
^
include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
^
include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
__ptr = (unsigned long) (ptr);                                                              ^
include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
^
drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^~~~~~~~~~~
cpu_map_ops
include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
#define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
^
include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
^
include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
(typeof(ptr)) (__ptr + (off)); })
^
include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
^
drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^~~~~~~~~~~
cpu_map_ops
include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
#define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
^
include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
^
include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
(typeof(ptr)) (__ptr + (off)); })
^
include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
^
>> drivers/perf/arm_pmu.c:613:10: error: assigning to 'const struct pmu_irq_ops *' from incompatible type 'typeof (*((&(cpu_map_ops))))' (aka 'const struct bpf_map_ops')
irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/perf/arm_pmu.c:614:18: error: use of undeclared identifier 'pmunmi_ops'
if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
^
drivers/perf/arm_pmu.c:614:44: error: use of undeclared identifier 'percpu_pmunmi_ops'
if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
^
8 errors generated.

vim +613 drivers/perf/arm_pmu.c

   608	
   609	bool arm_pmu_irq_is_nmi(void)
   610	{
   611		const struct pmu_irq_ops *irq_ops;
   612	
 > 613		irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
   614		if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
   615			return true;
   616		else
   617			return false;
   618	}
   619	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 41217 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-15 19:51 ` kbuild test robot
@ 2020-05-18  5:55   ` Sumit Garg
  2020-05-18 23:51     ` Philip Li
  0 siblings, 1 reply; 8+ messages in thread
From: Sumit Garg @ 2020-05-18  5:55 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 7589 bytes --]

Hi,

On Sat, 16 May 2020 at 01:21, kbuild test robot <lkp@intel.com> wrote:
>
> Hi Sumit,
>
> [FYI, it's a private test report for your RFC patch.]
> [auto build test ERROR on arm64/for-next/core]
> [also build test ERROR on arm-soc/for-next arm/for-next kvmarm/next linus/master v5.7-rc5 next-20200515]
> [if your patch is applied to the wrong git tree, please drop us a note to help
> improve the system. BTW, we also suggest to use '--base' option to specify the
> base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
>

This isn't a correct report as it doesn't take in account the
dependency of this patch on other patch-set [1] mentioned after "---".

[1] https://patchwork.kernel.org/cover/11047407/

-Sumit

> url:    https://github.com/0day-ci/linux/commits/Sumit-Garg/arm64-Enable-perf-events-based-hard-lockup-detector/20200515-165226
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
> config: arm64-randconfig-r025-20200515 (attached as .config)
> compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 9d4cf5bd421fb6467ff5f00e26a37527246dd4d6)
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install arm64 cross compiling tool for clang build
>         # apt-get install binutils-aarch64-linux-gnu
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kbuild test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>, old ones prefixed by <<):
>
> drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^~~~~~~~~~~
> cpu_map_ops
> include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> ^
> include/linux/percpu-defs.h:235:20: note: expanded from macro 'per_cpu_ptr'
> __verify_pcpu_ptr(ptr);                                                                      ^
> include/linux/percpu-defs.h:219:47: note: expanded from macro '__verify_pcpu_ptr'
> const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;                                                            ^
> include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> ^
> drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^~~~~~~~~~~
> cpu_map_ops
> include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> ^
> include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
> RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> ^
> include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
> __ptr = (unsigned long) (ptr);                                                              ^
> include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> ^
> drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^~~~~~~~~~~
> cpu_map_ops
> include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> ^
> include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
> RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> ^
> include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
> __ptr = (unsigned long) (ptr);                                                              ^
> include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> ^
> drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^~~~~~~~~~~
> cpu_map_ops
> include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> ^
> include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
> RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> ^
> include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
> (typeof(ptr)) (__ptr + (off)); })
> ^
> include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> ^
> drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^~~~~~~~~~~
> cpu_map_ops
> include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> ^
> include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
> RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> ^
> include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
> (typeof(ptr)) (__ptr + (off)); })
> ^
> include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> ^
> >> drivers/perf/arm_pmu.c:613:10: error: assigning to 'const struct pmu_irq_ops *' from incompatible type 'typeof (*((&(cpu_map_ops))))' (aka 'const struct bpf_map_ops')
> irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/perf/arm_pmu.c:614:18: error: use of undeclared identifier 'pmunmi_ops'
> if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> ^
> drivers/perf/arm_pmu.c:614:44: error: use of undeclared identifier 'percpu_pmunmi_ops'
> if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> ^
> 8 errors generated.
>
> vim +613 drivers/perf/arm_pmu.c
>
>    608
>    609  bool arm_pmu_irq_is_nmi(void)
>    610  {
>    611          const struct pmu_irq_ops *irq_ops;
>    612
>  > 613          irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
>    614          if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
>    615                  return true;
>    616          else
>    617                  return false;
>    618  }
>    619
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-15  8:49 [RFC] arm64: Enable perf events based hard lockup detector Sumit Garg
  2020-05-15 14:34 ` kbuild test robot
  2020-05-15 19:51 ` kbuild test robot
@ 2020-05-18 14:34 ` Mark Rutland
  2020-05-18 14:52   ` Daniel Thompson
  2 siblings, 1 reply; 8+ messages in thread
From: Mark Rutland @ 2020-05-18 14:34 UTC (permalink / raw)
  To: Sumit Garg
  Cc: daniel.thompson, peterz, catalin.marinas, jolsa, dianders, acme,
	alexander.shishkin, mingo, julien.thierry.kdev, namhyung, tglx,
	will, linux-arm-kernel

Hi Sumit,

On Fri, May 15, 2020 at 02:19:53PM +0530, Sumit Garg wrote:
> With the recent feature added to enable perf events to use pseudo NMIs
> as interrupts on platforms which support GICv3 or later, its now been
> possible to enable hard lockup detector (or NMI watchdog) on arm64
> platforms. So enable corresponding support.

Where/when do we expect to see this used?

I thought for server systems we'd expect to have the SBSA watchdog, so
why would we need this?

> One thing to note here is that normally lockup detector is initialized
> just after the early initcalls but PMU on arm64 comes up much later as
> device_initcall(). So we need to re-initialize lockup detection once
> PMU has been initialized.
> 
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> ---
> 
> This patch is dependent on perf NMI patch-set [1].
> 
> [1] https://patchwork.kernel.org/cover/11047407/
> 
>  arch/arm64/Kconfig             |  2 ++
>  arch/arm64/kernel/perf_event.c | 32 ++++++++++++++++++++++++++++++--
>  drivers/perf/arm_pmu.c         | 11 +++++++++++
>  include/linux/perf/arm_pmu.h   |  2 ++
>  4 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 40fb05d..36f75c2 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -160,6 +160,8 @@ config ARM64
>  	select HAVE_NMI
>  	select HAVE_PATA_PLATFORM
>  	select HAVE_PERF_EVENTS
> +	select HAVE_PERF_EVENTS_NMI if ARM64_PSEUDO_NMI
> +	select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
>  	select HAVE_PERF_REGS
>  	select HAVE_PERF_USER_STACK_DUMP
>  	select HAVE_REGS_AND_STACK_ACCESS_API
> diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> index 3ad5c8f..df57360 100644
> --- a/arch/arm64/kernel/perf_event.c
> +++ b/arch/arm64/kernel/perf_event.c
> @@ -20,6 +20,8 @@
>  #include <linux/perf/arm_pmu.h>
>  #include <linux/platform_device.h>
>  #include <linux/smp.h>
> +#include <linux/nmi.h>
> +#include <linux/cpufreq.h>
>  
>  /* ARMv8 Cortex-A53 specific event types. */
>  #define ARMV8_A53_PERFCTR_PREF_LINEFILL				0xC2
> @@ -1190,10 +1192,21 @@ static struct platform_driver armv8_pmu_driver = {
>  
>  static int __init armv8_pmu_driver_init(void)
>  {
> +	int ret;
> +
>  	if (acpi_disabled)
> -		return platform_driver_register(&armv8_pmu_driver);
> +		ret = platform_driver_register(&armv8_pmu_driver);
>  	else
> -		return arm_pmu_acpi_probe(armv8_pmuv3_init);
> +		ret = arm_pmu_acpi_probe(armv8_pmuv3_init);
> +
> +	/*
> +	 * Try to re-initialize lockup detector after PMU init in
> +	 * case PMU events are triggered via NMIs.
> +	 */
> +	if (arm_pmu_irq_is_nmi())
> +		lockup_detector_init();
> +
> +	return ret;
>  }
>  device_initcall(armv8_pmu_driver_init)
>  
> @@ -1225,3 +1238,18 @@ void arch_perf_update_userpage(struct perf_event *event,
>  	userpg->time_shift = (u16)shift;
>  	userpg->time_offset = -now;
>  }
> +
> +#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
> +#define SAFE_MAX_CPU_FREQ	4000000000UL // 4 GHz

Why is 4GHz "safe"?

There's no architectural requirement on max frequency, and it's
conceviable that there could be parts faster than this.

If the frequency is critical, then we should bail out when it is
unknown rather than guessing. If it is not cirital then we should
explain what the requirements are and why using a hard-coded value is
sane.

> +u64 hw_nmi_get_sample_period(int watchdog_thresh)
> +{
> +	unsigned int cpu = smp_processor_id();
> +	unsigned int max_cpu_freq;
> +
> +	max_cpu_freq = cpufreq_get_hw_max_freq(cpu);
> +	if (max_cpu_freq)
> +		return (u64)max_cpu_freq * 1000 * watchdog_thresh;
> +	else
> +		return (u64)SAFE_MAX_CPU_FREQ * watchdog_thresh;
> +}

I take it this uses CPU cycles?

AFAIK those can be gated in idle/retention states (e.g. for WFI/WFE or
any other instruction that could block). So if the CPU were blocked on
one of those, the counter would never overflow and trigger the
interrupt.

i.e. this isn't going to detect a hard lockup of that sort.

> +#endif
> diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> index f96cfc4..691dfc9 100644
> --- a/drivers/perf/arm_pmu.c
> +++ b/drivers/perf/arm_pmu.c
> @@ -718,6 +718,17 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
>  	return per_cpu(hw_events->irq, cpu);
>  }
>  
> +bool arm_pmu_irq_is_nmi(void)
> +{
> +	const struct pmu_irq_ops *irq_ops;
> +
> +	irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> +	if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> +		return true;
> +	else
> +		return false;

You can simplify:

| if (x)
|	return true;
| else
|	return false;

... to:

| return x;

Thanks,
Mark.

> +}
> +
>  /*
>   * PMU hardware loses all context when a CPU goes offline.
>   * When a CPU is hotplugged back in, since some hardware registers are
> diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
> index d9b8b76..a71f029 100644
> --- a/include/linux/perf/arm_pmu.h
> +++ b/include/linux/perf/arm_pmu.h
> @@ -155,6 +155,8 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
>  static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
>  #endif
>  
> +bool arm_pmu_irq_is_nmi(void);
> +
>  /* Internal functions only for core arm_pmu code */
>  struct arm_pmu *armpmu_alloc(void);
>  struct arm_pmu *armpmu_alloc_atomic(void);
> -- 
> 2.7.4
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-18 14:34 ` Mark Rutland
@ 2020-05-18 14:52   ` Daniel Thompson
  2020-05-19  6:36     ` Sumit Garg
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Thompson @ 2020-05-18 14:52 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Sumit Garg, peterz, catalin.marinas, jolsa, dianders, acme,
	alexander.shishkin, mingo, julien.thierry.kdev, namhyung, tglx,
	will, linux-arm-kernel

On Mon, May 18, 2020 at 03:34:55PM +0100, Mark Rutland wrote:
> Hi Sumit,
> 
> On Fri, May 15, 2020 at 02:19:53PM +0530, Sumit Garg wrote:
> > With the recent feature added to enable perf events to use pseudo NMIs
> > as interrupts on platforms which support GICv3 or later, its now been
> > possible to enable hard lockup detector (or NMI watchdog) on arm64
> > platforms. So enable corresponding support.
> 
> Where/when do we expect to see this used?
> 
> I thought for server systems we'd expect to have the SBSA watchdog, so
> why would we need this?

I view the lockup detector as a debug tool rather than a traditional
watchdog.

Certainly kernel machinery that prints the stack trace of a CPU that
has got wedged in a manner where it cannot service interrupts should
have fairly obvious applications for debugging embedded systems.


Daniel.


> 
> > One thing to note here is that normally lockup detector is initialized
> > just after the early initcalls but PMU on arm64 comes up much later as
> > device_initcall(). So we need to re-initialize lockup detection once
> > PMU has been initialized.
> > 
> > Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> > ---
> > 
> > This patch is dependent on perf NMI patch-set [1].
> > 
> > [1] https://patchwork.kernel.org/cover/11047407/
> > 
> >  arch/arm64/Kconfig             |  2 ++
> >  arch/arm64/kernel/perf_event.c | 32 ++++++++++++++++++++++++++++++--
> >  drivers/perf/arm_pmu.c         | 11 +++++++++++
> >  include/linux/perf/arm_pmu.h   |  2 ++
> >  4 files changed, 45 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> > index 40fb05d..36f75c2 100644
> > --- a/arch/arm64/Kconfig
> > +++ b/arch/arm64/Kconfig
> > @@ -160,6 +160,8 @@ config ARM64
> >  	select HAVE_NMI
> >  	select HAVE_PATA_PLATFORM
> >  	select HAVE_PERF_EVENTS
> > +	select HAVE_PERF_EVENTS_NMI if ARM64_PSEUDO_NMI
> > +	select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
> >  	select HAVE_PERF_REGS
> >  	select HAVE_PERF_USER_STACK_DUMP
> >  	select HAVE_REGS_AND_STACK_ACCESS_API
> > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> > index 3ad5c8f..df57360 100644
> > --- a/arch/arm64/kernel/perf_event.c
> > +++ b/arch/arm64/kernel/perf_event.c
> > @@ -20,6 +20,8 @@
> >  #include <linux/perf/arm_pmu.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/smp.h>
> > +#include <linux/nmi.h>
> > +#include <linux/cpufreq.h>
> >  
> >  /* ARMv8 Cortex-A53 specific event types. */
> >  #define ARMV8_A53_PERFCTR_PREF_LINEFILL				0xC2
> > @@ -1190,10 +1192,21 @@ static struct platform_driver armv8_pmu_driver = {
> >  
> >  static int __init armv8_pmu_driver_init(void)
> >  {
> > +	int ret;
> > +
> >  	if (acpi_disabled)
> > -		return platform_driver_register(&armv8_pmu_driver);
> > +		ret = platform_driver_register(&armv8_pmu_driver);
> >  	else
> > -		return arm_pmu_acpi_probe(armv8_pmuv3_init);
> > +		ret = arm_pmu_acpi_probe(armv8_pmuv3_init);
> > +
> > +	/*
> > +	 * Try to re-initialize lockup detector after PMU init in
> > +	 * case PMU events are triggered via NMIs.
> > +	 */
> > +	if (arm_pmu_irq_is_nmi())
> > +		lockup_detector_init();
> > +
> > +	return ret;
> >  }
> >  device_initcall(armv8_pmu_driver_init)
> >  
> > @@ -1225,3 +1238,18 @@ void arch_perf_update_userpage(struct perf_event *event,
> >  	userpg->time_shift = (u16)shift;
> >  	userpg->time_offset = -now;
> >  }
> > +
> > +#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
> > +#define SAFE_MAX_CPU_FREQ	4000000000UL // 4 GHz
> 
> Why is 4GHz "safe"?
> 
> There's no architectural requirement on max frequency, and it's
> conceviable that there could be parts faster than this.
> 
> If the frequency is critical, then we should bail out when it is
> unknown rather than guessing. If it is not cirital then we should
> explain what the requirements are and why using a hard-coded value is
> sane.
> 
> > +u64 hw_nmi_get_sample_period(int watchdog_thresh)
> > +{
> > +	unsigned int cpu = smp_processor_id();
> > +	unsigned int max_cpu_freq;
> > +
> > +	max_cpu_freq = cpufreq_get_hw_max_freq(cpu);
> > +	if (max_cpu_freq)
> > +		return (u64)max_cpu_freq * 1000 * watchdog_thresh;
> > +	else
> > +		return (u64)SAFE_MAX_CPU_FREQ * watchdog_thresh;
> > +}
> 
> I take it this uses CPU cycles?
> 
> AFAIK those can be gated in idle/retention states (e.g. for WFI/WFE or
> any other instruction that could block). So if the CPU were blocked on
> one of those, the counter would never overflow and trigger the
> interrupt.
> 
> i.e. this isn't going to detect a hard lockup of that sort.
> 
> > +#endif
> > diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> > index f96cfc4..691dfc9 100644
> > --- a/drivers/perf/arm_pmu.c
> > +++ b/drivers/perf/arm_pmu.c
> > @@ -718,6 +718,17 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
> >  	return per_cpu(hw_events->irq, cpu);
> >  }
> >  
> > +bool arm_pmu_irq_is_nmi(void)
> > +{
> > +	const struct pmu_irq_ops *irq_ops;
> > +
> > +	irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > +	if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> > +		return true;
> > +	else
> > +		return false;
> 
> You can simplify:
> 
> | if (x)
> |	return true;
> | else
> |	return false;
> 
> ... to:
> 
> | return x;
> 
> Thanks,
> Mark.
> 
> > +}
> > +
> >  /*
> >   * PMU hardware loses all context when a CPU goes offline.
> >   * When a CPU is hotplugged back in, since some hardware registers are
> > diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
> > index d9b8b76..a71f029 100644
> > --- a/include/linux/perf/arm_pmu.h
> > +++ b/include/linux/perf/arm_pmu.h
> > @@ -155,6 +155,8 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
> >  static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
> >  #endif
> >  
> > +bool arm_pmu_irq_is_nmi(void);
> > +
> >  /* Internal functions only for core arm_pmu code */
> >  struct arm_pmu *armpmu_alloc(void);
> >  struct arm_pmu *armpmu_alloc_atomic(void);
> > -- 
> > 2.7.4
> > 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-18  5:55   ` Sumit Garg
@ 2020-05-18 23:51     ` Philip Li
  0 siblings, 0 replies; 8+ messages in thread
From: Philip Li @ 2020-05-18 23:51 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 8274 bytes --]

On Mon, May 18, 2020 at 11:25:37AM +0530, Sumit Garg wrote:
> Hi,
> 
> On Sat, 16 May 2020 at 01:21, kbuild test robot <lkp@intel.com> wrote:
> >
> > Hi Sumit,
> >
> > [FYI, it's a private test report for your RFC patch.]
> > [auto build test ERROR on arm64/for-next/core]
> > [also build test ERROR on arm-soc/for-next arm/for-next kvmarm/next linus/master v5.7-rc5 next-20200515]
> > [if your patch is applied to the wrong git tree, please drop us a note to help
> > improve the system. BTW, we also suggest to use '--base' option to specify the
> > base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
> >
> 
> This isn't a correct report as it doesn't take in account the
> dependency of this patch on other patch-set [1] mentioned after "---".
thanks for the input, kindly ignore this false report. So far,
the bot is not able to parse base info like this, thus leads
to false positive.

> 
> [1] https://patchwork.kernel.org/cover/11047407/
> 
> -Sumit
> 
> > url:    https://github.com/0day-ci/linux/commits/Sumit-Garg/arm64-Enable-perf-events-based-hard-lockup-detector/20200515-165226
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
> > config: arm64-randconfig-r025-20200515 (attached as .config)
> > compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 9d4cf5bd421fb6467ff5f00e26a37527246dd4d6)
> > reproduce:
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install arm64 cross compiling tool for clang build
> >         # apt-get install binutils-aarch64-linux-gnu
> >         # save the attached .config to linux build tree
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
> >
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kbuild test robot <lkp@intel.com>
> >
> > All errors (new ones prefixed by >>, old ones prefixed by <<):
> >
> > drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^~~~~~~~~~~
> > cpu_map_ops
> > include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> > #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> > ^
> > include/linux/percpu-defs.h:235:20: note: expanded from macro 'per_cpu_ptr'
> > __verify_pcpu_ptr(ptr);                                                                      ^
> > include/linux/percpu-defs.h:219:47: note: expanded from macro '__verify_pcpu_ptr'
> > const void __percpu *__vpp_verify = (typeof((ptr) + 0))NULL;                                                            ^
> > include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> > BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> > ^
> > drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^~~~~~~~~~~
> > cpu_map_ops
> > include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> > #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> > ^
> > include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> > SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> > include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
> > RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> > ^
> > include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
> > __ptr = (unsigned long) (ptr);                                                              ^
> > include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> > BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> > ^
> > drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^~~~~~~~~~~
> > cpu_map_ops
> > include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> > #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> > ^
> > include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> > SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> > include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
> > RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> > ^
> > include/linux/compiler.h:165:31: note: expanded from macro 'RELOC_HIDE'
> > __ptr = (unsigned long) (ptr);                                                              ^
> > include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> > BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> > ^
> > drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^~~~~~~~~~~
> > cpu_map_ops
> > include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> > #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> > ^
> > include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> > SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> > include/linux/percpu-defs.h:231:23: note: expanded from macro 'SHIFT_PERCPU_PTR'
> > RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> > ^
> > include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
> > (typeof(ptr)) (__ptr + (off)); })
> > ^
> > include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> > BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> > ^
> > drivers/perf/arm_pmu.c:613:20: error: use of undeclared identifier 'cpu_irq_ops'; did you mean 'cpu_map_ops'?
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^~~~~~~~~~~
> > cpu_map_ops
> > include/linux/percpu-defs.h:269:43: note: expanded from macro 'per_cpu'
> > #define per_cpu(var, cpu)       (*per_cpu_ptr(&(var), cpu))
> > ^
> > include/linux/percpu-defs.h:236:20: note: expanded from macro 'per_cpu_ptr'
> > SHIFT_PERCPU_PTR((ptr), per_cpu_offset((cpu)));                                              ^
> > include/linux/percpu-defs.h:231:49: note: expanded from macro 'SHIFT_PERCPU_PTR'
> > RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset))
> > ^
> > include/linux/compiler.h:166:13: note: expanded from macro 'RELOC_HIDE'
> > (typeof(ptr)) (__ptr + (off)); })
> > ^
> > include/linux/bpf_types.h:108:35: note: 'cpu_map_ops' declared here
> > BPF_MAP_TYPE(BPF_MAP_TYPE_CPUMAP, cpu_map_ops)
> > ^
> > >> drivers/perf/arm_pmu.c:613:10: error: assigning to 'const struct pmu_irq_ops *' from incompatible type 'typeof (*((&(cpu_map_ops))))' (aka 'const struct bpf_map_ops')
> > irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > drivers/perf/arm_pmu.c:614:18: error: use of undeclared identifier 'pmunmi_ops'
> > if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> > ^
> > drivers/perf/arm_pmu.c:614:44: error: use of undeclared identifier 'percpu_pmunmi_ops'
> > if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> > ^
> > 8 errors generated.
> >
> > vim +613 drivers/perf/arm_pmu.c
> >
> >    608
> >    609  bool arm_pmu_irq_is_nmi(void)
> >    610  {
> >    611          const struct pmu_irq_ops *irq_ops;
> >    612
> >  > 613          irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> >    614          if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> >    615                  return true;
> >    616          else
> >    617                  return false;
> >    618  }
> >    619
> >
> > ---
> > 0-DAY CI Kernel Test Service, Intel Corporation
> > https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
> _______________________________________________
> kbuild-all mailing list -- kbuild-all(a)lists.01.org
> To unsubscribe send an email to kbuild-all-leave(a)lists.01.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] arm64: Enable perf events based hard lockup detector
  2020-05-18 14:52   ` Daniel Thompson
@ 2020-05-19  6:36     ` Sumit Garg
  0 siblings, 0 replies; 8+ messages in thread
From: Sumit Garg @ 2020-05-19  6:36 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Daniel Thompson, Peter Zijlstra, Catalin Marinas, jolsa,
	Douglas Anderson, acme, alexander.shishkin, mingo,
	julien.thierry.kdev, namhyung, Thomas Gleixner, Will Deacon,
	linux-arm-kernel

Hi Mark,

On Mon, 18 May 2020 at 20:22, Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>
> On Mon, May 18, 2020 at 03:34:55PM +0100, Mark Rutland wrote:
> > Hi Sumit,
> >
> > On Fri, May 15, 2020 at 02:19:53PM +0530, Sumit Garg wrote:
> > > With the recent feature added to enable perf events to use pseudo NMIs
> > > as interrupts on platforms which support GICv3 or later, its now been
> > > possible to enable hard lockup detector (or NMI watchdog) on arm64
> > > platforms. So enable corresponding support.
> >
> > Where/when do we expect to see this used?
> >
> > I thought for server systems we'd expect to have the SBSA watchdog, so
> > why would we need this?
>
> I view the lockup detector as a debug tool rather than a traditional
> watchdog.
>
> Certainly kernel machinery that prints the stack trace of a CPU that
> has got wedged in a manner where it cannot service interrupts should
> have fairly obvious applications for debugging embedded systems.
>

+1

>
>
> >
> > > One thing to note here is that normally lockup detector is initialized
> > > just after the early initcalls but PMU on arm64 comes up much later as
> > > device_initcall(). So we need to re-initialize lockup detection once
> > > PMU has been initialized.
> > >
> > > Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> > > ---
> > >
> > > This patch is dependent on perf NMI patch-set [1].
> > >
> > > [1] https://patchwork.kernel.org/cover/11047407/
> > >
> > >  arch/arm64/Kconfig             |  2 ++
> > >  arch/arm64/kernel/perf_event.c | 32 ++++++++++++++++++++++++++++++--
> > >  drivers/perf/arm_pmu.c         | 11 +++++++++++
> > >  include/linux/perf/arm_pmu.h   |  2 ++
> > >  4 files changed, 45 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> > > index 40fb05d..36f75c2 100644
> > > --- a/arch/arm64/Kconfig
> > > +++ b/arch/arm64/Kconfig
> > > @@ -160,6 +160,8 @@ config ARM64
> > >     select HAVE_NMI
> > >     select HAVE_PATA_PLATFORM
> > >     select HAVE_PERF_EVENTS
> > > +   select HAVE_PERF_EVENTS_NMI if ARM64_PSEUDO_NMI
> > > +   select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_NMI
> > >     select HAVE_PERF_REGS
> > >     select HAVE_PERF_USER_STACK_DUMP
> > >     select HAVE_REGS_AND_STACK_ACCESS_API
> > > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
> > > index 3ad5c8f..df57360 100644
> > > --- a/arch/arm64/kernel/perf_event.c
> > > +++ b/arch/arm64/kernel/perf_event.c
> > > @@ -20,6 +20,8 @@
> > >  #include <linux/perf/arm_pmu.h>
> > >  #include <linux/platform_device.h>
> > >  #include <linux/smp.h>
> > > +#include <linux/nmi.h>
> > > +#include <linux/cpufreq.h>
> > >
> > >  /* ARMv8 Cortex-A53 specific event types. */
> > >  #define ARMV8_A53_PERFCTR_PREF_LINEFILL                            0xC2
> > > @@ -1190,10 +1192,21 @@ static struct platform_driver armv8_pmu_driver = {
> > >
> > >  static int __init armv8_pmu_driver_init(void)
> > >  {
> > > +   int ret;
> > > +
> > >     if (acpi_disabled)
> > > -           return platform_driver_register(&armv8_pmu_driver);
> > > +           ret = platform_driver_register(&armv8_pmu_driver);
> > >     else
> > > -           return arm_pmu_acpi_probe(armv8_pmuv3_init);
> > > +           ret = arm_pmu_acpi_probe(armv8_pmuv3_init);
> > > +
> > > +   /*
> > > +    * Try to re-initialize lockup detector after PMU init in
> > > +    * case PMU events are triggered via NMIs.
> > > +    */
> > > +   if (arm_pmu_irq_is_nmi())
> > > +           lockup_detector_init();
> > > +
> > > +   return ret;
> > >  }
> > >  device_initcall(armv8_pmu_driver_init)
> > >
> > > @@ -1225,3 +1238,18 @@ void arch_perf_update_userpage(struct perf_event *event,
> > >     userpg->time_shift = (u16)shift;
> > >     userpg->time_offset = -now;
> > >  }
> > > +
> > > +#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
> > > +#define SAFE_MAX_CPU_FREQ  4000000000UL // 4 GHz
> >
> > Why is 4GHz "safe"?
> >
> > There's no architectural requirement on max frequency, and it's
> > conceviable that there could be parts faster than this.
> >
> > If the frequency is critical, then we should bail out when it is
> > unknown rather than guessing. If it is not cirital then we should
> > explain what the requirements are and why using a hard-coded value is
> > sane.

The frequency is critical in the sense that it shouldn't lead to a
timeout less than watchdog threshold (10 sec.) for hard-lockup
detector. And we can't simply bail out here, since there could be
platforms which doesn't implement cpufreq driver (eg. Developerbox).

I chose 4GHz as a safe maximum here as I couldn't find any real parts
as of now running faster than 4GHz. But I agree with you that
architecture doesn't put any restrictions on max. frequency. So we can
certainly put a higher hardcoded value here and the only side effect
of this would be a bigger hard-lockup detector timeout (which I think
should be acceptable) on parts which are running slower (eg. 1GHz on
Developerbox) and doesn't possess a cpufreq driver.

> >
> > > +u64 hw_nmi_get_sample_period(int watchdog_thresh)
> > > +{
> > > +   unsigned int cpu = smp_processor_id();
> > > +   unsigned int max_cpu_freq;
> > > +
> > > +   max_cpu_freq = cpufreq_get_hw_max_freq(cpu);
> > > +   if (max_cpu_freq)
> > > +           return (u64)max_cpu_freq * 1000 * watchdog_thresh;
> > > +   else
> > > +           return (u64)SAFE_MAX_CPU_FREQ * watchdog_thresh;
> > > +}
> >
> > I take it this uses CPU cycles?

Yes its based on perf event with config attribute as PERF_COUNT_HW_CPU_CYCLES.

> >
> > AFAIK those can be gated in idle/retention states (e.g. for WFI/WFE or
> > any other instruction that could block). So if the CPU were blocked on
> > one of those, the counter would never overflow and trigger the
> > interrupt.
> >
> > i.e. this isn't going to detect a hard lockup of that sort.

Isn't this a correct behaviour as we shouldn't raise a false
hard-lockup detection while the CPU is actually in idle/retention
states? IMO, this feature is useful for debugging purposes when a
particular CPU is stuck in a deadlock loop with interrupts disabled.

> >
> > > +#endif
> > > diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
> > > index f96cfc4..691dfc9 100644
> > > --- a/drivers/perf/arm_pmu.c
> > > +++ b/drivers/perf/arm_pmu.c
> > > @@ -718,6 +718,17 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
> > >     return per_cpu(hw_events->irq, cpu);
> > >  }
> > >
> > > +bool arm_pmu_irq_is_nmi(void)
> > > +{
> > > +   const struct pmu_irq_ops *irq_ops;
> > > +
> > > +   irq_ops = per_cpu(cpu_irq_ops, smp_processor_id());
> > > +   if (irq_ops == &pmunmi_ops || irq_ops == &percpu_pmunmi_ops)
> > > +           return true;
> > > +   else
> > > +           return false;
> >
> > You can simplify:
> >
> > | if (x)
> > |     return true;
> > | else
> > |     return false;
> >
> > ... to:
> >
> > | return x;
> >

Looks clean, will use it instead.

-Sumit

> > Thanks,
> > Mark.
> >
> > > +}
> > > +
> > >  /*
> > >   * PMU hardware loses all context when a CPU goes offline.
> > >   * When a CPU is hotplugged back in, since some hardware registers are
> > > diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
> > > index d9b8b76..a71f029 100644
> > > --- a/include/linux/perf/arm_pmu.h
> > > +++ b/include/linux/perf/arm_pmu.h
> > > @@ -155,6 +155,8 @@ int arm_pmu_acpi_probe(armpmu_init_fn init_fn);
> > >  static inline int arm_pmu_acpi_probe(armpmu_init_fn init_fn) { return 0; }
> > >  #endif
> > >
> > > +bool arm_pmu_irq_is_nmi(void);
> > > +
> > >  /* Internal functions only for core arm_pmu code */
> > >  struct arm_pmu *armpmu_alloc(void);
> > >  struct arm_pmu *armpmu_alloc_atomic(void);
> > > --
> > > 2.7.4
> > >

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-05-19  6:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15  8:49 [RFC] arm64: Enable perf events based hard lockup detector Sumit Garg
2020-05-15 14:34 ` kbuild test robot
2020-05-15 19:51 ` kbuild test robot
2020-05-18  5:55   ` Sumit Garg
2020-05-18 23:51     ` Philip Li
2020-05-18 14:34 ` Mark Rutland
2020-05-18 14:52   ` Daniel Thompson
2020-05-19  6:36     ` Sumit Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.