diff mbox series

[RFC,blktrace-tools,04/10] blktrace.c: add support for extensions

Message ID 20190501043317.5507-5-chaitanya.kulkarni@wdc.com (mailing list archive)
State New, archived
Headers show
Series blktrace: add blktrace extension support | expand

Commit Message

Chaitanya Kulkarni May 1, 2019, 4:33 a.m. UTC
This patch adds support for blktrace tool to use the blktrace extension.
Here we also add the support for priority tracking and using priority
mask from the command line just like action mask.

Here we also increase the size of the various bufferes.
We add three new command line options so that user can specify whethere
to track priority and priority mask just like actiom mask.
In order to keep the backward compaibility we by default we turn off
the priority tracking.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 blktrace.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 80 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/blktrace.c b/blktrace.c
index d0d271f..e5105f5 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -57,10 +57,17 @@ 
  * You may want to increase this even more, if you are logging at a high
  * rate and see skipped/missed events
  */
+#ifdef CONFIG_BLKTRACE_EXT
+#define BUF_SIZE		(1024 * 1024)
+#define BUF_NR			(4)
+
+#define FILE_VBUF_SIZE		(256 * 1024)
+#else
 #define BUF_SIZE		(512 * 1024)
 #define BUF_NR			(4)
 
 #define FILE_VBUF_SIZE		(128 * 1024)
+#endif /* CONFIG_BLKTRACE_EXT */
 
 #define DEBUGFS_TYPE		(0x64626720)
 #define TRACE_NET_PORT		(8462)
@@ -279,7 +286,15 @@  static int max_cpus;
 static int ncpus;
 static cpu_set_t *online_cpus;
 static int pagesize;
+
+#ifdef CONFIG_BLKTRACE_EXT
+static uint64_t act_mask = -1ULL;
+/* by default don't trace priority */
+static uint32_t blktrace_prio_mask = 0;
+int btrace_track_prio;
+#else
 static int act_mask = ~0U;
+#endif /* CONFIG_BLKTRACE_EXT */
 static int kill_running_trace;
 static int stop_watch;
 static int piped_output;
@@ -329,7 +344,11 @@  static int *cl_fds;
 static int (*handle_pfds)(struct tracer *, int, int);
 static int (*handle_list)(struct tracer_devpath_head *, struct list_head *);
 
+#ifdef CONFIG_BLKTRACE_EXT
+#define S_OPTS	"d:a:A:r:o:kw:vVb:n:D:lh:p:sI:Px:X:"
+#else
 #define S_OPTS	"d:a:A:r:o:kw:vVb:n:D:lh:p:sI:"
+#endif /* CONFIG_BLKTRACE_EXT */
 static struct option l_opts[] = {
 	{
 		.name = "dev",
@@ -427,6 +446,24 @@  static struct option l_opts[] = {
 		.flag = NULL,
 		.val = 'p'
 	},
+	{
+		.name = "track-priority",
+		.has_arg = no_argument,
+		.flag = NULL,
+		.val = 'P'
+	},
+	{
+		.name = "prio-mask",
+		.has_arg = required_argument,
+		.flag = NULL,
+		.val = 'x'
+	},
+	{
+		.name = "prio-set-mask",
+		.has_arg = required_argument,
+		.flag = NULL,
+		.val = 'X'
+	},
 	{
 		.name = "no-sendfile",
 		.has_arg = no_argument,
@@ -453,6 +490,9 @@  static char usage_str[] = "\n\n" \
         "[ -p <port number>   | --port=<port number>]\n" \
         "[ -s                 | --no-sendfile]\n" \
         "[ -I <devs file>     | --input-devs=<devs file>]\n" \
+        "[ -P                 | --track-priority ]\n" \
+        "[ -x <ioprio field>  | --prio-mask=<ioprio field> ]\n" \
+        "[ -X <ioprio mask>   | --set-mask=<ioprio mask> ]\n" \
         "[ -v <version>       | --version]\n" \
         "[ -V <version>       | --version]\n" \
 
@@ -468,6 +508,9 @@  static char usage_str[] = "\n\n" \
 	"\t-l Run in network listen mode (blktrace server)\n" \
 	"\t-h Run in network client mode, connecting to the given host\n" \
 	"\t-p Network port to use (default 8462)\n" \
+	"\t-P Enable tracking priorites.\n" \
+	"\t-a Only priority specified actions.\n" \
+	"\t-A Give priority mask as a single value.\n" \
 	"\t-s Make the network client NOT use sendfile() to transfer data\n" \
 	"\t-I Add devices found in <devs file>\n" \
 	"\t-v Print program version info\n" \
@@ -633,11 +676,11 @@  static int lock_on_cpu(int cpu)
 	CPU_ZERO_S(size, cpu_mask);
 	CPU_SET_S(cpu, size, cpu_mask);
 	if (sched_setaffinity(0, size, cpu_mask) < 0) {
-		CPU_FREE(cpu_mask);		
+		CPU_FREE(cpu_mask);
 		return errno;
 	}
 
-	CPU_FREE(cpu_mask);		
+	CPU_FREE(cpu_mask);
 	return 0;
 }
 
@@ -1080,7 +1123,9 @@  static int setup_buts(void)
 		buts.buf_size = buf_size;
 		buts.buf_nr = buf_nr;
 		buts.act_mask = act_mask;
-
+#ifdef CONFIG_BLKTRACE_EXT
+		buts.prio_mask = btrace_track_prio ? blktrace_prio_mask : 0;
+#endif /* CONFIG_BLKTRACE_EXT */
 		if (ioctl(dpp->fd, BLKTRACESETUP, &buts) >= 0) {
 			dpp->ncpus = max_cpus;
 			dpp->buts_name = strdup(buts.name);
@@ -2104,7 +2149,7 @@  static int handle_args(int argc, char *argv[])
 {
 	int c, i;
 	struct statfs st;
-	int act_mask_tmp = 0;
+	unsigned int act_mask_tmp = 0;
 
 	while ((c = getopt_long(argc, argv, S_OPTS, l_opts, NULL)) >= 0) {
 		switch (c) {
@@ -2211,6 +2256,29 @@  static int handle_args(int argc, char *argv[])
 		case 'p':
 			net_port = atoi(optarg);
 			break;
+#ifdef CONFIG_BLKTRACE_EXT
+		case 'P': /* enable priority tracking */
+			btrace_track_prio = 1;
+			break;
+		case 'x': /* priority mask values in string */
+			i = find_prio_mask_map(optarg);
+			if (i < 0) {
+				fprintf(stderr,"Invalid prio mask %s\n",
+						optarg);
+				return 1;
+			}
+			blktrace_prio_mask |= i;
+			break;
+		case 'X': /* priority mask values in hex */
+			if ((sscanf(optarg, "%x", &i) != 1) ||
+					!valid_prio_opt(i)) {
+				fprintf(stderr, "Invalid prio mask %s/0x%x\n",
+						optarg, i);
+				return 1;
+			}
+			blktrace_prio_mask = i;
+			break;
+#endif /* CONFIG_BLKTRACE_EXT */
 		case 's':
 			net_use_sendfile = 0;
 			break;
@@ -2243,7 +2311,14 @@  static int handle_args(int argc, char *argv[])
 
 	if (act_mask_tmp != 0)
 		act_mask = act_mask_tmp;
-
+#ifdef CONFIG_BLKTRACE_EXT
+	/*
+	 * When track-priority is on and user didn't specify prio_mask then
+	 * trace all the classes.
+	 */
+	if (btrace_track_prio && !blktrace_prio_mask)
+		blktrace_prio_mask = TRACE_ALL_IOPRIO;
+#endif /* CONFIG_BLKTRACE_EXT */
 	if (net_mode == Net_client && net_setup_addr())
 		return 1;