Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1473293rdb; Mon, 2 Oct 2023 10:29:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdz7jOh3vzX7A9wLSIkj64lNbeSLA7cZBRjRRqC1wtwBbz0Fmx2ejFHghJVfYHrJ6+E99O X-Received: by 2002:a05:6a20:5604:b0:15d:5f9a:391c with SMTP id ir4-20020a056a20560400b0015d5f9a391cmr9318690pzc.33.1696267754208; Mon, 02 Oct 2023 10:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696267754; cv=none; d=google.com; s=arc-20160816; b=R3ci1hBUeT+a84Olr8ZCceiPK0VNwKoPGFsO9ANX5hk15Of+MbIXMbuUmjnvzl2cuU ORapRO6Dd7h/5ExCoTHNY8Wf0rpnXyRkgEcMcjrbaSOzB1l1XixJOqVLSaHH/WnzeptB qldBcSJRM48ZNBZVBKF1u05bJtAYQs708ATL4UmaSCsvUU5be3pl+jqbwI1ldCDTMFIT NExX5R+TyOFSechjw+IhEg5w1CwqclnXgU1w9ICV8B1fJWW2Pb+OjW0S66jSiQkNU8sY okCQQcSNYmDprw7nBiCxaUApTn1OEyhOWsj7PmyZ6q2rsvrfN/rPSwHzbrWkMJPQM+eG OWqw== 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=ttnDvYpWgMvTjf+0dEP2kht6WC3whxjt9OhSv87ziXU=; fh=3blkj9jwkcxpO2El+FNh4zbUYhaV0kFaIYqDZjm/Wn4=; b=vmFuir+eccEr4fjZxNUVLZyxygtwCIFTPcGvtA85bnwR9vY8V+y+IQSAiaqv2DJbcM vZhOBi/Lwuf/LTGyzEZQYmcwGTpC9xTqLgcR2FZ+fIHSesuZPwm69nDfZS887VPgVGsh jc1hSIaQ6+xtriTVuuT5qsDey0RfXZq8sMmGxzkdYag2Rh955TqIJ/JumgteXf0ymob+ u9kKwPtIGf5YbfiHI4bziuFYdDDjWZeVObH1SAF1Ok3A7bWwVWmKqMB8eLbQZjPtJhga 26bHgWrzxlYgxYYXFZ6iYu2MOT4MMwYmNWh7XjALRU8x1MSLEU1Rj6nf3TOI5hXmd+g8 8V/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=AOyEcTQH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t10-20020a056a0021ca00b00690c0051dcdsi29479330pfj.143.2023.10.02.10.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 10:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=AOyEcTQH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id A71BB80C9A69; Mon, 2 Oct 2023 06:05:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237297AbjJBNFc (ORCPT + 99 others); Mon, 2 Oct 2023 09:05:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236163AbjJBNFa (ORCPT ); Mon, 2 Oct 2023 09:05:30 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F12E93 for ; Mon, 2 Oct 2023 06:05:27 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 27A532185D; Mon, 2 Oct 2023 13:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1696251926; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ttnDvYpWgMvTjf+0dEP2kht6WC3whxjt9OhSv87ziXU=; b=AOyEcTQH3P2Sk3FPLf42UuEmjhuEvwEpfiOZXiicIFk3FKfLpE3yHqkD3URM8Ae/8W/Khs TPCqWmLX488XpBOENXerj70opvnVuwmybxLKyiMCZESPuWjZNYKztyHMI4gv//RLOawqPR 8zAbu3HGh4Za3dsanpLYqmbFyLsX7rw= Received: from suse.cz (pmladek.tcp.ovpn2.prg.suse.de [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A47F52C142; Mon, 2 Oct 2023 13:05:25 +0000 (UTC) Date: Mon, 2 Oct 2023 15:05:25 +0200 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Todd Brandt Subject: Re: [PATCH printk] printk: flush consoles before checking progress Message-ID: References: <20230929113233.863824-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230929113233.863824-1-john.ogness@linutronix.de> 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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 02 Oct 2023 06:05:41 -0700 (PDT) On Fri 2023-09-29 13:38:33, John Ogness wrote: > Finally, in case pr_flush() needs to poll-wait (for example, > because there has been a handover to another CPU), reduce the > polling interval from 100ms to 1ms. In the bug report it was > mentioned that 100ms is unnecessarily long. > > Reported-by: Todd Brandt > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217955 > Fixes: 9e70a5e109a4 ("printk: Add per-console suspended state") > Signed-off-by: John Ogness > --- > kernel/printk/printk.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 7e0b4dd02398..cf7841fc6eef 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -3775,16 +3781,11 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre > if (diff == 0 || remaining == 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); I was about to push this patch and ran checkpatch.pl. It warned about WARNING: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst #73: FILE: kernel/printk/printk.c:3782: + msleep(1); And indeed, Documentation/timers/timers-howto.rst says that msleep() might sleep longer that expected for <20ms delays. I guess that it is somehow related to jiffies, HZ, and load on the system. I think that we need to count jiffies here. Something like: diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index db81b68d7f14..6ea500d95fd9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3723,7 +3723,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 timeout_end = jiffies + timeout_jiffies; struct console *c; u64 last_diff = 0; u64 printk_seq; @@ -3772,24 +3773,19 @@ 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; + timeout_end = jiffies + timeout_jiffies; console_unlock(); /* Note: @diff is 0 if there are no usable consoles. */ - if (diff == 0 || remaining == 0) + if (diff == 0) break; - if (remaining < 0) { - /* no timeout limit */ - msleep(100); - } else if (remaining < 100) { - msleep(remaining); - remaining = 0; - } else { - msleep(100); - remaining -= 100; - } + /* Negative timeout means an infinite wait. */ + if (timeout_ms >= 0 && time_after_eq(jiffies, timeout_end)) + break; + + msleep(2000 / HZ); last_diff = diff; } Note that I used 2000 / HZ to make sure that it will be >= 1. And we should do this in a separate patch. It seems that sleeping is a bigger magic than I expected. Best Regards, Petr