From nobody Fri Dec 19 17:19:36 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 ED14A3054D1 for ; Tue, 14 Oct 2025 03:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760411702; cv=none; b=CUeOWsqeVmDMhslHhZSnE6S4kxZVDzpv2COiS9K4uMQae1JaSuoEIzLoXGWsLwV9x/RG32GpXU3bESHsI1r8zbA1uKd+xVWOUQ1tvxQUFJqbmqESy/1Csa8INwO3050nWwRN6fhQHle9pCJ4I6/7m36S9buMvECzh9NgZxGAAJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760411702; c=relaxed/simple; bh=V9FM7Tg9n3f4d7CYo7NE9JJpV4txYTiyYxsaaJYPrfc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s5I3O+1HsqsY5lE8EhyPr8XnyAb3cV1MmbT9r1CEuMQ09TIIlMuuGNvPKB+GsIMRSTN1ZrBAQZcI8m5xguxq/4GSe7a4PajUBQ065mDCdmisYAhNwrwg7sd3E6/m/VDFmSuWMe/KaL4Ul0/mPEPEV+/ctbhZC64dIP5ZMp47YFI= 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=YzF/wxSs; arc=none smtp.client-ip=209.85.214.182 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="YzF/wxSs" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-269639879c3so47026235ad.2 for ; Mon, 13 Oct 2025 20:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1760411700; x=1761016500; 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=U0CkwtYJ00kWUx1+j2pAoMdQDJBRSeEDCDOjkRoM+EY=; b=YzF/wxSsmh9ibOrVNAqQnfxvElm0Qvtnm/1Hrc6iaiHCNbZIaOUXOpai8DUa/heczM snvSo72iBSwYbrnjlZO6CvGcqoeIij3EWAwo8hDM6HShjrwccGYp1azw1lHe6kz75DaH GFHV6MfFeSMXX+kLpnJFC7P9izTdAv7U+aSRHD2c9A9rrMd3eLKp34ad8LN304p8h1B9 ksbAV6HWQBlGIPlmGhV/JmhMS6+acfN6QORkVDzASA8xqaCPIohUKIvnqxBNS33JAvDk tCBoI6ong1besMUqqea9J+0g5GaPmBjc5WNLb4z7GkvnYjEiN46kLrFoQ4SPNPHbFMHy 5vsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760411700; x=1761016500; 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=U0CkwtYJ00kWUx1+j2pAoMdQDJBRSeEDCDOjkRoM+EY=; b=xRJtv22j2fgDiv9Doq/zDEyQEg5WLaF4/aqjehFYb/vguSS9sRJKYE2FILspMfGRlh zer/BkwIVbNPpFzPY/A3iBQvWS2HexVE4a8xLAzENeuH51ko6ZjOhWqEMhF3wbiTkZge k8Z0MA8ACFuSw3T9keX6FHmXk1I7WJV0Vc7B+W2TODpPphPqgrpCBkKfvbsRe9+m8gYE Rgt5tZ/mqGMuosI/VWqMixQ4kOlw/CjuJsujS3otFQRCYQadvlxjxvVmdvh6sW8YkA1Q NKVZTekxwkCw1SRf0E7vdOww0e1O75i0rtInzxwRaJ+BN/bKVo9+C+1ILIeizuTaLPNJ FVOQ== X-Forwarded-Encrypted: i=1; AJvYcCVS0EyqX4GU0k7//SpoJymSuKeBsqLPpdxErqVBIY2416PMh9ZthO08Z9yFV0lDkfWcwYPOv41RhVOEti8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+98RwPL8m6PquzKHDmVo7Z8ID4Q2A6pXCmHzOeDEsaZobuUfk tllg39gnU1joQNGvYRqUXlThes8qtBjy9ZEMcoi8mgxNy2LX5Hzn1ar0qV5LVCwpyCI= X-Gm-Gg: ASbGncvOtaSAmfugQaT853UI5y9uUvSoZoeQU80o8jiqbJr95RisUdcxOCktKdLLm8W 5k1yDnN/yqy7KjjcJtf3zCty8uh4JD5DWgAvM9Nf5KxuS1Z325YEybTpntc2zA4eOkNNVeGzG/y nXlLmB+04ygwCJ8IVVQF84chK4KSHqvz/87H9EGpVG5R6C62Z+pR488sPVk4rHiCaPI4uiHnd+X q+T8/VSAfgzeV5YlouIjZ8FR84eJF3gLXBl7tRNCO69Gz/Zw43teYy/9QVx920Bp9s0tp6aWQOa aHY+K+QTf6y9c9MgIC2f2E+7HGYZ0Ofld26HroNU5TJFgQbyfYcaM1ClE76kxA2IGZCqJDed2Ow kyot9dwWnwy4Enw3+Js++tk+cSgLZAxaKEQISbYvudusdu3duZ7kDksQcrp9RJ24Ee9ZX5fhTQG XWwBRX2aunwc0AjWDQ X-Google-Smtp-Source: AGHT+IHuXcrJrrIrjll72fsxv4RHpCBmdn7Yx1Z4GmzqoA4/59E8YLw53tmhFZ/k1k4idVPxjl767A== X-Received: by 2002:a17:903:94e:b0:290:55d5:41dd with SMTP id d9443c01a7336-29055d5427dmr141146545ad.5.1760411700144; Mon, 13 Oct 2025 20:15:00 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29034f3de4asm148315845ad.92.2025.10.13.20.14.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Oct 2025 20:14:59 -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 v4 1/2] watchdog: move arm64 watchdog_hld into common code Date: Tue, 14 Oct 2025 11:14:24 +0800 Message-Id: <20251014031425.93284-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251014031425.93284-1-cuiyunhui@bytedance.com> References: <20251014031425.93284-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 b5438ff4772ce..33072adc88332 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 && 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 17:19:36 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.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 8BC7C309DDB for ; Tue, 14 Oct 2025 03:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760411715; cv=none; b=irdZ+hVP09ImCTUgwLYDAsKH405iM7FRbWCXgNEvmxNruff4ev5rLIKj2cT3k1ZBg3985rrcA6ZlN7RZ97mS0lI6YZTUWGYHif7sTMmb46My/+hPhiu9LDC63VCLr+PQEkJBE5+6pYNvJH8Jvxzc95X3VLxDFT6UF+Ymy5M8aUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760411715; c=relaxed/simple; bh=OsVZTQ1MyiSKr3/7iUE60rxwcYFEmk0jXWEJNuaWHSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mT5ChH5a38ZTIxLiXmK4GgsBs/tNUWVo5k458+hZuMlP6DAQF4NJwc6g2Gguz3LHVRcaFJDMrxl/oCs8RS8ggJEPOvdwIscjpABIuxNuiCQTrJjQiRFsC9S1oGtBzlYlphF6RcUuCNxNtrN3XBYIa1JCN1VqTz0LjIrzaY8GzxE= 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=Xx0hOixa; arc=none smtp.client-ip=209.85.214.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="Xx0hOixa" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-27d4d6b7ab5so67156595ad.2 for ; Mon, 13 Oct 2025 20:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1760411711; x=1761016511; 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=6P8xZEQeIO5H4AzeXprUKU3oEf9nN+exJfE8nbRaRqY=; b=Xx0hOixavcFeu6tPsgTydMQDUVjaGTL+jFou2oMet9/laxKUBHnzvZP/kKfzbK+OKX 5z/B5S7TWtUnysMNccO2p1Y7TA+GbrfyOppkxdNhv2s/mHbH6RiR1aFDcIf9Gv3ZOq4Z GufDcxHH9e6Dna9WlgBHLM73h5uNLKqoVQtHS73q2LDqcXqsRspsvvfMXbTsVym6zEpT DXDECAHmsM+wv/CzIm4R1kEZYwGBfMySFqmMVjGdCM6ZK66Kh5VXy+xem78m+wKjG/Vo zvunj+ZEGI7vxq8cb3ll7luThcIdkTyArY3YGmcjpUcByVz69GycfkH5M9hilYAP6o6j +bzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760411711; x=1761016511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6P8xZEQeIO5H4AzeXprUKU3oEf9nN+exJfE8nbRaRqY=; b=nroog/cjsksNY2l8s8kHatIfKpsWt6W8kTgT3O3FTw6xFEYq308HBT/Hkex0T+T80A rasWHsdVjYaDSo4UB2bRLoQjsyHpCTlQutKSROe2XknDlIuEPe8xuwvncRCJsuTd93wE kFrYUDVmIu7VLrVojRd5JgJ98HIjACaNSl1s5kmeL3ea0YmWClYMInmmbK2+vxzp4fPc s41CfYBIMn0U4uegvEudVM08lvAxbyIm2C1G70NvhXDZcrJqDJSKvNSY6i7XH1r6OH+Y vci5Ox7p67D3uDdjkQtQJqZUyBJTLYsb2lwi0sqtmkvnAdevH1sTLblD6SUZHqwFkbbU thgA== X-Forwarded-Encrypted: i=1; AJvYcCXNoswwY84fDXXFSceu4uOk9wNF71Up1cw1M4/b9XcSLu6SS6XCW/WQem5kvsfUlr7oEYSEzzwVxu82nt8=@vger.kernel.org X-Gm-Message-State: AOJu0YzJKNMoIxED5H01gYSVCQ/IKssq0CbEfa2Aln/dzgZIbDHjMt1P a2h4M8lK8+xu9afRn/do/5njjmzfFkxhcQdTgwIDY4/RB7ri+gj9CsRLx3udr+VviN4= X-Gm-Gg: ASbGncv4R5NSwgJBexWRfnp3hK5KLaLHf1nMNhyM4W1GMugxc1DlLcfKbwGFWbtfaIX eEjeidh6Wd1pn94UVjU9zIZDMULVSXHGaMJ6v/43adMgn4sdMdo4luYeJoY2fE1WiOpp2i3jTKu 7TGWPLw3CqtsbSosQlTA6ryrGc449lV+mUCDAIsz2MmlcRgMQb/IItQ8FPmNo23Hnjynl5cvEVr 99USM6C1/CDe5EBvVi4VNlU/5NTbg1Omi91jnNTvBWInDNTyu7uq2/6pbR1rJb2t6Qh7v30ZAYn m4efNbASO1vKP+StbO+T6RzvJP0kiORUZ/cXexOYfpP8wS4ljxyO4iN35KvXpUidRiuXdmWIYO4 PjpfxkBctojFhBEp6TE2NxPavXikmXPPNNxIap8yO5TR2/jYM9I1wddnFrmYjt2iv41jH7n92S8 q68XpErf5NAoWxcMPs2LtrrwpIB2c= X-Google-Smtp-Source: AGHT+IEnhbhgD5wvfXgKIYQpP+Lfyce302o3Owp60kynW6BbE9VY04c0yKjSZIvlB5ornO/n4cUtAg== X-Received: by 2002:a17:902:ef07:b0:269:82a5:fa19 with SMTP id d9443c01a7336-290272e3adcmr281603745ad.45.1760411710696; Mon, 13 Oct 2025 20:15:10 -0700 (PDT) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29034f3de4asm148315845ad.92.2025.10.13.20.15.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Oct 2025 20:15:10 -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 Cc: Paul Walmsley Subject: [PATCH v4 2/2] riscv: add HARDLOCKUP_DETECTOR_PERF support Date: Tue, 14 Oct 2025 11:14:25 +0800 Message-Id: <20251014031425.93284-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20251014031425.93284-1-cuiyunhui@bytedance.com> References: <20251014031425.93284-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 badbb2b366946..0ae3291b303f9 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 && 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