From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Amit Shah <amit.shah@redhat.com>,
Anthony Liguori <anthony@codemonkey.ws>,
Arnd Bergmann <arnd@arndb.de>, Borislav Petkov <bp@amd64.org>,
"Franch Ch. Eigler" <fche@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Herbert Xu <herbert@gondor.hengli.com.au>,
Ingo Molnar <mingo@redhat.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Rusty Russell <rusty@rustcorp.com.au>,
linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, qemu-devel@nongnu.org,
yrl.pp-manager.tt@hitachi.com,
Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Subject: [PATCH 5/5] trace-cmd: Use polling function
Date: Wed, 22 Aug 2012 17:43:43 +0900 [thread overview]
Message-ID: <20120822084343.17293.28556.stgit@ltc189.sdl.hitachi.co.jp> (raw)
In-Reply-To: <20120822084251.17293.69086.stgit@ltc189.sdl.hitachi.co.jp>
Use poll() for avoiding a busy loop to read trace data of a guest from FIFO.
Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
---
trace-recorder.c | 42 ++++++++++++++++++++++++++++++++++++------
1 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/trace-recorder.c b/trace-recorder.c
index 6577fe8..bdf9798 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -34,9 +34,12 @@
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
+#include <poll.h>
#include "trace-cmd.h"
+#define WAIT_MSEC 1
+
struct tracecmd_recorder {
int fd;
int trace_fd;
@@ -235,9 +238,37 @@ static void stop_operation_to_trace_agent(int ctl_fd)
operation_to_trace_agent(ctl_fd, false);
}
-int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
+static int wait_data(struct tracecmd_recorder *recorder, unsigned long sleep)
{
+ struct pollfd poll_fd;
struct timespec req;
+ int ret = 0;
+
+ if (recorder->agent_existing) {
+ poll_fd.fd = recorder->trace_fd;
+ poll_fd.events = POLLIN;
+ while (1) {
+ ret = poll(&poll_fd, 1, WAIT_MSEC);
+
+ if(ret < 0) {
+ warning("polling error");
+ return ret;
+ }
+
+ if (ret)
+ break;
+ }
+ } else if (sleep) {
+ req.tv_sec = sleep / 1000000;
+ req.tv_nsec = (sleep % 1000000) * 1000;
+ nanosleep(&req, NULL);
+ }
+
+ return ret;
+}
+
+int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep)
+{
long ret;
recorder->stop = 0;
@@ -246,11 +277,10 @@ int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long s
run_operation_to_trace_agent(recorder->ctl_fd);
do {
- if (sleep) {
- req.tv_sec = sleep / 1000000;
- req.tv_nsec = (sleep % 1000000) * 1000;
- nanosleep(&req, NULL);
- }
+ ret = wait_data(recorder, sleep);
+ if (ret < 0)
+ return ret;
+
ret = splice_data(recorder);
if (ret < 0)
return ret;
prev parent reply other threads:[~2012-08-22 8:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-22 8:42 [PATCH 0/5] trace-cmd: Add a recorder readable feature for virtio-trace Yoshihiro YUNOMAE
2012-08-22 8:43 ` [PATCH 1/5] trace-cmd: Use TRACE_DIR envrionment variable if defined Yoshihiro YUNOMAE
2012-08-22 13:37 ` Steven Rostedt
2012-08-22 8:43 ` [PATCH 2/5] trace-cmd: Use tracing directory to count CPUs Yoshihiro YUNOMAE
2012-08-22 13:41 ` Steven Rostedt
2012-08-23 2:01 ` Masami Hiramatsu
2012-08-23 3:00 ` Masami Hiramatsu
2012-08-23 9:08 ` Steven Rostedt
2012-08-23 12:30 ` Masami Hiramatsu
2012-08-22 8:43 ` [PATCH 3/5] trace-cmd: Support trace-agent of virtio-trace Yoshihiro YUNOMAE
2012-08-22 13:51 ` Steven Rostedt
2012-08-23 3:13 ` Yoshihiro YUNOMAE
2012-08-22 8:43 ` [PATCH 4/5] trace-cmd: Add non-blocking option for open() and splice_read() Yoshihiro YUNOMAE
2012-08-22 8:43 ` Yoshihiro YUNOMAE [this message]
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=20120822084343.17293.28556.stgit@ltc189.sdl.hitachi.co.jp \
--to=yoshihiro.yunomae.ez@hitachi.com \
--cc=amit.shah@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=arnd@arndb.de \
--cc=bp@amd64.org \
--cc=fche@redhat.com \
--cc=fweisbec@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.hengli.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rostedt@goodmis.org \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
--cc=yrl.pp-manager.tt@hitachi.com \
/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;
as well as URLs for NNTP newsgroup(s).