blob: 95cebcb3536cf12718d17a391e3727834bd84066 [file] [log] [blame]
subrata_modak55d04e42009-10-26 11:25:55 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modak55d04e42009-10-26 11:25:55 +000017 */
18#include "ffsb_tg.h"
19#include "ffsb_thread.h"
20#include "ffsb_op.h"
21#include "util.h"
22
Wanlong Gao354ebb42012-12-07 10:10:04 +080023void init_ffsb_thread(ffsb_thread_t * ft, struct ffsb_tg *tg, unsigned bufsize,
subrata_modak55d04e42009-10-26 11:25:55 +000024 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 Gao354ebb42012-12-07 10:10:04 +080038void destroy_ffsb_thread(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000039{
40 free(ft->mallocbuf);
41 destroy_random(&ft->rd);
42 if (ft->fsd.config)
43 ffsb_statsd_destroy(&ft->fsd);
44}
45
Wanlong Gao354ebb42012-12-07 10:10:04 +080046void ft_set_statsc(ffsb_thread_t * ft, ffsb_statsc_t * fsc)
subrata_modak55d04e42009-10-26 11:25:55 +000047{
48 ffsb_statsd_init(&ft->fsd, fsc);
49}
50
51void *ft_run(void *data)
52{
Wanlong Gao354ebb42012-12-07 10:10:04 +080053 ffsb_thread_t *ft = (ffsb_thread_t *) data;
subrata_modak55d04e42009-10-26 11:25:55 +000054 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, &params);
62 do_op(ft, params.fs, params.opnum);
63 ffsb_milli_sleep(wait_time);
64 }
65 return NULL;
66}
67
Wanlong Gao354ebb42012-12-07 10:10:04 +080068void ft_alter_bufsize(ffsb_thread_t * ft, unsigned bufsize)
subrata_modak55d04e42009-10-26 11:25:55 +000069{
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 Gao354ebb42012-12-07 10:10:04 +080076char *ft_getbuf(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000077{
78 return ft->alignedbuf;
79}
80
Wanlong Gao354ebb42012-12-07 10:10:04 +080081int ft_get_read_random(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000082{
83 return tg_get_read_random(ft->tg);
84}
85
Wanlong Gao354ebb42012-12-07 10:10:04 +080086uint32_t ft_get_read_size(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000087{
88 return tg_get_read_size(ft->tg);
89}
90
Wanlong Gao354ebb42012-12-07 10:10:04 +080091uint32_t ft_get_read_blocksize(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000092{
93 return tg_get_read_blocksize(ft->tg);
94}
95
Wanlong Gao354ebb42012-12-07 10:10:04 +080096int ft_get_write_random(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +000097{
98 return tg_get_write_random(ft->tg);
99}
100
Wanlong Gao354ebb42012-12-07 10:10:04 +0800101uint32_t ft_get_write_size(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000102{
103 return tg_get_write_size(ft->tg);
104}
105
Wanlong Gao354ebb42012-12-07 10:10:04 +0800106uint32_t ft_get_write_blocksize(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000107{
108 return tg_get_write_blocksize(ft->tg);
109}
110
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111int ft_get_fsync_file(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000112{
113 return tg_get_fsync_file(ft->tg);
114}
115
Wanlong Gao354ebb42012-12-07 10:10:04 +0800116randdata_t *ft_get_randdata(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000117{
118 return &ft->rd;
119}
120
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121void ft_incr_op(ffsb_thread_t * ft, unsigned opnum, unsigned increment,
122 uint64_t bytes)
subrata_modak55d04e42009-10-26 11:25:55 +0000123{
124 ft->results.ops[opnum] += increment;
125 ft->results.op_weight[opnum]++;
126 ft->results.bytes[opnum] += bytes;
127}
128
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129void ft_add_readbytes(ffsb_thread_t * ft, uint32_t bytes)
subrata_modak55d04e42009-10-26 11:25:55 +0000130{
131 ft->results.read_bytes += bytes;
132}
133
Wanlong Gao354ebb42012-12-07 10:10:04 +0800134void ft_add_writebytes(ffsb_thread_t * ft, uint32_t bytes)
subrata_modak55d04e42009-10-26 11:25:55 +0000135{
136 ft->results.write_bytes += bytes;
137}
138
Wanlong Gao354ebb42012-12-07 10:10:04 +0800139ffsb_op_results_t *ft_get_results(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000140{
141 return &ft->results;
142}
143
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144int ft_get_read_skip(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000145{
146 return tg_get_read_skip(ft->tg);
147}
148
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149uint32_t ft_get_read_skipsize(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000150{
151 return tg_get_read_skipsize(ft->tg);
152}
153
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154int ft_needs_stats(ffsb_thread_t * ft, syscall_t sys)
subrata_modak55d04e42009-10-26 11:25:55 +0000155{
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 Gao354ebb42012-12-07 10:10:04 +0800162void ft_add_stat(ffsb_thread_t * ft, syscall_t sys, uint32_t val)
subrata_modak55d04e42009-10-26 11:25:55 +0000163{
164 if (ft)
165 ffsb_add_data(&ft->fsd, sys, val);
166}
167
Wanlong Gao354ebb42012-12-07 10:10:04 +0800168ffsb_statsd_t *ft_get_stats_data(ffsb_thread_t * ft)
subrata_modak55d04e42009-10-26 11:25:55 +0000169{
170 return &ft->fsd;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700171}