[PATCH] fio: convert all internal accounting to sectors
authorJens Axboe <axboe@suse.de>
Mon, 7 Nov 2005 08:41:52 +0000 (09:41 +0100)
committerJens Axboe <axboe@suse.de>
Mon, 7 Nov 2005 08:41:52 +0000 (09:41 +0100)
fio.c

diff --git a/fio.c b/fio.c
index 42846b38a3e20daf361e8817c0343d935b9a1165..f8bfef21595ba25695c7bf0f60ab332bb8d361f2 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -281,15 +281,16 @@ struct thread_data {
        unsigned int ratecycle;
        unsigned long rate_usec_cycle;
        long rate_pending_usleep;
-       unsigned long rate_kb;
+       unsigned long rate_sectors;
        struct timeval lastrate;
 
        unsigned long runtime;          /* sec */
-       unsigned long kb;
+       unsigned long sectors;
+
        unsigned long io_blocks;
-       unsigned long io_kb;
-       unsigned long this_io_kb;
-       unsigned long last_kb;
+       unsigned long io_sectors;
+       unsigned long this_io_sectors;
+       unsigned long last_sectors;
        sem_t mutex;
        struct drand48_data random_state;
 
@@ -300,7 +301,7 @@ struct thread_data {
        struct io_stat slat_stat;               /* submission latency */
 
        struct io_stat bw_stat;                 /* bandwidth stats */
-       unsigned long stat_io_kb;
+       unsigned long stat_io_sectors;
        struct timeval stat_sample_time;
 
        struct io_log *lat_log;
@@ -413,12 +414,13 @@ static unsigned long long get_next_offset(struct thread_data *td)
 
        if (!td->sequential) {
                int min_bs_kb = td->min_bs >> 10;
+               unsigned long max_kb = td->sectors << 1;
 
                lrand48_r(&td->random_state, &r);
-               kb = (1+(double) (td->kb-1) * r / (RAND_MAX+1.0));
+               kb = (1+(double) (max_kb-1) * r / (RAND_MAX+1.0));
                kb = (kb + min_bs_kb - 1) & ~(min_bs_kb - 1);
        } else
-               kb = td->last_kb;
+               kb = td->last_sectors << 1;
 
        return (kb << 10) + td->file_offset;
 }
@@ -436,10 +438,10 @@ static unsigned int get_next_buflen(struct thread_data *td)
                buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1);
        }
 
-       if (buflen > ((td->kb - td->this_io_kb) << 10))
-               buflen = (td->kb - td->this_io_kb) << 10;
+       if (buflen > ((td->sectors - td->this_io_sectors) << 9))
+               buflen = (td->sectors - td->this_io_sectors) << 9;
 
-       td->last_kb += buflen >> 10;
+       td->last_sectors += buflen >> 9;
        return buflen;
 }
 
@@ -492,14 +494,14 @@ static void add_bw_sample(struct thread_data *td)
        if (spent < td->bw_avg_time)
                return;
 
-       rate = ((td->this_io_kb - td->stat_io_kb) * 1024) / spent;
+       rate = ((td->this_io_sectors - td->stat_io_sectors) << 9) / spent;
        add_stat_sample(td, &td->bw_stat, rate);
 
        if (td->bw_log)
                add_log_sample(td, td->bw_log, rate);
 
        gettimeofday(&td->stat_sample_time, NULL);
-       td->stat_io_kb = td->this_io_kb;
+       td->stat_io_sectors = td->this_io_sectors;
 }
 
 static void usec_sleep(int usec)
@@ -556,12 +558,12 @@ static int check_min_rate(struct thread_data *td, struct timeval *now)
        /*
         * if rate blocks is set, sample is running
         */
-       if (td->rate_kb) {
+       if (td->rate_sectors) {
                spent = mtime_since(&td->lastrate, now);
                if (spent < td->ratecycle)
                        return 0;
 
-               rate = ((td->this_io_kb - td->rate_kb) * 1024) / spent;
+               rate = ((td->this_io_sectors - td->rate_sectors) << 9) / spent;
                if (rate < td->ratemin) {
                        printf("Client%d: min rate %d not met, got %ldKiB/sec\n", td->thread_number, td->ratemin, rate);
                        if (rate_quit)
@@ -570,7 +572,7 @@ static int check_min_rate(struct thread_data *td, struct timeval *now)
                }
        }
 
-       td->rate_kb = td->this_io_kb;
+       td->rate_sectors = td->this_io_sectors;
        memcpy(&td->lastrate, now, sizeof(*now));
        return 0;
 }
@@ -730,7 +732,7 @@ static void do_sync_verify(struct thread_data *td)
        io_u = __get_io_u(td);
 
        if (!td->odirect) {
-               unsigned long size = td->kb << 10;
+               unsigned long size = td->sectors << 9;
 
                if (fadvise(td->fd, 0, size, POSIX_FADV_DONTNEED) < 0) {
                        td->error = errno;
@@ -821,7 +823,7 @@ static void do_sync_io(struct thread_data *td)
        struct io_u *io_u = NULL;
        struct timeval e;
 
-       while (td->this_io_kb < td->kb) {
+       while (td->this_io_sectors < td->sectors) {
                int ret;
 
                if (td->terminate)
@@ -853,8 +855,8 @@ static void do_sync_io(struct thread_data *td)
                        log_io_piece(td, io_u);
 
                td->io_blocks++;
-               td->io_kb += io_u->buflen >> 10;
-               td->this_io_kb += io_u->buflen >> 10;
+               td->io_sectors += io_u->buflen >> 9;
+               td->this_io_sectors += io_u->buflen >> 9;
                td->cur_off = io_u->offset + io_u->buflen;
 
                gettimeofday(&e, NULL);
@@ -929,8 +931,8 @@ static int ios_completed(struct thread_data *td, int nr)
                io_u = ev_to_iou(td->aio_events + i);
 
                td->io_blocks++;
-               td->io_kb += io_u->buflen >> 10;
-               td->this_io_kb += io_u->buflen >> 10;
+               td->io_sectors += io_u->buflen >> 9;
+               td->this_io_sectors += io_u->buflen >> 9;
 
                msec = mtime_since(&io_u->issue_time, &e);
 
@@ -1065,7 +1067,7 @@ static void do_async_io(struct thread_data *td)
        struct timeval s, e;
        unsigned long usec;
 
-       while (td->this_io_kb < td->kb) {
+       while (td->this_io_sectors < td->sectors) {
                struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
                struct timespec *timeout;
                int ret, min_evts = 0;
@@ -1287,7 +1289,7 @@ static int create_file(struct thread_data *td)
                return 1;
        }
 
-       td->kb = td->file_size >> 10;
+       td->sectors = td->file_size >> 9;
        b = malloc(td->max_bs);
        memset(b, 0, td->max_bs);
 
@@ -1383,8 +1385,8 @@ static int setup_file(struct thread_data *td)
                st.st_size = td->file_size;
        }
 
-       td->kb = (st.st_size - td->file_offset) / 1024;
-       if (!td->kb) {
+       td->sectors = (st.st_size - td->file_offset) / 1024;
+       if (!td->sectors) {
                fprintf(stderr, "Client%d: no io blocks\n", td->thread_number);
                td->error = EINVAL;
                return 1;
@@ -1403,9 +1405,9 @@ static int setup_file(struct thread_data *td)
 static void clear_io_state(struct thread_data *td)
 {
        td->cur_off = 0;
-       td->last_kb = 0;
-       td->stat_io_kb = 0;
-       td->this_io_kb = 0;
+       td->last_sectors = 0;
+       td->stat_io_sectors = 0;
+       td->this_io_sectors = 0;
 }
 
 static void *thread_main(int shm_id, int offset, char *argv[])
@@ -1548,16 +1550,16 @@ static void show_thread_status(struct thread_data *td)
        unsigned long min, max, bw = 0;
        double mean, dev;
 
-       if (!td->io_kb && !td->error)
+       if (!td->io_sectors && !td->error)
                return;
 
        if (td->runtime)
-               bw = td->io_kb * 1024 / td->runtime;
+               bw = (td->io_sectors << 9) / td->runtime;
 
        prio = td->ioprio & 0xff;
        prio_class = td->ioprio >> IOPRIO_CLASS_SHIFT;
 
-       printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/s, runt=%6lumsec\n", td->thread_number, td->error, td->io_kb >> 10, bw, td->runtime);
+       printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/s, runt=%6lumsec\n", td->thread_number, td->error, td->io_sectors << 9, bw, td->runtime);
 
        if (calc_lat(&td->slat_stat, &min, &max, &mean, &dev))
                printf("  slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
@@ -2371,13 +2373,13 @@ int main(int argc, char *argv[])
                                max_run[td->ddir] = td->runtime;
 
                        if (td->runtime)
-                               bw = td->io_kb * 1024 / td->runtime;
+                               bw = (td->io_sectors << 9) / td->runtime;
                        if (bw < min_bw[td->ddir])
                                min_bw[td->ddir] = bw;
                        if (bw > max_bw[td->ddir])
                                max_bw[td->ddir] = bw;
 
-                       io_mb[td->ddir] += td->io_kb >> 10;
+                       io_mb[td->ddir] += td->io_sectors >> 9;
                }
 
                show_thread_status(td);