Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1444365img; Tue, 19 Mar 2019 07:48:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYsGGEgVEKid93wEfOAIW667eNXnDMZ77EQGB5aCSep4HxlLWAFm4/C9Ej2FigkL/AvK5m X-Received: by 2002:a65:568b:: with SMTP id v11mr2660057pgs.23.1553006885843; Tue, 19 Mar 2019 07:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553006885; cv=none; d=google.com; s=arc-20160816; b=lw/q00t+SSGz5K4/XGppWPRGV4opf/1n6RixGay0cv1PdBpPgwqRUXh/1d3p+szMI3 VwYGwOX6VMMMFiLKCzlSDqK1uKlJD3jwfhIU1+9cW1VeUaTw1C8156LlueHQ/Ld1UZQ3 UUCgoCEukOKsULRFupRV8xTmx12AAmnKEMlDvT+iNGuukSac1vCC8mAMwSoYFBXfsCiK 7wTCKvBihBKsQIRFv7vW02K+ojrFmruutJgfOSkaiWQ6BbTMyLDAvRH2pFVcfw7c8a3Q zLVqDpe35sdke+86hYDHsdOt1T7HVW+71Xcc7HMkZunOiy/cGzQV41VmvbVuAw3laUGC K2yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fkIUslYOQ11EGhiFvtaB0L6PyS4FFkyPHlpF2YOJkzc=; b=CsdfnEMj6VxudykGzGjrKo48zGGs5OlZtZAIaOzzVc5banrgDIifTgHmXYVnFS5An1 Nt1HuEEGKNfofCmP3yhI+RpJK9DgJp0v+pCAaOzr9rFaH1LdH7hBEYIjnQqOxnDfiFUJ jGzlOfHzo36w5NmdYaGgqrw9eLIDLWLEeroXYhkJmLtObeIL/gWZpfb0JFG3zjL2zeui a45E+CDD4xkiobvjhkgN3AaUtrfvRgFfab7VLxKwqAJlVO00AsCxeoI+Vamz1DrJTyyo Ik7G8J8YwINPtqzG3Zo8qA7DzuB0xxl2BZm0r083PZ4+hmnDoJceuDQ9YOmeuzjXox33 mGsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=F8K4J6ph; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16si12242965pfe.152.2019.03.19.07.47.50; Tue, 19 Mar 2019 07:48:05 -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; dkim=pass header.i=@chromium.org header.s=google header.b=F8K4J6ph; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727468AbfCSOpz (ORCPT + 99 others); Tue, 19 Mar 2019 10:45:55 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:38866 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbfCSOpz (ORCPT ); Tue, 19 Mar 2019 10:45:55 -0400 Received: by mail-ua1-f67.google.com with SMTP id d4so6547805uap.5 for ; Tue, 19 Mar 2019 07:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fkIUslYOQ11EGhiFvtaB0L6PyS4FFkyPHlpF2YOJkzc=; b=F8K4J6phY+chGmbKPTOvZo45yIvc71j0JqzCWTXYAquKjXaCwIiJOs+Mhb0l7WNoTJ KymHYHdP3/4IADDK2jp8zBg8ELrDoYoQYdxK3PFDFn06PAo0SlRi1oJnL8EsWHV0VMiU aVD5Qf1EQqhpUWe1ytrLJfxWuKRjJxfgTj2Ag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fkIUslYOQ11EGhiFvtaB0L6PyS4FFkyPHlpF2YOJkzc=; b=n0KiSx5cA4Cf98Vo0P7OYzSvOtrIw4R9bhVlycJEJKb31ZsGGX/orsxr4W1yjJo+Ly hAkrzwiDsQIrUH72+Xvk0SHeCxJngGWBODAqKSRBa8ZSUo+y0x+zLbocYBdlwR9X/ya5 Ty8uiNrjNGU66U/c5lXyw4B84ZRh4X6S8PG89K0ozj97gzbRdVtmuIxWXeb7jey7GjSc /L6nBf+BIQtkJ5JZvR+8KBWB3KKj6ONaTvPcPGDbqxFAUuUhaynLiapaisI8C7iBlQkj u6FU6e9hUI8x4TlLjilJl4twqq65xm/o2lLZgOP3G5NKBNRGdA0FOIX+HL1Giw6pqc3d x72A== X-Gm-Message-State: APjAAAVIhxF6XjntcJTzDlBRt5RR6jZ9lSGjiCV0RytmWJB0u4zy7VJX DRPzBNx6wDxrYIQYhB4+KIiuiGZuJjU= X-Received: by 2002:ab0:28d6:: with SMTP id g22mr1396460uaq.75.1553006753434; Tue, 19 Mar 2019 07:45:53 -0700 (PDT) Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com. [209.85.222.48]) by smtp.gmail.com with ESMTPSA id c124sm2494450vsd.3.2019.03.19.07.45.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Mar 2019 07:45:51 -0700 (PDT) Received: by mail-ua1-f48.google.com with SMTP id c13so4488452uao.12 for ; Tue, 19 Mar 2019 07:45:50 -0700 (PDT) X-Received: by 2002:ab0:3445:: with SMTP id a5mr1419745uaq.130.1553006750663; Tue, 19 Mar 2019 07:45:50 -0700 (PDT) MIME-Version: 1.0 References: <20190318204741.116550-1-dianders@chromium.org> <20190318204741.116550-2-dianders@chromium.org> <20190319112537.5yi7gelkk4ixswmu@holly.lan> In-Reply-To: <20190319112537.5yi7gelkk4ixswmu@holly.lan> From: Doug Anderson Date: Tue, 19 Mar 2019 07:45:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 2/3] tracing: Add trace_total_entries() / trace_total_entries_cpu() To: Daniel Thompson Cc: Steven Rostedt , Ingo Molnar , Jason Wessel , kgdb-bugreport@lists.sourceforge.net, Brian Norris , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Mar 19, 2019 at 4:25 AM Daniel Thompson wrote: > > On Mon, Mar 18, 2019 at 01:47:40PM -0700, Douglas Anderson wrote: > > These two new exported functions will be used in a future patch by > > kdb_ftdump() to quickly skip all but the last few trace entries. > > > > Suggested-by: Steven Rostedt > > Signed-off-by: Douglas Anderson > > --- > > > > Changes in v5: None > > Changes in v4: > > - trace_total_entries() / trace_total_entries_cpu() new for v4 > > > > Changes in v3: None > > > > kernel/trace/trace.c | 65 ++++++++++++++++++++++++++++++++++---------- > > kernel/trace/trace.h | 3 ++ > > 2 files changed, 53 insertions(+), 15 deletions(-) > > > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > index ccd759eaad79..7afc90f82e53 100644 > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -3490,34 +3490,69 @@ static void s_stop(struct seq_file *m, void *p) > > trace_event_read_unlock(); > > } > > > > +static void > > +get_total_entries_cpu(struct trace_buffer *buf, unsigned long *total, > > + unsigned long *entries, int cpu) > > +{ > > + unsigned long count; > > + > > + count = ring_buffer_entries_cpu(buf->buffer, cpu); > > + /* > > + * If this buffer has skipped entries, then we hold all > > + * entries for the trace and we need to ignore the > > + * ones before the time stamp. > > + */ > > + if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { > > + count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; > > + /* total is the same as the entries */ > > + *total = count; > > + } else > > + *total = count + > > + ring_buffer_overrun_cpu(buf->buffer, cpu); > > + *entries = count; > > +} > > + > > static void > > get_total_entries(struct trace_buffer *buf, > > unsigned long *total, unsigned long *entries) > > { > > - unsigned long count; > > + unsigned long t, e; > > int cpu; > > > > *total = 0; > > *entries = 0; > > > > for_each_tracing_cpu(cpu) { > > - count = ring_buffer_entries_cpu(buf->buffer, cpu); > > - /* > > - * If this buffer has skipped entries, then we hold all > > - * entries for the trace and we need to ignore the > > - * ones before the time stamp. > > - */ > > - if (per_cpu_ptr(buf->data, cpu)->skipped_entries) { > > - count -= per_cpu_ptr(buf->data, cpu)->skipped_entries; > > - /* total is the same as the entries */ > > - *total += count; > > - } else > > - *total += count + > > - ring_buffer_overrun_cpu(buf->buffer, cpu); > > - *entries += count; > > + get_total_entries_cpu(buf, &t, &e, cpu); > > + *total += t; > > + *entries += e; > > } > > } > > > > +unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu) > > +{ > > + unsigned long total, entries; > > + > > + if (!tr) > > + tr = &global_trace; > > This function is only ever called with tr set to NULL which means tr is > an argument looking for a user. > > I wouldn't mind except if this was following copying prior art to keep > the API feel the same but I can't find any other trace function where > the trace_array can be substituted for NULL. AFAICT all the existing > sites where global_trace is used will use it unconditionally. Happy to change this if you guys want. At the moment the trace_total_entries() comes straight from Steven's suggestion at: https://lkml.kernel.org/r/20190315144130.1aa36931@gandalf.local.home Ugh, but while looking at this it looks like I totally forgot one piece of feedback from Steven: to move the disabling of the tracing out so it's not re-enabled after counting but before dumping. Not sure how I missed that. :( I'll wait to spin until I hear from Steven if he wants me to remove the "struct trace_array *tr" argument, then I'll post out a v6 with the fix I forgot... -Doug