From nobody Fri Dec 19 09:00:51 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 6E2BD235061 for ; Thu, 9 Oct 2025 03:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759980575; cv=none; b=i6yzN5vMvcYj0X/WSDETunTOXv4780dX8d6/+1cz+CqjFpfq83Jyt/eXNmBLG2X9qCrv/FVg2/Ydpy/IDOnGpKb+Sgf+G67EagVLoVYLHCPuluI+p0U7dLKQL/yaguiwGs7CMwmUuVRfVXDICjkqyh9DsR9HwDQaHLvI4gfd5A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759980575; c=relaxed/simple; bh=IhC/UOFnmSHyLzQ1EP+Y/4bstcN+xHbWA7vQc/bR6Q4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=glLplVy6foNlqHS44IYDvY1bwkahsC8sUVsA4K69OV0+UgOl7wZmf3XF01tS/KQcetC5gaK4TlAkUQy0Wu8ZKNDLiN7XnSRvCCl+tTxgxnokcfgUnBImkxCYtarI6NIai2CTxuTW9nVRJEE+T8d2DLiQW7g+QjCfSL326dkE6Qk= 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=XQN6zkC3; arc=none smtp.client-ip=209.85.210.176 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="XQN6zkC3" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-791c287c10dso446166b3a.1 for ; Wed, 08 Oct 2025 20:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1759980573; x=1760585373; 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=qCf+yVl6FKe7XvOkXqCLKdcU8Ah3TZ2cAs6NdRK29XY=; b=XQN6zkC34iZMcxPGuFiq8KEMAKiEV/5KH4e7X+8BwEEfCWM6fDvcGvzceU9zIU7fHz ZDzoI66KEvmJ/Z7i0ZZhwlu0QAnqylAYQPVs3VwA2lPWkbpJj3z+z3JPihF32MWfg7t8 X1Z3kFiVoODNcavyMYOb/ssDlUJt64bWDtGNeIhuLNlvZ3XYLRGFOOaTe72WYXDC15uO 0tHGpZiDrKz2YiZm0AB7xqg/uDy51G3M1ejaa9Cfl1EVjna4VbXyWn5x/k0ZRq73jmVA i4EUcje59SBHUq6ahmOh5o5tthUcD3E+7YjhvS22qd7iqg9WMjVXEa83B5tIvLizVS7w R9CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759980573; x=1760585373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qCf+yVl6FKe7XvOkXqCLKdcU8Ah3TZ2cAs6NdRK29XY=; b=NipNc5GyBT30kWh6klwg4lt9+9Ld6e0NLk0LvaZMjcTJ3eQc4GfoL49ZOXLGH+52Bl 95zlixt30ZNR1OPKChH9xlZnnn8ANY6eR98Rs/eVbu/H/ah0/XdxurD38llLvfABTDaS iWApKYwPZio4tAiZHe2FD4GKpsM+BCj1CPhQ5UtO9Z0gtYEMkFEpZ050b6Mzj1uqkvVA QXXybvDhP5SSU6+8RE6Ln7NAsf17ii6OJCm5M2T2gulo/KnSivAhIcGZzZ77jE4wZNgi TFnIsmXppFl8jND4MBkQnehR8iLVKUK4GdXloxTa9rpfn2QiaJP1q38n4OKrVrV66MY8 ubLA== X-Forwarded-Encrypted: i=1; AJvYcCWL/3YBXYTNmQIhZ5r0jKkMvnuTEUNwmjhNYhu/1FiCzCGO4qHNMtynZ/o6/rK21t2pbwSV6Zvb/IpTR9w=@vger.kernel.org X-Gm-Message-State: AOJu0YxIWCkwPC2hHv+M2ywX8lxAt/otfycvKpSeQaZycKBt9jUDzkci bkQF9VfPE27tF+BxTC9TnqZUzHtHXKIz/anFs5qyyv/1vhe6gq7VpJuIVFCbziSpq7I= X-Gm-Gg: ASbGncsZ+PwooHSJPpT380gGjyAPE/KuP9m2+wNvNL7fP//mMubGE0uFP0cwvIi1sgt UB2Ee8ATUvjnIKtb9DqwQI97beapRA4HYjQk0BOt3s5yVoYOmNITg2RV9IdTqMJCBCcHdu6Z7kY M5Y9a+5q0ef2L8LisX/wfL4MwZEVpZwrOl985s9r35i5lN1tAD5ihLUN2/ID7J1IUSAofTLXdYk kWGNlujwe57bMH0KK0x8KQEcOBHAqUosc+SOKmTABxJFcKP0f8rEJ7SQxVKl8I82Ae5z8fEWxG7 vsy48sxRLMBCZ4xG8m9qEEf7KWWlr0KkhFhelUfdK4M7pS7v9QjmbsAE+6fUZqLkOhQAtA7Z9mE wifqa1gCBSwgIYM6eXagqCqNR33YkJHLRULc+S98xWElZeAnOKPLXoaL5TOSlZLrE4V7rN4xuUf rD6VF+OuCt4wWmVcNXgh4A1w== X-Google-Smtp-Source: AGHT+IGhZeVH2PNsAStZMZBUbOw+9Eh0fVx4dMmZeKZLPg4dSUrgAfXZgYcjF6y9cAKQU1C+TuNk+w== X-Received: by 2002:a05:6a21:9999:b0:32b:7001:6601 with SMTP id adf61e73a8af0-32da814f674mr7740486637.25.1759980572407; Wed, 08 Oct 2025 20:29:32 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-794d4b39400sm1271306b3a.15.2025.10.08.20.29.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 Oct 2025 20:29:32 -0700 (PDT) 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 v3 1/2] watchdog: move arm64 watchdog_hld into common code Date: Thu, 9 Oct 2025 11:28:37 +0800 Message-Id: <20251009032838.63060-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251009032838.63060-1-cuiyunhui@bytedance.com> References: <20251009032838.63060-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 | 2 + 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, 102 insertions(+), 98 deletions(-) delete mode 100644 arch/arm64/kernel/watchdog_hld.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index b5438ff4772ce..4759e4969c4a6 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -231,6 +231,8 @@ 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 && \ + CPU_FREQ 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 5c310e803dd78..ca4e1d07b61cb 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -696,10 +697,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 93c9a26492fcf..6b53fb453fd63 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -184,8 +184,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..a61e35fc9673e 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 +__weak 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 099abf128ce67..ceba3e28cb0d0 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1200,6 +1200,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 09:00:51 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 34308238C0F for ; Thu, 9 Oct 2025 03:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759980584; cv=none; b=B2nyom6JvaOsTUlegXJULfe9GWWya7swqqqAR0p0ussGlU+9Mp6JnZ5MboIT1/Ytdt+fq+WNnaL4YImF/ZeHQY7uUHehhrKHaJdveU2x8mpLQcdaGX5KY6G/I6KcJTaOEg2SF9XkRcQVgZuGu5H5xrywJfDdn3kcuDhGygNn8U0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759980584; c=relaxed/simple; bh=QiIUdpJzLvVWvY1Zmn2ap/QqQJGM8PGQTOCIrjyiUC8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XS2JTxk28Fpf4GB7qCjNl+fAs+Z63vXPUqm8bt6RqRZm/hcLFBbD7UZpDQUjtlQxWetBI5ficxnss5EIpgqjcu1NGOVLOASnIGW1xB8dpl0ImjevkoU57wwsQhWGPUWQiA0l+glvYv5fq24bSKa88dvQZgTIhrKV+Qct74tHID4= 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=QUS4yzDc; arc=none smtp.client-ip=209.85.210.177 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="QUS4yzDc" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-77f67ba775aso694013b3a.3 for ; Wed, 08 Oct 2025 20:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1759980582; x=1760585382; 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=jnXMECOikkNGPVLHGk2/W+70TGvv+oQ3PJ6DV32z1EM=; b=QUS4yzDc8qyjy6eUMr3QBizPME0g5NTZnrtDKdY70R7lrXu2XUFNd76oOcPzyZSDVs gS7KQ+sCxjkSOL1Nzl2LA1wDhJs5UcX9IqFGd9gQIx/lxZ9gjUF3GjVQ8LGBFLfUsyR3 95hB0/M0OQJveplysWhEw/JBNZxbYUhB9qCFqJXv4p+2Ou/iYKIvAYTKySu4lZtMLLnm kWgpMmadHQpdpkOS7snvK3W2jBTMqehCrySK9K67q+BaGG04/WaZq23XxlpCfQRCfhjw 8Q4x7NiChllGhw5K8UhNXo6HwVRtlw47n0TC8C+ss6Laeay1Iq9cEe+jg3BEEMrgYvbh S0yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759980582; x=1760585382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jnXMECOikkNGPVLHGk2/W+70TGvv+oQ3PJ6DV32z1EM=; b=dDpR8JJQOXjvHRJ35OI22TaVSaBbGRHy3phXmlEcLScuaTr/Wotz8nhA4+OvaNzNpL bcOPXENZarvOEjFB2SatzMxDsAkeOOa3+iLCpsVpKGQ6phudi2f+zOOhdRjsr8C1Ley9 D1sf8lvkVlADdfDuU0ZgNRJGBOK+NG70WCT18LiDI9HGJWRMdGPWoWrNb/449KjXmEx2 swNH69KjamAlvv6C3K+HsNBCSL8pxbIuHz2FdYK4+wjM9h1vdStEAS7gZJjEyqp61xrt 2KQY1lcEmmyBioHR9g1iysXzA0ZLguTox+nKEq3VKTboM8AtjPhe82VCKIQj6ifdlyv0 /mlQ== X-Forwarded-Encrypted: i=1; AJvYcCWORmMgfh1YBuHy86PPhjYUAYoomk/xtC0JQriH4rxLnJYzl7pM4biJArWqUApOrg7QrGENhLdBk+YLb38=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9tUpqS28TKrWbO3T4ycQ2Uq8SjdzRwsjelhQxXpJ9WewMuzxh +uM0lFRa3eLWgRGoxYKRvTdLbxgUKlNBQJyglxl5KnwD4ehYz8OqU+WFpSUXixuoMeU= X-Gm-Gg: ASbGncu6cRubbPR31hj9eK3VXcMbER8caY8yY04lGvUHy3H178UIwmTPkf07NMTuzfo /8uL8wg+nK03EIqkLisu8Rjgk2poEPtC9fjGU0tuVwVyQDj0H/CgUOeRemc8difzrah9Ye6MYXN bBMAv+3WR1gCTbBiZA8THIKC/NTtOwRBGOdQFVddgm141QAb+BHUc+8ohzhgNF8v8kO2vh3Y2G6 MD5Zb2QVyIvrVoB6E41n3Dra2qTkdPNybtUYiZUnf+B5vKlOhhNHAcR4Uiw6g4edW+QuYL3svVM yfQYwTWzg9vFj08APfmu/5G3td1xRKCjIKFMK9jt02b4S73874AQombxHDFBil8zWVQsnD6XGdA GObunEVWvhaP1RS7wuOBREQeaNA8ZrgHJ3LaiNyzei7d0Jbs7KQCFZuPXefcwUU324A1x1Ngtnx mCaIRid42O4aU= X-Google-Smtp-Source: AGHT+IHbZEm5frc8fvTXu54yWtTCugs4CwZJHmN7TKBRMpR5Iwopkp0MBjhRhFZXa74I0jkchu8wVA== X-Received: by 2002:a05:6a00:3cca:b0:77e:9ae8:c7d0 with SMTP id d2e1a72fcca58-79384f48886mr7305182b3a.1.1759980582231; Wed, 08 Oct 2025 20:29:42 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-794d4b39400sm1271306b3a.15.2025.10.08.20.29.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 08 Oct 2025 20:29:41 -0700 (PDT) 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 v3 2/2] riscv: add HARDLOCKUP_DETECTOR_PERF support Date: Thu, 9 Oct 2025 11:28:38 +0800 Message-Id: <20251009032838.63060-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251009032838.63060-1-cuiyunhui@bytedance.com> References: <20251009032838.63060-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 Acked-by: Paul Walmsley # for arch/riscv Reviewed-by: Douglas Anderson --- arch/riscv/Kconfig | 4 ++++ drivers/perf/riscv_pmu_sbi.c | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index badbb2b366946..6a7b4d2517c4b 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -186,6 +186,10 @@ 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 && \ + CPU_FREQ 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