linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: axboe@kernel.dk, viro@zeniv.linux.org.uk, rostedt@goodmis.org,
	mingo@redhat.com, chaitanya.kulkarni@wdc.com,
	johannes.thumshirn@wdc.com, damien.lemoal@wdc.com,
	bvanassche@acm.org, dongli.zhang@oracle.com,
	aravind.ramesh@wdc.com, joshi.k@samsung.com,
	niklas.cassel@wdc.com, hch@lst.de, osandov@fb.com,
	martin.petersen@oracle.com
Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 07/39] blktrace: add core trace API
Date: Wed, 24 Feb 2021 23:01:59 -0800	[thread overview]
Message-ID: <20210225070231.21136-8-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20210225070231.21136-1-chaitanya.kulkarni@wdc.com>

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

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index feb823b917ec..1aef55fdefa9 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -462,6 +462,136 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
 	local_irq_restore(flags);
 }
 
+/*
+ * Data direction bit lookup
+ */
+static const u64 ddir_act_ext[2] = { BLK_TC_ACT_EXT(BLK_TC_READ),
+				 BLK_TC_ACT_EXT(BLK_TC_WRITE) };
+
+/* The ilog2() calls fall out because they're constant */
+#define MASK_TC_BIT_EXT(rw, __name) ((rw & REQ_ ## __name) << \
+	  (ilog2(BLK_TC_ ## __name) + BLK_TC_SHIFT_EXT - __REQ_ ## __name))
+
+/*
+ * The worker for the various blk_add_trace*() types. Fills out a
+ * blk_io_trace structure and places it in a per-cpu subbuffer.
+ */
+static void __blk_add_trace_ext(struct blk_trace_ext *bt, sector_t sector, int bytes,
+		     int op, int op_flags, u64 what, int error, int pdu_len,
+		     void *pdu_data, u64 cgid, u32 ioprio)
+{
+	struct task_struct *tsk = current;
+	struct ring_buffer_event *event = NULL;
+	struct trace_buffer *buffer = NULL;
+	struct blk_io_trace_ext *t;
+	unsigned long flags = 0;
+	unsigned long *sequence;
+	pid_t pid;
+	int cpu, pc = 0;
+	bool blk_tracer = blk_tracer_enabled;
+	ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
+
+	if (unlikely(bt->trace_state != Blktrace_running && !blk_tracer))
+		return;
+
+	what |= ddir_act_ext[op_is_write(op) ? WRITE : READ];
+	what |= MASK_TC_BIT_EXT(op_flags, SYNC);
+	what |= MASK_TC_BIT_EXT(op_flags, RAHEAD);
+	what |= MASK_TC_BIT_EXT(op_flags, META);
+	what |= MASK_TC_BIT_EXT(op_flags, PREFLUSH);
+	what |= MASK_TC_BIT_EXT(op_flags, FUA);
+	if (op == REQ_OP_ZONE_APPEND)
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_APPEND);
+	if (op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)
+		what |= BLK_TC_ACT_EXT(BLK_TC_DISCARD);
+	if (op == REQ_OP_FLUSH)
+		what |= BLK_TC_ACT_EXT(BLK_TC_FLUSH);
+	if (unlikely(op == REQ_OP_WRITE_ZEROES))
+		what |= BLK_TC_ACT_EXT(BLK_TC_WRITE_ZEROES);
+	if (unlikely(op == REQ_OP_ZONE_RESET))
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_RESET);
+	if (unlikely(op == REQ_OP_ZONE_RESET_ALL))
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_RESET_ALL);
+	if (unlikely(op == REQ_OP_ZONE_OPEN))
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_OPEN);
+	if (unlikely(op == REQ_OP_ZONE_CLOSE))
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_CLOSE);
+	if (unlikely(op == REQ_OP_ZONE_FINISH))
+		what |= BLK_TC_ACT_EXT(BLK_TC_ZONE_FINISH);
+
+	if (cgid)
+		what |= __BLK_TA_CGROUP;
+
+	pid = tsk->pid;
+	if (act_log_check_ext(bt, what, sector, pid))
+		return;
+	if (bt->prio_mask && !prio_log_check(bt, ioprio))
+		return;
+
+	cpu = raw_smp_processor_id();
+
+	if (blk_tracer) {
+		tracing_record_cmdline(current);
+
+		buffer = blk_tr->array_buffer.buffer;
+		pc = preempt_count();
+		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
+						  sizeof(*t) + pdu_len + cgid_len,
+						  0, pc);
+		if (!event)
+			return;
+		t = ring_buffer_event_data(event);
+		goto record_it;
+	}
+
+	if (unlikely(tsk->btrace_seq != blktrace_seq))
+		trace_note_tsk_ext(tsk, ioprio);
+
+	/*
+	 * A word about the locking here - we disable interrupts to reserve
+	 * some space in the relay per-cpu buffer, to prevent an irq
+	 * from coming in and stepping on our toes.
+	 */
+	local_irq_save(flags);
+	t = relay_reserve(bt->rchan, sizeof(*t) + pdu_len + cgid_len);
+	if (t) {
+		sequence = per_cpu_ptr(bt->sequence, cpu);
+
+		t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION_EXT;
+		t->sequence = ++(*sequence);
+		t->time = ktime_to_ns(ktime_get());
+record_it:
+		/*
+		 * These two are not needed in ftrace as they are in the
+		 * generic trace_entry, filled by tracing_generic_entry_update,
+		 * but for the trace_event->bin() synthesizer benefit we do it
+		 * here too.
+		 */
+		t->cpu = cpu;
+		t->pid = pid;
+
+		t->sector = sector;
+		t->bytes = bytes;
+		t->action = what;
+		t->ioprio = ioprio;
+		t->device = bt->dev;
+		t->error = error;
+		t->pdu_len = pdu_len + cgid_len;
+
+		if (cgid_len)
+			memcpy((void *)t + sizeof(*t), &cgid, cgid_len);
+		if (pdu_len)
+			memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len);
+
+		if (blk_tracer) {
+			trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
+			return;
+		}
+	}
+
+	local_irq_restore(flags);
+}
+
 static void blk_trace_free(struct blk_trace *bt)
 {
 	relay_close(bt->rchan);
-- 
2.22.1


  parent reply	other threads:[~2021-02-25  7:05 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210225070231.21136-1-chaitanya.kulkarni@wdc.com>
2021-02-25  7:01 ` [RFC PATCH 01/39] blktrace_api: add new trace definitions Chaitanya Kulkarni
2021-02-26  4:31   ` Damien Le Moal
2021-02-25  7:01 ` [RFC PATCH 02/39] blktrace_api: add new trace definition Chaitanya Kulkarni
2021-02-26  4:33   ` Damien Le Moal
2021-02-25  7:01 ` [RFC PATCH 03/39] blkdev.h: add new trace ext as a queue member Chaitanya Kulkarni
2021-02-26  4:35   ` Damien Le Moal
2021-02-25  7:01 ` [RFC PATCH 04/39] blktrace: add a new global list Chaitanya Kulkarni
2021-02-26  4:36   ` Damien Le Moal
2021-02-25  7:01 ` [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
2021-02-26  4:39   ` Damien Le Moal
2021-02-25  7:01 ` [RFC PATCH 06/39] blktrace: add act and prio check helpers Chaitanya Kulkarni
2021-02-26  4:41   ` Damien Le Moal
2021-02-25  7:01 ` Chaitanya Kulkarni [this message]
2021-02-26  4:44   ` [RFC PATCH 07/39] blktrace: add core trace API Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 08/39] blktrace: update blk_add_trace_rq() Chaitanya Kulkarni
2021-02-26  4:46   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 09/39] blktrace: update blk_add_trace_rq_insert() Chaitanya Kulkarni
2021-02-26  4:48   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 10/39] blktrace: update blk_add_trace_rq_issue() Chaitanya Kulkarni
2021-02-26  4:48   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 11/39] blktrace: update blk_add_trace_rq_requeue() Chaitanya Kulkarni
2021-02-26  4:48   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 12/39] blktrace: update blk_add_trace_rq_complete() Chaitanya Kulkarni
2021-02-26  4:48   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 13/39] blktrace: update blk_add_trace_bio() Chaitanya Kulkarni
2021-02-26  4:49   ` Damien Le Moal
2021-02-25  7:02 ` [RFC PATCH 14/39] blktrace: update blk_add_trace_bio_bounce() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 15/39] blktrace: update blk_add_trace_bio_complete() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 16/39] blktrace: update blk_add_trace_bio_backmerge() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 17/39] blktrace: update blk_add_trace_bio_frontmerge() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 18/39] blktrace: update blk_add_trace_bio_queue() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 19/39] blktrace: update blk_add_trace_getrq() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 20/39] blktrace: update blk_add_trace_plug() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 21/39] blktrace: update blk_add_trace_unplug() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 22/39] blktrace: update blk_add_trace_split() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 23/39] blktrace: update blk_add_trace_bio_remap() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 24/39] blktrace: update blk_add_trace_rq_remap() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 25/39] blktrace: update blk_add_driver_data() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 26/39] blktrace: add trace entry & pdu helpers Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 27/39] blktrace: add a new formatting routine Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 28/39] blktrace: add blk_log_xxx helpers() Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 29/39] blktrace: link blk_log_xxx() to trace action Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 30/39] blktrace: add trace event print helper Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 31/39] blktrace: add trace_synthesize helper Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 32/39] blktrace: add trace print helpers Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 33/39] blktrace: add blkext tracer Chaitanya Kulkarni
     [not found]   ` <20210227114440.GA22871@xsang-OptiPlex-9020>
2021-02-27 14:49     ` [blktrace] c055908abe: WARNING:at_kernel/trace/trace.c:#create_trace_option_files Steven Rostedt
2021-02-27 19:51       ` Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 34/39] blktrace: implement setup-start-stop ioclts Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 35/39] block: update blkdev_ioctl with new trace ioctls Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 36/39] blktrace: add integrity tracking support Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 37/39] blktrace: update blk_fill_rwbs() with new requests Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 38/39] blktrace: track zone appaend completion sector Chaitanya Kulkarni
2021-02-25  7:02 ` [RFC PATCH 39/39] blktrace: debug patch for the demo Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210225070231.21136-8-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=aravind.ramesh@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=damien.lemoal@wdc.com \
    --cc=dongli.zhang@oracle.com \
    --cc=hch@lst.de \
    --cc=johannes.thumshirn@wdc.com \
    --cc=joshi.k@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mingo@redhat.com \
    --cc=niklas.cassel@wdc.com \
    --cc=osandov@fb.com \
    --cc=rostedt@goodmis.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).