Skip to contentSkip to conversation

iolog: add version 3 with timestamp support

PATCH Applied Mohamad Gebai 2 participants 6 messages Apr 7, 2022 – Apr 8, 2022

lore
Share & tools
lore
#0 lore raw

v3 cover iolog: add version 3 with timestamp support

This set of patches introduces version 3 of the iolog replay. This version adds support for timestamps on both iolog_read and iolog_write. The 'wait' action is no longer supported with version 3, as the same behavior can be achieved with timestamps, and it keeps the iolog file easier to follow. This could also allow to potentially deprecate the 'wait' action eventually.

Changes from v2:
* Update documentation in fio.1.

Mohamad Gebai (3):
iolog: add version 3 to support timestamp-based replay
iolog: add iolog_write for version 3
iolog: update man page for version 3

 HOWTO.rst  |  29 ++++++++++++++-
 blktrace.c |  17 ++-------
 fio.1      |  35 +++++++++++++++++-
 fio.h      |   4 ++-
 iolog.c    | 104 ++++++++++++++++++++++++++++++++++++++++++-----------
 iolog.h    |   8 ++---
 6 files changed, 155 insertions(+), 42 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 1/3 iolog: add version 3 to support timestamp-based replay

Version 3 format looks as follows:

timestamp filename action offset length

All file and IO actions must have timestamps, including 'add'. The 'wait' action is not allowed with version 3 so that we can leave all timing functionality to timestamps.

---
 blktrace.c | 17 ++---------
 fio.h      |  3 +-
 iolog.c    | 89 +++++++++++++++++++++++++++++++++++++++++++-----------
 iolog.h    |  8 ++---
 4 files changed, 80 insertions(+), 37 deletions(-)
blktrace.c +3 -14
index ead60130..619121c7 100644
@@ -306,39 +306,28 @@ static bool handle_trace_flush(struct thread_data *td, struct blk_io_trace *t,
 }
 
 /*
  * We only care for queue traces, most of the others are side effects
  * due to internal workings of the block layer.
  */
 static bool queue_trace(struct thread_data *td, struct blk_io_trace *t,
 			 unsigned long *ios, unsigned long long *bs,
 			 struct file_cache *cache)
 {
-	unsigned long long *last_ttime = &td->io_log_blktrace_last_ttime;
+	unsigned long long *last_ttime = &td->io_log_last_ttime;
 	unsigned long long delay = 0;
 
 	if ((t->action & 0xffff) != __BLK_TA_QUEUE)
 		return false;
 
 	if (!(t->action & BLK_TC_ACT(BLK_TC_NOTIFY))) {
-		if (!*last_ttime || td->o.no_stall || t->time < *last_ttime)
-			delay = 0;
-		else if (td->o.replay_time_scale == 100)
-			delay = t->time - *last_ttime;
-		else {
-			double tmp = t->time - *last_ttime;
-			double scale;
-
-			scale = (double) 100.0 / (double) td->o.replay_time_scale;
-			tmp *= scale;
-			delay = tmp;
-		}
+		delay = delay_since_ttime(td, t->time);
 		*last_ttime = t->time;
 	}
 
 	t_bytes_align(&td->o, t);
 
 	if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
 		return handle_trace_notify(t);
 	else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
 		return handle_trace_discard(td, t, delay, ios, bs, cache);
 	else if (t->action & BLK_TC_ACT(BLK_TC_FLUSH))
@@ -415,21 +404,21 @@ static void depth_end(struct blk_io_trace *t, int *this_depth, int *depth)
 bool init_blktrace_read(struct thread_data *td, const char *filename, int need_swap)
 {
 	int old_state;
 
 	td->io_log_rfile = fopen(filename, "rb");
 	if (!td->io_log_rfile) {
 		td_verror(td, errno, "open blktrace file");
 		goto err;
 	}
 	td->io_log_blktrace_swap = need_swap;
-	td->io_log_blktrace_last_ttime = 0;
+	td->io_log_last_ttime = 0;
 	td->o.size = 0;
 
 	free_release_files(td);
 
 	old_state = td_bump_runstate(td, TD_SETTING_UP);
 
 	if (!read_blktrace(td)) {
 		goto err;
 	}
 
fio.h +2 -1
index 776fb51f..8830ff34 100644
@@ -424,24 +424,25 @@ struct thread_data {
 	struct flist_head io_hist_list;
 	unsigned long io_hist_len;
 
 	/*
 	 * For IO replaying
 	 */
 	struct flist_head io_log_list;
 	FILE *io_log_rfile;
 	unsigned int io_log_blktrace;
 	unsigned int io_log_blktrace_swap;
-	unsigned long long io_log_blktrace_last_ttime;
+	unsigned long long io_log_last_ttime;
 	unsigned int io_log_current;
 	unsigned int io_log_checkmark;
 	unsigned int io_log_highmark;
+	unsigned int io_log_version;
 	struct timespec io_log_highmark_time;
 
 	/*
 	 * For tracking/handling discards
 	 */
 	struct flist_head trim_list;
 	unsigned long trim_entries;
 
 	/*
 	 * for fileservice, how often to switch to a new file
iolog.c +71 -18

307 lines not on this page · raw message

iolog.h +4 -4
index a3986309..62cbd1b0 100644
@@ -220,24 +220,22 @@ struct io_piece {
 	struct flist_head trim_list;
 	union {
 		int fileno;
 		struct fio_file *file;
 	};
 	unsigned long long offset;
 	unsigned short numberio;
 	unsigned long len;
 	unsigned int flags;
 	enum fio_ddir ddir;
-	union {
-		unsigned long delay;
-		unsigned int file_action;
-	};
+	unsigned long delay;
+	unsigned int file_action;
 };
 
 /*
  * Log exports
  */
 enum file_log_act {
 	FIO_LOG_ADD_FILE,
 	FIO_LOG_OPEN_FILE,
 	FIO_LOG_CLOSE_FILE,
 	FIO_LOG_UNLINK_FILE,
@@ -252,20 +250,22 @@ extern void log_io_piece(struct thread_data *, struct io_u *);
 extern void unlog_io_piece(struct thread_data *, struct io_u *);
 extern void trim_io_piece(const struct io_u *);
 extern void queue_io_piece(struct thread_data *, struct io_piece *);
 extern void prune_io_piece_log(struct thread_data *);
 extern void write_iolog_close(struct thread_data *);
 int64_t iolog_items_to_fetch(struct thread_data *td);
 extern int iolog_compress_init(struct thread_data *, struct sk_out *);
 extern void iolog_compress_exit(struct thread_data *);
 extern size_t log_chunk_sizes(struct io_log *);
 extern int init_io_u_buffers(struct thread_data *);
+extern unsigned long long delay_since_ttime(const struct thread_data *,
+					     unsigned long long);
 
 #ifdef CONFIG_ZLIB
 extern int iolog_file_inflate(const char *);
 #endif
 
 /*
  * Logging
  */
 struct log_params {
 	struct thread_data *td;
Signature · 1 line
2.30.2
#2 lore raw

PATCH v3 2/3 iolog: add iolog_write for version 3

In reply to Mohamad Gebai

Add timestamps to all actions for iolog version 3. Fio now generates iolog files using version 3 by default, and only supports writing using that version. Reading iolog v2 still works as expected.

---
 fio.h   |  1 +
 iolog.c | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)
fio.h +1 -0
index 8830ff34..de7eca79 100644
@@ -425,20 +425,21 @@ struct thread_data {
 	unsigned long io_hist_len;
 
 	/*
 	 * For IO replaying
 	 */
 	struct flist_head io_log_list;
 	FILE *io_log_rfile;
 	unsigned int io_log_blktrace;
 	unsigned int io_log_blktrace_swap;
 	unsigned long long io_log_last_ttime;
+	struct timespec io_log_start_time;
 	unsigned int io_log_current;
 	unsigned int io_log_checkmark;
 	unsigned int io_log_highmark;
 	unsigned int io_log_version;
 	struct timespec io_log_highmark_time;
 
 	/*
 	 * For tracking/handling discards
 	 */
 	struct flist_head trim_list;
iolog.c +12 -3
index f6023ee2..51aecd43 100644
@@ -34,46 +34,54 @@ static const char iolog_ver2[] = "fio version 2 iolog";
 static const char iolog_ver3[] = "fio version 3 iolog";
 
 void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
 {
 	flist_add_tail(&ipo->list, &td->io_log_list);
 	td->total_io_size += ipo->len;
 }
 
 void log_io_u(const struct thread_data *td, const struct io_u *io_u)
 {
+	struct timespec now;
+
 	if (!td->o.write_iolog_file)
 		return;
 
-	fprintf(td->iolog_f, "%s %s %llu %llu\n", io_u->file->file_name,
+	fio_gettime(&now, NULL);
+	fprintf(td->iolog_f, "%lu %s %s %llu %llu\n", utime_since_now(&td->io_log_start_time),
+						io_u->file->file_name,
 						io_ddir_name(io_u->ddir),
 						io_u->offset, io_u->buflen);
+
 }
 
 void log_file(struct thread_data *td, struct fio_file *f,
 	      enum file_log_act what)
 {
 	const char *act[] = { "add", "open", "close" };
+	struct timespec now;
 
 	assert(what < 3);
 
 	if (!td->o.write_iolog_file)
 		return;
 
 
 	/*
 	 * this happens on the pre-open/close done before the job starts
 	 */
 	if (!td->iolog_f)
 		return;
 
-	fprintf(td->iolog_f, "%s %s\n", f->file_name, act[what]);
+	fio_gettime(&now, NULL);
+	fprintf(td->iolog_f, "%lu %s %s\n", utime_since_now(&td->io_log_start_time),
+						f->file_name, act[what]);
 }
 
 static void iolog_delay(struct thread_data *td, unsigned long delay)
 {
 	uint64_t usec = utime_since_now(&td->last_issue);
 	unsigned long orig_delay = delay;
 	uint64_t this_delay;
 	struct timespec ts;
 
 	if (delay < td->time_offset) {
@@ -731,25 +739,26 @@ static bool init_iolog_write(struct thread_data *td)
 		perror("fopen write iolog");
 		return false;
 	}
 
 	/*
 	 * That's it for writing, setup a log buffer and we're done.
 	  */
 	td->iolog_f = f;
 	td->iolog_buf = malloc(8192);
 	setvbuf(f, td->iolog_buf, _IOFBF, 8192);
+	fio_gettime(&td->io_log_start_time, NULL);
 
 	/*
 	 * write our version line
 	 */
-	if (fprintf(f, "%s\n", iolog_ver2) < 0) {
+	if (fprintf(f, "%s\n", iolog_ver3) < 0) {
 		perror("iolog init\n");
 		return false;
 	}
 
 	/*
 	 * add all known files
 	 */
 	for_each_file(td, ff, i)
 		log_file(td, ff, FIO_LOG_ADD_FILE);
 
Signature · 1 line
2.30.2
#3 lore raw

PATCH v3 3/3 iolog: update man page for version 3

In reply to Mohamad Gebai

Add documentation for iolog version 3, mainly the differences between versions 2 and 3.

---
 HOWTO.rst | 29 ++++++++++++++++++++++++++++-
 fio.1     | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 2 deletions(-)
HOWTO.rst +28 -1
index 0978879c..a5fa432e 100644
@@ -4391,33 +4391,60 @@ The `filename` is given as an absolute path. The `action` can be one of these:
 The file I/O action format::
 
     filename action offset length
 
 The `filename` is given as an absolute path, and has to have been added and
 opened before it can be used with this format. The `offset` and `length` are
 given in bytes. The `action` can be one of these:
 
 **wait**
 	   Wait for `offset` microseconds. Everything below 100 is discarded.
-	   The time is relative to the previous `wait` statement.
+	   The time is relative to the previous `wait` statement. Note that
+	   action `wait` is not allowed as of version 3, as the same behavior
+	   can be achieved using timestamps.
 **read**
 	   Read `length` bytes beginning from `offset`.
 **write**
 	   Write `length` bytes beginning from `offset`.
 **sync**
 	   :manpage:`fsync(2)` the file.
 **datasync**
 	   :manpage:`fdatasync(2)` the file.
 **trim**
 	   Trim the given file from the given `offset` for `length` bytes.
 
 
+Trace file format v3
+~~~~~~~~~~~~~~~~~~~~
+
+The third version of the trace file format was added in fio version 3.31. It
+forces each action to have a timestamp associated with it.
+
+The first line of the trace file has to be::
+
+    fio version 3 iolog
+
+Following this can be lines in two different formats, which are described below.
+
+The file management format::
+
+    timestamp filename action
+
+The file I/O action format::
+
+    timestamp filename action offset length
+
+The `timestamp` is relative to the beginning of the run (ie starts at 0). The
+`filename`, `action`, `offset` and `length`  are identical to version 2, except
+that version 3 does not allow the `wait` action.
+
+
 I/O Replay - Merging Traces
 ---------------------------
 
 Colocation is a common practice used to get the most out of a machine.
 Knowing which workloads play nicely with each other and which ones don't is
 a much harder task. While fio can replay workloads concurrently via multiple
 jobs, it leaves some variability up to the scheduler making results harder to
 reproduce. Merging is a way to make the order of events consistent.
 
 Merging is integrated into I/O replay and done when a
fio.1 +34 -1
index 98410655..a2ec836f 100644
@@ -4110,38 +4110,71 @@ The file I/O action format:
 .RS
 filename action offset length
 .P
 The `filename' is given as an absolute path, and has to have been \fBadd\fRed and
 \fBopen\fRed before it can be used with this format. The `offset' and `length' are
 given in bytes. The `action' can be one of these:
 .RS
 .TP
 .B wait
 Wait for `offset' microseconds. Everything below 100 is discarded.
-The time is relative to the previous `wait' statement.
+The time is relative to the previous `wait' statement. Note that action `wait`
+is not allowed as of version 3, as the same behavior can be achieved using
+timestamps.
 .TP
 .B read
 Read `length' bytes beginning from `offset'.
 .TP
 .B write
 Write `length' bytes beginning from `offset'.
 .TP
 .B sync
 \fBfsync\fR\|(2) the file.
 .TP
 .B datasync
 \fBfdatasync\fR\|(2) the file.
 .TP
 .B trim
 Trim the given file from the given `offset' for `length' bytes.
 .RE
 .RE
+.RE
+.TP
+.B Trace file format v3
+The third version of the trace file format was added in fio version 3.31. It
+forces each action to have a timestamp associated with it.
+.RS
+.P
+The first line of the trace file has to be:
+.RS
+.P
+"fio version 3 iolog"
+.RE
+.P
+Following this can be lines in two different formats, which are described below.
+.P
+.B
+The file management format:
+.RS
+timestamp filename action
+.P
+.RE
+.B
+The file I/O action format:
+.RS
+timestamp filename action offset length
+.P
+The `timestamp` is relative to the beginning of the run (ie starts at 0). The
+`filename`, `action`, `offset` and `length`  are identical to version 2, except
+that version 3 does not allow the `wait` action.
+.RE
+.RE
 .SH I/O REPLAY \- MERGING TRACES
 Colocation is a common practice used to get the most out of a machine.
 Knowing which workloads play nicely with each other and which ones don't is
 a much harder task. While fio can replay workloads concurrently via multiple
 jobs, it leaves some variability up to the scheduler making results harder to
 reproduce. Merging is a way to make the order of events consistent.
 .P
 Merging is integrated into I/O replay and done when a \fBmerge_blktrace_file\fR
 is specified. The list of files passed to \fBread_iolog\fR go through the merge
 process and output a single file stored to the specified file. The output file is
Signature · 1 line
2.30.2
Applied
#4 lore raw
In reply to Mohamad Gebai
Quoted 8 lines · Mohamad Gebai

This set of patches introduces version 3 of the iolog replay. This version adds support for timestamps on both iolog_read and iolog_write. The 'wait' action is no longer supported with version 3, as the same behavior can be achieved with timestamps, and it keeps the iolog file easier to follow. This could also allow to potentially deprecate the 'wait' action eventually.

[...]

Applied, thanks!

[1/3] iolog: add version 3 to support timestamp-based replay

      commit: 315bbf01119ea783554d274add04db98c0a3b433
[2/3] iolog: add iolog_write for version 3
      commit: e8cf24e570e0bda05dd8f9c390911ebc280956ea
[3/3] iolog: update man page for version 3
      commit: 5c2c0db4c5d9911f381546ae7d0d07d15b3ccc64

Best regards,

Signature · 1 line
Jens Axboe
#5 lore raw
In reply to Mohamad Gebai
Quoted 6 lines · Mohamad Gebai

This set of patches introduces version 3 of the iolog replay. This version adds support for timestamps on both iolog_read and iolog_write. The 'wait' action is no longer supported with version 3, as the same behavior can be achieved with timestamps, and it keeps the iolog file easier to follow. This could also allow to potentially deprecate the 'wait' action eventually.

Needed a fixup on 32-bit, otherwise looks fine to me.

Signature · 1 line
Jens Axboe