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
16 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18#ifndef _FFSB_THREAD_H_
19#define _FFSB_THREAD_H_
20
21#include <pthread.h>
22#include <inttypes.h>
23
24#include "rand.h"
25#include "ffsb_op.h"
26#include "ffsb_tg.h"
27#include "ffsb_stats.h"
28
29#include "util.h" /* for barrier stuff */
30
31struct ffsb_tg;
32struct ffsb_op_results;
33
34/* FFSB thread object
35 *
36 * The thread object doesn't store any configuration information, it
37 * mostly just holds per-thread state information such as the random
38 * data store and the per-thread buffer to copy data to/from disk
39 */
40
41typedef struct ffsb_thread {
42	unsigned thread_num;
43	unsigned tg_num;
44	pthread_t ptid;
45	struct randdata rd;
46	struct ffsb_tg *tg; /* owning thread group */
47
48	/* If we are using Direct IO, then we must only use a 4k
49	 * aligned buffer so, alignedbuf_4k is a pointer into
50	 * "mallocbuf" which is what malloc gave us.
51	 */
52	char *alignedbuf;
53	char *mallocbuf;
54
55	struct ffsb_op_results results;
56
57	/* stats */
58	ffsb_statsd_t fsd;
59} ffsb_thread_t ;
60
61void init_ffsb_thread(ffsb_thread_t *, struct ffsb_tg *, unsigned,
62		       unsigned, unsigned);
63void destroy_ffsb_thread(ffsb_thread_t *);
64
65/* Owning thread group will start thread with this, thread runs until
66 * *ft->checkval == ft->stopval.  Yes this is not strictly
67 * synchronized, but that is okay for our purposes, and it limits (IMO
68 * expensive) bus-locking.
69 *
70 * pthread_create() is called by tg with this function as a parameter
71 * data is a (ffsb_thread_t*)
72 */
73void *ft_run(void *);
74
75void ft_alter_bufsize(ffsb_thread_t *, unsigned);
76char *ft_getbuf(ffsb_thread_t *);
77
78int ft_get_read_random(ffsb_thread_t *);
79uint32_t ft_get_read_size(ffsb_thread_t *);
80uint32_t ft_get_read_blocksize(ffsb_thread_t *);
81
82int ft_get_write_random(ffsb_thread_t *);
83uint32_t ft_get_write_size(ffsb_thread_t *);
84uint32_t ft_get_write_blocksize(ffsb_thread_t *);
85
86int ft_get_fsync_file(ffsb_thread_t *);
87
88randdata_t *ft_get_randdata(ffsb_thread_t *);
89
90void ft_incr_op(ffsb_thread_t *ft, unsigned opnum, unsigned increment, uint64_t bytes);
91
92void ft_add_readbytes(ffsb_thread_t *, uint32_t);
93void ft_add_writebytes(ffsb_thread_t *, uint32_t);
94
95int ft_get_read_skip(ffsb_thread_t *);
96uint32_t ft_get_read_skipsize(ffsb_thread_t *);
97
98ffsb_op_results_t *ft_get_results(ffsb_thread_t *);
99
100void ft_set_statsc(ffsb_thread_t *, ffsb_statsc_t *);
101
102/* for these two, ft == NULL is OK */
103int ft_needs_stats(ffsb_thread_t *, syscall_t);
104void ft_add_stat(ffsb_thread_t *, syscall_t, uint32_t);
105
106ffsb_statsd_t *ft_get_stats_data(ffsb_thread_t *);
107
108#endif /* _FFSB_THREAD_H_ */
109