Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp767578img; Mon, 18 Mar 2019 13:50:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqw97nYuTGNffgTm7SKOlRtMVqHwnFZVvtwVIu1uaGoQSiPlJIv5Xys13re6u4axmFYwNPRi X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr21959384plh.140.1552942238565; Mon, 18 Mar 2019 13:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552942238; cv=none; d=google.com; s=arc-20160816; b=U0zAldz2kWVSx25clH7NjBAoYwdt9UAF42H+jG2Q7MTglRYPxL32h+9db83sYgZf14 0bq51iHVsbydWRWNNKJZbKBkdd461sMtRBMIrhkT+iMiAn8STS+rRvCfbv5jP0EAH38Z 6TjjPk4HKWlXpj/JxW7jv5pU1Foz8MsDozSN0HF3SbbS1UTs5BDLvOhIXY26i+/P2p8M a/bJRLSeVD9Aqda4GOrOTqV5f6g0fTKTh8mc5blrxiD1K1khsNMnHMg4/OBaO7s+vVtq TeSg6M8cOqJhGv+j5M4xzNwtL071wOeQGZ5KiIx7tz6KuSJ1/5cDHy36diASoNHnCEVF Jtbw== 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=xusOAsbnqqNnhBbt+QowjeQ3ehACsPkn2AdnDEd2Od0=; b=ksvTx7X5NYQTdZnquwEWfUfNWrjebsoVIgMPuhDqNFgNWS5zjazMgQuG4VWv+jAVfx E2DwhjJ4jMqhxIZj6zdIqVHachmF84cvKoT9sG2q+O22eOJVCRhNsfNGA+hYfOsg+8cg e4SmnuvVQ/8DlPCeZ9inB/foRyLIAMOFWS7cnOlRqsb+Qx68XujbuqadOfoKbRFQ/ztv azh5Ot27GrUsdhW4TVVA9s01qRlX4EC0xXwfvnGltjU7vnECpyqOKF24Uyy4zrkllFmD IR9j2og9KOofpNHMIBvXv+yv4Mcx3lCFrO4CeiXYrjslyqe1T1I7ZUrHaAcU27PgK9fR mVPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yhdbc+ft; 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 61si10355033plz.177.2019.03.18.13.50.22; Mon, 18 Mar 2019 13:50:38 -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=Yhdbc+ft; 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 S1727835AbfCRUrv (ORCPT + 99 others); Mon, 18 Mar 2019 16:47:51 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41910 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbfCRUrs (ORCPT ); Mon, 18 Mar 2019 16:47:48 -0400 Received: by mail-pg1-f195.google.com with SMTP id k11so12204407pgb.8 for ; Mon, 18 Mar 2019 13:47:48 -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=xusOAsbnqqNnhBbt+QowjeQ3ehACsPkn2AdnDEd2Od0=; b=Yhdbc+ftyYzPacVDGUecRKB7KUbdxxXDrEwEmm46m7clmPKZQ0flvdlDYADRS1CcTr UMmllioJuStdqzMba9W5TqEBTvIwLe7iIM+A1NYoO30HukJ03Bdz+AP8nNm3QiAGinVJ lZJfc/Rv8X40V2LuqW/Qeoh4qitTSarPsmjvU= 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=xusOAsbnqqNnhBbt+QowjeQ3ehACsPkn2AdnDEd2Od0=; b=eRHFpx2JDCY+2i8APaug83bvtbI7o3cTn9PxqdMBwzlk+mvH3rl+oNI4lumgMD4HJZ Tzs+1PGF6uiku8XeLbAjNvx4l+sMTayvTdsztTDNMVa9nVKuB96aUQ3qA46mThIVjdLf dfyarLWfgeumwvk5ILEj0pRQHUTJRrM6xgk17oX6dMjufeq+gTR4O+PmyEGXuvgAmIbv FJrOvMhPBK/iw2xn562oeVHw0G4ppnRsThzbT2a7OKyT9ctJMCc3dNp73B7YHYkRAZ5b aTRCpOaCOVhayS14u0WjlFENSBMEDWQVSl9dxPk9gUTBkLBlgwpbTvsbzrXVpiQcKC2V igtA== X-Gm-Message-State: APjAAAVYaQ26kl9HHinneUYHtl9a98lYnRA7WedjcGwv9sLoBTx6Qu5W 22HAakVIbrOZhaaReR6WlGJu2A== X-Received: by 2002:a65:6489:: with SMTP id e9mr19372413pgv.260.1552942067796; Mon, 18 Mar 2019 13:47:47 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id u14sm16835807pfm.66.2019.03.18.13.47.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 13:47:47 -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 v5 2/3] tracing: Add trace_total_entries() / trace_total_entries_cpu() Date: Mon, 18 Mar 2019 13:47:40 -0700 Message-Id: <20190318204741.116550-2-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog In-Reply-To: <20190318204741.116550-1-dianders@chromium.org> References: <20190318204741.116550-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 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; + + 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.225.g810b269d1ac-goog