diff mbox series

[RFC,07/18] blktrace: allow user to track iopriority

Message ID 20190501042831.5313-8-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:28 a.m. UTC
Now that we have added the support for to track the iopriority
update the blktrace extension code to actually track the priority
and use priority mask to filter out the log.

Priority mask just works same as action mask where we discard all the
traces where they don't match the priority mask.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 kernel/trace/blktrace.c | 60 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 6d2b4adae76e..1b113ba284fe 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -16,6 +16,7 @@ 
 #include <linux/uaccess.h>
 #include <linux/list.h>
 #include <linux/blk-cgroup.h>
+#include <linux/ioprio.h>
 
 #include "../../block/blk.h"
 
@@ -189,6 +190,54 @@  EXPORT_SYMBOL_GPL(__trace_note_message);
 
 
 #ifdef CONFIG_BLKTRACE_EXT
+static bool prio_log_check(struct blk_trace *bt, u32 ioprio)
+{
+	bool ret;
+
+	switch (IOPRIO_PRIO_CLASS(ioprio)) {
+	case IOPRIO_CLASS_NONE:
+	case IOPRIO_CLASS_RT:
+	case IOPRIO_CLASS_BE:
+	case IOPRIO_CLASS_IDLE:
+		break;
+	default:
+		/*XXX: print rate limit warn here */
+		ret = false;
+		goto out;
+	}
+
+	switch (IOPRIO_PRIO_CLASS(ioprio)) {
+	case IOPRIO_CLASS_NONE:
+		if (bt->prio_mask & 0x01)
+			ret = true;
+		else
+			ret = false;
+		break;
+	case IOPRIO_CLASS_RT:
+		if (bt->prio_mask & 0x02)
+			ret = true;
+		else
+			ret = false;
+		break;
+	case IOPRIO_CLASS_BE:
+		if (bt->prio_mask & 0x04)
+			ret = true;
+		else
+			ret = false;
+		break;
+	case IOPRIO_CLASS_IDLE:
+		if (bt->prio_mask & 0x08)
+			ret = true;
+		else
+			ret = false;
+		break;
+	default:
+		ret = false;
+	}
+out:
+	return ret;
+}
+
 static int act_log_check(struct blk_trace *bt, u64 what, sector_t sector,
 			 pid_t pid)
 #else
@@ -279,6 +328,10 @@  static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
 	pid = tsk->pid;
 	if (act_log_check(bt, what, sector, pid))
 		return;
+#ifdef CONFIG_BLKTRACE_EXT
+	if (bt->prio_mask && !prio_log_check(bt, ioprio))
+		return;
+#endif /* CONFIG_BLKTRACE_EXT */
 	cpu = raw_smp_processor_id();
 
 	if (blk_tracer) {
@@ -324,6 +377,9 @@  static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
 		t->sector = sector;
 		t->bytes = bytes;
 		t->action = what;
+#ifdef CONFIG_BLKTRACE_EXT
+		t->ioprio = ioprio;
+#endif /* CONFIG_BLKTRACE_EXT */
 		t->device = bt->dev;
 		t->error = error;
 		t->pdu_len = pdu_len + cgid_len;
@@ -574,6 +630,7 @@  static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 #ifdef CONFIG_BLKTRACE_EXT
 	if (!bt->act_mask)
 		bt->act_mask = (u64) -1ULL;
+	bt->prio_mask = buts->prio_mask;
 #else
 	if (!bt->act_mask)
 		bt->act_mask = (u16) -1;
@@ -1773,7 +1830,8 @@  static int blk_trace_setup_queue(struct request_queue *q,
 
 #ifdef CONFIG_BLKTRACE_EXT
 	bt->act_mask = (u64)-1ULL;
-
+	/* do not track priorities by default */
+	bt->prio_mask = 0;
 #else
 	bt->act_mask = (u16)-1;
 #endif /* CONFIG_BLKTRACE_EXT */