Received: by 2002:ac8:3b51:0:b0:3f3:9eb6:4eb6 with SMTP id r17csp1145642qtf; Wed, 17 May 2023 11:22:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6H1R0iC686jKzauXYZ1l7BI/2LJCpY0LI2C9B05eIOXI9y3gKsecsp45vUnwmAPtLBZnSa X-Received: by 2002:a05:6a00:134a:b0:646:1f13:7fce with SMTP id k10-20020a056a00134a00b006461f137fcemr901840pfu.2.1684347730764; Wed, 17 May 2023 11:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684347730; cv=none; d=google.com; s=arc-20160816; b=Dg2tTh+nw0ekjLIgNI5XzkN5HHLq8bNKXV5uurOsNMNpXUXhbMOJvx7k1N068IqceM 7RcGj8eMsOc/HL3yIaZzu9NXCQ+1pI9AxqQ/IdxxPRXEXm3jIuIRUpwRpW/zfTSEzi72 i7EZd2nPNQ7BfTDsPzyXZU6KVlOK+TrzTGanPJkaxwbBVAQ6qPCCxj4Y85nYlZOMyofN i1miBBmzpDd2G0ISPN3GFY17nJbx8rxFOlN6ixi7fF5BLLhae0XvbbXkz23M+yDzY+m0 786Lt0I9nzm3JkX9u7kXg05b/HzP+CNGyPnYcirUnx4UVGtxJ3X4O7d/Wo70QXAfkXBn GxaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=QF8V4r4WD5bW9zdxM3MhRlIkLHvLUS7ijqEIZvzheRw=; b=AVS/gUYMsK8kOXKssr8KjV8LD2FVPeJv3RpNhoANg2mLmcuABRxWluXP84/0dWg7xP 2RCrMPUMtAJDjD512uDi1iI9+7Q63EB8jt3QejR5KaKvZuFIhLBSJ8Gv5TwXJfE0Or8u PPI/pJuwBQdbI9CLHN4Kl5W6EBY+GKJPDsL3HWOmpvupgIABQ6bVxexq9YdNNC2Z15zm fZCF0frLFU3ZAZqmAyRfuMatGxdPDBFRZNopsLUoc9r/XCgooE8VVpDLhaItXzyXpFu9 kKnrHlh+fZBEZXCU6PvhJJEAKdLmx/VRVZr0noOQLkGgaRvnqkWUcYasNkwhiKsuITNp kuaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w7-20020a626207000000b00627e8781dbfsi23011729pfb.266.2023.05.17.11.21.52; Wed, 17 May 2023 11:22:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbjEQRvu convert rfc822-to-8bit (ORCPT + 99 others); Wed, 17 May 2023 13:51:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjEQRvt (ORCPT ); Wed, 17 May 2023 13:51:49 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C36C535B5 for ; Wed, 17 May 2023 10:51:28 -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 34HH1SVH002117 for ; Wed, 17 May 2023 10:51:28 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3qmrcccj29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 17 May 2023 10:51:27 -0700 Received: from ash-exhub204.TheFacebook.com (2620:10d:c0a8:83::4) by ash-exhub201.TheFacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 17 May 2023 10:51:26 -0700 Received: from twshared29562.14.frc2.facebook.com (2620:10d:c0a8:1b::2d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 17 May 2023 10:51:26 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id D5ECB1DC3A20D; Wed, 17 May 2023 10:51:11 -0700 (PDT) From: Song Liu To: CC: , Song Liu , Andrew Morton , Peter Zijlstra Subject: [PATCH v3] watchdog: Allow nmi watchdog to use "ref-cycles" event Date: Wed, 17 May 2023 10:51:04 -0700 Message-ID: <20230517175105.1614575-1-song@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: P_vrUK5B1Izk-ncGcXpXnHLEZvo5ibGa X-Proofpoint-ORIG-GUID: P_vrUK5B1Izk-ncGcXpXnHLEZvo5ibGa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-17_02,2023-05-17_02,2023-02-09_01 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Add kernel cmdline arg nmi_watchdog=ref-cycles to configure the watchdog to use "ref-cycles" event instead of "cycles". Cc: Andrew Morton Cc: Peter Zijlstra Signed-off-by: Song Liu --- Changes in v3: Pivot the design to use kernel arg nmi_watchdog=ref-cycles (Peter) --- Documentation/admin-guide/kernel-parameters.txt | 5 +++-- include/linux/nmi.h | 2 ++ kernel/watchdog.c | 2 ++ kernel/watchdog_hld.c | 9 +++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9e5bab29685f..d378e23dad7c 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3593,10 +3593,12 @@ Format: [state][,regs][,debounce][,die] nmi_watchdog= [KNL,BUGS=X86] Debugging features for SMP kernels - Format: [panic,][nopanic,][num] + Format: [panic,][nopanic,][ref-cycles][num] Valid num: 0 or 1 0 - turn hardlockup detector in nmi_watchdog off 1 - turn hardlockup detector in nmi_watchdog on + ref-cycles - configure the watchdog with perf event + "ref-cycles" instead of "cycles" When panic is specified, panic when an NMI watchdog timeout occurs (or 'nopanic' to not panic on an NMI watchdog, if CONFIG_BOOTPARAM_HARDLOCKUP_PANIC is set) @@ -7097,4 +7099,3 @@ memory, and other data can't be written using xmon commands. off xmon is disabled. - diff --git a/include/linux/nmi.h b/include/linux/nmi.h index 048c0b9aa623..9fe1c1831287 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -102,12 +102,14 @@ extern void hardlockup_detector_perf_disable(void); extern void hardlockup_detector_perf_enable(void); extern void hardlockup_detector_perf_cleanup(void); extern int hardlockup_detector_perf_init(void); +extern void hardlockup_config_perf_event(const char *str); #else static inline void hardlockup_detector_perf_stop(void) { } static inline void hardlockup_detector_perf_restart(void) { } static inline void hardlockup_detector_perf_disable(void) { } static inline void hardlockup_detector_perf_enable(void) { } static inline void hardlockup_detector_perf_cleanup(void) { } +extern void hardlockup_config_perf_event(const char *str) { } # if !defined(CONFIG_HAVE_NMI_WATCHDOG) static inline int hardlockup_detector_perf_init(void) { return -ENODEV; } static inline void arch_touch_nmi_watchdog(void) {} diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 8e61f21e7e33..fed4f0be8e1a 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -81,6 +81,8 @@ static int __init hardlockup_panic_setup(char *str) nmi_watchdog_user_enabled = 0; else if (!strncmp(str, "1", 1)) nmi_watchdog_user_enabled = 1; + else if (!strncmp(str, "ref-cycles", 10)) + hardlockup_config_perf_event(str); return 1; } __setup("nmi_watchdog=", hardlockup_panic_setup); diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c index 247bf0b1582c..4deca58ba6ed 100644 --- a/kernel/watchdog_hld.c +++ b/kernel/watchdog_hld.c @@ -294,3 +294,12 @@ int __init hardlockup_detector_perf_init(void) } return ret; } + +/** + * hardlockup_config_perf_event - Overwrite config of wd_hw_attr + */ +void __init hardlockup_config_perf_event(const char *str) +{ + if (!strncmp(str, "ref-cycles", 10)) + wd_hw_attr.config = PERF_COUNT_HW_REF_CPU_CYCLES; +} -- 2.34.1