Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1278729img; Tue, 19 Mar 2019 04:26:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBsvEq2UGMYzhwPfTCix8ofi7PLJZekoBgSkfxyiae27yFolLEJZvEfiTPhNmJb5ZDkav3 X-Received: by 2002:a62:1e06:: with SMTP id e6mr24135868pfe.168.1552994800558; Tue, 19 Mar 2019 04:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552994800; cv=none; d=google.com; s=arc-20160816; b=XnJMMlD0Cgd8L1JoYV43WrTnmGFJONPx5WBV63y6MmQiNEI7mbqleeTClBL0CNedz+ KH4eT2c7NbMiHluh1cbM6YeM9vZdyNRHiD+9la6f+asxDZX8yDHW9AR0GdzIg+Q0aZm5 xBug/incetVV9OrucXvUz60p15DKA9UnLsSU8rDQw1U9MN9UtkoS0st0hErk3JrXIRCQ tmDk8H0ProKCRMka8yWvGi3pJSyB9M8XpeYmCay3TILxwfw/achj7p/wSFmYzNDYIwbb PSevQ4oCwAxotfQlg3nWHB4tTFDcBo5A/v06PnAnhqgsZ5q5WxDDKkvZa9u+4TCq5kEI RjZg== 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:dkim-signature; bh=A3JgLHFiJiDKRWwNVpEhyRSFZhkZ10MYX6wZTJJU16w=; b=z0jwn0km2saMpmDdKsJElWay40sAW+X/ZhQP1JnmUoxkjduVUamF2p4/V6daBcuMl4 103knjYo7lWj2Sy/wUW2+ZXhUlXFzcw912V85TkzPF8Krj0ueHYZKWXm9FtHRZjqRKJh B9IGNgy5w6SdpERsRJgO9UzqRmQo2G7sbevt0+yRIq/QLBywUBUcyWlUgiBf5yH0XJri gVPK92gjN59h25AFxy+DH/jRCVxqAdUbw3NAASXrhulx4ETT+Edd3XvtZPytkIFUZc37 tgsw/XriuPz3FeSheSeA/IUtB4y8zbUkf8S0ZoaPXK1NADP59xW/ajzJaebyEjnCKFyz bF7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mETSIgJ1; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m6si10930523pgq.24.2019.03.19.04.26.24; Tue, 19 Mar 2019 04:26:40 -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=@linaro.org header.s=google header.b=mETSIgJ1; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727143AbfCSLZm (ORCPT + 99 others); Tue, 19 Mar 2019 07:25:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42728 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfCSLZm (ORCPT ); Tue, 19 Mar 2019 07:25:42 -0400 Received: by mail-wr1-f68.google.com with SMTP id n9so16512152wrr.9 for ; Tue, 19 Mar 2019 04:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=A3JgLHFiJiDKRWwNVpEhyRSFZhkZ10MYX6wZTJJU16w=; b=mETSIgJ1/NOhnEXBqXdeYCCF+zbNRGDUPzqsxFIG96ZmiCk62vHDjfWnQnykRc7KFy gWhQ11a/AMFBCO4Lbdl0hHwk3J9eaMX6U9u+T7+eKspENgYUVlPm7fXG9tuwuwP8qESp VXK2JU1S9+dfeUYQgfqXFaDMJvNnI2bJPreXJ0yjkoWYwHJlv4Jt/uB6NFtEblBv6fVj ZJeRhzHwgeC/k2bCI37aruuoCc/fMvr+nG3KZ6Rv8wLzBLWLAMdi9opSITfTaX0XiaId uSE753n1uwfdgOgLfAF/lJd39DXf8BWiFYJQ3a9duiXgJaGJ1QIpj5420uPNNo5fv6Za uk8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=A3JgLHFiJiDKRWwNVpEhyRSFZhkZ10MYX6wZTJJU16w=; b=lQTOiMpFlKmno2zgVa14CIdQia+akVL4mUjNJ3GXtpBxVdnOTRq3yDdewgL9BArhA/ c0v5M55lIKYD4waC3aTdsUWbjwfr37eJZO9n5D2uVbh0s2P6MIhHt5pezb9A0YlS4f/U mFgke1RYOyarGO/NWHfpqBV503tCUkvRF2O1vsXvtoC+ZeMtPiMGDmjdXsICK8ut6TCS ARXS3346s8mjH/ZS5KIK86B83LHpW6gXpsMNj9GN8hnfFughcGO9lFopQFNRi2hs4nrS xQi0IDwxyEa2xtcl39t+TT11KVTd5hlImxPHkZetx1fWmKOoGCjfO5Kidel8nwxCX+Bt 8qDQ== X-Gm-Message-State: APjAAAVzhEcV4mOMkZq+yQm45BahPcdHnZe8WcwHtBPPbUCUVtljfCRT cXFXFSA8ItPT1CbjGyJPntAxcA== X-Received: by 2002:a5d:464e:: with SMTP id j14mr17467772wrs.109.1552994739515; Tue, 19 Mar 2019 04:25:39 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id o8sm2610073wma.1.2019.03.19.04.25.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Mar 2019 04:25:38 -0700 (PDT) Date: Tue, 19 Mar 2019 11:25:37 +0000 From: Daniel Thompson To: Douglas Anderson Cc: Steven Rostedt , Ingo Molnar , Jason Wessel , kgdb-bugreport@lists.sourceforge.net, Brian Norris , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/3] tracing: Add trace_total_entries() / trace_total_entries_cpu() Message-ID: <20190319112537.5yi7gelkk4ixswmu@holly.lan> References: <20190318204741.116550-1-dianders@chromium.org> <20190318204741.116550-2-dianders@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190318204741.116550-2-dianders@chromium.org> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > + > + get_total_entries_cpu(&tr->trace_buffer, &total, &entries, cpu); > + > + return entries; > +} > + > +unsigned long trace_total_entries(struct trace_array *tr) > +{ > + unsigned long total, entries; > + > + if (!tr) > + tr = &global_trace; Ditto. Daniel. > + > + get_total_entries(&tr->trace_buffer, &total, &entries); > + > + return entries; > +} > + > static void print_lat_help_header(struct seq_file *m) > { > seq_puts(m, "# _------=> CPU# \n" > diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h > index d80cee49e0eb..4562b30eda9d 100644 > --- a/kernel/trace/trace.h > +++ b/kernel/trace/trace.h > @@ -719,6 +719,9 @@ void trace_init_global_iter(struct trace_iterator *iter); > > void tracing_iter_reset(struct trace_iterator *iter, int cpu); > > +unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu); > +unsigned long trace_total_entries(struct trace_array *tr); > + > void trace_function(struct trace_array *tr, > unsigned long ip, > unsigned long parent_ip, > -- > 2.21.0.225.g810b269d1ac-goog >