[PATCH 5/5] trace-cmd: Use polling function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use poll() for avoiding a busy loop to read trace data of a guest from FIFO.

Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@xxxxxxxxxxx>
---

 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;


_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux