steadystate: instead of including ss_sum_y in thread_stat record whether ss_sum_y...
[fio.git] / client.c
index 27a764da8389b60d587ca11062dab60d3c202ee4..f1c7596364373d96a97c08e3ddb0cdaeb14b886e 100644 (file)
--- a/client.c
+++ b/client.c
@@ -33,6 +33,8 @@ static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
 
+static void convert_text(struct fio_net_cmd *cmd);
+
 struct client_ops fio_client_ops = {
        .text           = handle_text,
        .disk_util      = handle_du,
@@ -215,12 +217,32 @@ static int fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
        return 1;
 }
 
+static void fio_drain_client_text(struct fio_client *client)
+{
+       do {
+               struct fio_net_cmd *cmd;
+
+               cmd = fio_net_recv_cmd(client->fd, false);
+               if (!cmd)
+                       break;
+
+               if (cmd->opcode == FIO_NET_CMD_TEXT) {
+                       convert_text(cmd);
+                       client->ops->text(client, cmd);
+               }
+
+               free(cmd);
+       } while (1);
+}
+
 static void remove_client(struct fio_client *client)
 {
        assert(client->refs);
 
        dprint(FD_NET, "client: removed <%s>\n", client->hostname);
 
+       fio_drain_client_text(client);
+
        if (!flist_empty(&client->list))
                flist_del_init(&client->list);
 
@@ -325,7 +347,7 @@ err:
        return NULL;
 }
 
-int fio_client_add_ini_file(void *cookie, const char *ini_file, int remote)
+int fio_client_add_ini_file(void *cookie, const char *ini_file, bool remote)
 {
        struct fio_client *client = cookie;
        struct client_file *cf;
@@ -767,7 +789,7 @@ static int __fio_client_send_local_ini(struct fio_client *client,
 }
 
 int fio_client_send_ini(struct fio_client *client, const char *filename,
-                       int remote)
+                       bool remote)
 {
        int ret;
 
@@ -794,6 +816,8 @@ int fio_clients_send_ini(const char *filename)
        struct flist_head *entry, *tmp;
 
        flist_for_each_safe(entry, tmp, &client_list) {
+               bool failed = false;
+
                client = flist_entry(entry, struct fio_client, list);
 
                if (client->nr_files) {
@@ -805,12 +829,13 @@ int fio_clients_send_ini(const char *filename)
                                cf = &client->files[i];
 
                                if (fio_client_send_cf(client, cf)) {
+                                       failed = true;
                                        remove_client(client);
                                        break;
                                }
                        }
                }
-               if (client->sent_job)
+               if (client->sent_job || failed)
                        continue;
                if (!filename || fio_client_send_ini(client, filename, 0))
                        remove_client(client);
@@ -921,6 +946,21 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
        dst->nr_block_infos     = le64_to_cpu(src->nr_block_infos);
        for (i = 0; i < dst->nr_block_infos; i++)
                dst->block_infos[i] = le32_to_cpu(src->block_infos[i]);
+
+       dst->ss_dur             = le64_to_cpu(src->ss_dur);
+       dst->ss_state           = le32_to_cpu(src->ss_state);
+       dst->ss_head            = le32_to_cpu(src->ss_head);
+       dst->ss_limit.u.f       = fio_uint64_to_double(le64_to_cpu(src->ss_limit.u.i));
+       dst->ss_slope.u.f       = fio_uint64_to_double(le64_to_cpu(src->ss_slope.u.i));
+       dst->ss_deviation.u.f   = fio_uint64_to_double(le64_to_cpu(src->ss_deviation.u.i));
+       dst->ss_criterion.u.f   = fio_uint64_to_double(le64_to_cpu(src->ss_criterion.u.i));
+
+       if (dst->ss_state & __FIO_SS_DATA) {
+               for (i = 0; i < dst->ss_dur; i++ ) {
+                       dst->ss_iops_data[i] = le64_to_cpu(src->ss_iops_data[i]);
+                       dst->ss_bw_data[i] = le64_to_cpu(src->ss_bw_data[i]);
+               }
+       }
 }
 
 static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src)
@@ -1226,14 +1266,17 @@ static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
        fio_client_dec_jobs_eta(eta, client->ops->eta);
 }
 
-void fio_client_handle_iolog(struct fio_client *client, struct fio_net_cmd *cmd)
+static int fio_client_handle_iolog(struct fio_client *client,
+                                  struct fio_net_cmd *cmd)
 {
        struct cmd_iolog_pdu *pdu;
        bool store_direct;
 
        pdu = convert_iolog(cmd, &store_direct);
-       if (!pdu)
-               return;
+       if (!pdu) {
+               log_err("fio: failed converting IO log\n");
+               return 1;
+       }
 
        if (store_direct) {
                ssize_t ret;
@@ -1243,26 +1286,33 @@ void fio_client_handle_iolog(struct fio_client *client, struct fio_net_cmd *cmd)
                fd = open((const char *) pdu->name,
                                O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd < 0) {
-                       perror("open log");
-                       return;
+                       log_err("fio: open log: %s\n", strerror(errno));
+                       return 1;
                }
+
                sz = cmd->pdu_len - sizeof(*pdu);
                ret = write(fd, pdu->samples, sz);
-               if (ret != sz)
-                       log_err("fio: short write on compressed log\n");
                close(fd);
+
+               if (ret != sz) {
+                       log_err("fio: short write on compressed log\n");
+                       return 1;
+               }
+
+               return 0;
        } else {
                FILE *f;
 
                f = fopen((const char *) pdu->name, "w");
                if (!f) {
-                       perror("fopen log");
-                       return;
+                       log_err("fio: fopen log: %s\n", strerror(errno));
+                       return 1;
                }
 
                flush_samples(f, pdu->samples,
                                pdu->nr_samples * sizeof(struct io_sample));
                fclose(f);
+               return 0;
        }
 }
 
@@ -1428,7 +1478,6 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd,
                return NULL;
 #endif
                ret = convert_iolog_gz(cmd, pdu);
-               printf("compressed iolog, %p\n", ret);
                if (!ret) {
                        log_err("fio: failed decompressing log\n");
                        return NULL;
@@ -1475,8 +1524,8 @@ static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
        fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
 }
 
-static int send_file(struct fio_client *client, struct cmd_sendfile *pdu,
-                    uint64_t tag)
+static int fio_send_file(struct fio_client *client, struct cmd_sendfile *pdu,
+                        uint64_t tag)
 {
        struct cmd_sendfile_reply *rep;
        struct stat sb;
@@ -1513,10 +1562,11 @@ int fio_handle_client(struct fio_client *client)
 {
        struct client_ops *ops = client->ops;
        struct fio_net_cmd *cmd;
+       int size;
 
        dprint(FD_NET, "client: handle %s\n", client->hostname);
 
-       cmd = fio_net_recv_cmd(client->fd);
+       cmd = fio_net_recv_cmd(client->fd, true);
        if (!cmd)
                return 0;
 
@@ -1545,6 +1595,15 @@ int fio_handle_client(struct fio_client *client)
        case FIO_NET_CMD_TS: {
                struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
 
+               dprint(FD_NET, "client: ts->ss_state = %u\n", (unsigned int) le32_to_cpu(p->ts.ss_state));
+               if (le32_to_cpu(p->ts.ss_state) & __FIO_SS_DATA) {
+                       dprint(FD_NET, "client: received steadystate ring buffers\n");
+
+                       size = le64_to_cpu(p->ts.ss_dur);
+                       p->ts.ss_iops_data = (uint64_t *) ((struct cmd_ts_pdu *)cmd->payload + 1);
+                       p->ts.ss_bw_data = p->ts.ss_iops_data + size;
+               }
+
                convert_ts(&p->ts, &p->ts);
                convert_gs(&p->rs, &p->rs);
 
@@ -1626,7 +1685,7 @@ int fio_handle_client(struct fio_client *client)
                }
        case FIO_NET_CMD_SENDFILE: {
                struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload;
-               send_file(client, pdu, cmd->tag);
+               fio_send_file(client, pdu, cmd->tag);
                break;
                }
        case FIO_NET_CMD_JOB_OPT: {