subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) International Business Machines Corp., 2001-2004 |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 12 | * the GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 17 | */ |
| 18 | #include "ffsb_tg.h" |
| 19 | #include "ffsb_thread.h" |
| 20 | #include "ffsb_op.h" |
| 21 | #include "util.h" |
| 22 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 23 | void init_ffsb_thread(ffsb_thread_t * ft, struct ffsb_tg *tg, unsigned bufsize, |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 24 | unsigned tg_num, unsigned thread_num) |
| 25 | { |
| 26 | memset(ft, 0, sizeof(ffsb_thread_t)); |
| 27 | |
| 28 | ft->tg = tg; |
| 29 | ft->tg_num = tg_num; |
| 30 | ft->thread_num = thread_num; |
| 31 | |
| 32 | if (bufsize) |
| 33 | ft_alter_bufsize(ft, bufsize); |
| 34 | |
| 35 | init_random(&ft->rd, MAX_RANDBUF_SIZE); |
| 36 | } |
| 37 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 38 | void destroy_ffsb_thread(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 39 | { |
| 40 | free(ft->mallocbuf); |
| 41 | destroy_random(&ft->rd); |
| 42 | if (ft->fsd.config) |
| 43 | ffsb_statsd_destroy(&ft->fsd); |
| 44 | } |
| 45 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 46 | void ft_set_statsc(ffsb_thread_t * ft, ffsb_statsc_t * fsc) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 47 | { |
| 48 | ffsb_statsd_init(&ft->fsd, fsc); |
| 49 | } |
| 50 | |
| 51 | void *ft_run(void *data) |
| 52 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 53 | ffsb_thread_t *ft = (ffsb_thread_t *) data; |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 54 | tg_op_params_t params; |
| 55 | unsigned wait_time = tg_get_waittime(ft->tg); |
| 56 | int stopval = tg_get_stopval(ft->tg); |
| 57 | |
| 58 | ffsb_barrier_wait(tg_get_start_barrier(ft->tg)); |
| 59 | |
| 60 | while (tg_get_flagval(ft->tg) != stopval) { |
| 61 | tg_get_op(ft->tg, &ft->rd, ¶ms); |
| 62 | do_op(ft, params.fs, params.opnum); |
| 63 | ffsb_milli_sleep(wait_time); |
| 64 | } |
| 65 | return NULL; |
| 66 | } |
| 67 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 68 | void ft_alter_bufsize(ffsb_thread_t * ft, unsigned bufsize) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 69 | { |
| 70 | if (ft->mallocbuf != NULL) |
| 71 | free(ft->mallocbuf); |
| 72 | ft->mallocbuf = ffsb_malloc(bufsize + 4096); |
| 73 | ft->alignedbuf = ffsb_align_4k(ft->mallocbuf + (4096 - 1)); |
| 74 | } |
| 75 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 76 | char *ft_getbuf(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 77 | { |
| 78 | return ft->alignedbuf; |
| 79 | } |
| 80 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | int ft_get_read_random(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 82 | { |
| 83 | return tg_get_read_random(ft->tg); |
| 84 | } |
| 85 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 86 | uint32_t ft_get_read_size(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 87 | { |
| 88 | return tg_get_read_size(ft->tg); |
| 89 | } |
| 90 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 91 | uint32_t ft_get_read_blocksize(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 92 | { |
| 93 | return tg_get_read_blocksize(ft->tg); |
| 94 | } |
| 95 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 96 | int ft_get_write_random(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 97 | { |
| 98 | return tg_get_write_random(ft->tg); |
| 99 | } |
| 100 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 101 | uint32_t ft_get_write_size(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 102 | { |
| 103 | return tg_get_write_size(ft->tg); |
| 104 | } |
| 105 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 106 | uint32_t ft_get_write_blocksize(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 107 | { |
| 108 | return tg_get_write_blocksize(ft->tg); |
| 109 | } |
| 110 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 111 | int ft_get_fsync_file(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 112 | { |
| 113 | return tg_get_fsync_file(ft->tg); |
| 114 | } |
| 115 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 116 | randdata_t *ft_get_randdata(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 117 | { |
| 118 | return &ft->rd; |
| 119 | } |
| 120 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | void ft_incr_op(ffsb_thread_t * ft, unsigned opnum, unsigned increment, |
| 122 | uint64_t bytes) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 123 | { |
| 124 | ft->results.ops[opnum] += increment; |
| 125 | ft->results.op_weight[opnum]++; |
| 126 | ft->results.bytes[opnum] += bytes; |
| 127 | } |
| 128 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | void ft_add_readbytes(ffsb_thread_t * ft, uint32_t bytes) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 130 | { |
| 131 | ft->results.read_bytes += bytes; |
| 132 | } |
| 133 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 134 | void ft_add_writebytes(ffsb_thread_t * ft, uint32_t bytes) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 135 | { |
| 136 | ft->results.write_bytes += bytes; |
| 137 | } |
| 138 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 139 | ffsb_op_results_t *ft_get_results(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 140 | { |
| 141 | return &ft->results; |
| 142 | } |
| 143 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | int ft_get_read_skip(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 145 | { |
| 146 | return tg_get_read_skip(ft->tg); |
| 147 | } |
| 148 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | uint32_t ft_get_read_skipsize(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 150 | { |
| 151 | return tg_get_read_skipsize(ft->tg); |
| 152 | } |
| 153 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | int ft_needs_stats(ffsb_thread_t * ft, syscall_t sys) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 155 | { |
| 156 | int ret = 0; |
| 157 | if (ft && ft->fsd.config && !fsc_ignore_sys(ft->fsd.config, sys)) |
| 158 | ret = 1; |
| 159 | return ret; |
| 160 | } |
| 161 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 162 | void ft_add_stat(ffsb_thread_t * ft, syscall_t sys, uint32_t val) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 163 | { |
| 164 | if (ft) |
| 165 | ffsb_add_data(&ft->fsd, sys, val); |
| 166 | } |
| 167 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 168 | ffsb_statsd_t *ft_get_stats_data(ffsb_thread_t * ft) |
subrata_modak | 55d04e4 | 2009-10-26 11:25:55 +0000 | [diff] [blame] | 169 | { |
| 170 | return &ft->fsd; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 171 | } |