Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2504352rdb; Wed, 4 Oct 2023 03:25:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHkD1IAXiW6unF9W2YPQYw0Q3hb+jZ8zjw4wttee4gevWjn1y9T9jKCCA1w+nw25oybroM X-Received: by 2002:a17:902:e850:b0:1c5:d1a2:c3e8 with SMTP id t16-20020a170902e85000b001c5d1a2c3e8mr2202782plg.5.1696415116998; Wed, 04 Oct 2023 03:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696415116; cv=none; d=google.com; s=arc-20160816; b=Gfc6cxTKBMVPLH+xzfviHp8vXNsks+6N25oqrCiDaNBI9ZpD9ORgydrxEp8oNohqN6 iBE/rUv2iZTTVzjrv2gdE0S9gv/Nd9ozv+H8i6hxm6tLjn5WCm3NAKdDsiSxxr2Yq0U0 kkIFdND9ZEWBDlFpbTHhGlQOwWN7qmo9znAi6vcIQQSrTAmubxsrfadgGlNF+7eAuHgm 1O4Srqc2TvBSwqWjQviciZEqcExi0FD4k2ixs4e841PukEiTeCbtPIFyNgOOxlnhbCJJ gFdSjamr46uh/FuAfZLjuWc775YMYroDLiLr/fe/nhsEAKOvGICzo8mvZdK25OeQTNSu xFow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=JTyylAzC8frK5geYcRE1ljeQ4FXoAjG7xVcVT7SH0zc=; fh=+WiQ2jjWv7hkX4n01jo89PecmvbVaG49N7UAN6x9A/o=; b=Gy6mHTXQ68HJU2PB/SZxh3NCSUeNESVGmCp2jk6CZlDYrvJltgYyZVkPqhhDojwZAi 7VB/vPqUe9NEVaj/YrezeYkxuWFh3qQi0lnC6IVSNnoIjZh3HyZDN+cCyN7YpWc3LvU5 1C62FlV+xJsWkW2ecWJ7fRKgwx4s0sVprUaPpBaf+Bz214skziqDM6PjS6ADh6p5wX8n kT1TRIpwtJO1e4+PBpxElBtYbbP5lYDDpXbRxQYxhZmqMPK13e+N3+IPGdKtodFkMQJ2 VXX5zZZluVpk0eY5W1inxfdv7rirleaPodoH7DpsAf5yPe16smaAhORi9HP5jcUV6T2A 4Hjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cGGqmAWc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id j10-20020a170902da8a00b001bbc0ca8650si3834071plx.370.2023.10.04.03.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 03:25:16 -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=@linutronix.de header.s=2020 header.b=cGGqmAWc; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id ECC5D83348BA; Wed, 4 Oct 2023 03:25:15 -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 S242171AbjJDKZP (ORCPT + 99 others); Wed, 4 Oct 2023 06:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242116AbjJDKZO (ORCPT ); Wed, 4 Oct 2023 06:25:14 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702DCB4 for ; Wed, 4 Oct 2023 03:25:11 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696415109; h=from:from:reply-to:subject:subject: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=JTyylAzC8frK5geYcRE1ljeQ4FXoAjG7xVcVT7SH0zc=; b=cGGqmAWcYEV9nAldg4P7m8UdpFr/96/n5vkWSAp9ph6995vvwEGv41zhYACTC8KUjktW61 jVnzjPMF8h+a0ZpTXtSp+3c6ZyfgsfI9QnLVgwSA30wiJT6GZxC8MqZsFr8xlTPrfyrs5m UMt2Yf6uGlcosgMvMS4PyiTRzRGvcFvhMB2IwjW80coc2a9tXUi/y+FqibE/jLWapU9On6 ai+/eIxgPVEOhBrNfm0q0kpzobZa61Cn3eP8sdKsb15RaiOCZmH07j659Kq8ksJJuCgL/q g4BroMK4H7xdzBA/732Kx3IcpiDWynyyG+vGl9I+0J5WvmXhKCr7+rK/kB7SoA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696415109; h=from:from:reply-to:subject:subject: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=JTyylAzC8frK5geYcRE1ljeQ4FXoAjG7xVcVT7SH0zc=; b=xJihxi2knh20Hh/jP24o5YtEkJB1V02mdU2zU2a+RL8wRc6LT7Bw34vjtArWLEx/5kZju0 dKM7fROtLSaJJ5Dg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Todd Brandt Subject: Re: [PATCH printk] printk: flush consoles before checking progress In-Reply-To: References: <20230929113233.863824-1-john.ogness@linutronix.de> Date: Wed, 04 Oct 2023 12:31:07 +0206 Message-ID: <87h6n64rcs.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 03:25:16 -0700 (PDT) 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 > @@ -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); 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. > last_diff = diff; > } > > And we should do this in a separate patch. It seems that sleeping > is a bigger magic than I expected. Agreed. John