Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp41888imc; Fri, 15 Mar 2019 16:11:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5PC09r8Ao/OSeZo7O4sg3B01mZyML+7SOQWDFHp5lzMhsHA18mWcxx6IFryrKiWGWr8ky X-Received: by 2002:a63:c04a:: with SMTP id z10mr5963097pgi.115.1552691486831; Fri, 15 Mar 2019 16:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552691486; cv=none; d=google.com; s=arc-20160816; b=WGnNONBuUHa5SCFO71ZRU/RQw1yCr1gIitRQ0UGoVXwyQEnTYzi8oSjG1sCK50C6vE hPKFFQzZMTROvNGlZC1RTzuN45KX/DhGrlNNS+0i+OWvRlV1mzJzFh58kgXmcwWTkvQB SOkhkCfvds4M+TldFFU50yjQr89gsx7n37JxdhEWRFEXq2pbC0B7kTklpP9gjQXF9esL Q/lh2ImCainpeb5o9ZIxEFHSV6/TLFrZFuzIn3WodLWpGfGuFfapJXBZDDJR69y+9pWm BJ09yLU9szwGQWo1CdSEpgPjoxkX9+jUkyOVmWcQDlccoccqW1uZNwHNUTU20XycBGCh iI4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y0uPhIN+I7ZuLQj48Ft/0PCdlUfnS3imxj2Pv3kQjr8=; b=bubCJoHWLiKpO6+D3nGua6vIE3x869qIf0wzbElhsFkDsaBRz/tAcbev1gfAoiIjyC ylVey/p+n9JdVvmCFxStd4kPCJul8H4juP9xAkvHnjiPOynQw3Ir6n9xE0us6loGZRTC 8sbqYOVoocPMaiUYJ6quS/CQjnCXvUlZyXNgvEYo+GNfYnwM58v3LKM0cjLYGkMDayzZ 7z0t1WZ6XVyLCg5JoD1sai8VD0n9Eg/JYz/z8bt7ESInjJ53kwO68cbfCkjTpyT83PGA R9cdNMWpe4cg3xyS+LMVfbZeCWH6oqQbMxW2BbRn9LoOz1Rkcsz5o1Z5AQ1HHMdFhba2 aTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SJa6R8II; 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 s26si2921044pfm.143.2019.03.15.16.11.11; Fri, 15 Mar 2019 16:11:26 -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=SJa6R8II; 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 S1727598AbfCOXJs (ORCPT + 99 others); Fri, 15 Mar 2019 19:09:48 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41222 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727649AbfCOXJk (ORCPT ); Fri, 15 Mar 2019 19:09:40 -0400 Received: by mail-pg1-f195.google.com with SMTP id k11so7422275pgb.8 for ; Fri, 15 Mar 2019 16:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y0uPhIN+I7ZuLQj48Ft/0PCdlUfnS3imxj2Pv3kQjr8=; b=SJa6R8II+deAQAjL2MznzUedkonNZnMENdd+iIRom65beSm5Jds9IKa82RxwLrwuz6 D7HNbvT+CWAZv3lGJw3WknIL0cBpkCJs7mWHv6hytIRcx1MhCKqDwpjzGRr1fX6Y2V6O Q49z5bJSI93t0uoKfZA13Wre6FkNYjzenY/GA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y0uPhIN+I7ZuLQj48Ft/0PCdlUfnS3imxj2Pv3kQjr8=; b=hr7xCDLGGEPdKHGy66Q//bSNoDpOTMslSiNmf25fsZk9LJO07E3MA8aqjW61+XgtLR cfRYQcFkRX45Rs7tWPK8yi/Aav4QoISP/xhH+XfljbOTykwb83pOiP9onPNaXBPwlwKP dW4VrN+B2tns1U7OZ46ahg9rQ6MHX8vR+e9esF1Ptou1O/Ae3w2HbfQU8/2JxmML9kB3 T403vYemCqS2dtJuPewrwRkZUrucg8/EtQzMkWX0ziXDWI36E/76+0fhRcPeGoilDHQs I3uz47EzPs+Rl+mDek5WoQnhre08y9pDAMWKd/2opfJQUlFUS0i27OnMK5zRZx4GP3ra hDPA== X-Gm-Message-State: APjAAAWy1QFrKffZBffV4EKjoJcKPqurytXeIsFw9rXVWh+VCGHII2Kp 4CwK7ErGUuo50B72+oCeOsy9pw== X-Received: by 2002:aa7:8051:: with SMTP id y17mr6577775pfm.92.1552691379320; Fri, 15 Mar 2019 16:09:39 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q62sm8192428pfi.183.2019.03.15.16.09.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 16:09:38 -0700 (PDT) From: Douglas Anderson To: Steven Rostedt , Ingo Molnar , Jason Wessel , Daniel Thompson Cc: kgdb-bugreport@lists.sourceforge.net, Brian Norris , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] tracing: Add trace_total_entries() / trace_total_entries_cpu() Date: Fri, 15 Mar 2019 16:09:05 -0700 Message-Id: <20190315230906.250598-2-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog In-Reply-To: <20190315230906.250598-1-dianders@chromium.org> References: <20190315230906.250598-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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; + + 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; + + 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.360.g471c308f928-goog