Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp343589imp; Wed, 20 Feb 2019 01:02:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IaYNxEFnf6qUOcVzNzkIpD+wge6jb4AZ/OdHhXX0WyYliGvfZM0nF8d47R5hBUC/+Omk2aw X-Received: by 2002:a17:902:bb89:: with SMTP id m9mr35269100pls.320.1550653355403; Wed, 20 Feb 2019 01:02:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550653355; cv=none; d=google.com; s=arc-20160816; b=LY1Ma+hUjKjevLubFf0fbn1UAQYbypHtDLtekDNaWiSpE5cpGPvmUBrZMPRMqZCddX HYfSc2ee69SvmQsDQMAKSrkFmvt1gC1WdrMTGkJ0fVD8n/VZivnUlGoNiNJ9hFWhlBwL 632yAoGXq4rxbX8Z81ZxhcUjYE8Wri4FaHznQVE23pCQ79jtMv/aR3SBaS9CEAm+5ZXm C0spKGXvpYWwFnhDhYxRcf6RestDo0lgQe7089PSFiNUkych/Lt2w8+aWZBtlid+Ht51 FA0lj3wdVIWWIyAWhs+TgVcChQCQ+sUeM5kIvznkoqvDUTXL06pc/FrSwk91xh/dEYfr hPcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=sy3ofovoJ7ez7Kb0F/08Oo7eaOgOWSlOG2D+2F4B3II=; b=XsTSAeiPEpx8hCxCJEL2KgBsqssqbmQFHIw26TgUVSTSpLLzelaZwXAucPR6fVBuvL 9dTaYVGaVg2jcGbX0W9q24rG9ZHQ6iMxCeSaYshCEuIieA6DoymXreax5NDlAuOqOEuS NRvK2SSBALPViMldFRBl1mZcPD7UamK6Nnn59tYwTf8Nrl3hldgZ9JH8zt9E5ztGGIW2 UqW+k4udwCjIhuBeEcrTNJKImvqef0OABNFRWD1PkW8ag2zp0Z/nRWgfrDcWHxGxahrg NpVPGavzFbcvpeO1ZpSE6JUF8serfSGXHZflwAM0AKvTbV4alKgsKt/8bxXvkCwDdz2m hAmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g98si20061956plb.99.2019.02.20.01.02.19; Wed, 20 Feb 2019 01:02:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726469AbfBTJBP (ORCPT + 99 others); Wed, 20 Feb 2019 04:01:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:34772 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725861AbfBTJBP (ORCPT ); Wed, 20 Feb 2019 04:01:15 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0A315B0B6; Wed, 20 Feb 2019 09:01:13 +0000 (UTC) Date: Wed, 20 Feb 2019 10:01:12 +0100 From: Petr Mladek To: John Ogness Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Sergey Senozhatsky , Steven Rostedt , Daniel Wang , Andrew Morton , Linus Torvalds , Greg Kroah-Hartman , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky Subject: Re: [RFC PATCH v1 10/25] printk: redirect emit/store to new ringbuffer Message-ID: <20190220090112.xbnauwt2w7gwtebo@pathway.suse.cz> References: <20190212143003.48446-1-john.ogness@linutronix.de> <20190212143003.48446-11-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190212143003.48446-11-john.ogness@linutronix.de> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2019-02-12 15:29:48, John Ogness wrote: > vprintk_emit and vprintk_store are the main functions that all printk > variants eventually go through. Change these to store the message in > the new printk ring buffer that the printk kthread is reading. We need to switch the two buffers in a single commit without disabling important functionality. By other words, we need to change vprintk_emit(), vprintk_store(), console_unlock(), syslog(), devkmsg(), and syslog in one patch. The only exception might continuous lines handling. We might temporary store them right away. It should not break bisectability. The patch will be huge but I do not see other reasonable solution at the moment. In each case, the patch should do only a "straightforward" switch. Any refactoring or logical changes should be done in preliminary patches. > Remove functions no longer in use because of the changes to > vprintk_emit and vprintk_store. > > In order to handle interrupts and NMIs, a second per-cpu ring buffer > (sprint_rb) is added. This ring buffer is used for NMI-safe memory > allocation in order to format the printk messages. > > NOTE: LOG_CONT is ignored for now and handled as individual messages. > LOG_CONT functions are masked behind "#if 0" blocks until their > functionality can be restored > > Signed-off-by: John Ogness > --- > kernel/printk/printk.c | 319 ++++++++----------------------------------------- > 1 file changed, 51 insertions(+), 268 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 5a5a685bb128..b6a6f1002741 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -584,54 +500,36 @@ static int log_store(int facility, int level, > const char *text, u16 text_len) > memcpy(log_dict(msg), dict, dict_len); > msg->dict_len = dict_len; > msg->facility = facility; > msg->level = level & 7; > msg->flags = flags & 0x1f; The existing struct printk_log is stored into the data field of struct prb_entry. It is because printk_ring_buffer is supposed to be a generic ring buffer. It makes the code more complicated. Also it needs more space for the size and seq items from struct prb_entry. printk() is already very complicated code. We should not make it unnecessarily worse. Please, are there any candidates or plans to reuse the new ring buffer implementation? For example, would it be usable for ftrace? Steven? If not, I would prefer to make it printk-specific and hopefully simplify the code a bit. > - if (ts_nsec > 0) > - msg->ts_nsec = ts_nsec; > - else > - msg->ts_nsec = local_clock(); > - memset(log_dict(msg) + dict_len, 0, pad_len); > + msg->ts_nsec = ts_nsec; > msg->len = size; > > /* insert message */ > - log_next_idx += msg->len; > - log_next_seq++; > + prb_commit(&h); > > return msg->text_len; > } [...] > int vprintk_store(int facility, int level, > const char *dict, size_t dictlen, > const char *fmt, va_list args) > { > - static char textbuf[LOG_LINE_MAX]; > - char *text = textbuf; > - size_t text_len; > + return vprintk_emit(facility, level, dict, dictlen, fmt, args); > +} > + > +/* ring buffer used as memory allocator for temporary sprint buffers */ > +DECLARE_STATIC_PRINTKRB(sprint_rb, > + ilog2(PRINTK_RECORD_MAX + sizeof(struct prb_entry) + > + sizeof(long)) + 2, &printk_cpulock); > + > +asmlinkage int vprintk_emit(int facility, int level, > + const char *dict, size_t dictlen, > + const char *fmt, va_list args) [...] > + rbuf = prb_reserve(&h, &sprint_rb, PRINTK_SPRINT_MAX); The second ring buffer for temporary buffers is really interesting idea. Well, it brings some questions. For example, how many users might need a reservation in parallel. Or if the nested use might cause some problems when we decide to use printk-specific ring buffer implementation. I still have to think about it. > - /* If called from the scheduler, we can not call up(). */ > - if (!in_sched && pending_output) { > - /* > - * Disable preemption to avoid being preempted while holding > - * console_sem which would prevent anyone from printing to > - * console > - */ > - preempt_disable(); > - /* > - * Try to acquire and then immediately release the console > - * semaphore. The release will print out buffers and wake up > - * /dev/kmsg and syslog() users. > - */ > - if (console_trylock_spinning()) > - console_unlock(); > - preempt_enable(); > - } I guess that it is clear from the other mails. But to be sure. This patch should just switch the buffers. The console handling optimizations/fixes should be done in later patches or even in a separate patchset. Best Regards, Petr PS: I have just finished a mail that I started writing yesterday evening. I am going to proceed some other pending mails now. I'll come back to this thread soon.