Add an '--ioprio' option to request a trace with I/O priorities recorded in it from the Kernel. Signed-off-by: Johannes Thumshirn --- blktrace.c | 29 +++++++++++++++++++++++++++++ blktrace_api.h | 5 ++++- doc/blktrace.8 | 5 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/blktrace.c b/blktrace.c index 89a8f8a..9ba3b3e 100644 --- a/blktrace.c +++ b/blktrace.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -284,6 +285,7 @@ static int kill_running_trace; static int stop_watch; static int piped_output; static int trace_ver; +static bool ioprio_trace; static char *debugfs_path = "/sys/kernel/debug"; static char *output_name; @@ -332,6 +334,7 @@ static int (*handle_list)(struct tracer_devpath_head *, struct list_head *); enum { OPT_TRACE_VERSION = 256, + OPT_IO_PRIO = 257, }; #define S_OPTS "d:a:A:r:o:kw:vVb:n:D:lh:p:sI:" @@ -444,6 +447,12 @@ static struct option l_opts[] = { .flag = NULL, .val = OPT_TRACE_VERSION }, + { + .name = "ioprio", + .has_arg = no_argument, + .flag = NULL, + .val = OPT_IO_PRIO, + }, { .name = NULL, } @@ -466,6 +475,7 @@ static char usage_str[] = "\n\n" \ "[ -I | --input-devs=]\n" \ "[ -v | --version]\n" \ "[ -V | --version]\n" \ + "[ --ioprio ]\n" \ "[ --trace-version=<1|2> ]\n" \ "\t-d Use specified device. May also be given last after options\n" \ @@ -484,6 +494,7 @@ static char usage_str[] = "\n\n" \ "\t-I Add devices found in \n" \ "\t-v Print program version info\n" \ "\t-V Print program version info\n" \ + "\t--ioprio Record I/O priorities (requires trace version 2)\n" \ "\t--trace-version Request trace protocol version 1 or 2 from the kernel\n\n"; static void clear_events(struct pollfd *pfd) @@ -1093,6 +1104,7 @@ static int setup_buts2(void) buts2.buf_size = buf_size; buts2.buf_nr = buf_nr; buts2.act_mask = act_mask; + buts2.flags = ioprio_trace ? BLKTRACE_FLAG_IOPRIO : 0; if (ioctl(dpp->fd, BLKTRACESETUP2, &buts2) >= 0) { dpp->ncpus = max_cpus; @@ -1103,6 +1115,10 @@ static int setup_buts2(void) dpp->stats = calloc(dpp->ncpus, sizeof(*dpp->stats)); memset(dpp->stats, 0, dpp->ncpus * sizeof(*dpp->stats)); } else { + if (errno == EINVAL && ioprio_trace) + fprintf(stderr, + "BLKTRACESETUP2 %s: kernel does not support ioprio tracing\n", + dpp->path); ret++; } } @@ -2264,6 +2280,9 @@ static int handle_args(int argc, char *argv[]) exit(1); } break; + case OPT_IO_PRIO: + ioprio_trace = true; + break; default: show_usage(argv[0]); exit(1); @@ -2291,6 +2310,11 @@ static int handle_args(int argc, char *argv[]) return 1; } + if (ioprio_trace && trace_ver == 1) { + show_usage(argv[0]); + return 1; + } + if (act_mask_tmp != 0) act_mask = act_mask_tmp; @@ -2735,6 +2759,11 @@ static int run_tracers(void) printf("blktrace: connecting to %s\n", hostname); if (trace_ver == 1 || setup_buts2()) { + if (trace_ver != 1 && ioprio_trace) { + done = 1; + return 1; + } + if (setup_buts()) { done = 1; return 1; diff --git a/blktrace_api.h b/blktrace_api.h index 4b56e96..884a718 100644 --- a/blktrace_api.h +++ b/blktrace_api.h @@ -188,10 +188,13 @@ struct blk_user_trace_setup2 { __u64 start_lba; __u64 end_lba; __u32 pid; - __u32 flags; /* currently unused */ + __u32 flags; /* input */ __u64 reserved[11]; }; +#define BLKTRACE_FLAG_IOPRIO (1U << 0) +#define BLKTRACE_FLAGS_MASK (BLKTRACE_FLAG_IOPRIO) + #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) #define BLKTRACESTART _IO(0x12,116) #define BLKTRACESTOP _IO(0x12,117) diff --git a/doc/blktrace.8 b/doc/blktrace.8 index c502adc..d35cbbf 100644 --- a/doc/blktrace.8 +++ b/doc/blktrace.8 @@ -191,6 +191,11 @@ Outputs version Sets run time to the number of seconds specified .RE +\-\-ioprio\fR +.RS +Record I/O priorities (requires trace version 2) +.RE + \-\-trace\-version=\fI1|2\fR .RS Selects the trace protocol version requested from the kernel. Requesting -- 2.56.1