Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp228307rdb; Fri, 6 Oct 2023 01:22:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeZ0PG1oCBCkAUgY2npRh4pbt1LSK98hPNEXvAPrhQ88COwsvajtqiUHzs2XNxJuLuBz4B X-Received: by 2002:a05:6a00:8c7:b0:68a:4d66:caf with SMTP id s7-20020a056a0008c700b0068a4d660cafmr9007287pfu.34.1696580569721; Fri, 06 Oct 2023 01:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696580569; cv=none; d=google.com; s=arc-20160816; b=xx+/7YRIfPufg9HY6ikOnn5ZltLYZ2MyZgBF2xtE4E4WZ1VX06tIcDkHTR8zJ4PJou u3Y0BNor+NymdxWiiuXKW9OyGZ6LYbyVyX9xvQabTJLyyGYPqEq3qlT6c89/1hysVdot bL/R1AyoqXz1oFRdOfvsF/u6+CAy2X5JVl4sDf/fPSLbPct2OPw6Kq2jL+xAxtggeqB5 3AiOZINzIvYPEMLtyK5lzzW0Kaw4ITnmTVXO+7Cmtmndx4l+y/szyffsMYecQVtxsQdu WI+OSG5vIol4GHBhfJB6uPBxst3hLJXLfJ6AzeNRBPRUGeBu5JBAHFgcuiIaXa+Vlx/T 9ldQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WSmnkbiXNcms5De0+4SZuPr7BeXTZtGKvtsnAwyE9jk=; fh=Rkem9DZLVtB3ZM00Hf1TNke3sV6aftsNytr1Ms93Wzw=; b=Fr0MPVViFWbvcfOtLNqW/x4uEALqfKXk8nigcL4X38FSkRpPuSw62LPyEvp2DLlz6L cUTtjI0EBTswkoMJLM+VYuDdapwPM/w64/bZZgS30PCe9X1hQvf8JbJnBuYcyP5jVnxH TUn72MZVRmucM/n9zKWrmvdMe3PBMYzgQ3fmt+7LWIF7H5g2Mgq54IA02ScIR95l9YpQ RmqBCdIp8a7k7wn99EwhN28nAdbFx5sBgasjf8FxZf0P10Ug+uVEMi5MV34VJO5ZSRoA 1an++Rbp8jkXCcFJ/G2fd7NHaRy4nzdTPTmOsa8YOOnaHn+s/QClTV9qg6BUpDMhV5LE sBJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=JW4N2tk5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id r37-20020a635165000000b0055e607f1e99si3129616pgl.882.2023.10.06.01.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 01:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=JW4N2tk5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A96768088A8B; Fri, 6 Oct 2023 01:22:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjJFIWe (ORCPT + 99 others); Fri, 6 Oct 2023 04:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbjJFIWc (ORCPT ); Fri, 6 Oct 2023 04:22:32 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90EE3FD for ; Fri, 6 Oct 2023 01:22:30 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 195D91F45F; Fri, 6 Oct 2023 08:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1696580549; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WSmnkbiXNcms5De0+4SZuPr7BeXTZtGKvtsnAwyE9jk=; b=JW4N2tk5qgw7RYAA3OFBrzdMc/f0B1Zxur+qGQpunG1O1bh85cAG0hJmOpJVCW4oQbwqMb iOysJjttuKdNby5J39QAeFT0vUdfEjARkQeIa4YthyYFhOU0ZJWSAzhjJU3DLiOrIhr/Xb sRPCtjAQp19pS/XqWvAWAfliLvAHA7A= Received: from alley.nue2.suse.org (pmladek.udp.ovpn1.nue.suse.de [10.163.31.190]) by relay2.suse.de (Postfix) with ESMTP id BB6512C142; Fri, 6 Oct 2023 08:22:28 +0000 (UTC) From: Petr Mladek To: John Ogness , Sergey Senozhatsky , Steven Rostedt Cc: Thomas Gleixner , Todd Brandt , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v2 2/2] printk: Reduce pr_flush() pooling time Date: Fri, 6 Oct 2023 10:21:51 +0200 Message-Id: <20231006082151.6969-3-pmladek@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231006082151.6969-1-pmladek@suse.com> References: <20231006082151.6969-1-pmladek@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 06 Oct 2023 01:22:47 -0700 (PDT) pr_flush() does not guarantee that all messages would really get flushed to the console. The best it could do is to wait with a given timeout.[*] The current interval 100ms for checking the progress might seem too long in some situations. For example, such delays are not appreciated during suspend and resume especially when the consoles have been flushed "long" time before the check. One the other hand, the sleeping wait might be useful in other situations. Especially, it would allow flushing the messages using printk kthreads on the same CPU[*]. Use msleep(1) as a compromise. Also measure the time using jiffies. msleep() does not guarantee precise wakeup after the given delay. It might be much longer, especially for times < 20s. See Documentation/timers/timers-howto.rst for more details. Note that msecs_to_jiffies() already translates a negative value into an infinite timeout. [*] console_unlock() does not guarantee flushing the consoles since the commit dbdda842fe96f893 ("printk: Add console owner and waiter logic to load balance console writes"). It would be possible to guarantee it another way. For example, the spinning might be enabled only when the console_lock has been taken via console_trylock(). But the load balancing is helpful. And more importantly, the flush with a timeout has been added as a preparation step for introducing printk kthreads. Signed-off-by: Petr Mladek --- kernel/printk/printk.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0b3af1529778..c0e13c0e68b2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3728,7 +3728,8 @@ late_initcall(printk_late_init); /* If @con is specified, only wait for that console. Otherwise wait for all. */ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { - int remaining = timeout_ms; + unsigned long timeout_jiffies = msecs_to_jiffies(timeout_ms); + unsigned long remaining_jiffies = timeout_jiffies; struct console *c; u64 last_diff = 0; u64 printk_seq; @@ -3745,6 +3746,9 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre console_unlock(); for (;;) { + unsigned long begin_jiffies; + unsigned long slept_jiffies; + diff = 0; /* @@ -3773,24 +3777,20 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre console_srcu_read_unlock(cookie); if (diff != last_diff && reset_on_progress) - remaining = timeout_ms; + remaining_jiffies = timeout_jiffies; console_unlock(); /* Note: @diff is 0 if there are no usable consoles. */ - if (diff == 0 || remaining == 0) + if (diff == 0 || remaining_jiffies == 0) break; - if (remaining < 0) { - /* no timeout limit */ - msleep(100); - } else if (remaining < 100) { - msleep(remaining); - remaining = 0; - } else { - msleep(100); - remaining -= 100; - } + /* msleep(1) might sleep much longer. Check time by jiffies. */ + begin_jiffies = jiffies; + msleep(1); + slept_jiffies = jiffies - begin_jiffies; + + remaining_jiffies -= min(slept_jiffies, remaining_jiffies); last_diff = diff; } -- 2.35.3