blob: 5a9b079661023487642179b84dfad0b8b3d330e0 [file] [log] [blame]
Jens Axboe7c9b1bc2009-06-03 09:25:57 +02001#ifndef FIO_DISKUTIL_H
2#define FIO_DISKUTIL_H
3
Jens Axboed09a64a2011-10-13 11:38:56 +02004#define FIO_DU_NAME_SZ 64
5
Jens Axboe7c9b1bc2009-06-03 09:25:57 +02006/*
7 * Disk utils as read in /sys/block/<dev>/stat
8 */
9struct disk_util_stat {
Jens Axboed09a64a2011-10-13 11:38:56 +020010 uint8_t name[FIO_DU_NAME_SZ];
11 uint32_t ios[2];
12 uint32_t merges[2];
13 uint64_t sectors[2];
14 uint32_t ticks[2];
15 uint32_t io_ticks;
16 uint32_t time_in_queue;
17 uint64_t msec;
18};
19
20struct disk_util_agg {
21 uint32_t ios[2];
22 uint32_t merges[2];
23 uint64_t sectors[2];
24 uint32_t ticks[2];
25 uint32_t io_ticks;
26 uint32_t time_in_queue;
27 uint32_t slavecount;
28 fio_fp64_t max_util;
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020029};
30
31/*
32 * Per-device disk util management
33 */
34struct disk_util {
35 struct flist_head list;
36 /* If this disk is a slave, hook it into the master's
37 * list using this head.
38 */
39 struct flist_head slavelist;
40
41 char *name;
42 char *sysfs_root;
43 char path[256];
44 int major, minor;
45
46 struct disk_util_stat dus;
47 struct disk_util_stat last_dus;
48
Jens Axboed09a64a2011-10-13 11:38:56 +020049 struct disk_util_agg agg;
50
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020051 /* For software raids, this entry maintains pointers to the
52 * entries for the slave devices. The disk_util entries for
53 * the slaves devices should primarily be maintained through
54 * the disk_list list, i.e. for memory allocation and
55 * de-allocation, etc. Whereas this list should be used only
56 * for aggregating a software RAID's disk util figures.
57 */
58 struct flist_head slaves;
59
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020060 struct timeval time;
61
62 struct fio_mutex *lock;
63 unsigned long users;
64};
65
Jens Axboee99ca812009-10-01 19:44:36 +020066static inline void disk_util_mod(struct disk_util *du, int val)
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020067{
68 if (du) {
Jens Axboee99ca812009-10-01 19:44:36 +020069 struct flist_head *n;
70
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020071 fio_mutex_down(du->lock);
Jens Axboee99ca812009-10-01 19:44:36 +020072 du->users += val;
73
74 flist_for_each(n, &du->slavelist) {
75 struct disk_util *slave;
76
77 slave = flist_entry(n, struct disk_util, slavelist);
78 slave->users += val;
79 }
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020080 fio_mutex_up(du->lock);
81 }
82}
Jens Axboee99ca812009-10-01 19:44:36 +020083static inline void disk_util_inc(struct disk_util *du)
84{
85 disk_util_mod(du, 1);
86}
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020087
88static inline void disk_util_dec(struct disk_util *du)
89{
Jens Axboee99ca812009-10-01 19:44:36 +020090 disk_util_mod(du, -1);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020091}
92
93#define DISK_UTIL_MSEC (250)
94
Jens Axboed09a64a2011-10-13 11:38:56 +020095extern struct flist_head disk_list;
96
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020097/*
98 * disk util stuff
99 */
100#ifdef FIO_HAVE_DISK_UTIL
Jens Axboef2f788d2011-10-13 14:03:52 +0200101extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int terse);
102extern void show_disk_util(int terse);
Jens Axboed09a64a2011-10-13 11:38:56 +0200103extern void free_disk_util(void);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200104extern void init_disk_util(struct thread_data *);
105extern void update_io_ticks(void);
106#else
Jens Axboef2f788d2011-10-13 14:03:52 +0200107#define print_disk_util(dus, agg, terse)
108#define show_disk_util(terse)
Jens Axboed09a64a2011-10-13 11:38:56 +0200109#define free_disk_util()
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200110#define init_disk_util(td)
111#define update_io_ticks()
112#endif
113
114#endif