From nobody Fri Dec 19 08:59:18 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B78F6219313 for ; Fri, 14 Nov 2025 03:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763091187; cv=none; b=L3QpqvecOH4S4hLMTzKVBvLvdFOTL/qXQh/iMoNXu1XG69Us/TNdYMleLf9//vko0tdie46EAmTrg5qpPmsjQGlM/Pth+TpVNMXtBoRN1CEcoRv2kbSxTUatuTfi6y/voUnR54tnr5bmmUBfoFKZm9F4fnXc7L/gjOUdmaNPO8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763091187; c=relaxed/simple; bh=dFdvyDN8cJwEZ2SlK+FUFUzTIB7G8ldfrmCDIVLTAMM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Hb5IRTpV3J5yC+JN9Z6Qs/D41rBLZgFj6U9APbCu3Z4pndyw39IdzXoUpIqhUUYaKVb2O0FzfObXGB1ACLUW+VxAJq7WlcuoYRtBMHAGwjmFgL9nGJCdBXkH9J/h3vGhTpK3NbS+XyTAzdPK1e0HQT8SM9V0rGA8vzqqHBHRgvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=UjjI8YC8; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="UjjI8YC8" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-298145fe27eso18162815ad.1 for ; Thu, 13 Nov 2025 19:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1763091184; x=1763695984; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sy8ufhf77jyVm5UegRGiIo/nMsISXeDDGy6ne/zkAk8=; b=UjjI8YC8U4P8g41arO5Ufy9TOWTKLydWZdHX/3nI7B+J8Lrw38NTPhqfH8+ovCtnoC Okgv8Wn+6Rc52EKf01bJIrKFNDzHvl7VbvN5w101ZYxVur/+nMNgjc8dHFHKN6Tbse6Y 5TgL4uvYkwie6JwsxYRotvtzhmaiis608EK+PfLUaCmVHaTMX36O+IldqQ1iSBSMqGrR KwyOWc+kEG67DxdHYfPhuzV96/ODoaJvCUD5RW3VBtpT60R3U7MsyWVLM5N8jnUy14u8 vjEcYIzWmIbHNU7Hd9OnObI6l9Oh9lDLkIn928FgM/qHt/JgbSXEUwA6NzxyefPoLtL8 jhlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763091184; x=1763695984; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sy8ufhf77jyVm5UegRGiIo/nMsISXeDDGy6ne/zkAk8=; b=WwVgBJ+u5H/ppCeC0OTAewKk2ZSXuJ9XYiZJLA5epvDSTUNEnwKM0/KE3swzt5CPZO dHlJGSkknbocKiHizlbEHPy/t0EowxU07BKF/M264vBZdneb1QcaTM//1lonWBKw28eB KRv5O99mJC4jMfhz5kInyol1RBerGBQalqAx4qLVkIAitWShLNHQUlBuxnzMpbkeBEAy ydQCjb3DomGwR0tQk7TlNE3mhmQHyA9lU913slFmG15RJRwlnf5jklPsyYtHcEzRqPNK cit4cDJGLt43ESwlv0pGqW56JQm9to4gIokWr8QzUGixmkICyOu0mQzFo6iKxJQV5CcB 7ykQ== X-Forwarded-Encrypted: i=1; AJvYcCWLSjtvVKYMLdQJTrUGMnwW5gqx/uiGu+SU8aGAgTE73R3zT20kZMMAP+FFzFwrjSFuoPz3GOxdNGmPRDY=@vger.kernel.org X-Gm-Message-State: AOJu0YwBkreP36bzwJKpj1lVEx58hj2v6gXZXyrr41/vmFGh+zonGFEP Kqu3/m+ph7v9DiNjKwny16TnQU8661bruYcEIuGT3gsbygB7epPNaD6D3lRhjCik8mM= X-Gm-Gg: ASbGncu9DD45wqp+LaXY9qzXAyB4fHaLBxNyzImHtSu3CNp/8fkEk+x27hvWXz2eqKC 8OQTmQkdZlnnVP9e8hqJ772V6OBt32PgPWeHV+pf9Y5qJES4g/i60uSzBF4QMFd4LTXJZY1ReIt UkpcXxfWYN03UhoLxD78PInT1Bl1MIDjNQCuFNBdaZdLlaFUuERCnLTWe0sAERrfycKChiXw4Ru 3zL9onaOyeN39AASBJ3PDExKyhpMUvJ7RaUUFnlhGn7Vy2LNVuNg30eIMmgnHHiZNyBfxoOkMG7 5JJKb32ipgkCvf5e4SNXoN0uOBdWqsCfIe91w3CYqdd6NtUKeZXtDysV17Uy0aJqwr+/Ri5UN/I hRAKmjpSe2VKlYm/jEvbmia10yXy3v4LUJKog7q4Fjn0DicXxdLBAth9l2sn8BA3PKJ5GpWEMoo nnI9szx3wHvYuUuIApFfjlbLnRTDcJ0Q== X-Google-Smtp-Source: AGHT+IG/4zHUWKqxMS401ES7xnodSOwrmv3r2ygCcv3FlGsAoT4tVlnp649tXVNvhI8rAh9GPPmYqg== X-Received: by 2002:a17:903:2b10:b0:297:d777:a2d4 with SMTP id d9443c01a7336-2986a752800mr15662975ad.46.1763091183808; Thu, 13 Nov 2025 19:33:03 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2b0bf0sm40334405ad.71.2025.11.13.19.32.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 13 Nov 2025 19:33:03 -0800 (PST) From: Yunhui Cui To: akpm@linux-foundation.org, alex@ghiti.fr, anup@brainfault.org, aou@eecs.berkeley.edu, atish.patra@linux.dev, catalin.marinas@arm.com, cuiyunhui@bytedance.com, dianders@chromium.org, johannes@sipsolutions.net, lihuafei1@huawei.com, mark.rutland@arm.com, masahiroy@kernel.org, maz@kernel.org, mingo@kernel.org, nicolas.schier@linux.dev, palmer@dabbelt.com, paul.walmsley@sifive.com, suzuki.poulose@arm.com, thorsten.blum@linux.dev, wangjinchao600@gmail.com, will@kernel.org, yangyicong@hisilicon.com, zhanjie9@hisilicon.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v6 1/2] watchdog: move arm64 watchdog_hld into common code Date: Fri, 14 Nov 2025 11:32:42 +0800 Message-Id: <20251114033243.76509-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251114033243.76509-1-cuiyunhui@bytedance.com> References: <20251114033243.76509-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the contents of arch/arm64/watchdog_hld.c to kernel/watchdog_perf.c to create a generic implementation that can be reused by other arch, such as RISC-V. Signed-off-by: Yunhui Cui Reviewed-by: Douglas Anderson --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/watchdog_hld.c | 94 -------------------------------- drivers/perf/arm_pmu.c | 10 +++- include/linux/perf/arm_pmu.h | 2 - kernel/watchdog_perf.c | 83 ++++++++++++++++++++++++++++ lib/Kconfig.debug | 8 +++ 7 files changed, 101 insertions(+), 98 deletions(-) delete mode 100644 arch/arm64/kernel/watchdog_hld.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6663ffd23f252..6614ff45b1e06 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -231,6 +231,7 @@ config ARM64 select HAVE_GCC_PLUGINS select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && \ HW_PERF_EVENTS && HAVE_PERF_EVENTS_NMI + select WATCHDOG_PERF_ADJUST_PERIOD if HARDLOCKUP_DETECTOR_PERF select HAVE_HW_BREAKPOINT if PERF_EVENTS select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 76f32e424065e..12d77f373fea4 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -44,7 +44,6 @@ obj-$(CONFIG_KUSER_HELPERS) +=3D kuser32.o obj-$(CONFIG_FUNCTION_TRACER) +=3D ftrace.o entry-ftrace.o obj-$(CONFIG_MODULES) +=3D module.o module-plts.o obj-$(CONFIG_PERF_EVENTS) +=3D perf_regs.o perf_callchain.o -obj-$(CONFIG_HARDLOCKUP_DETECTOR_PERF) +=3D watchdog_hld.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) +=3D hw_breakpoint.o obj-$(CONFIG_CPU_PM) +=3D sleep.o suspend.o obj-$(CONFIG_KGDB) +=3D kgdb.o diff --git a/arch/arm64/kernel/watchdog_hld.c b/arch/arm64/kernel/watchdog_= hld.c deleted file mode 100644 index 3093037dcb7be..0000000000000 --- a/arch/arm64/kernel/watchdog_hld.c +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include - -/* - * Safe maximum CPU frequency in case a particular platform doesn't implem= ent - * cpufreq driver. Although, architecture doesn't put any restrictions on - * maximum frequency but 5 GHz seems to be safe maximum given the available - * Arm CPUs in the market which are clocked much less than 5 GHz. On the o= ther - * hand, we can't make it much higher as it would lead to a large hard-loc= kup - * detection timeout on parts which are running slower (eg. 1GHz on - * Developerbox) and doesn't possess a cpufreq driver. - */ -#define SAFE_MAX_CPU_FREQ 5000000000UL // 5 GHz -u64 hw_nmi_get_sample_period(int watchdog_thresh) -{ - unsigned int cpu =3D smp_processor_id(); - unsigned long max_cpu_freq; - - max_cpu_freq =3D cpufreq_get_hw_max_freq(cpu) * 1000UL; - if (!max_cpu_freq) - max_cpu_freq =3D SAFE_MAX_CPU_FREQ; - - return (u64)max_cpu_freq * watchdog_thresh; -} - -bool __init arch_perf_nmi_is_available(void) -{ - /* - * hardlockup_detector_perf_init() will success even if Pseudo-NMI turns = off, - * however, the pmu interrupts will act like a normal interrupt instead of - * NMI and the hardlockup detector would be broken. - */ - return arm_pmu_irq_is_nmi(); -} - -static int watchdog_perf_update_period(void *data) -{ - int cpu =3D smp_processor_id(); - u64 max_cpu_freq, new_period; - - max_cpu_freq =3D cpufreq_get_hw_max_freq(cpu) * 1000UL; - if (!max_cpu_freq) - return 0; - - new_period =3D watchdog_thresh * max_cpu_freq; - hardlockup_detector_perf_adjust_period(new_period); - - return 0; -} - -static int watchdog_freq_notifier_callback(struct notifier_block *nb, - unsigned long val, void *data) -{ - struct cpufreq_policy *policy =3D data; - int cpu; - - if (val !=3D CPUFREQ_CREATE_POLICY) - return NOTIFY_DONE; - - /* - * Let each online CPU related to the policy update the period by their - * own. This will serialize with the framework on start/stop the lockup - * detector (softlockup_{start,stop}_all) and avoid potential race - * condition. Otherwise we may have below theoretical race condition: - * (core 0/1 share the same policy) - * [core 0] [core 1] - * hardlockup_detector_event_create() - * hw_nmi_get_sample_period() - * (cpufreq registered, notifier callback invoked) - * watchdog_freq_notifier_callback() - * watchdog_perf_update_period() - * (since core 1's event's not yet created, - * the period is not set) - * perf_event_create_kernel_counter() - * (event's period is SAFE_MAX_CPU_FREQ) - */ - for_each_cpu(cpu, policy->cpus) - smp_call_on_cpu(cpu, watchdog_perf_update_period, NULL, false); - - return NOTIFY_DONE; -} - -static struct notifier_block watchdog_freq_notifier =3D { - .notifier_call =3D watchdog_freq_notifier_callback, -}; - -static int __init init_watchdog_freq_notifier(void) -{ - return cpufreq_register_notifier(&watchdog_freq_notifier, - CPUFREQ_POLICY_NOTIFIER); -} -core_initcall(init_watchdog_freq_notifier); diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 973a027d90639..294a5c3438ad1 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -703,10 +704,17 @@ static int armpmu_get_cpu_irq(struct arm_pmu *pmu, in= t cpu) return per_cpu(hw_events->irq, cpu); } =20 -bool arm_pmu_irq_is_nmi(void) +#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF +bool arch_perf_nmi_is_available(void) { + /* + * watchdog_hardlockup_probe() will success even if Pseudo-NMI turns off, + * however, the pmu interrupts will act like a normal interrupt instead of + * NMI and the hardlockup detector would be broken. + */ return has_nmi; } +#endif =20 /* * PMU hardware loses all context when a CPU goes offline. diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 52b37f7bdbf9e..8f06751f1e176 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -183,8 +183,6 @@ void kvm_host_pmu_init(struct arm_pmu *pmu); #define kvm_host_pmu_init(x) do { } while(0) #endif =20 -bool arm_pmu_irq_is_nmi(void); - /* Internal functions only for core arm_pmu code */ struct arm_pmu *armpmu_alloc(void); void armpmu_free(struct arm_pmu *pmu); diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c index d3ca70e3c256a..8aa5e9a0ba20a 100644 --- a/kernel/watchdog_perf.c +++ b/kernel/watchdog_perf.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -306,3 +307,85 @@ void __init hardlockup_config_perf_event(const char *s= tr) wd_hw_attr.type =3D PERF_TYPE_RAW; wd_hw_attr.config =3D config; } + +#ifdef CONFIG_WATCHDOG_PERF_ADJUST_PERIOD +/* + * Safe maximum CPU frequency in case a particular platform doesn't implem= ent + * cpufreq driver. Although, architecture doesn't put any restrictions on + * maximum frequency but 5 GHz seems to be safe maximum given the available + * CPUs in the market which are clocked much less than 5 GHz. On the other + * hand, we can't make it much higher as it would lead to a large hard-loc= kup + * detection timeout on parts which are running slower (eg. 1GHz on + * Developerbox) and doesn't possess a cpufreq driver. + */ +#define SAFE_MAX_CPU_FREQ 5000000000UL // 5 GHz +u64 hw_nmi_get_sample_period(int watchdog_thresh) +{ + unsigned int cpu =3D smp_processor_id(); + unsigned long max_cpu_freq; + + max_cpu_freq =3D cpufreq_get_hw_max_freq(cpu) * 1000UL; + if (!max_cpu_freq) + max_cpu_freq =3D SAFE_MAX_CPU_FREQ; + + return (u64)max_cpu_freq * watchdog_thresh; +} + +static int watchdog_perf_update_period(void *data) +{ + int cpu =3D smp_processor_id(); + u64 max_cpu_freq, new_period; + + max_cpu_freq =3D cpufreq_get_hw_max_freq(cpu) * 1000UL; + if (!max_cpu_freq) + return 0; + + new_period =3D watchdog_thresh * max_cpu_freq; + hardlockup_detector_perf_adjust_period(new_period); + + return 0; +} + +static int watchdog_freq_notifier_callback(struct notifier_block *nb, + unsigned long val, void *data) +{ + struct cpufreq_policy *policy =3D data; + int cpu; + + if (val !=3D CPUFREQ_CREATE_POLICY) + return NOTIFY_DONE; + + /* + * Let each online CPU related to the policy update the period by their + * own. This will serialize with the framework on start/stop the lockup + * detector (softlockup_{start,stop}_all) and avoid potential race + * condition. Otherwise we may have below theoretical race condition: + * (core 0/1 share the same policy) + * [core 0] [core 1] + * hardlockup_detector_event_create() + * hw_nmi_get_sample_period() + * (cpufreq registered, notifier callback invoked) + * watchdog_freq_notifier_callback() + * watchdog_perf_update_period() + * (since core 1's event's not yet created, + * the period is not set) + * perf_event_create_kernel_counter() + * (event's period is SAFE_MAX_CPU_FREQ) + */ + for_each_cpu(cpu, policy->cpus) + smp_call_on_cpu(cpu, watchdog_perf_update_period, NULL, false); + + return NOTIFY_DONE; +} + +static struct notifier_block watchdog_freq_notifier =3D { + .notifier_call =3D watchdog_freq_notifier_callback, +}; + +static int __init init_watchdog_freq_notifier(void) +{ + return cpufreq_register_notifier(&watchdog_freq_notifier, + CPUFREQ_POLICY_NOTIFIER); +} +core_initcall(init_watchdog_freq_notifier); +#endif diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2cbfa3dead0be..85fdfa9b52346 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1193,6 +1193,14 @@ config HARDLOCKUP_DETECTOR_PERF depends on !HAVE_HARDLOCKUP_DETECTOR_ARCH select HARDLOCKUP_DETECTOR_COUNTS_HRTIMER =20 +config WATCHDOG_PERF_ADJUST_PERIOD + bool + help + Adjust the watchdog hardlockup detector's period based on CPU max + frequency. Uses cpufreq if available; falls back to a safe 5 GHz + default otherwise. Registers a cpufreq notifier to update the period + automatically. + config HARDLOCKUP_DETECTOR_BUDDY bool depends on HARDLOCKUP_DETECTOR --=20 2.39.5 From nobody Fri Dec 19 08:59:18 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82A3C26056D for ; Fri, 14 Nov 2025 03:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763091195; cv=none; b=XabTarmROTa9FYjDxnkcwCQzE1rPvb+qkwlo3AWFFBIygV4ei/xtieYsqCMckZ8PSepXvUx8+EmZbTx0ElOH7uAiWgFY0NsX0E7XVfcdRt7vNI48iy1LEDDQgm33Tu3OzJo1fVA8YxNZ25QFQF4FPVXFh9WHu94KQl12Kr2z+Mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763091195; c=relaxed/simple; bh=MEktD7Q4lr4BzIQfNar3Unfhcxo9clcZUzcd+NqIv1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YjrHDjFsS633xM7GOn9CzeMFEFLAwZf0lCooX8lDoxHuRWfgPv085Vvx5LbiJBaXlhi4wCALbRwu9XFcqkzvTTdC4F37yXKCi1ozVtZuWVA51Fm/0HtZ0EUlFPtwylv7imtQ1tEV1jy3sc1YWpIHCvwxb4571nQB61lrfNI/138= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=XFxhFgfW; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="XFxhFgfW" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-297d4a56f97so14960855ad.1 for ; Thu, 13 Nov 2025 19:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1763091192; x=1763695992; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwoYW3TpVbjpnbuDSYglQbGQzGJdKy4yKIu8+Puv/Yk=; b=XFxhFgfWOMISEOkzt1hh+/qg8Dtms8qdfA5+6D3ZRiR12aE2diTYHpjV7Lg8+XI+42 BCGdtIW17X24ZwXvuIpggXzZOGr8uNzeAILLleYOP4ztjrTCxdv4upwaepjDSxlaW0KF Z/ackthbYRXdQZNli+YPYWOBtzKFcwkMqP5yFlxb4AWB3EGYu95nB85FJxss8tnbJC4G ur5vlLe18pRGhGgy1cRyOFvzSEXSsxeC5tk65/eD96z8OG2yIfaPmABKK2dHDkr+aszd uTHrcI2nXxcMxJHegzENpPHPYHOOZUCYBAlltmSqtZ4YhfZSGD6ec+fK6JJc0KQDj2hY t15Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763091192; x=1763695992; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RwoYW3TpVbjpnbuDSYglQbGQzGJdKy4yKIu8+Puv/Yk=; b=tXI+kPLjOCSvN7aDA0oEcBe3vGic+MZcGpLEmD5+Uz4SqVFEZcnC+tuj8SfqKCpvah 6kr3I2AMam4rH94LJlOMaJRF6QH0vw7TdNrqAANrMHXKN0yj/0PNcxPaX9qFbL1a2tcw aLcnriYlfNpr1eASnV7ihb8ka3HxFJCrGGg1qzPhv79aJTEIpEmKFKcgL2Ocg4E5KcuY c/3RmvOGy7ynG9hBm2gVTJ3q1FcrM1j8O5SE3zhDWSTdxYNUzbWz141lor/FpaQHQH2x t8WguQ5ww1mN8FdUQqdgkS1nvZ6G9LyeawB0HsFxB7zNF0sAvLHBnWtyv4qUOdf/hkQc 1FPw== X-Forwarded-Encrypted: i=1; AJvYcCUnVLXhKRGn6lFQlXskL15ZuNvnKQp98wGUJbX26vWnLhp34xUzaGfznPMOulXYWWyXwb5s8G1Zova5RMQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwnL7B+h7CuS3LxvvVLEmGtlAFDyQk5nKq1GVW/7/0Mwv5hcVlK niwhkGrM02MYmypmaKmhIsDPI82TEnpxq/rY0mTDPvoCzJlCtLvK1xAi95qX9doTlB8= X-Gm-Gg: ASbGncufZaj95yLyBPhUrKR1aWiUs8Wn+CN0e+HlqXjvk4PR2gxh4HTrq48VLeYJkhN eMANlFfNKZfja0Q3lOGhB1UMTIHeQCb+O9KJEmtvypB9Gwwq3X/2NBf9WVn5IW3kjevdZqx/JQ2 UVod4jeWWK8uNfk/c7Ffe0AuVIemaCSQQ4f3jZJKD7bBspiiCRAg2LznMrMHDkX5oHIjJ91zjfQ /QwbRaYPQGkqcDTZ4Cx2q57/wOI4tTTL1DQPwGxhT0yW2nfLd/CgB6TK0dgqGuWpjkbQnsJ2zYr no6OonDFaKcT1MgwmcndS3XZpncArrhndPU1D/owRUkWXiu3v3G1TKNZyS2gViVh10IqrHyyQOx yccf5YPE9L5pAFIsjJLFF9uQ8af9acpR4rQS9JroWrkbPSY9ZKDLdritgvF1hz37aquRSGwd971 GYzl1PBnIutYrSYGfcns2ofwTrtCCr0A== X-Google-Smtp-Source: AGHT+IHfXjnRp3cTFGa+8Qanqxwy10UGsb/fLvaOOKkhNjGlyR2g6kaDXFitMh3x5rYeK43UijaMTw== X-Received: by 2002:a17:903:247:b0:252:a80c:3cc5 with SMTP id d9443c01a7336-2986a6beeb4mr15742395ad.22.1763091191709; Thu, 13 Nov 2025 19:33:11 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([61.213.176.8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2b0bf0sm40334405ad.71.2025.11.13.19.33.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 13 Nov 2025 19:33:11 -0800 (PST) From: Yunhui Cui To: akpm@linux-foundation.org, alex@ghiti.fr, anup@brainfault.org, aou@eecs.berkeley.edu, atish.patra@linux.dev, catalin.marinas@arm.com, cuiyunhui@bytedance.com, dianders@chromium.org, johannes@sipsolutions.net, lihuafei1@huawei.com, mark.rutland@arm.com, masahiroy@kernel.org, maz@kernel.org, mingo@kernel.org, nicolas.schier@linux.dev, palmer@dabbelt.com, paul.walmsley@sifive.com, suzuki.poulose@arm.com, thorsten.blum@linux.dev, wangjinchao600@gmail.com, will@kernel.org, yangyicong@hisilicon.com, zhanjie9@hisilicon.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Paul Walmsley Subject: [PATCH v6 2/2] riscv: add HARDLOCKUP_DETECTOR_PERF support Date: Fri, 14 Nov 2025 11:32:43 +0800 Message-Id: <20251114033243.76509-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251114033243.76509-1-cuiyunhui@bytedance.com> References: <20251114033243.76509-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable the HARDLOCKUP_DETECTOR_PERF function based on RISC-V SSE. Signed-off-by: Yunhui Cui Reviewed-by: Douglas Anderson Acked-by: Paul Walmsley --- arch/riscv/Kconfig | 3 +++ drivers/perf/riscv_pmu_sbi.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index fadec20b87a8e..46ccd33732fa8 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -186,6 +186,9 @@ config RISCV select HAVE_PAGE_SIZE_4KB select HAVE_PCI select HAVE_PERF_EVENTS + select HAVE_PERF_EVENTS_NMI if RISCV_PMU_SBI_SSE + select HAVE_HARDLOCKUP_DETECTOR_PERF if PERF_EVENTS && HAVE_PERF_EVENTS_N= MI + select WATCHDOG_PERF_ADJUST_PERIOD if HARDLOCKUP_DETECTOR_PERF select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_POSIX_CPU_TIMERS_TASK_WORK diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index c852f64a50221..0c7c5924687c9 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -22,6 +22,7 @@ #include #include #include +#include =20 #include #include @@ -1192,6 +1193,13 @@ static int pmu_sbi_setup_sse(struct riscv_pmu *pmu) } #endif =20 +#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF +bool arch_perf_nmi_is_available(void) +{ + return IS_ENABLED(CONFIG_RISCV_PMU_SBI_SSE); +} +#endif + static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node) { struct riscv_pmu *pmu =3D hlist_entry_safe(node, struct riscv_pmu, node); @@ -1618,6 +1626,8 @@ static int __init pmu_sbi_devinit(void) /* Notify legacy implementation that SBI pmu is available*/ riscv_pmu_legacy_skip_init(); =20 + lockup_detector_retry_init(); + return ret; } device_initcall(pmu_sbi_devinit) --=20 2.39.5