blob: b387f48d1600b651a47f7969e0ab3c9ea8ffe49b [file] [log] [blame]
Jens Axboe5995a6a2009-06-03 08:53:28 +02001#ifndef FIO_IOLOG_H
2#define FIO_IOLOG_H
3
Jens Axboe05775432012-03-21 14:07:11 +01004#include "lib/rbtree.h"
Jens Axboec7c6cb42011-10-13 14:12:40 +02005#include "lib/ieee754.h"
Jens Axboe836fcc02013-01-24 09:08:45 -07006#include "flist.h"
Jens Axboeec412652012-03-08 12:37:31 +01007#include "ioengine.h"
Jens Axboe802ad4a2011-10-05 09:51:58 +02008
Jens Axboe5995a6a2009-06-03 08:53:28 +02009/*
10 * Use for maintaining statistics
11 */
12struct io_stat {
Jens Axboe7b9f7332011-10-03 10:06:44 +020013 uint64_t max_val;
14 uint64_t min_val;
15 uint64_t samples;
Jens Axboe5995a6a2009-06-03 08:53:28 +020016
Jens Axboe802ad4a2011-10-05 09:51:58 +020017 fio_fp64_t mean;
18 fio_fp64_t S;
Jens Axboe5995a6a2009-06-03 08:53:28 +020019};
20
21/*
22 * A single data sample
23 */
24struct io_sample {
Jens Axboe1b427252012-03-14 15:03:03 +010025 uint64_t time;
26 uint64_t val;
27 uint32_t ddir;
28 uint32_t bs;
Jens Axboe5995a6a2009-06-03 08:53:28 +020029};
30
Jens Axboeccefd5f2014-06-30 20:59:03 -060031struct io_sample_offset {
32 struct io_sample s;
33 uint64_t offset;
34};
35
Jens Axboeea51b952012-03-14 11:39:13 +010036enum {
37 IO_LOG_TYPE_LAT = 1,
38 IO_LOG_TYPE_CLAT,
39 IO_LOG_TYPE_SLAT,
40 IO_LOG_TYPE_BW,
41 IO_LOG_TYPE_IOPS,
42};
43
Jens Axboe5995a6a2009-06-03 08:53:28 +020044/*
45 * Dynamically growing data sample log
46 */
47struct io_log {
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010048 /*
49 * Entries already logged
50 */
Jens Axboe5995a6a2009-06-03 08:53:28 +020051 unsigned long nr_samples;
52 unsigned long max_samples;
Jens Axboeccefd5f2014-06-30 20:59:03 -060053 void *log;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010054
Jens Axboe1b427252012-03-14 15:03:03 +010055 unsigned int log_type;
Jens Axboeea51b952012-03-14 11:39:13 +010056
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010057 /*
Jens Axboe3c568232013-09-30 12:17:34 -060058 * If we fail extending the log, stop collecting more entries.
59 */
60 unsigned int disabled;
61
62 /*
Jens Axboeccefd5f2014-06-30 20:59:03 -060063 * Log offsets
64 */
65 unsigned int log_offset;
66
67 /*
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010068 * Windowed average, for logging single entries average over some
69 * period of time.
70 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +020071 struct io_stat avg_window[DDIR_RWDIR_CNT];
Jens Axboeb8bc8cb2011-12-01 09:04:31 +010072 unsigned long avg_msec;
73 unsigned long avg_last;
Jens Axboe5995a6a2009-06-03 08:53:28 +020074};
75
Jens Axboeccefd5f2014-06-30 20:59:03 -060076static inline size_t __log_entry_sz(int log_offset)
77{
78 if (log_offset)
79 return sizeof(struct io_sample_offset);
80 else
81 return sizeof(struct io_sample);
82}
83
84static inline size_t log_entry_sz(struct io_log *log)
85{
86 return __log_entry_sz(log->log_offset);
87}
88
89static inline struct io_sample *__get_sample(void *samples, int log_offset,
90 uint64_t sample)
91{
92 return samples + sample * __log_entry_sz(log_offset);
93}
94
95static inline struct io_sample *get_sample(struct io_log *iolog,
96 uint64_t sample)
97{
98 return __get_sample(iolog->log, iolog->log_offset, sample);
99}
100
Jens Axboe0d29de82010-09-01 13:54:15 +0200101enum {
102 IP_F_ONRB = 1,
103 IP_F_ONLIST = 2,
104 IP_F_TRIMMED = 4,
Jens Axboef9401282014-02-06 12:17:37 -0700105 IP_F_IN_FLIGHT = 8,
Jens Axboe0d29de82010-09-01 13:54:15 +0200106};
107
Jens Axboe5995a6a2009-06-03 08:53:28 +0200108/*
109 * When logging io actions, this matches a single sent io_u
110 */
111struct io_piece {
112 union {
113 struct rb_node rb_node;
114 struct flist_head list;
115 };
Jens Axboe0d29de82010-09-01 13:54:15 +0200116 struct flist_head trim_list;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200117 union {
118 int fileno;
119 struct fio_file *file;
120 };
121 unsigned long long offset;
Juan Casseda0a7bd2013-09-17 14:06:12 -0700122 unsigned short numberio;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200123 unsigned long len;
Jens Axboea917a8b2010-09-02 13:23:20 +0200124 unsigned int flags;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200125 enum fio_ddir ddir;
126 union {
127 unsigned long delay;
128 unsigned int file_action;
129 };
130};
131
132/*
133 * Log exports
134 */
135enum file_log_act {
136 FIO_LOG_ADD_FILE,
137 FIO_LOG_OPEN_FILE,
138 FIO_LOG_CLOSE_FILE,
139 FIO_LOG_UNLINK_FILE,
140};
141
Jens Axboe8062f522013-04-10 15:01:42 +0200142struct io_u;
Jens Axboe5995a6a2009-06-03 08:53:28 +0200143extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
144extern void log_io_u(struct thread_data *, struct io_u *);
145extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
146extern int __must_check init_iolog(struct thread_data *td);
147extern void log_io_piece(struct thread_data *, struct io_u *);
Jens Axboe890b6652014-05-06 19:06:51 -0600148extern void unlog_io_piece(struct thread_data *, struct io_u *);
149extern void trim_io_piece(struct thread_data *, struct io_u *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200150extern void queue_io_piece(struct thread_data *, struct io_piece *);
151extern void prune_io_piece_log(struct thread_data *);
152extern void write_iolog_close(struct thread_data *);
153
154/*
155 * Logging
156 */
Peter Oberparleiter99007062014-02-20 14:20:05 +0100157extern void finalize_logs(struct thread_data *td);
Jens Axboe02af0982010-06-24 09:59:34 +0200158extern void add_lat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600159 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200160extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600161 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200162extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
Jens Axboeccefd5f2014-06-30 20:59:03 -0600163 unsigned int, uint64_t);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200164extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
165 struct timeval *);
Erwan Velu9b7e6002013-08-02 16:39:40 +0200166extern void add_iops_sample(struct thread_data *, enum fio_ddir, unsigned int,
167 struct timeval *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200168extern void init_disk_util(struct thread_data *);
169extern void update_rusage_stat(struct thread_data *);
Jens Axboeccefd5f2014-06-30 20:59:03 -0600170extern void setup_log(struct io_log **, unsigned long, int, int);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200171extern void __finish_log(struct io_log *, const char *);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200172extern struct io_log *agg_io_log[DDIR_RWDIR_CNT];
Jens Axboe5995a6a2009-06-03 08:53:28 +0200173extern int write_bw_log;
174extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
Jens Axboe905e3d42014-04-02 20:01:27 -0600175extern void fio_writeout_logs(struct thread_data *);
Jens Axboe5995a6a2009-06-03 08:53:28 +0200176
Jens Axboe0d29de82010-09-01 13:54:15 +0200177static inline void init_ipo(struct io_piece *ipo)
178{
179 memset(ipo, 0, sizeof(*ipo));
180 INIT_FLIST_HEAD(&ipo->trim_list);
181}
182
Jens Axboe5995a6a2009-06-03 08:53:28 +0200183#endif