From nobody Thu Oct 2 02:16:50 2025 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74F6F306499; Thu, 25 Sep 2025 15:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758812748; cv=none; b=hVlXN1Xjcde+/sTDrow0XUfc5PU4SEFy9FOED5zAl9ht1suBonNwMzpK8OTM+KcJtL2guTIwCaYhGvK0pl2/8KugLDRp6Wd9a8nyAkoB+/HZiJgxGOPm6ArQA+cB84viuXNmMG0s9lrV0W4LzEhdr2YWnRddlgkpHdk20lyKz/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758812748; c=relaxed/simple; bh=NlP9p8yLWcSJahQC+UEL2+MNqHwl4Hkpnif3ssjYDYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eef08lvFl6YhqsUKGee45Ww1OzCqG8CpIu+tvqTX0rds4QM3yED8gbSUd9pexmz9nD5Fa/L6O4djGcFQ9NAGXLoRmIE5xaUs9eW8vLHVp7jwlFo++44Y/9NQzirkEfw///3IvonywWdDKMXXgTFpA2RNzS73cd7ytvpGwbgPrbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=JSW2bw1v; arc=none smtp.client-ip=216.71.153.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="JSW2bw1v" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1758812746; x=1790348746; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NlP9p8yLWcSJahQC+UEL2+MNqHwl4Hkpnif3ssjYDYs=; b=JSW2bw1vipMyb6RFb3zZq2/EDEdXgh2quUJjfIM/IMvTFCwywQRVSqtI +B6XszSN9qepj7KUGhJdN72Z+z/gvBRulXjrR4+r89B4yrzOddFyZROVI rvYcg9O8sS5qooU3XvQ97WUubkJwq3Q5igNxTqSdXDu+RpVeW3ZvtQluM Dykpyn1BFOaBPbdLFg+AhCaGxmeyMYfx6byl1dfVjhYTlX1YqjTTSQK7U 9cQJiOGvtewBRH4aXtaeWCxUUYzC2COkzddXVNeZpTt4Vm76pl1o//A2R DVGkffhYKmHThZclWKZIHB4cY3TQHXf4LlUlXMxeD/P512/j4Pno9PhRH g==; X-CSE-ConnectionGUID: vjANS3GtSDmwj6eseH42uA== X-CSE-MsgGUID: UEXeBfu+St+n75Sd9210wg== X-IronPort-AV: E=Sophos;i="6.18,292,1751212800"; d="scan'208";a="130349485" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Sep 2025 23:05:45 +0800 IronPort-SDR: 68d55a49_cQyJbW5pGslHfQDndoa+VS80tDtadeapm4JOmAQpZ0Ek9ZC usEduMwA+QIDXTNu6pe1jRjtYVCEoUhUyl2bR2A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Sep 2025 08:05:46 -0700 WDCIronportException: Internal Received: from c02g55f6ml85.ad.shared (HELO C02G55F6ML85.wdc.com) ([10.224.183.46]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Sep 2025 08:05:43 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-btrace@vger.kernel.org, John Garry , Hannes Reinecke , Damien Le Moal , Christoph Hellwig , Naohiro Aota , Shinichiro Kawasaki , Chaitanya Kulkarni , "Martin K . Petersen" , Johannes Thumshirn Subject: [PATCH blktrace v2 17/22] blkparse: natively parse blk_io_trace2 Date: Thu, 25 Sep 2025 17:04:22 +0200 Message-ID: <20250925150427.67394-18-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250925150427.67394-1-johannes.thumshirn@wdc.com> References: <20250925150427.67394-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Natively parse 'struct blk_io_trace2' from a blktrace binary. Signed-off-by: Johannes Thumshirn --- blkparse.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++ blktrace.h | 18 +++++++++ 2 files changed, 130 insertions(+) diff --git a/blkparse.c b/blkparse.c index 7100009..2eec3a9 100644 --- a/blkparse.c +++ b/blkparse.c @@ -2471,6 +2471,37 @@ static int read_one_bit(int fd, struct blk_io_trace2= **bit2, int block, return 0; } =20 +static int read_one_bit2(int fd, struct blk_io_trace2 **bit2, int block, + int *fdblock) +{ + struct blk_io_trace2 *new =3D *bit2; + int ret; + int pdu_len; + void *p; + + p =3D (void *) ((u8 *)new + sizeof(__u32)); + + ret =3D read_data(fd, p, sizeof(*new) - sizeof(__u32), block, fdblock); + if (ret) + return ret; + + pdu_len =3D get_pdulen(new->pdu_len); + if (pdu_len) { + void *ptr =3D realloc(new, sizeof(*new) + pdu_len); + + ret =3D read_data(fd, ptr + sizeof(*new), pdu_len, 1, fdblock); + if (ret) { + free(ptr); + return ret; + } + new =3D ptr; + } + + bit2_trace_to_cpu(new); + *bit2 =3D new; + + return 0; +} static int read_events(int fd, int always_block, int *fdblock) { struct per_dev_info *pdi =3D NULL; @@ -2538,6 +2569,44 @@ static int read_events(int fd, int always_block, int= *fdblock) t->next =3D trace_list; trace_list =3D t; =20 + if (!pdi || pdi->dev !=3D bit->device) + pdi =3D get_dev_info(bit->device); + + if (bit->time > pdi->last_read_time) + pdi->last_read_time =3D bit->time; + } else if (version =3D=3D SUPPORTED_VERSION2) { + struct blk_io_trace2 *bit; + bit =3D bit_alloc(); + bit->magic =3D magic; + + ret =3D read_one_bit2(fd, &bit, 1, fdblock); + if (ret) + break; + + /* + * not a real trace, so grab and handle it here + */ + if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY) && + (bit->action & ~__BLK_TN_CGROUP) !=3D BLK_TN_MESSAGE) { + handle_notify(bit); + output_binary(bit, sizeof(*bit) + bit->pdu_len); + continue; + } + + if (verify_trace(bit->magic)) { + bit_free(bit); + bit =3D NULL; + continue; + } + + t =3D t_alloc(); + memset(t, 0, sizeof(*t)); + t->bit =3D bit; + t->read_sequence =3D read_sequence; + + t->next =3D trace_list; + trace_list =3D t; + if (!pdi || pdi->dev !=3D bit->device) pdi =3D get_dev_info(bit->device); =20 @@ -2698,6 +2767,49 @@ static int ms_prime(struct ms_stream *msp) msp->last->next =3D t; msp->last =3D t; } + } else if (version =3D=3D SUPPORTED_VERSION2) { + bit =3D bit_alloc(); + bit->magic =3D magic; + + ret =3D read_one_bit2(pci->fd, &bit, 1, &pci->fdblock); + if (ret) + goto err; + + if (verify_trace(bit->magic)) + goto err; + + if (bit->cpu !=3D pci->cpu) { + fprintf(stderr, + "cpu %d trace info has error cpu %d\n", + pci->cpu, bit->cpu); + continue; + } + + if (bit->action & BLK_TC_ACT(BLK_TC_NOTIFY) && + (bit->action & ~__BLK_TN_CGROUP) !=3D BLK_TN_MESSAGE) { + handle_notify(bit); + output_binary(bit, sizeof(*bit) + bit->pdu_len); + bit_free(bit); + bit =3D NULL; + + i -=3D 1; + continue; + } + + if (bit->time > pdi->last_read_time) + pdi->last_read_time =3D bit->time; + + t =3D t_alloc(); + memset(t, 0, sizeof(*t)); + t->bit =3D bit; + + if (msp->first =3D=3D NULL) + msp->first =3D msp->last =3D t; + else { + msp->last->next =3D t; + msp->last =3D t; + } + } else { fprintf(stderr, "unsupported version %d\n", version); continue; diff --git a/blktrace.h b/blktrace.h index 196b3c9..ba06237 100644 --- a/blktrace.h +++ b/blktrace.h @@ -129,6 +129,24 @@ static inline void bit_to_bit2(struct blk_io_trace *ol= d, old->pdu_len); } =20 +static inline void bit2_trace_to_cpu(struct blk_io_trace2 *t) +{ + if (data_is_native) + return; + + t->magic =3D be32_to_cpu(t->magic); + t->sequence =3D be32_to_cpu(t->sequence); + t->time =3D be64_to_cpu(t->time); + t->sector =3D be64_to_cpu(t->sector); + t->bytes =3D be32_to_cpu(t->bytes); + t->action =3D be64_to_cpu(t->action); + t->pid =3D be32_to_cpu(t->pid); + t->device =3D be32_to_cpu(t->device); + t->cpu =3D be32_to_cpu(t->cpu); + t->error =3D be16_to_cpu(t->error); + t->pdu_len =3D be16_to_cpu(t->pdu_len); +} + static inline void bit_trace_to_cpu(struct blk_io_trace *t) { if (data_is_native) --=20 2.51.0