Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1347612pxy; Thu, 6 May 2021 06:17:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywrtHyDlwmspXISE/aQY/FCkR7xEI9uHeo69sD272DtLRvKry4cdOnGe7C2Y+QjJEvOP7u X-Received: by 2002:a17:907:2cc2:: with SMTP id hg2mr4146273ejc.62.1620307035660; Thu, 06 May 2021 06:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620307035; cv=none; d=google.com; s=arc-20160816; b=a4CWg5PQ0Eoz3ZOgCE+cq5chQX3AoRLLvfEQlAzCof1nN2j7J1HprLW5cHkUFIMuWy ty+iPtX/fHwNDaJpm2uNuUW+V1OALCC5j3H6ZJkGTFKVRjvKsvDhr1I/IRfI036uLGBB Os3V1vOm3B1Cdu/zeEEv7WcXS/YALowhCfCWDP5ZSeUsKlto8V1sm0kQ5bN1uG4WFNhb BoHbHCqZrTkVesZVFQ26ke9kGArKUpj1SMd3ui9kb0bVqchZjQp0QbvJ+kSMvIpAYFVN BHjPc/2LvkqweZupKjY5skSp//DWZqXc+RHF/imh8lDWpVqhed4XASzOz3Z05eqPn2AQ mQKA== 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:subject:cc:to:from:date; bh=Bfra4UaCw9ila2exdrw7qYnAd2NRxt9NSRpChA9h4ic=; b=FaV8dQDLnaCAYrpR03KtZdcvIy01bu8ef/mD173BxcVN3ooZmjCZa0KEk+2xq9j3Cg fhlKIu73aKV0CUCWXTcxbXPmawErwtTmLuG4eMDXRUjyVZeTLulMKOxPueOjZRrs6NNk 0bUW++H01VilV03koo19uCSJO8r5Ctj6DVZL2olXeC5lJh04SPgfWz6cRcbL+X4nLiJP CP9aHewn+R7adjVzTnz+cS826X47pj2LgVam1X+HX6OkzkqsgZTN/DGDsHv+wWeGe86p jOVRbbQv+qyGQgLjTSp1lDvwRKLG71Aajp1z9dUF3r+eeBXEKc/c7ucoCy8FKzF3J6FA iWGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si2231598eds.491.2021.05.06.06.16.51; Thu, 06 May 2021 06:17:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232992AbhEFNOY (ORCPT + 99 others); Thu, 6 May 2021 09:14:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:36608 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbhEFNOX (ORCPT ); Thu, 6 May 2021 09:14:23 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4988610FA; Thu, 6 May 2021 13:13:24 +0000 (UTC) Date: Thu, 6 May 2021 09:13:23 -0400 From: Steven Rostedt To: Luo Jiaxing Cc: , , , , , Subject: Re: [PATCH] printk: stop spining waiter when console resume to flush prb Message-ID: <20210506091323.20ba2464@gandalf.local.home> In-Reply-To: <1620288026-5373-1-git-send-email-luojiaxing@huawei.com> References: <1620288026-5373-1-git-send-email-luojiaxing@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 6 May 2021 16:00:26 +0800 Luo Jiaxing wrote: > Some threads still call printk() for printing when resume_console() is > being executed. In practice, the printk() is executed for a period of time > and then returned. The duration is determined by the number of prints > cached in the prb during the suspend/resume process. At the same time, > resume_console() returns quickly. > > Base on owner/waiter machanism, the frist one who fail to lock console will > become waiter, and start spining. When current owner finish print one > informance, if a waiter is waitting, owner will give up and let waiter > become a new owner. New owner need to flush the whole prb unitl prb empty > or another new waiter come and take the job from him. > > So the first waiter after resume_console() will take seconds to help to > flush prb, but driver which call printk() may be bothered by this. New > a flag to mark resume flushing prb. When the console resume, before the > prb is empty, stop to set a new waiter temporarily. > > Signed-off-by: Luo Jiaxing > --- > kernel/printk/printk.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 575a34b..2c680a5 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -287,6 +287,9 @@ EXPORT_SYMBOL(console_set_on_cmdline); > /* Flag: console code may call schedule() */ > static int console_may_schedule; > > +/* Flags: console flushing prb when resume */ > +static atomic_t console_resume_flush_prb = ATOMIC_INIT(0); Why are you using an atomic? It's accessed within locks. static bool console_resuming; > + > enum con_msg_format_flags { > MSG_FORMAT_DEFAULT = 0, > MSG_FORMAT_SYSLOG = (1 << 0), > @@ -1781,7 +1784,8 @@ static int console_trylock_spinning(void) > raw_spin_lock(&console_owner_lock); > owner = READ_ONCE(console_owner); > waiter = READ_ONCE(console_waiter); resuming = READ_ONCE(console_removing); > - if (!waiter && owner && owner != current) { if (!resuming && (!waiter ... > + if (!waiter && owner && owner != current && > + !atomic_read(&console_resume_flush_prb)) { > WRITE_ONCE(console_waiter, true); > spin = true; > } > @@ -2355,6 +2359,7 @@ void resume_console(void) > if (!console_suspend_enabled) > return; > down_console_sem(); > + atomic_set(&console_resume_flush_prb, 1); > console_suspended = 0; resuming = true; > console_unlock(); /* Keep clearing resume from entering the console_unlock */ smp_wmb(); resuming = false; > } > @@ -2592,6 +2597,8 @@ void console_unlock(void) > raw_spin_unlock(&logbuf_lock); > > up_console_sem(); > + if (atomic_read(&console_resume_flush_prb)) > + atomic_set(&console_resume_flush_prb, 0); Get rid of the above. -- Steve > > /* > * Someone could have filled up the buffer again, so re-check if there's