mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fb.com>
To: <linux-kernel@vger.kernel.org>, <kernel-team@fb.com>,
	<rostedt@goodmis.org>
Subject: [PATCH] trace-cmd: use nonblocking reads for streaming
Date: Thu, 17 Dec 2015 12:01:52 -0500	[thread overview]
Message-ID: <1450371712-12218-1-git-send-email-jbacik@fb.com> (raw)

I noticed while using the streaming infrastructure in trace-cmd that I was
seemingly missing events.  Using other tracing methods I got these events and
record->missed_events was never being set.  This is because the streaming
infrastructure uses blocking reads on the per cpu trace pipe's, which means
we'll wait for an entire pages worth of data to be ready before passing it along
to the recorder.  This makes it impossible to do long term tracing that requires
coupling two different events that could occur on different CPU's, and I imagine
it has been what is screwing up my trace-cmd profile runs on our giant 40 cpu
boxes.  Fix trace-cmd instead to use a nonblocking read with select to wait for
data on the pipe so we don't burn CPU unnecessarily.  With this patch I'm no
longer seeing missed events in my app.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 trace-cmd.h      |  1 +
 trace-record.c   |  9 +++++++--
 trace-recorder.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/trace-cmd.h b/trace-cmd.h
index 3a230b4..c94f784 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -282,6 +282,7 @@ struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int
 struct tracecmd_recorder *tracecmd_create_buffer_recorder_maxkb(const char *file, int cpu, unsigned flags, const char *buffer, int maxkb);
 
 int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep);
+long tracecmd_stream_recording(struct tracecmd_recorder *recorder, unsigned long sleep);
 void tracecmd_stop_recording(struct tracecmd_recorder *recorder);
 void tracecmd_stat_cpu(struct trace_seq *s, int cpu);
 long tracecmd_flush_recording(struct tracecmd_recorder *recorder);
diff --git a/trace-record.c b/trace-record.c
index 49a8280..7981932 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -2450,8 +2450,13 @@ static int create_recorder(struct buffer_instance *instance, int cpu,
 	}
 
 	while (!finished) {
-		if (tracecmd_start_recording(recorder, sleep_time) < 0)
-			break;
+		if (type == TRACE_TYPE_STREAM) {
+			if (tracecmd_stream_recording(recorder, sleep_time) < 0)
+				break;
+		} else {
+			if (tracecmd_start_recording(recorder, sleep_time) < 0)
+				break;
+		}
 	}
 	tracecmd_free_recorder(recorder);
 
diff --git a/trace-recorder.c b/trace-recorder.c
index 16d1be0..13e2e9f 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -440,6 +440,36 @@ long tracecmd_flush_recording(struct tracecmd_recorder *recorder)
 	return total;
 }
 
+#define USECS_IN_SEC 1000000UL
+long tracecmd_stream_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
+{
+	static int nonblock = 0;
+	fd_set rfds;
+	struct timeval tv;
+	long total = 0;
+	long ret;
+
+	if (!nonblock)
+		set_nonblock(recorder);
+
+	FD_ZERO(&rfds);
+	FD_SET(recorder->trace_fd, &rfds);
+	tv.tv_sec = sleep / USECS_IN_SEC;
+	tv.tv_usec = sleep % USECS_IN_SEC;
+	ret = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
+	if (ret <= 0)
+		return 0;
+
+	do {
+		ret = read_data(recorder);
+		if (ret < 0)
+			return ret;
+		total += ret;
+	} while (ret);
+
+	return total;
+}
+
 int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
 {
 	struct timespec req;
-- 
2.5.0


             reply	other threads:[~2015-12-17 17:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 17:01 Josef Bacik [this message]
2016-02-23 23:17 ` Steven Rostedt
2016-02-24 18:27   ` Josef Bacik

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=1450371712-12218-1-git-send-email-jbacik@fb.com \
    --to=jbacik@fb.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®