blob: dc89cc51ac5261d81afaa3f8383cacb3e68ff123 [file] [log] [blame]
Jens Axboe7c9b1bc2009-06-03 09:25:57 +02001#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
Jens Axboee99ca812009-10-01 19:44:36 +020050static inline void disk_util_mod(struct disk_util *du, int val)
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020051{
52 if (du) {
Jens Axboee99ca812009-10-01 19:44:36 +020053 struct flist_head *n;
54
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020055 fio_mutex_down(du->lock);
Jens Axboee99ca812009-10-01 19:44:36 +020056 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 }
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020064 fio_mutex_up(du->lock);
65 }
66}
Jens Axboee99ca812009-10-01 19:44:36 +020067static inline void disk_util_inc(struct disk_util *du)
68{
69 disk_util_mod(du, 1);
70}
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020071
72static inline void disk_util_dec(struct disk_util *du)
73{
Jens Axboee99ca812009-10-01 19:44:36 +020074 disk_util_mod(du, -1);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020075}
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