From patchwork Sun Jul 23 18:31:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Costa Shulyupin X-Patchwork-Id: 124528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1387371vqg; Sun, 23 Jul 2023 11:54:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHL5JbGTv87sHq1q4ptymrogHkBOz0YpNNUFSg5lCNa2wUwuUT0lbPZFZKtQKuqYjtKnEjv X-Received: by 2002:aa7:d791:0:b0:521:8ca5:6070 with SMTP id s17-20020aa7d791000000b005218ca56070mr6691927edq.33.1690138470323; Sun, 23 Jul 2023 11:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690138470; cv=none; d=google.com; s=arc-20160816; b=BYlBNzdrbOC44z2ePF0IlsflR3Abf/JGBiuGdjmsX/7n6Nb5qxWr3r0iI9S6SMmAv+ bLX9PnfiAIyiOyQL9MZqQFj2P1oz1pw0MQauJqPQlvI3898rqxFzibyNVb4d2ImkbRwE JRpW7pbbSfC6neGcGFiVc1wOekbKC04OkohCyekpXrilaH7TOwk6t8OLl1V7Fg6X+UiE ITNUUcZqnfO5WRrbVvi4ocS8EIsmQ/+ATwQg1y0df3v8ZIr93gyG8a3kxgb/CRmHWqci WRkKeNt0M+a/VeWucqRSMCO7MQeEAIrUnUpAwk1tLsNRtLJ0pciklK7Ngoy0OL5ebqP4 q8GQ== 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=Xne8idaRlbxCOrCJa4iK/MOIRttrSCYL5hIu0XZTkzs=; fh=QqWsSpka5bQT9mpF0QbLRSyxBvqneTdOMXwFPexsND4=; b=psixR8lf2PewYML6kH/XZlM2B/6LGIh7Nlsm6Rt8w0EehBrudwjFjph3Phw0SHObzg SsMtcWW4Ltntq3Ci52zM9ABKU3WYYZAcy83dXQ558Erd4v9vrVxIqmpYmCQqVGOHWcwo sE8iOXMdDYAmH+BoF9dGRBGLFc91kjxEl04nGxGboXpd+IbW1QLfWtBQSbXp8nBpzKEW SvS7dW4We9u1VsOEDfdvoxbs9p6Xd54uqGr3pwLZd3qI+BQ6NpveMpW2ypHffj+SM/HS i7vL4nngIcsRFJKpcNxDhJHCKGj4YOJO9vSd3j//6LOMg0UIszJ9VybIGE3gYji+YPyg 3k+A== 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l22-20020a056402125600b0051d9ca7745esi5466348edw.537.2023.07.23.11.54.07; Sun, 23 Jul 2023 11:54:30 -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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjGWSdV (ORCPT + 99 others); Sun, 23 Jul 2023 14:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbjGWSdU (ORCPT ); Sun, 23 Jul 2023 14:33:20 -0400 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B62AE64 for ; Sun, 23 Jul 2023 11:33:19 -0700 (PDT) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-3fbc5d5746cso33876165e9.2 for ; Sun, 23 Jul 2023 11:33:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690137198; x=1690741998; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Xne8idaRlbxCOrCJa4iK/MOIRttrSCYL5hIu0XZTkzs=; b=QhrOwKsegSQVu5wdtm+vkeCAnVWj9NhSsCjAkWV6+57Mguz5mCnqzZ+WJItNU+qEB2 jwPnj95r9dtb17v4ZPwDqXwRmy8AS7CB2/KgKo8YUac3uyPZYk1z6r2Qe3KFB7bA2yxM GNRRUJuIhbq15xTt3/Gm/6jtEdikLakDgsRpP0C5B/MwNaHFo8vGVLsRTWPOWwg+pJLV lRUe5Gbo+Qa7XU6yBKFFSvxH6H7GO8KjG6mhnc4WI1T1gJr8E+/pD3bjB1hNhwNHUYxJ 90dBVzAo1ead94RpRtsWhHkvyhbN38EPvO2jaRER7ldqXiHI54IoMWhznBdU9V/WwoV1 C9gg== X-Gm-Message-State: ABy/qLZTXl50h8YnJu9r7q3Os1rW76uCDs2CUHJ9/VSihmnyZc38kdmx cRw4gsf0K5pgXKiCaRbuJ09Tqdi6K1Ad4UQX X-Received: by 2002:a05:600c:210b:b0:3fb:b56b:470f with SMTP id u11-20020a05600c210b00b003fbb56b470fmr6309026wml.14.1690137197505; Sun, 23 Jul 2023 11:33:17 -0700 (PDT) Received: from costa-tp.bos2.lab ([2a00:a040:199:8930:2c90:cb9e:b154:73dc]) by smtp.gmail.com with ESMTPSA id h14-20020a05600c314e00b003fc3b03e41dsm11202145wmo.0.2023.07.23.11.33.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 11:33:16 -0700 (PDT) From: Costa Shulyupin To: Thomas Gleixner , Costa Shulyupin , "Paul E. McKenney" , linux-kernel@vger.kernel.org (open list) Cc: junxiao.chang@intel.com, pauld@redhat.com, prarit@redhat.com Subject: [RFC PATCH] hrtimer: warn when delay is too long Date: Sun, 23 Jul 2023 21:31:30 +0300 Message-ID: <20230723183132.1910579-1-costa.shul@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772238636716734829 X-GMAIL-MSGID: 1772238636716734829 Checking hrtimer_get_softexpires value because sometimes it is 1, at least for 4.18.0-372.49.1.rt7.206.el8_6. This patch helped debug a very big problem and find this solution: https://lore.kernel.org/lkml/20221208075604.811710-1-junxiao.chang@intel.com/ Signed-off-by: Costa Shulyupin --- kernel/time/Kconfig | 6 ++++++ kernel/time/hrtimer.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index bae8f11070be..ccc1458b2ba6 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -196,6 +196,12 @@ config HIGH_RES_TIMERS hardware is not capable then this option only increases the size of the kernel image. +config HIGH_RES_TIMERS_DEBUG + bool "High Resolution Timer Debug" + default y if HIGH_RES_TIMERS && DEBUG_KERNEL + help + Warn when hrtimer delay is too long. + config CLOCKSOURCE_WATCHDOG_MAX_SKEW_US int "Clocksource watchdog maximum allowable skew (in μs)" depends on CLOCKSOURCE_WATCHDOG diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index 238262e4aba7..d0087b709bc1 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -123,6 +123,10 @@ static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = { [CLOCK_TAI] = HRTIMER_BASE_TAI, }; +#ifdef CONFIG_HIGH_RES_TIMERS_DEBUG +int timer_threshold_ns = 1000000; +#endif + /* * Functions and macros which are different for UP/SMP systems are kept in a * single place @@ -1651,6 +1655,16 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base, bool expires_in_hardirq; int restart; +#ifdef CONFIG_HIGH_RES_TIMERS_DEBUG + if (timer_threshold_ns && hrtimer_get_softexpires(timer) > 0) { + s64 delay_ns = ktime_to_ns(ktime_sub(*now, + hrtimer_get_softexpires(timer))); + + if (delay_ns > timer_threshold_ns) + printk_deferred(KERN_WARNING + "hrtimer: delay_ns=%lld\n", delay_ns); + } +#endif lockdep_assert_held(&cpu_base->lock); debug_deactivate(timer);