lkml.org 
[lkml]   [2012]   [Aug]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 5/5] trace-cmd: Use polling function
Date
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;



\
 
 \ /
  Last update: 2012-08-22 20:41    [W:0.251 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site