Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2575017rdb; Wed, 4 Oct 2023 05:39:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEd9xMZckohDB9KmoYxCDPL0zuLEFzkkijO1+SeRg7lfeM2v3IVsgAij4HCRljdyqQb//08 X-Received: by 2002:a05:6808:b3a:b0:3af:a107:cf68 with SMTP id t26-20020a0568080b3a00b003afa107cf68mr2261355oij.40.1696423181401; Wed, 04 Oct 2023 05:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696423181; cv=none; d=google.com; s=arc-20160816; b=PkoIvz2wHtpqInfRyoE+bkUw1hHx1wraYp6yrN6lh/qdsbw4wNnuMdqW7omsohg1Vs xnjUz2gP0ExVEqc8L5d7xxjIT2f4rb9LYlL77tAAbd+j6IFn6+11aEX4zwXcr8Btn4iK eiqpDJr3/m7E3vzZA0UIeG0U+TPsm8xxaorPPoMSJzNkV2wqZNOL3kIYXwNAlAgDNKEm a/4aIBtmq1BuvCq0BauLfyyky49v7jBfmVZavMpXU5oaQyF36T/Q5L0Gm5gUO4ia57U2 rRCupuvJiop8BXMrkwOXvtx01xytJA5Oe0DvEVKsbY74LTTFrbzgTJ+yGPQeLsLD6jpV NHmg== 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=oLNINpIKof+eEy/1RFZQDSKVWzj5eMFFhG6a4cq09TY=; fh=3blkj9jwkcxpO2El+FNh4zbUYhaV0kFaIYqDZjm/Wn4=; b=oQ/Yzm16P23NekQyyqQSWmPtU2t1jm3/HNnx8c45Eys8UYfg0J9Q+AH7Oa6+KwgNCJ f452mZ0tbMqMFxTGCjt7xRgpxSnTMt8SO9U3IzTdk3YeqkLTnpTEtVvyDrN7xKjLdPZY CPk0Qbw9Ku9hS3jmjrFCsPIyaSKcMsNHw+8DWrfymfVXxu3MsxoZcuoht2e5BhCRX3A5 3KaQv24o55nF5KSq7lCbVlp4XK6SQdkljTH4o5OkVT++pBCoWfgsIufgVddmmtjPnOxZ X21JJmILg7FblBy62nk2RdWkq12RXjFMhb6/ut0XAdTul1+Cy6C0I/HojQuOk/iUcZ5C MGwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=EkMWDXF0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x5-20020a654145000000b0056b4065299esi3592252pgp.621.2023.10.04.05.39.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 05:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=EkMWDXF0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 818BF8025792; Wed, 4 Oct 2023 05:39:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242348AbjJDMjj (ORCPT + 99 others); Wed, 4 Oct 2023 08:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233088AbjJDMji (ORCPT ); Wed, 4 Oct 2023 08:39:38 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6825A1 for ; Wed, 4 Oct 2023 05:39:34 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 3852821838; Wed, 4 Oct 2023 12:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1696423173; 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=oLNINpIKof+eEy/1RFZQDSKVWzj5eMFFhG6a4cq09TY=; b=EkMWDXF0BLTJnRvfOgbX4KJDouKYco9QVrz2ET01vlWb3XXz2+JkLtxbr8c/Q9Onbf2lBM O3zvLnwIJ8PUnq0wuEHpxd38UWLFdrVBGFGA4t+qqUwOZhp2eBBxZ+8d3VndHBrhUy6PlJ V+JbqToaN5T3vE+pV0szQFEzlR7jaWM= 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 C50342C142; Wed, 4 Oct 2023 12:39:32 +0000 (UTC) Date: Wed, 4 Oct 2023 14:39:32 +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> <87h6n64rcs.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87h6n64rcs.fsf@jogness.linutronix.de> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 05:39:40 -0700 (PDT) On Wed 2023-10-04 12:31:07, John Ogness wrote: > On 2023-10-02, Petr Mladek wrote: > > 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. > > Agreed. The @timeout_ms parameter should be respected. > > > 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 > > @@ -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); > > Is there really any advantage to this? I would just do msleep(1) and let > msleep round up. Everything else (tracking via jiffies) looks fine to me. It was attempt to synchronize it with a scheduler tick. I saw it somewhere ;-) But you are right. Let's keep it simple and use msleep(1). > > last_diff = diff; > > } > > > > And we should do this in a separate patch. It seems that sleeping > > is a bigger magic than I expected. > > Agreed. Are you going to prepare them or should I? Best Regards, Petr