From nobody Wed Feb 11 10:42:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C468C7EE23 for ; Tue, 9 May 2023 22:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235053AbjEIWR6 convert rfc822-to-8bit (ORCPT ); Tue, 9 May 2023 18:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbjEIWR4 (ORCPT ); Tue, 9 May 2023 18:17:56 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0497B93 for ; Tue, 9 May 2023 15:17:43 -0700 (PDT) Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 349KVue4022845 for ; Tue, 9 May 2023 15:17:34 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3qfrf2u5t4-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 09 May 2023 15:17:34 -0700 Received: from twshared24695.38.frc1.facebook.com (2620:10d:c0a8:1b::2d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 9 May 2023 15:17:32 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id 8323F1D54669C; Tue, 9 May 2023 15:17:18 -0700 (PDT) From: Song Liu To: CC: , Song Liu , Andrew Morton , Peter Zijlstra Subject: [PATCH] watchdog: Prefer use "ref-cycles" for NMI watchdog Date: Tue, 9 May 2023 15:17:00 -0700 Message-ID: <20230509221700.859865-1-song@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-GUID: KAAC0ys7_igI88cCGTrVtA4ETSojQHhZ X-Proofpoint-ORIG-GUID: KAAC0ys7_igI88cCGTrVtA4ETSojQHhZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-09_14,2023-05-05_01,2023-02-09_01 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" NMI watchdog permanently consumes one hardware counters per CPU on the system. For systems that use many hardware counters, this causes more aggressive time multiplexing of perf events. OTOH, some CPUs (mostly Intel) support "ref-cycles" event, which is rarely used. Try use "ref-cycles" for the watchdog. If the CPU supports it, so that one more hardware counter is available to the user. If the CPU doesn't support "ref-cycles", fall back to "cycles". The downside of this change is that users of "ref-cycles" need to disable nmi_watchdog. Cc: Andrew Morton Cc: Peter Zijlstra Signed-off-by: Song Liu --- kernel/watchdog_hld.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c index 247bf0b1582c..f77109d98641 100644 --- a/kernel/watchdog_hld.c +++ b/kernel/watchdog_hld.c @@ -100,7 +100,7 @@ static inline bool watchdog_check_timestamp(void) =20 static struct perf_event_attr wd_hw_attr =3D { .type =3D PERF_TYPE_HARDWARE, - .config =3D PERF_COUNT_HW_CPU_CYCLES, + .config =3D PERF_COUNT_HW_REF_CPU_CYCLES, .size =3D sizeof(struct perf_event_attr), .pinned =3D 1, .disabled =3D 1, @@ -286,6 +286,12 @@ int __init hardlockup_detector_perf_init(void) { int ret =3D hardlockup_detector_event_create(); =20 + if (ret) { + /* Failed to create "ref-cycles", try "cycles" instead */ + wd_hw_attr.config =3D PERF_COUNT_HW_CPU_CYCLES; + ret =3D hardlockup_detector_event_create(); + } + if (ret) { pr_info("Perf NMI watchdog permanently disabled\n"); } else { --=20 2.34.1