From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F6582857CF for ; Thu, 11 Dec 2025 14:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765463875; cv=none; b=hlko7kBaZONRdPCcpeh2fzei2JQyxirKRkbDu5s4ASN58xtF9jSeyvPlixYySJnZgX1SEJiAgNztX/i0PB6DvGaI4P8fdTJc6jziI4I4mjbfboch9BQ434E3Ag+hgyPTwNt9oi81YBgfY7ukllwbD0LnhE3mqMXXyGdKp7zBajw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765463875; c=relaxed/simple; bh=3cYZTJm4iHNn1kNbmUCjAHD+NW+2lEKV46/dC6RZNnU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H58tWw6pjqRJ/N4C85t+cNTKbDJW99kVRVoT1iT4Cr3bIB0E8Im9X1k61El3oJ4nRIvoU2Z8lC0vSpDbIJHtnrVpEbAV87Wj9Ags+ugzAVzpvi8GBiexgJd4S9GnxbV85+uqr+S3RE9kxZHINHbaupHZfx4yH44KyKggRhTeOpI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=aCMUuZ6T; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="aCMUuZ6T" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4779aa4f928so2311315e9.1 for ; Thu, 11 Dec 2025 06:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765463870; x=1766068670; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6LvKyhHkba61T5tK+EW96HG+8id+6OrGRaD4fKDT6Wc=; b=aCMUuZ6TpVuFcetX4C/oQH0qqXvSmWe8Fk1Gjvy2xEqK71PisUFPj2IpsSsawDZ6K+ hRe2l13ihkTbJIxKr1uAb6MLTOLmHy8Nfs7/Kgd7rzTncckObCKM2ekKx0ax0LwreHUF hSaXuq3W6jqc046ndzph4KE0u3DJRt/YB/ey6HbRfQ4t4Y5dgM3mnGjwANGymqmpCsUn ze7Rzs4eyZIsRHMm9gnuOp/SC6M334twJThUOXjCXkeoaRv2mbZO6nAGueCldGP9b8P0 ejWR2SafdYmkWGNRH/Nod5SYpR9RdCif2GCUHUvliXRhSegECKEn41j7DOe6OdzKogtU LPJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765463870; x=1766068670; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6LvKyhHkba61T5tK+EW96HG+8id+6OrGRaD4fKDT6Wc=; b=qD96/jfJ2VUxg17m7amrbK2RbCiWKpYVIogl+IVHEK/wXA80ubapapOdPRJzWZERab 9iJoG2e4WVjhwNci4d/PLgh9UGfpuLzbT72OLCyaNz77VkrRvgt11VgmgFG8w6Pv8bSw vLOsHlp6rhLY3siX8B5weVKY2jPCg+l9vBP+8PR0nk84g/SV594aDD7W7kAwffLuvkcS iJa6D8lGBQYEtpMS4CbAFvLXvPKdwbDe9WguiYxBu2/4ZnrWZHrTJnOzLTGYbeU32uGU FsFHN5de5PNGc1fyRkI5JYJXfnW5TdgLr4zxnyVTbWXWio4B+KC38rc+/5jEMt8M9NvX PtMA== X-Gm-Message-State: AOJu0YxSp2SHY1Ey0PS6wsYtF3IDUP5Ge/5FXc7bXrXBzmpTC74v90mC e0zLhdid9cREPKj4lBs0CTHhbv28o1/jCcBDOLQcamtSKlnZ6hQ/J9PVxWJU3bEJw1qdRVB8GC3 XlO6H X-Gm-Gg: AY/fxX5iLNkVS44SYe0RBnIkloagZegLWj86xDF7ao4HnYCnDoZSRDMfN/126m+cmkO tvDNhao5NadmMNBE81vIAPl/EfBgb2XSg2BTsxfoBdOhyuRXZjspEwzATWD33gVSP4KV/Zytj0C 39H3esNyG7S6MnhQWQVYp3R6svDNQda6lnkK07to0ezwC3p88d42Z0c2FXBdRk+j1Uh5aY1hhFw 4p1FvVI136cFQDsqZeOV5yIg4PG8bvDam1bV0Ta7isMjopkqjIOpKfMrUYNLt2j0ly1hyd4NC9Z kymVtko093rxmE5VoNRdiZoOELsmXOSiTrLB7NjUwr0bl6gER4UiPfafhMT1pDULN/1idaeX84i z5ETsfe0qzwd+8mnC7juRHI49GM8Dba+7OJJ1DuzGVtC9fTDIQ0mDOY6+RyovPL3jOKxplgbHU6 MxvTo= X-Google-Smtp-Source: AGHT+IHX/r/nGaKOuyOXaA0Zt0r8zr6NnM1FQFiHMpKbuD865iiQj5pz6wkGwk8WCNBj42Uu3N0ZKA== X-Received: by 2002:a05:600c:a47:b0:477:76bf:e1fb with SMTP id 5b1f17b1804b1-47a8380cd25mr77551675e9.16.1765463870369; Thu, 11 Dec 2025 06:37:50 -0800 (PST) Received: from pathway ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a89d04393sm39686835e9.0.2025.12.11.06.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Dec 2025 06:37:50 -0800 (PST) Date: Thu, 11 Dec 2025 15:37:48 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: Re: [PATCH v8 09/21] printk: Optimise printk_delay() to avoid walking consoles under SRCU Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri 2025-11-28 03:43:42, Chris Down wrote: > As part of the per-console loglevel implementation, printk_delay() > introduces a call to suppress_message_printing_everywhere() within > printk_delay(). This check acquires the console SRCU lock and iterates > through all registered consoles to determine if the message implies a > delay based on per-console loglevels. > > Since printk_delay() is called in the hotpath of vprintk_emit(), this > introduces measurable overhead (locking and pointer chasing) for every > printk message, even on systems where no delay is configured. > > Optimise this by short-circuiting the function. If neither a boot delay > nor a runtime printk_delay_msec is configured, return immediately. This > avoids the expensive console list iteration in the common case where > delays are disabled. > > Signed-off-by: Chris Down > --- > kernel/printk/printk.c | 25 ++++++++++++++++++------- > 1 file changed, 18 insertions(+), 7 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 0d7f3dac8177..13e17d892ec9 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -2233,20 +2233,31 @@ int printk_delay_msec __read_mostly; > > static inline void printk_delay(int level) > { > + bool boot_delay_active = false; > + int m; > + > +#ifdef CONFIG_BOOT_PRINTK_DELAY > + boot_delay_active = boot_delay && system_state < SYSTEM_RUNNING; > +#endif The same code is used also in boot_delay_msec(). It can be removed there. But still, it would be better to create a helper function and avoid the #ifdef in the middle of the function. > + if (!boot_delay_active && !READ_ONCE(printk_delay_msec)) There is another READ_ONCE(printk_delay_msec) below. It would be better to read the value at the beginning of the function and use it everywhere. > + return; > + > /* If the message is forced (e.g. panic), we must delay */ > if (!is_printk_force_console() && > suppress_message_printing_everywhere(level)) > return; > > - boot_delay_msec(); > + if (boot_delay_active) > + boot_delay_msec(); > > - if (unlikely(printk_delay_msec)) { > - int m = printk_delay_msec; > + m = READ_ONCE(printk_delay_msec); > + if (!m) > + return; > > - while (m--) { > - mdelay(1); > - touch_nmi_watchdog(); > - } > + while (m--) { > + mdelay(1); > + touch_nmi_watchdog(); > } > } I played with the code. I am going to send my variant as a reply to the 1st patch where I proposed 2 alternative solutions, see https://lore.kernel.org/all/aThQ5mZNIijc1G94@pathway Best Regards, Petr