Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4277336ybi; Tue, 18 Jun 2019 15:14:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0ieQLEZbxapjP+LEFDVX65yY7KFI3o8C+oywGpEmAxSEb9CKrjdoZQnIIq1jGAh+Rdn6N X-Received: by 2002:a62:d149:: with SMTP id t9mr102599380pfl.173.1560896092932; Tue, 18 Jun 2019 15:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560896092; cv=none; d=google.com; s=arc-20160816; b=LBdEBkzglc73YiGuRjK90jZ8FfrYhvLT2iRJfTZRGka8B20EvV/XSpodxl+z5yQnv3 gxl0h3FMQJVOnrqkNxq9JFjVef2NcqMkQp4qw2HYQAyiYtQ5EbEdpbIowiV89RI4wWSF M5YHascC2GAQcp8aKL9DX0/agUYiEe8JhbDF+qSg3wK6Jw6ldBfb1Pr4G08+dBwpryWN iK9zcZ8Q6QWA3urKjQl1+QSxua8BIPO05XSdRg9jymuh5298Nk61U0XxDOtYVvhj7N6z yV8TQuV7Et4iLLoVPBvP41TXocJ9gvP7JXB3Djwb/LmT3Thaz4xGrzqSHPVGegUe6GPL hZag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :subject:cc:to:from; bh=ZXOc/aHvq7dz6Z+rXMTfFd3k9Ztt3N6nnZpDaz6tgzA=; b=fl/nqRJ7bkIt/7eChXctPd8WNPMtTs71CvetVad5/NwxDl/WmBuiPjv4wPygsdokyN 31PyU90PgqAOijLB58a+hucLmCOX/S1CqX9aMwy3z93ZcsfBy8eoV6ddpOP0hs7Y5HK4 Fh5bNMQC92Lppz4LLmhk0AYFeq7viykcSjLH2kFXVsH5Qtf5XpEjJMkMJa1gSIhFyqzn otCDCe6mVjWBo271OYQWd/mDq/yah43ubgFMWgo2OLwjIs8kGolatyBnplPycNZL/TTW AgELf9cedH5b6c4VMyVAo4JxDXErKpomwr5Ji7lcJsQRNBN0wYUWUuNV8BhtYrzn8SoX 6LCw== 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 v16si4763267pfe.39.2019.06.18.15.14.37; Tue, 18 Jun 2019 15:14:52 -0700 (PDT) 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 S1730804AbfFRWND (ORCPT + 99 others); Tue, 18 Jun 2019 18:13:03 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:48940 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730398AbfFRWND (ORCPT ); Tue, 18 Jun 2019 18:13:03 -0400 Received: from localhost ([127.0.0.1] helo=vostro.local) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1hdMLQ-0005xi-8L; Wed, 19 Jun 2019 00:12:48 +0200 From: John Ogness To: Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Petr Mladek , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Sergey Senozhatsky Subject: Re: [RFC PATCH v2 1/2] printk-rb: add a new printk ringbuffer implementation References: <20190607162349.18199-1-john.ogness@linutronix.de> <20190607162349.18199-2-john.ogness@linutronix.de> <20190618045117.GA7419@jagdpanzerIV> Date: Wed, 19 Jun 2019 00:12:43 +0200 Message-ID: <87imt2bl0k.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-06-18, Sergey Senozhatsky wrote: >> + struct prb_reserved_entry e; >> + char *s; >> + >> + s = prb_reserve(&e, &rb, 32); >> + if (s) { >> + sprintf(s, "Hello, world!"); >> + prb_commit(&e); >> + } > > A nit: snprintf(). > > sprintf() is tricky, it may write "slightly more than was > anticipated" bytes - all those string_nocheck(" disabled"), > error_string("pK-error"), etc. Agreed. Documentation should show good examples. >> +Sample reader code:: >> + >> + DECLARE_PRINTKRB_ENTRY(entry, 128); >> + DECLARE_PRINTKRB_ITER(iter, &test_rb, &entry); >> + u64 last_seq = 0; >> + int len; >> + char *s; >> + >> + prb_for_each_entry(&iter, len) { >> + if (entry.seq - last_seq != 1) { >> + printf("LOST %llu ENTRIES\n", >> + entry.seq - (last_seq + 1)); >> + } >> + last_seq = entry.seq; >> + >> + s = (char *)&entry.buffer[0]; >> + if (len >= 128) >> + s[128 - 1] = 0; >> + printf("data: %s\n", s); >> + } > > How are we going to handle pr_cont() loops? > > print_modules() > preempt_disable(); > list_for_each_entry_rcu(mod, &modules, list) { > pr_cont(" %s%s", mod->name, module_flags(mod, buf)); > } > preempt_enable(); pr_cont() (in its current form) is not related to the printk buffer because cont messages use their own separate struct cont buffer. And for the initial integration of the new ringbuffer I would leave that as it is. Which means initially, pr_cont() would still sit behind a raw spinlock and pr_cont() from NMI context would be stored as individual messages. However, to remove the spinlock of the cont buffer and allow pr_cont() to work from NMI context, I would like to introduce a separate lockless ringbuffer instance for cont that contains all the cont pieces (including the caller_id). As soon as the caller_id changes from the oldest record in the cont ringbuffer, that caller would assemble the full cont message, popping all the pieces from the ringbuffer (with a single cmpxchg) and insert the message to the printk ringbuffer. John Ogness