Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10265288rwr; Fri, 12 May 2023 06:08:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QNO2Gih1F6kxjtvWtiwLjCD2Sxo+cDGWnnuK798kG0jI7fC4OPyCscFMjc6/XXFd8gJ/9 X-Received: by 2002:a17:903:4d5:b0:1ac:aac1:e344 with SMTP id jm21-20020a17090304d500b001acaac1e344mr12172632plb.36.1683896929860; Fri, 12 May 2023 06:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683896929; cv=none; d=google.com; s=arc-20160816; b=EGIr2gx8kDDfgrYRXhrCMwfAGinVkSgRVBTWbcMBUg8x5aspguNWLjjMU2aqTY1ELG doAKcb8wX6eNvXa64OO489lkUBCa6DcNmPLiQOYUpd2UcGJ1u31LjESt86bXYyxr6M4d sLCwKnPfp6K4Rgnoi9G4Fd+xXRGLW+TpQywhs1lXL0uh+fDhoLn/Emhwsr74+RmzSe9a 6AKUGXAeqE3X3uWGdXRJ3QQPwcy5iOe1By1R1YorOpjErvYB309vIWwJydUTHbLbrmYz oKwi7EAFjytsCLedJdbdm6fNxhZmv+a3UgUBCwqT7YP1ZOm0GFI5G5ARBifw9g6ZCTiY Azig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vdTxcgWO1By0iF6Z2i/LtR0GY0S19282UkV3RoglxSU=; b=mWMAAbyFGS4ZeAOjzQ/r9IoSRJqJrbqYK5xydYxj3B0av70oTBnDxWvP1ty1x3rjT2 ya91byCSvxBiRx8d8HzUU3qfRJZfsrSGbN5M9ovQHj6u8fb6s9HZ0W8DlcsEi9lrp5SJ +fJVyytVsIPH2L70RF9yQ9ZhWt+OK5NRHaFek4tKiPIenGsZqzbkgumkFR1qjzHpH9W/ zEQKby7kDiD5T6s+lTJqUOkJB5Lp7d32z7ou3QD6OsUZWaLiSPZpOyzEBNUZsMZ5eV/C PY62P3e9xN/hRK2gcsSD9VI3QApQGhcDr8eZ15+HFahCkTo4rwsg/LXjIo4uV47gyCpI tm4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=J7tfRUcT; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a170902e5cb00b0019ccffb3fd3si9648064plf.509.2023.05.12.06.08.36; Fri, 12 May 2023 06:08:49 -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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=J7tfRUcT; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240332AbjELMrU (ORCPT + 99 others); Fri, 12 May 2023 08:47:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240603AbjELMrR (ORCPT ); Fri, 12 May 2023 08:47:17 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D2E711D82 for ; Fri, 12 May 2023 05:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vdTxcgWO1By0iF6Z2i/LtR0GY0S19282UkV3RoglxSU=; b=J7tfRUcTFK/19zRMwE1+/3cQHP 1xlkCSvFVYR26IwUsXfpPKGHpgXJMnPRD6uqgHNudHlZYDk1dAI5ZsPchNBRTDADgW9T3Vu+DIJ+H cr1QFLjxzel+Y4Q6C5PtEm5pP8NobNBXX5r6XFRjviH+02Em4Bmt40yVoK6IddQdhE/VYcoybaTb4 t373NN+aH4EPi/c4aE21CYG5+HkVwkxMe7Wfr6MeHIdqasuampx8CnjCxoQFFrXcl5fGgOXSf90Hh KajsaafsgVDWOHXjRGyGDJ2F46rSrTemzZ153QLlf5Gr2aGZT6/Aet4IkIAoUZEBwthywJQQanbDV umtsBXRQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pxSAn-00993y-0E; Fri, 12 May 2023 12:47:01 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 6FB35300451; Fri, 12 May 2023 14:46:59 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5049A2C8B6A87; Fri, 12 May 2023 14:46:59 +0200 (CEST) Date: Fri, 12 May 2023 14:46:59 +0200 From: Peter Zijlstra To: Song Liu Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, Andrew Morton , Thomas Gleixner Subject: Re: [PATCH] watchdog: Prefer use "ref-cycles" for NMI watchdog Message-ID: <20230512124659.GY4253@hirez.programming.kicks-ass.net> References: <20230509221700.859865-1-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230509221700.859865-1-song@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Tue, May 09, 2023 at 03:17:00PM -0700, Song Liu wrote: > 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. Urgh.. how about something like so instead; then you can use whatever event you like... --- include/linux/nmi.h | 2 ++ kernel/watchdog.c | 45 ++++++++++++++++++++++++++++++++++++--------- kernel/watchdog_hld.c | 4 ++-- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/include/linux/nmi.h b/include/linux/nmi.h index 048c0b9aa623..8b6307837346 100644 --- a/include/linux/nmi.h +++ b/include/linux/nmi.h @@ -19,6 +19,8 @@ bool is_hardlockup(void); extern int watchdog_user_enabled; extern int nmi_watchdog_user_enabled; +extern int nmi_watchdog_type; +extern u64 nmi_watchdog_config; extern int soft_watchdog_user_enabled; extern int watchdog_thresh; extern unsigned long watchdog_enabled; diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 8e61f21e7e33..b3c09e0f96a3 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -40,6 +40,8 @@ static DEFINE_MUTEX(watchdog_mutex); unsigned long __read_mostly watchdog_enabled; int __read_mostly watchdog_user_enabled = 1; int __read_mostly nmi_watchdog_user_enabled = NMI_WATCHDOG_DEFAULT; +int __ro_after_init nmi_watchdog_type = PERF_TYPE_HARDWARE; +u64 __ro_after_init nmi_watchdog_config = PERF_COUNT_HW_CPU_CYCLES; int __read_mostly soft_watchdog_user_enabled = 1; int __read_mostly watchdog_thresh = 10; static int __read_mostly nmi_watchdog_available; @@ -73,15 +75,40 @@ void __init hardlockup_detector_disable(void) static int __init hardlockup_panic_setup(char *str) { - if (!strncmp(str, "panic", 5)) - hardlockup_panic = 1; - else if (!strncmp(str, "nopanic", 7)) - hardlockup_panic = 0; - else if (!strncmp(str, "0", 1)) - nmi_watchdog_user_enabled = 0; - else if (!strncmp(str, "1", 1)) - nmi_watchdog_user_enabled = 1; - return 1; + int ret = 1; + + if (!str) + return -EINVAL; + + while (str) { + char *next = strchr(str, ','); + if (next) { + *next = 0; + next++; + } + + if (!strcmp(str, "panic")) + hardlockup_panic = 1; + else if (!strcmp(str, "nopanic")) + hardlockup_panic = 0; + else if (!strcmp(str, "0")) + nmi_watchdog_user_enabled = 0; + else if (!strcmp(str, "1")) + nmi_watchdog_user_enabled = 1; + else if (str[0] == 'r') { + str++; + ret = kstrtou64(str, 16, &nmi_watchdog_config); + if (ret) + break; + nmi_watchdog_type = PERF_TYPE_RAW; + nmi_watchdog_user_enabled = 1; + } + + str = next; + } + + return ret; + } __setup("nmi_watchdog=", hardlockup_panic_setup); diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c index 247bf0b1582c..27bc15f9a92a 100644 --- a/kernel/watchdog_hld.c +++ b/kernel/watchdog_hld.c @@ -99,8 +99,6 @@ static inline bool watchdog_check_timestamp(void) #endif static struct perf_event_attr wd_hw_attr = { - .type = PERF_TYPE_HARDWARE, - .config = PERF_COUNT_HW_CPU_CYCLES, .size = sizeof(struct perf_event_attr), .pinned = 1, .disabled = 1, @@ -170,6 +168,8 @@ static int hardlockup_detector_event_create(void) struct perf_event *evt; wd_attr = &wd_hw_attr; + wd_attr->type = nmi_watchdog_type; + wd_attr->config = nmi_watchdog_config; wd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh); /* Try to register using hardware perf events */