Makefile: Suppress `-Wimplicit-fallthrough` when compiling `lex.yy`
[fio.git] / diskutil.h
CommitLineData
7c9b1bce
JA
1#ifndef FIO_DISKUTIL_H
2#define FIO_DISKUTIL_H
d09a64a0
JA
3#define FIO_DU_NAME_SZ 64
4
6a16e9e9
JA
5#include <limits.h>
6
e2bb0e58 7#include "helper_thread.h"
971caeb1 8#include "fio_sem.h"
27357187 9
a3b4cf7d 10struct disk_util_stats {
504bc961
JA
11 uint64_t ios[2];
12 uint64_t merges[2];
d09a64a0 13 uint64_t sectors[2];
504bc961
JA
14 uint64_t ticks[2];
15 uint64_t io_ticks;
16 uint64_t time_in_queue;
d09a64a0
JA
17 uint64_t msec;
18};
19
a3b4cf7d
JA
20/*
21 * Disk utils as read in /sys/block/<dev>/stat
22 */
23struct disk_util_stat {
24 uint8_t name[FIO_DU_NAME_SZ];
25 struct disk_util_stats s;
26};
27
d09a64a0 28struct disk_util_agg {
504bc961
JA
29 uint64_t ios[2];
30 uint64_t merges[2];
d09a64a0 31 uint64_t sectors[2];
504bc961
JA
32 uint64_t ticks[2];
33 uint64_t io_ticks;
34 uint64_t time_in_queue;
d09a64a0 35 uint32_t slavecount;
504bc961 36 uint32_t pad;
d09a64a0 37 fio_fp64_t max_util;
7c9b1bce
JA
38};
39
40/*
41 * Per-device disk util management
42 */
43struct disk_util {
44 struct flist_head list;
45 /* If this disk is a slave, hook it into the master's
46 * list using this head.
47 */
48 struct flist_head slavelist;
49
7c9b1bce 50 char *sysfs_root;
4b919f77 51 char path[PATH_MAX];
7c9b1bce
JA
52 int major, minor;
53
54 struct disk_util_stat dus;
55 struct disk_util_stat last_dus;
56
d09a64a0
JA
57 struct disk_util_agg agg;
58
7c9b1bce
JA
59 /* For software raids, this entry maintains pointers to the
60 * entries for the slave devices. The disk_util entries for
61 * the slaves devices should primarily be maintained through
62 * the disk_list list, i.e. for memory allocation and
63 * de-allocation, etc. Whereas this list should be used only
64 * for aggregating a software RAID's disk util figures.
65 */
66 struct flist_head slaves;
67
8b6a404c 68 struct timespec time;
7c9b1bce 69
971caeb1 70 struct fio_sem *lock;
7c9b1bce
JA
71 unsigned long users;
72};
73
e99ca81d 74static inline void disk_util_mod(struct disk_util *du, int val)
7c9b1bce
JA
75{
76 if (du) {
e99ca81d
JA
77 struct flist_head *n;
78
971caeb1 79 fio_sem_down(du->lock);
e99ca81d
JA
80 du->users += val;
81
82 flist_for_each(n, &du->slavelist) {
83 struct disk_util *slave;
84
85 slave = flist_entry(n, struct disk_util, slavelist);
86 slave->users += val;
87 }
971caeb1 88 fio_sem_up(du->lock);
7c9b1bce
JA
89 }
90}
e99ca81d
JA
91static inline void disk_util_inc(struct disk_util *du)
92{
93 disk_util_mod(du, 1);
94}
7c9b1bce
JA
95
96static inline void disk_util_dec(struct disk_util *du)
97{
e99ca81d 98 disk_util_mod(du, -1);
7c9b1bce
JA
99}
100
101#define DISK_UTIL_MSEC (250)
102
d09a64a0
JA
103extern struct flist_head disk_list;
104
7c9b1bce
JA
105/*
106 * disk util stuff
107 */
108#ifdef FIO_HAVE_DISK_UTIL
7c9b1bce 109extern void init_disk_util(struct thread_data *);
9ec7779f
JA
110extern int update_io_ticks(void);
111extern void setup_disk_util(void);
27357187 112extern void disk_util_prune_entries(void);
7c9b1bce 113#else
9aa6aa64 114/* keep this as a function to avoid a warning in handle_du() */
27357187 115#define disk_util_prune_entries()
7c9b1bce 116#define init_disk_util(td)
9ec7779f 117#define setup_disk_util()
952b05e0 118
9ec7779f
JA
119static inline int update_io_ticks(void)
120{
e2bb0e58 121 return helper_should_exit();
9ec7779f 122}
7c9b1bce
JA
123#endif
124
125#endif