From: Damien Le Moal <dlemoal@kernel.org>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
Jens Axboe <axboe@kernel.dk>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, linux-btrace@vger.kernel.org,
John Garry <john.g.garry@oracle.com>,
Hannes Reinecke <hare@suse.de>, Christoph Hellwig <hch@lst.de>,
Naohiro Aota <naohiro.aota@wdc.com>,
Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Chaitanya Kulkarni <chaitanyak@nvidia.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Subject: Re: [PATCH v2 10/15] blktrace: differentiate between blk_io_trace versions
Date: Wed, 1 Oct 2025 16:21:34 +0900 [thread overview]
Message-ID: <16684b73-7659-49e9-82db-cdd54bf0d2cd@kernel.org> (raw)
In-Reply-To: <20250925150231.67342-11-johannes.thumshirn@wdc.com>
On 9/26/25 00:02, Johannes Thumshirn wrote:
> Differentiate between blk_io_trace and blk_io_trace2 when relaying to
> user-space depending on which version has been requested by the blktrace
> utility.
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> kernel/trace/blktrace.c | 62 +++++++++++++++++++++++++++++++++++++----
> 1 file changed, 57 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index 9cd8eb9e7b4b..82ad626d6202 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -91,6 +91,29 @@ static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
> memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len);
> }
>
> +static void record_blktrace_event2(struct blk_io_trace2 *t2, pid_t pid, int cpu,
> + sector_t sector, int bytes, u64 what,
> + dev_t dev, int error, u64 cgid,
> + ssize_t cgid_len, void *pdu_data,
> + int pdu_len)
> +
Extra blank line not needed.
> +{
> + t2->pid = pid;
> + t2->cpu = cpu;
> +
> + t2->sector = sector;
> + t2->bytes = bytes;
> + t2->action = what;
> + t2->device = dev;
> + t2->error = error;
> + t2->pdu_len = pdu_len + cgid_len;
> +
> + if (cgid_len)
> + memcpy((void *)t2 + sizeof(*t2), &cgid, cgid_len);
> + if (pdu_len)
> + memcpy((void *)t2 + sizeof(*t2) + cgid_len, pdu_data, pdu_len);
> +}
> +
> static void relay_blktrace_event(struct blk_trace *bt, unsigned long sequence,
> pid_t pid, int cpu, sector_t sector, int bytes,
> u32 what, int error, u64 cgid,
> @@ -111,6 +134,26 @@ static void relay_blktrace_event(struct blk_trace *bt, unsigned long sequence,
> cgid, cgid_len, pdu_data, pdu_len);
> }
>
> +static void relay_blktrace_event2(struct blk_trace *bt, unsigned long sequence,
> + pid_t pid, int cpu, sector_t sector,
> + int bytes, u64 what, int error, u64 cgid,
> + ssize_t cgid_len, void *pdu_data, int pdu_len)
> +{
> + struct blk_io_trace2 *t;
> + size_t trace_len = sizeof(struct blk_io_trace2) + pdu_len + cgid_len;
> +
> + t = relay_reserve(bt->rchan, trace_len);
> + if (!t)
> + return;
> +
> + t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE2_VERSION;
> + t->sequence = sequence;
> + t->time = ktime_to_ns(ktime_get());
> +
> + record_blktrace_event2(t, pid, cpu, sector, bytes, what, bt->dev, error,
> + cgid, cgid_len, pdu_data, pdu_len);
> +}
See below.
> +
> /*
> * Send out a notify message.
> */
> @@ -146,8 +189,12 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
> if (!bt->rchan)
> return;
>
> - relay_blktrace_event(bt, 0, pid, cpu, 0, 0, action, 0, cgid,
> - cgid_len, (void *)data, len);
> + if (bt->version == 1)
> + relay_blktrace_event(bt, 0, pid, cpu, 0, 0, action, 0, cgid,
> + cgid_len, (void *)data, len);
> + else
> + relay_blktrace_event2(bt, 0, pid, cpu, 0, 0, action, 0, cgid,
> + cgid_len, (void *)data, len);
Since you pass bt pointer to the relay function, the version is known in that
function and this could be done inside it, no ?
That would avoid this if repetition.
> }
>
> /*
> @@ -329,9 +376,14 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
> local_irq_save(flags);
> sequence = per_cpu_ptr(bt->sequence, cpu);
> (*sequence)++;
> - relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes,
> - lower_32_bits(what), error, cgid, cgid_len,
> - pdu_data, pdu_len);
> + if (bt->version == 1)
> + relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes,
> + lower_32_bits(what), error, cgid,
> + cgid_len, pdu_data, pdu_len);
> + else
> + relay_blktrace_event2(bt, *sequence, pid, cpu, sector, bytes,
> + what, error, cgid, cgid_len, pdu_data,
> + pdu_len);
> local_irq_restore(flags);
> }
>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2025-10-01 7:21 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 15:02 [PATCH v2 00/15] block: add blktrace support for zoned block device commands Johannes Thumshirn
2025-09-25 15:02 ` [PATCH v2 01/15] blktrace: only calculate trace length once Johannes Thumshirn
2025-10-01 6:12 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 02/15] blktrace: factor out recording a blktrace event Johannes Thumshirn
2025-10-01 6:14 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 03/15] blktrace: split out relaying " Johannes Thumshirn
2025-10-01 6:19 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 04/15] blktrace: untangle if/else sequence in __blk_add_trace Johannes Thumshirn
2025-10-01 6:19 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 05/15] blktrace: change the internal action to 64bit Johannes Thumshirn
2025-10-01 6:21 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 06/15] blktrace: split do_blk_trace_setup into two functions Johannes Thumshirn
2025-10-01 6:25 ` Damien Le Moal
2025-10-03 7:27 ` Christoph Hellwig
2025-09-25 15:02 ` [PATCH v2 07/15] blktrace: add definitions for blk_user_trace_setup2 Johannes Thumshirn
2025-10-01 6:27 ` Damien Le Moal
2025-10-03 7:29 ` Christoph Hellwig
2025-09-25 15:02 ` [PATCH v2 08/15] blktrace: pass blk_user_trace2 to setup functions Johannes Thumshirn
2025-10-01 6:34 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 09/15] blktrace: add definitions for struct blk_io_trace2 Johannes Thumshirn
2025-10-01 6:37 ` Damien Le Moal
2025-10-03 7:31 ` Christoph Hellwig
2025-09-25 15:02 ` [PATCH v2 10/15] blktrace: differentiate between blk_io_trace versions Johannes Thumshirn
2025-10-01 7:21 ` Damien Le Moal [this message]
2025-09-25 15:02 ` [PATCH v2 11/15] blktrace: add block trace commands for zone operations Johannes Thumshirn
2025-10-01 7:23 ` Damien Le Moal
2025-10-03 7:32 ` Christoph Hellwig
2025-10-07 13:08 ` Johannes Thumshirn
2025-10-08 6:14 ` hch
2025-10-08 6:16 ` Johannes Thumshirn
2025-10-09 11:17 ` Johannes Thumshirn
2025-10-10 7:32 ` hch
2025-09-25 15:02 ` [PATCH v2 12/15] blktrace: expose ZONE APPEND completions to blktrace Johannes Thumshirn
2025-10-01 7:28 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 13/15] blktrace: trace zone management operations Johannes Thumshirn
2025-10-01 7:30 ` Damien Le Moal
2025-10-08 13:29 ` Johannes Thumshirn
2025-10-08 22:41 ` Damien Le Moal
2025-10-09 9:57 ` Johannes Thumshirn
2025-09-25 15:02 ` [PATCH v2 14/15] blktrace: trace zone write plugging operations Johannes Thumshirn
2025-10-01 7:31 ` Damien Le Moal
2025-09-25 15:02 ` [PATCH v2 15/15] blktrace: handle BLKTRACESETUP2 ioctl Johannes Thumshirn
2025-10-01 7:35 ` Damien Le Moal
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=16684b73-7659-49e9-82db-cdd54bf0d2cd@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=chaitanyak@nvidia.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=johannes.thumshirn@wdc.com \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrace@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=rostedt@goodmis.org \
--cc=shinichiro.kawasaki@wdc.com \
/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).