Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1127098rwb; Tue, 27 Sep 2022 08:45:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4d1eLwjKcpCMiVHfwVR7IPkPsOGo/rMZBZSv2qEToPQE+2w7slbcYFDo6rRfqNs57RLzf3 X-Received: by 2002:a17:90b:33c5:b0:202:fa60:3765 with SMTP id lk5-20020a17090b33c500b00202fa603765mr5383426pjb.137.1664293546098; Tue, 27 Sep 2022 08:45:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664293546; cv=none; d=google.com; s=arc-20160816; b=HZaenAsVs+JMvL3h13H92RbRkgKBX4Kg3TwVbNcyeZmTTtYcoGQ2ALgR2/n6oh4hEc m3WKDRb2yU4ZePbJDMvdOpvYaaqFbg0SK1C+7g7JlBJFMZ9cpNTXh7h6+T9USqB7Tq/m FjeAd5b3SH80Xxnn/omHnrKYq6ChxM3T7W+NBEaLHMRUH/+s3uEqj6TZFnPvX6+WxREg 3ZlSmR21iLzQ8Gv+4WpYTXAnB54FrTKipwZkTQ5E6MlOtQRP0TNXet4AEHBzg8Fj1UZC LMFzY4psI/PjbNGJNAjr+GH+gC1DVeFYrUDkzzfOgHzYHYD9ki+1ZeJkqv6hpZYutbpE yd7A== 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=wfZ+y69S5Kb6ArHkND0xlOW2EnHlhDe1FMbMze0LBBQ=; b=gPa3U+ACPlaJLRaWGVejYITnWVMAcewLXTLUkN7pSkbfCEKpg6bDFXKs4JrLNsU10h zi2fS69Ahr7+aaulLDnOlX7ydKM0ocvFKqdkmKTpnfx0JefTinQTfsKis8OE8DzSpk/E BB8RSONWcevADfzLcJLG4nJQsybCneZVcQ09a6uEQsh5CrAGMOFJwLZEGowL3NzHPJaK svoly/W+3IVGpL1tt5KiEfOeFs3M3UuPA/cLGX14cJcCGD9BfM7g5N+Ch3Pr7cBb5euM lusVbnSSZ2SDlvAVGK9X7P+dV1iunevrt9oauxIaMoIygxneqZKiFzBQeAzTkZaA5+bA hk7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ii6hF6qF; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a633847000000b004391cc2bf9fsi2135130pgn.175.2022.09.27.08.45.30; Tue, 27 Sep 2022 08:45:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ii6hF6qF; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231860AbiI0PBU (ORCPT + 99 others); Tue, 27 Sep 2022 11:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbiI0PBH (ORCPT ); Tue, 27 Sep 2022 11:01:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04E61386B3 for ; Tue, 27 Sep 2022 08:01:03 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1664290862; 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=wfZ+y69S5Kb6ArHkND0xlOW2EnHlhDe1FMbMze0LBBQ=; b=Ii6hF6qF8w+fRxRAgYIBtzio+KSO0fe/zm/v8cHxw9fUVrGYeixR3o/jrBcTRX2tSfG0vI 1K6qGC6X0GV+9MRpLj+aLAuOZqimMsQO5bGYy9JEgLNoeGb/4MNCZNaGGR0MvLyhpDpUG/ gnuKTWJsAWNViqkUlRzqXrzQ2NXsJq6GKjbhtmIgSapjiVRvuvHLg7jXN2KIDgt2Y2NgZu 7sNpTIHAW11FOinNuW92deVTCL7EvPY3BlybuNjpD3qaOX6RQ6WqdzDnNXYsW1REgMG134 53+CizBn50RkvI0VJBfEqgNnIRqsMYIbvtSqRIEH7S8yC0aK7wI7EgSB0XqE6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1664290862; 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=wfZ+y69S5Kb6ArHkND0xlOW2EnHlhDe1FMbMze0LBBQ=; b=OtXIekqyobgL1MWBktr1iN8hT1pbL41ESmwtWuVMphwz4bDgsmJJw+T+IG8NOBgdxXR/c0 RwBes69CRQd8kTAg== To: Thomas Gleixner , LKML Cc: Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Peter Zijlstra , "Paul E. McKenney" , Daniel Vetter , Greg Kroah-Hartman , Helge Deller , Jason Wessel , Daniel Thompson Subject: Re: [patch RFC 28/29] printk: Provide functions for atomic write enforcement In-Reply-To: <20220910222301.995758602@linutronix.de> References: <20220910221947.171557773@linutronix.de> <20220910222301.995758602@linutronix.de> Date: Tue, 27 Sep 2022 17:07:01 +0206 Message-ID: <87h70slv4i.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 Below is a fix that was used for the LPC2022 demo to avoid unnecessarily performing the console_lock/console_unlock dance. Add a new global boolean @have_bkl_console to be able to quickly identify if any legacy (bkl) consoles are registered. If there are none, the console_lock/console_unlock stuff can be skipped. The following patch does this and can be applied on top. --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1830,6 +1830,7 @@ static struct lockdep_map console_owner_dep_map = { static DEFINE_RAW_SPINLOCK(console_owner_lock); static struct task_struct *console_owner; static bool console_waiter; +static bool have_bkl_console; /** * console_lock_spinning_enable - mark beginning of code where another @@ -2285,7 +2286,7 @@ asmlinkage int vprintk_emit(int facility, int level, cons_atomic_flush(); /* If called from the scheduler, we can not call up(). */ - if (!in_sched) { + if (!in_sched && have_bkl_console) { /* * Try to acquire and then immediately release the console * semaphore. The release will print out buffers. With the @@ -2575,7 +2576,7 @@ void resume_console(void) */ static int console_cpu_notify(unsigned int cpu) { - if (!cpuhp_tasks_frozen) { + if (!cpuhp_tasks_frozen && have_bkl_console) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); @@ -3023,6 +3024,9 @@ void console_unblank(void) { struct console *c; + if (!have_bkl_console) + return; + /* * console_unblank can no longer be called in interrupt context unless * oops_in_progress is set to 1.. @@ -3052,6 +3056,9 @@ void console_unblank(void) */ void console_flush_on_panic(enum con_flush_mode mode) { + if (!have_bkl_console) + return; + /* * If someone else is holding the console lock, trylock will fail * and may_schedule may be set. Ignore and proceed to unlock so @@ -3311,6 +3318,10 @@ void register_console(struct console *newcon) /* Initialize the nobkl data in @newcon */ cons_nobkl_init(newcon); + /* Has a legacy (BKL) console registered? */ + if (!(newcon->flags & CON_NO_BKL)) + have_bkl_console = true; + /* * Put this console in the list and keep the referred driver at the * head of the list. @@ -3603,7 +3613,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) { int pending = this_cpu_xchg(printk_pending, 0); - if (pending & PRINTK_PENDING_OUTPUT) { + if (have_bkl_console && (pending & PRINTK_PENDING_OUTPUT)) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); John Ogness