From 70e0c3166fdb8048b1e7f84be2371fc60af04f87 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 4 Oct 2011 09:18:30 +0200 Subject: [PATCH] server: idle loop support Signed-off-by: Jens Axboe --- client.c | 2 +- fio.c | 4 ++-- server.c | 21 +++++++++++++-------- server.h | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/client.c b/client.c index b82c322c..464dce64 100644 --- a/client.c +++ b/client.c @@ -379,7 +379,7 @@ static int handle_client(struct fio_client *client) struct fio_net_cmd *cmd; int done = 0; - while ((cmd = fio_net_recv_cmd(client->fd)) != NULL) { + while ((cmd = fio_net_recv_cmd(client->fd, 1)) != NULL) { dprint(FD_NET, "%s: got cmd op %d\n", client->hostname, cmd->opcode); diff --git a/fio.c b/fio.c index d1faacae..3e4dbb74 100644 --- a/fio.c +++ b/fio.c @@ -1696,8 +1696,8 @@ static void run_threads(void) if (is_backend) fio_server_idle_loop(); - - usleep(10000); + else + usleep(10000); } update_io_ticks(); diff --git a/server.c b/server.c index 938f58bb..a48842e6 100644 --- a/server.c +++ b/server.c @@ -111,7 +111,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd) /* * Read (and defragment, if necessary) incoming commands */ -struct fio_net_cmd *fio_net_recv_cmd(int sk) +struct fio_net_cmd *fio_net_recv_cmd(int sk, int block) { struct fio_net_cmd cmd, *cmdret = NULL; size_t cmd_size = 0, pdu_offset = 0; @@ -126,14 +126,19 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk) pfd.events = POLLIN; ret = 0; do { - ret = poll(&pfd, 1, 100); + int timeo = block ? 100 : 10; + + ret = poll(&pfd, 1, timeo); if (ret < 0) { if (errno == EINTR) break; log_err("fio: poll: %s\n", strerror(errno)); break; - } else if (!ret) + } else if (!ret) { + if (!block) + return NULL; continue; + } if (pfd.revents & POLLIN) break; @@ -141,7 +146,7 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk) ret = 1; break; } - } while (ret >= 0); + } while (ret >= 0 && block); if (ret < 0) break; @@ -311,14 +316,14 @@ static int handle_command(struct fio_net_cmd *cmd) return ret; } -static int handle_connection(int sk) +static int handle_connection(int sk, int block) { struct fio_net_cmd *cmd = NULL; int ret = 0; /* read forever */ while (!exit_backend) { - cmd = fio_net_recv_cmd(sk); + cmd = fio_net_recv_cmd(sk, block); if (!cmd) { ret = -1; break; @@ -341,7 +346,7 @@ static int handle_connection(int sk) void fio_server_idle_loop(void) { if (server_fd != -1) - handle_connection(server_fd); + handle_connection(server_fd, 0); } static int accept_loop(int listen_sk) @@ -384,7 +389,7 @@ again: server_fd = sk; - exitval = handle_connection(sk); + exitval = handle_connection(sk, 1); server_fd = -1; close(sk); diff --git a/server.h b/server.h index 4783238b..494c326e 100644 --- a/server.h +++ b/server.h @@ -80,7 +80,7 @@ extern void fio_client_add(const char *); extern int fio_recv_data(int sk, void *p, unsigned int len); extern int fio_send_data(int sk, const void *p, unsigned int len); extern void fio_net_cmd_crc(struct fio_net_cmd *); -extern struct fio_net_cmd *fio_net_recv_cmd(int sk); +extern struct fio_net_cmd *fio_net_recv_cmd(int sk, int block); extern int exit_backend; extern int fio_net_port; -- 2.25.1