server: idle loop support
authorJens Axboe <axboe@kernel.dk>
Tue, 4 Oct 2011 07:18:30 +0000 (09:18 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Oct 2011 07:18:30 +0000 (09:18 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
fio.c
server.c
server.h

index b82c322c2e8dbf5feed42b364104c4f83080532c..464dce64542ac2f6e8c119068483d00e9b799d24 100644 (file)
--- 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;
 
        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);
 
                dprint(FD_NET, "%s: got cmd op %d\n", client->hostname,
                                                        cmd->opcode);
 
diff --git a/fio.c b/fio.c
index d1faacae860deaf97c90e9a8e8142aabb899f205..3e4dbb749fd97d9a7af718d27a22d5cc15cb749c 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1696,8 +1696,8 @@ static void run_threads(void)
 
                if (is_backend)
                        fio_server_idle_loop();
 
                if (is_backend)
                        fio_server_idle_loop();
-
-               usleep(10000);
+               else
+                       usleep(10000);
        }
 
        update_io_ticks();
        }
 
        update_io_ticks();
index 938f58bb3d4e39c9d308dd5aacf5dbb58e6e1f29..a48842e6deeb9062008681c0169eb19c3c1d2cd4 100644 (file)
--- 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
  */
 /*
  * 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;
 {
        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 {
                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;
                        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;
                                continue;
+                       }
 
                        if (pfd.revents & POLLIN)
                                break;
 
                        if (pfd.revents & POLLIN)
                                break;
@@ -141,7 +146,7 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk)
                                ret = 1;
                                break;
                        }
                                ret = 1;
                                break;
                        }
-               } while (ret >= 0);
+               } while (ret >= 0 && block);
 
                if (ret < 0)
                        break;
 
                if (ret < 0)
                        break;
@@ -311,14 +316,14 @@ static int handle_command(struct fio_net_cmd *cmd)
        return ret;
 }
 
        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) {
 {
        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;
                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)
 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)
 }
 
 static int accept_loop(int listen_sk)
@@ -384,7 +389,7 @@ again:
 
        server_fd = sk;
 
 
        server_fd = sk;
 
-       exitval = handle_connection(sk);
+       exitval = handle_connection(sk, 1);
 
        server_fd = -1;
        close(sk);
 
        server_fd = -1;
        close(sk);
index 4783238ba7e77c1b77e668bd60385948224db1bc..494c326ed252f20fc7004bd4abd96e9c25cf0fd8 100644 (file)
--- 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 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;
 
 extern int exit_backend;
 extern int fio_net_port;