From nobody Sun May 19 13:34:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601569787; cv=none; d=zohomail.com; s=zohoarc; b=cKuUuQmmcIiCHpCYX9k/v775fpFWSJ1jry/yPz+HPXcOzm4jyUP4r8SfnB2GgwCYWW+ELQcuMJHDKelK4LA2ptQKRpdOVtvedVTN9H/kFz/wkSx6VCSXT8UgqrXoENBJbshjR9SsG2pEPz1/SMdU2xqDmwdXUT/srD28LuiMI10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601569787; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=GFpPeAXjKc/8xBfSvvEE2WqFS5XinOd4OXRsQgDMK1U=; b=fKjjORD4DYed8oVHB0l9k4Nd//YVP3g5HLqDP+wpAYxeLVD1t1cSDCt1oYIVzdUH+CPJOtUb7AjSkKjiI1z+tR63G1HU1GsjHoHjShDAGYzuJfOxAu+dYVvUQjgkyuw5MtufhUZ9FORVUxWKfTRDRySdJw745pMv54/GRgAcbQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601569787294894.2590483233548; Thu, 1 Oct 2020 09:29:47 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-1b9zmCTePpiWCQXPWy6few-1; Thu, 01 Oct 2020 12:29:44 -0400 Received: by mail-wr1-f71.google.com with SMTP id l17so2236863wrw.11 for ; Thu, 01 Oct 2020 09:29:44 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (74.red-83-53-161.dynamicip.rima-tde.net. [83.53.161.74]) by smtp.gmail.com with ESMTPSA id m13sm704376wml.5.2020.10.01.09.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2020 09:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601569786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GFpPeAXjKc/8xBfSvvEE2WqFS5XinOd4OXRsQgDMK1U=; b=DP/RrD+BsQqiCGbYgawf4Q22qxh2yBH/gTaCSXp4b4G2FGYoP253cyVKJrpEK4meu+jW44 jAHNk0chO4EpJGSvrFN3Sv0dQoT/MMiIziHPfXCoKyBWVGQA1QtYkagYXWhiIKHyIcowey MOp+vQFeGeq6qg0wG9W91ARlJGlFIFM= X-MC-Unique: 1b9zmCTePpiWCQXPWy6few-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GFpPeAXjKc/8xBfSvvEE2WqFS5XinOd4OXRsQgDMK1U=; b=I+vdWh775xig0W6k7PGEYQiGP3b7NfgHeXgzTmlFJM6sLkuUS6FuvhrO2dBrLrtq0h lCbCNvlYBC0vIP5mVBIFDl+oqzMFTULX8TE5y8Dd86I2sV/iSrvZia9yLNhffGZ5G95H OUx53arTNA3Yqx0l1y/Oi2cOfsredbAve57H/18u1Z153OpKfSo26pfRKwlWFW1y7JtF QKD8nydFHxu4LBQKz24ep871zD3F5UJPlEatwwr4+AtG4wXTUReGKWK9RtP1Zf4NPPZK AfYxjtAvx2OZsOJU643pC6nNCRIgCeirMVQUmYrlTYSiBEkqHXyc8VLfcmnAGyBHeMYS kV8Q== X-Gm-Message-State: AOAM532Bn3xplfqoIGwggnlhnOVj+d8F7rla2CSYSuNawq1ulZGPNkwi XPRDuRKpL1DrKuLh5mcrI1VhlvZzQmuTfANWYMcBUSzQk0gSnaKlhaTHu/AX+HIu1MtMqiIbuOk NHjkERIx8x1VQhA== X-Received: by 2002:a5d:4811:: with SMTP id l17mr10297741wrq.252.1601569782873; Thu, 01 Oct 2020 09:29:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjTaHuHL75fRAn9iekkKWdwW9UYcdNq30QjO1/sEKgB54Xr0JqhV2TL9p0wC9M0U6PZhXgwg== X-Received: by 2002:a5d:4811:: with SMTP id l17mr10297721wrq.252.1601569782655; Thu, 01 Oct 2020 09:29:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Eric Blake , Fam Zheng , Max Reitz , Kevin Wolf , Stefan Hajnoczi , qemu-block@nongnu.org, Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi Subject: [PATCH v2] block/nvme: Add driver statistics for access alignment and hw errors Date: Thu, 1 Oct 2020 18:29:39 +0200 Message-Id: <20201001162939.1567915-1-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Keep statistics of some hardware errors, and number of aligned/unaligned I/O accesses. QMP example booting a full RHEL 8.3 aarch64 guest: { "execute": "query-blockstats" } { "return": [ { "device": "", "node-name": "drive0", "stats": { "flush_total_time_ns": 6026948, "wr_highest_offset": 3383991230464, "wr_total_time_ns": 807450995, "failed_wr_operations": 0, "failed_rd_operations": 0, "wr_merged": 3, "wr_bytes": 50133504, "failed_unmap_operations": 0, "failed_flush_operations": 0, "account_invalid": false, "rd_total_time_ns": 1846979900, "flush_operations": 130, "wr_operations": 659, "rd_merged": 1192, "rd_bytes": 218244096, "account_failed": false, "idle_time_ns": 2678641497, "rd_operations": 7406, }, "driver-specific": { "driver": "nvme", "completion-errors": 0, "unaligned-accesses": 2959, "aligned-accesses": 4477 }, "qdev": "/machine/peripheral-anon/device[0]/virtio-backend" } ] } Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Markus Armbruster --- v2: 'access-nb' -> 'accesses' (Stefan) --- qapi/block-core.json | 24 +++++++++++++++++++++++- block/nvme.c | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 86ed72ef9f..dec17e3036 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -941,6 +941,27 @@ 'discard-nb-failed': 'uint64', 'discard-bytes-ok': 'uint64' } } =20 +## +# @BlockStatsSpecificNvme: +# +# NVMe driver statistics +# +# @completion-errors: The number of completion errors. +# +# @aligned-accesses: The number of aligned accesses performed by +# the driver. +# +# @unaligned-accesses: The number of unaligned accesses performed by +# the driver. +# +# Since: 5.2 +## +{ 'struct': 'BlockStatsSpecificNvme', + 'data': { + 'completion-errors': 'uint64', + 'aligned-accesses': 'uint64', + 'unaligned-accesses': 'uint64' } } + ## # @BlockStatsSpecific: # @@ -953,7 +974,8 @@ 'discriminator': 'driver', 'data': { 'file': 'BlockStatsSpecificFile', - 'host_device': 'BlockStatsSpecificFile' } } + 'host_device': 'BlockStatsSpecificFile', + 'nvme': 'BlockStatsSpecificNvme' } } =20 ## # @BlockStats: diff --git a/block/nvme.c b/block/nvme.c index f4f27b6da7..ba6d066067 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -133,6 +133,12 @@ struct BDRVNVMeState { =20 /* PCI address (required for nvme_refresh_filename()) */ char *device; + + struct { + uint64_t completion_errors; + uint64_t aligned_accesses; + uint64_t unaligned_accesses; + } stats; }; =20 #define NVME_BLOCK_OPT_DEVICE "device" @@ -389,6 +395,9 @@ static bool nvme_process_completion(NVMeQueuePair *q) break; } ret =3D nvme_translate_error(c); + if (ret) { + s->stats.completion_errors++; + } q->cq.head =3D (q->cq.head + 1) % NVME_QUEUE_SIZE; if (!q->cq.head) { q->cq_phase =3D !q->cq_phase; @@ -1146,8 +1155,10 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_= t offset, uint64_t bytes, assert(QEMU_IS_ALIGNED(bytes, s->page_size)); assert(bytes <=3D s->max_transfer); if (nvme_qiov_aligned(bs, qiov)) { + s->stats.aligned_accesses++; return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flag= s); } + s->stats.unaligned_accesses++; trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); buf =3D qemu_try_memalign(s->page_size, bytes); =20 @@ -1443,6 +1454,21 @@ static void nvme_unregister_buf(BlockDriverState *bs= , void *host) qemu_vfio_dma_unmap(s->vfio, host); } =20 +static BlockStatsSpecific *nvme_get_specific_stats(BlockDriverState *bs) +{ + BlockStatsSpecific *stats =3D g_new(BlockStatsSpecific, 1); + BDRVNVMeState *s =3D bs->opaque; + + stats->driver =3D BLOCKDEV_DRIVER_NVME; + stats->u.nvme =3D (BlockStatsSpecificNvme) { + .completion_errors =3D s->stats.completion_errors, + .aligned_accesses =3D s->stats.aligned_accesses, + .unaligned_accesses =3D s->stats.unaligned_accesses, + }; + + return stats; +} + static const char *const nvme_strong_runtime_opts[] =3D { NVME_BLOCK_OPT_DEVICE, NVME_BLOCK_OPT_NAMESPACE, @@ -1476,6 +1502,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_refresh_filename =3D nvme_refresh_filename, .bdrv_refresh_limits =3D nvme_refresh_limits, .strong_runtime_opts =3D nvme_strong_runtime_opts, + .bdrv_get_specific_stats =3D nvme_get_specific_stats, =20 .bdrv_detach_aio_context =3D nvme_detach_aio_context, .bdrv_attach_aio_context =3D nvme_attach_aio_context, --=20 2.26.2