blob: 6ae4aeed2e78522edb037ccc976e4ceda26b7941 [file] [log] [blame]
Jens Axboe7c9b1bc2009-06-03 09:25:57 +02001#ifndef FIO_DISKUTIL_H
2#define FIO_DISKUTIL_H
Shaohua Licc372b12012-09-17 09:12:18 +02003#include "json.h"
Jens Axboed09a64a2011-10-13 11:38:56 +02004#define FIO_DU_NAME_SZ 64
5
Jens Axboe27357182012-09-27 11:31:50 +02006extern volatile int disk_util_exit;
7
Jens Axboe7c9b1bc2009-06-03 09:25:57 +02008/*
9 * Disk utils as read in /sys/block/<dev>/stat
10 */
11struct disk_util_stat {
Jens Axboed09a64a2011-10-13 11:38:56 +020012 uint8_t name[FIO_DU_NAME_SZ];
13 uint32_t ios[2];
14 uint32_t merges[2];
15 uint64_t sectors[2];
16 uint32_t ticks[2];
17 uint32_t io_ticks;
18 uint32_t time_in_queue;
19 uint64_t msec;
20};
21
22struct disk_util_agg {
23 uint32_t ios[2];
24 uint32_t merges[2];
25 uint64_t sectors[2];
26 uint32_t ticks[2];
27 uint32_t io_ticks;
28 uint32_t time_in_queue;
29 uint32_t slavecount;
30 fio_fp64_t max_util;
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020031};
32
33/*
34 * Per-device disk util management
35 */
36struct disk_util {
37 struct flist_head list;
38 /* If this disk is a slave, hook it into the master's
39 * list using this head.
40 */
41 struct flist_head slavelist;
42
43 char *name;
44 char *sysfs_root;
Ken Raeburn4b919f72013-01-29 10:18:13 +010045 char path[PATH_MAX];
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020046 int major, minor;
47
48 struct disk_util_stat dus;
49 struct disk_util_stat last_dus;
50
Jens Axboed09a64a2011-10-13 11:38:56 +020051 struct disk_util_agg agg;
52
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020053 /* For software raids, this entry maintains pointers to the
54 * entries for the slave devices. The disk_util entries for
55 * the slaves devices should primarily be maintained through
56 * the disk_list list, i.e. for memory allocation and
57 * de-allocation, etc. Whereas this list should be used only
58 * for aggregating a software RAID's disk util figures.
59 */
60 struct flist_head slaves;
61
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020062 struct timeval time;
63
64 struct fio_mutex *lock;
65 unsigned long users;
66};
67
Jens Axboee99ca812009-10-01 19:44:36 +020068static inline void disk_util_mod(struct disk_util *du, int val)
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020069{
70 if (du) {
Jens Axboee99ca812009-10-01 19:44:36 +020071 struct flist_head *n;
72
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020073 fio_mutex_down(du->lock);
Jens Axboee99ca812009-10-01 19:44:36 +020074 du->users += val;
75
76 flist_for_each(n, &du->slavelist) {
77 struct disk_util *slave;
78
79 slave = flist_entry(n, struct disk_util, slavelist);
80 slave->users += val;
81 }
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020082 fio_mutex_up(du->lock);
83 }
84}
Jens Axboee99ca812009-10-01 19:44:36 +020085static inline void disk_util_inc(struct disk_util *du)
86{
87 disk_util_mod(du, 1);
88}
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020089
90static inline void disk_util_dec(struct disk_util *du)
91{
Jens Axboee99ca812009-10-01 19:44:36 +020092 disk_util_mod(du, -1);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020093}
94
95#define DISK_UTIL_MSEC (250)
96
Jens Axboed09a64a2011-10-13 11:38:56 +020097extern struct flist_head disk_list;
98
Jens Axboe9ec77792012-08-02 08:27:41 +020099extern void wait_for_disk_thread_exit(void);
100
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200101/*
102 * disk util stuff
103 */
104#ifdef FIO_HAVE_DISK_UTIL
Jens Axboef2f788d2011-10-13 14:03:52 +0200105extern void print_disk_util(struct disk_util_stat *, struct disk_util_agg *, int terse);
Shaohua Licc372b12012-09-17 09:12:18 +0200106extern void show_disk_util(int terse, struct json_object *parent);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200107extern void init_disk_util(struct thread_data *);
Jens Axboe9ec77792012-08-02 08:27:41 +0200108extern int update_io_ticks(void);
109extern void setup_disk_util(void);
Jens Axboe27357182012-09-27 11:31:50 +0200110extern void disk_util_prune_entries(void);
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200111#else
Jens Axboe941bda92013-04-12 16:19:03 +0200112static inline void print_disk_util(struct disk_util_stat *du,
113 struct disk_util_agg *agg, int terse)
114{
115}
Shaohua Licc372b12012-09-17 09:12:18 +0200116#define show_disk_util(terse, parent)
Jens Axboe27357182012-09-27 11:31:50 +0200117#define disk_util_prune_entries()
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200118#define init_disk_util(td)
Jens Axboe9ec77792012-08-02 08:27:41 +0200119#define setup_disk_util()
120static inline int update_io_ticks(void)
121{
Jens Axboe27357182012-09-27 11:31:50 +0200122 return disk_util_exit;
Jens Axboe9ec77792012-08-02 08:27:41 +0200123}
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200124#endif
125
Jens Axboe27357182012-09-27 11:31:50 +0200126static inline void disk_util_start_exit(void)
127{
128 disk_util_exit = 1;
129}
130
Jens Axboe7c9b1bc2009-06-03 09:25:57 +0200131#endif