Message ID | 20230302195618.156940-16-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp42812wrd; Thu, 2 Mar 2023 12:01:12 -0800 (PST) X-Google-Smtp-Source: AK7set+Td1ENzfsBoers4BkKPOnneTRD7SNCOXTfly7AQRrsVMI/NJeiectYOrw3rXeVA0FhWilN X-Received: by 2002:a17:902:8201:b0:19e:65db:7ac3 with SMTP id x1-20020a170902820100b0019e65db7ac3mr3735928pln.68.1677787272553; Thu, 02 Mar 2023 12:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677787272; cv=none; d=google.com; s=arc-20160816; b=xta8CvfX+WY4gIJmXybAh1cSa/YY6hJ8Xs+KQQahD0EujMqsI7uYcihD7jqmEOf411 IwN6BE+NN40fnET2En7LhBZW938jtujeMgDuULi4E0HoROwkWdwHMRc44yy4L/x+b7RO OUYNmkepffG3Z4Z/qIfm/lmQgIKGzJvvS1qRqEhuttZqrONxk1LK2fvBQp5idH35MIQc LPIEBI84UURH6hyFS/7gGr00Z9ja1GuNOdULJGuLZ6D4TIk450JYf1YhMYIu4TrzFTuw B3RoWFYwkFTW/+dnizoYake5Ix5xMJh7pfap4ljbjT5//Ys+FcVSzQg2AkE1e+ifT1n1 XhTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=UbylHEX9bZ2Zz2vO7zrZ8IqoDnUW9FIGTcOLhEnljfc=; b=JS691WqUzMetu5BA3dL7vXbZblW3yMyGsrpLP/hcw95DjLmljsjaSs9s2oeCziRjZz oPDTDPGBjRJ6qs6NJ9IUO88McWgTvCwpQkYU/IxJz4IxawpoIkmuIax6MLYbRUBVQv4T uV6YLBpishaw9500PropjkZRjO23bEKx641FtFFX/VjfGd/3YrWU0tjVo8i1RTtrZh4M b48A4roTEopcqfPHiUrhqezGoDkBe9OgD3+awq3MbGJ8q0HpFtbvIVA/tt6ivjDq1DKV YwpMY5ShQEggybhXSadTvTDARj2k6lFwW8qmBCzQv/sPTBEmfWUUMU8pKpH1DzV5Eu7W Xnow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SzIhebPl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="VYNs/XHz"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a170902ce9200b0019e4154578esi274398plg.76.2023.03.02.12.00.58; Thu, 02 Mar 2023 12:01:12 -0800 (PST) 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=SzIhebPl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="VYNs/XHz"; 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 S230232AbjCBT6Z (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Thu, 2 Mar 2023 14:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbjCBT5w (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Mar 2023 14:57:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEFB474D7 for <linux-kernel@vger.kernel.org>; Thu, 2 Mar 2023 11:57:50 -0800 (PST) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677787067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UbylHEX9bZ2Zz2vO7zrZ8IqoDnUW9FIGTcOLhEnljfc=; b=SzIhebPlt8K1wgUDVQ2Wh7Tb6U0elzXDwN42e+qk6p2+KJA3FqCB72QdiDFkqN5Rz6hN+m HKUcbOR5LpLtLiX997qg9iueEXEFKN2UXb/CWtgNW8XLZYrbBmNQB8+Lu3RVnl2iThp0Ki DxsgqYmPYbWJfh2LqkjcVungwPE368w3ZQk6iDdxTq6zrYi/NaWzsyVo4dN03fhx+tw/G2 zPj6I4tuLNqgFTurakY8dVCGSaciIMuQ73HQmFp+JtFzviEiZhie9xMdGN3uK++J4f5h64 ZqTPB4S/Jt49sYX3tuTfBXSn1jkPLjqsJeJYRi9k/xiBbIlj9PzEhMOTAJb0Ew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677787067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UbylHEX9bZ2Zz2vO7zrZ8IqoDnUW9FIGTcOLhEnljfc=; b=VYNs/XHznKBn3ldggoAmpbvOhFfxFE91NmiYSlRyerxEjdw7bcVdX12/MvvF6kyEsz17Ug cnhlnMwLs693aCDA== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org Subject: [PATCH printk v1 15/18] printk: nobkl: Stop threads on shutdown/reboot Date: Thu, 2 Mar 2023 21:02:15 +0106 Message-Id: <20230302195618.156940-16-john.ogness@linutronix.de> In-Reply-To: <20230302195618.156940-1-john.ogness@linutronix.de> References: <20230302195618.156940-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759287466795902988?= X-GMAIL-MSGID: =?utf-8?q?1759287466795902988?= |
Series |
threaded/atomic console support
|
|
Commit Message
John Ogness
March 2, 2023, 7:56 p.m. UTC
Register a syscore_ops shutdown function to stop all threaded
printers on shutdown/reboot. This allows printk to transition back
to atomic printing in order to provide a robust mechanism for
outputting the final messages.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk_nobkl.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
Comments
On Thu 2023-03-02 21:02:15, John Ogness wrote: > Register a syscore_ops shutdown function to stop all threaded > printers on shutdown/reboot. This allows printk to transition back > to atomic printing in order to provide a robust mechanism for > outputting the final messages. > > --- a/kernel/printk/printk_nobkl.c > +++ b/kernel/printk/printk_nobkl.c > @@ -1763,3 +1764,33 @@ void cons_nobkl_cleanup(struct console *con) > cons_state_set(con, CON_STATE_REQ, &state); > cons_free_percpu_data(con); > } > + > +/** > + * printk_kthread_shutdown - shutdown all threaded printers > + * > + * On system shutdown all threaded printers are stopped. This allows printk > + * to transition back to atomic printing, thus providing a robust mechanism > + * for the final shutdown/reboot messages to be output. > + */ > +static void printk_kthread_shutdown(void) > +{ > + struct console *con; > + > + console_list_lock(); > + for_each_console(con) { > + if (con->flags & CON_NO_BKL) > + cons_kthread_stop(con); > + } > + console_list_unlock(); It would make sense to explicitly flush the consoles after stopping the kthreads. There might be pending messages... > +} > + > +static struct syscore_ops printk_syscore_ops = { > + .shutdown = printk_kthread_shutdown, > +}; > + > +static int __init printk_init_ops(void) > +{ > + register_syscore_ops(&printk_syscore_ops); > + return 0; > +} > +device_initcall(printk_init_ops); Otherwise it looks good. Best Regards, Petr
diff --git a/kernel/printk/printk_nobkl.c b/kernel/printk/printk_nobkl.c index 001a1ca9793f..53989c8f1dbc 100644 --- a/kernel/printk/printk_nobkl.c +++ b/kernel/printk/printk_nobkl.c @@ -7,6 +7,7 @@ #include <linux/delay.h> #include <linux/kthread.h> #include <linux/slab.h> +#include <linux/syscore_ops.h> #include "printk_ringbuffer.h" #include "internal.h" /* @@ -1763,3 +1764,33 @@ void cons_nobkl_cleanup(struct console *con) cons_state_set(con, CON_STATE_REQ, &state); cons_free_percpu_data(con); } + +/** + * printk_kthread_shutdown - shutdown all threaded printers + * + * On system shutdown all threaded printers are stopped. This allows printk + * to transition back to atomic printing, thus providing a robust mechanism + * for the final shutdown/reboot messages to be output. + */ +static void printk_kthread_shutdown(void) +{ + struct console *con; + + console_list_lock(); + for_each_console(con) { + if (con->flags & CON_NO_BKL) + cons_kthread_stop(con); + } + console_list_unlock(); +} + +static struct syscore_ops printk_syscore_ops = { + .shutdown = printk_kthread_shutdown, +}; + +static int __init printk_init_ops(void) +{ + register_syscore_ops(&printk_syscore_ops); + return 0; +} +device_initcall(printk_init_ops);