All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frank A. Cancio Bello" <frank@generalsoftwareinc.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Cc: joel@joelfernandes.org, saiprakash.ranjan@codeaurora.org,
	nachukannan@gmail.com
Subject: [PATCH] tracing: Resets the trace buffer after a snapshot
Date: Tue, 31 Dec 2019 03:58:22 -0500	[thread overview]
Message-ID: <20191231085822.yxhph6wcguejb7al@frank-laptop> (raw)

Currently, when a snapshot is taken the trace_buffer and the
max_buffer are swapped. After this swap, the "new" trace_buffer is
not reset. This produces an odd behavior: after a snapshot is taken
the previous snapshot entries become available to the next reader of
the trace_buffer as far as the reading occurs before the buffer is
refilled with new entries by a writer.

This patch resets the trace buffer after a snapshot is taken.

Signed-off-by: Frank A. Cancio Bello <frank@generalsoftwareinc.com>
---

The following commands illustrate this odd behavior:

# cd /sys/kernel/debug/tracing
# echo nop > current_tracer
# echo 1 > tracing_on
# echo m1 > trace_marker
# echo 1 > snapshot
# echo m2 > trace_marker
# echo 1 > snapshot
# cat trace
# tracer: nop
#
# entries-in-buffer/entries-written: 1/1   #P:2
#
#                              _-----=> irqs-off
#                             / _----=> need-resched
#                            | / _---=> hardirq/softirq
#                            || / _--=> preempt-depth
#                            ||| /     delay
#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
#              | |       |   ||||       |         |
            bash-550   [000] ....    50.479755: tracing_mark_write: m1


 kernel/trace/trace.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ddb7e7f5fe8d..58373b5ae0cf 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6867,10 +6867,13 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
 			break;
 		local_irq_disable();
 		/* Now, we're going to swap */
-		if (iter->cpu_file == RING_BUFFER_ALL_CPUS)
+		if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
 			update_max_tr(tr, current, smp_processor_id(), NULL);
-		else
+			tracing_reset_online_cpus(&tr->trace_buffer);
+		} else {
 			update_max_tr_single(tr, current, iter->cpu_file);
+			tracing_reset_cpu(&tr->trace_buffer, iter->cpu_file);
+		}
 		local_irq_enable();
 		break;
 	default:
-- 
2.17.1


             reply	other threads:[~2019-12-31  8:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-31  8:58 Frank A. Cancio Bello [this message]
2020-01-03 16:40 ` [PATCH] tracing: Resets the trace buffer after a snapshot Steven Rostedt
2020-01-03 22:37   ` Joel Fernandes
2020-01-05 10:31     ` Frank A. Cancio Bello
2020-01-06 17:41       ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191231085822.yxhph6wcguejb7al@frank-laptop \
    --to=frank@generalsoftwareinc.com \
    --cc=joel@joelfernandes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nachukannan@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=saiprakash.ranjan@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.