public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>,
	Aaron Fabbri <aaronx.j.fabbri@intel.com>,
	linux-kernel@vger.kernel.org,
	cti.systems-productivity-manager.ts@hitachi.com,
	Divya Vyas <edivya.vyas@gmail.com>,
	Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
	yoshihiro.yunomae@aktsk.jp
Subject: [PATCH trace-cmd V6 3/7] trace-cmd/msg: Use poll(2) to wait for a message
Date: Tue, 26 May 2015 15:55:28 +0900	[thread overview]
Message-ID: <20150526065528.16023.377.stgit@localhost.localdomain> (raw)
In-Reply-To: <20150526065522.16023.30813.stgit@localhost.localdomain>

From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>

Use poll(2) to wait for a message. If a client/server cannot send a message for
any reasons, the current server/client will wait in a blocking read operation.
So, we use poll(2) for avoiding remaining in a blocking state.

Signed-off-by: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

---
Changes in V4: Change the argument of tracecmd_msg_recv_wait()
               Fix some typos
---
 trace-msg.c |   42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/trace-msg.c b/trace-msg.c
index 5669dee..e3d4f3f 100644
--- a/trace-msg.c
+++ b/trace-msg.c
@@ -395,6 +395,27 @@ error:
 	return -ENOMSG;
 }
 
+#define MSG_WAIT_MSEC	5000
+
+/*
+ * A return value of 0 indicates time-out
+ */
+static int tracecmd_msg_recv_wait(int fd, struct tracecmd_msg *msg)
+{
+	struct pollfd pfd;
+	int ret;
+
+	pfd.fd = fd;
+	pfd.events = POLLIN;
+	ret = poll(&pfd, 1, MSG_WAIT_MSEC);
+	if (ret < 0)
+		return -errno;
+	else if (ret == 0)
+		return -ETIMEDOUT;
+
+	return tracecmd_msg_recv(fd, msg);
+}
+
 static void *tracecmd_msg_buf_access(struct tracecmd_msg *msg, int offset)
 {
 	return (void *)msg + offset;
@@ -405,9 +426,12 @@ static int tracecmd_msg_wait_for_msg(int fd, struct tracecmd_msg *msg)
 	u32 cmd;
 	int ret;
 
-	ret = tracecmd_msg_recv(fd, msg);
-	if (ret < 0)
+	ret = tracecmd_msg_recv_wait(fd, msg);
+	if (ret < 0) {
+		if (ret == -ETIMEDOUT)
+			warning("Connection timed out\n");
 		return ret;
+	}
 
 	cmd = ntohl(msg->cmd);
 	if (cmd == MSG_CLOSE)
@@ -487,9 +511,12 @@ int tracecmd_msg_initial_setting(int fd, int *cpus, int *pagesize)
 	u32 cmd;
 
 	msg = (struct tracecmd_msg *)buf;
-	ret = tracecmd_msg_recv(fd, msg);
-	if (ret < 0)
+	ret = tracecmd_msg_recv_wait(fd, msg);
+	if (ret < 0) {
+		if (ret == -ETIMEDOUT)
+			warning("Connection timed out\n");
 		return ret;
+	}
 
 	cmd = ntohl(msg->cmd);
 	if (cmd != MSG_TINIT) {
@@ -627,9 +654,12 @@ int tracecmd_msg_collect_metadata(int ifd, int ofd)
 	msg = (struct tracecmd_msg *)buf;
 
 	do {
-		ret = tracecmd_msg_recv(ifd, msg);
+		ret = tracecmd_msg_recv_wait(ifd, msg);
 		if (ret < 0) {
-			warning("reading client");
+			if (ret == -ETIMEDOUT)
+				warning("Connection timed out\n");
+			else
+				warning("reading client");
 			return ret;
 		}
 


  parent reply	other threads:[~2015-05-26  6:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26  6:55 [PATCH trace-cmd V6 0/7] trce-cmd: add virtual machine tracing Masami Hiramatsu
2015-05-26  6:55 ` [PATCH trace-cmd V6 1/7] trace-cmd: Support -N option for trace-cmd extract Masami Hiramatsu
2015-05-26  6:55 ` [PATCH trace-cmd V6 2/7] trace-cmd/listen: Introduce trace-msg protocol (protocol v2) Masami Hiramatsu
2015-05-26  6:55 ` Masami Hiramatsu [this message]
2015-05-26  6:55 ` [PATCH trace-cmd V6 4/7] trace-cmd/virt-server: Add virt-server mode for a virtualization environment Masami Hiramatsu
2015-05-26  6:55 ` [PATCH trace-cmd V6 5/7] trace-cmd/record: Add --virt option for record mode Masami Hiramatsu
2015-05-26  6:55 ` [PATCH trace-cmd V6 6/7] trace-cmd/virt-server: Add --dom option which makes a domain directory to virt-server Masami Hiramatsu
2015-05-26  6:55 ` [PATCH trace-cmd V6 7/7] trace-cmd: Use pid instead of libvirt virt domain name Masami Hiramatsu

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=20150526065528.16023.377.stgit@localhost.localdomain \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=aaronx.j.fabbri@intel.com \
    --cc=cti.systems-productivity-manager.ts@hitachi.com \
    --cc=edivya.vyas@gmail.com \
    --cc=hidehiro.kawai.ez@hitachi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=yoshihiro.yunomae.ez@hitachi.com \
    --cc=yoshihiro.yunomae@aktsk.jp \
    /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