Fio 1.50-rc2
[fio.git] / diskutil.h
CommitLineData
7c9b1bce
JA
1#ifndef FIO_DISKUTIL_H
2#define FIO_DISKUTIL_H
3
4/*
5 * Disk utils as read in /sys/block/<dev>/stat
6 */
7struct disk_util_stat {
8 unsigned ios[2];
9 unsigned merges[2];
10 unsigned long long sectors[2];
11 unsigned ticks[2];
12 unsigned io_ticks;
13 unsigned time_in_queue;
14};
15
16/*
17 * Per-device disk util management
18 */
19struct disk_util {
20 struct flist_head list;
21 /* If this disk is a slave, hook it into the master's
22 * list using this head.
23 */
24 struct flist_head slavelist;
25
26 char *name;
27 char *sysfs_root;
28 char path[256];
29 int major, minor;
30
31 struct disk_util_stat dus;
32 struct disk_util_stat last_dus;
33
34 /* For software raids, this entry maintains pointers to the
35 * entries for the slave devices. The disk_util entries for
36 * the slaves devices should primarily be maintained through
37 * the disk_list list, i.e. for memory allocation and
38 * de-allocation, etc. Whereas this list should be used only
39 * for aggregating a software RAID's disk util figures.
40 */
41 struct flist_head slaves;
42
43 unsigned long msec;
44 struct timeval time;
45
46 struct fio_mutex *lock;
47 unsigned long users;
48};
49
e99ca81d 50static inline void disk_util_mod(struct disk_util *du, int val)
7c9b1bce
JA
51{
52 if (du) {
e99ca81d
JA
53 struct flist_head *n;
54
7c9b1bce 55 fio_mutex_down(du->lock);
e99ca81d
JA
56 du->users += val;
57
58 flist_for_each(n, &du->slavelist) {
59 struct disk_util *slave;
60
61 slave = flist_entry(n, struct disk_util, slavelist);
62 slave->users += val;
63 }
7c9b1bce
JA
64 fio_mutex_up(du->lock);
65 }
66}
e99ca81d
JA
67static inline void disk_util_inc(struct disk_util *du)
68{
69 disk_util_mod(du, 1);
70}
7c9b1bce
JA
71
72static inline void disk_util_dec(struct disk_util *du)
73{
e99ca81d 74 disk_util_mod(du, -1);
7c9b1bce
JA
75}
76
77#define DISK_UTIL_MSEC (250)
78
79/*
80 * disk util stuff
81 */
82#ifdef FIO_HAVE_DISK_UTIL
83extern void show_disk_util(void);
84extern void init_disk_util(struct thread_data *);
85extern void update_io_ticks(void);
86#else
87#define show_disk_util()
88#define init_disk_util(td)
89#define update_io_ticks()
90#endif
91
92#endif