qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Fomichev <Dmitry.Fomichev@wdc.com>
To: Keith Busch <kbusch@kernel.org>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	Klaus Jensen <k.jensen@samsung.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Niklas Cassel" <Niklas.Cassel@wdc.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: RE: [PATCH 3/9] hw/block/nvme: support per-namespace smart log
Date: Tue, 6 Oct 2020 01:57:18 +0000	[thread overview]
Message-ID: <MN2PR04MB59511A76ECDD83C8A41DA61CE10D0@MN2PR04MB5951.namprd04.prod.outlook.com> (raw)
In-Reply-To: <20200930220414.562527-4-kbusch@kernel.org>

> -----Original Message-----
> From: Keith Busch <kbusch@kernel.org>
> Sent: Wednesday, September 30, 2020 6:04 PM
> To: qemu-block@nongnu.org; qemu-devel@nongnu.org; Klaus Jensen
> <k.jensen@samsung.com>
> Cc: Niklas Cassel <Niklas.Cassel@wdc.com>; Dmitry Fomichev
> <Dmitry.Fomichev@wdc.com>; Kevin Wolf <kwolf@redhat.com>; Philippe
> Mathieu-Daudé <philmd@redhat.com>; Keith Busch <kbusch@kernel.org>
> Subject: [PATCH 3/9] hw/block/nvme: support per-namespace smart log
> 
> Let the user specify a specific namespace if they want to get access
> stats for a specific namespace.
> 
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
>  hw/block/nvme.c      | 66 +++++++++++++++++++++++++++-----------------
>  include/block/nvme.h |  1 +
>  2 files changed, 41 insertions(+), 26 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index 8d2b5be567..41389b2b09 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -1164,48 +1164,62 @@ static uint16_t nvme_create_sq(NvmeCtrl *n,
> NvmeRequest *req)
>      return NVME_SUCCESS;
>  }
> 
> +struct nvme_stats {
> +    uint64_t units_read;
> +    uint64_t units_written;
> +    uint64_t read_commands;
> +    uint64_t write_commands;
> +};
> +
> +static void nvme_set_blk_stats(NvmeNamespace *ns, struct nvme_stats
> *stats)
> +{
> +    BlockAcctStats *s = blk_get_stats(ns->blkconf.blk);
> +
> +    stats->units_read += s->nr_bytes[BLOCK_ACCT_READ] >>
> BDRV_SECTOR_BITS;
> +    stats->units_written += s->nr_bytes[BLOCK_ACCT_WRITE] >>
> BDRV_SECTOR_BITS;
> +    stats->read_commands += s->nr_ops[BLOCK_ACCT_READ];
> +    stats->write_commands += s->nr_ops[BLOCK_ACCT_WRITE];
> +}
> +
>  static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t
> buf_len,
>                                  uint64_t off, NvmeRequest *req)
>  {
>      uint32_t nsid = le32_to_cpu(req->cmd.nsid);
> -
> +    struct nvme_stats stats = { 0 };
> +    NvmeSmartLog smart = { 0 };
>      uint32_t trans_len;
> +    NvmeNamespace *ns;
>      time_t current_ms;
> -    uint64_t units_read = 0, units_written = 0;
> -    uint64_t read_commands = 0, write_commands = 0;
> -    NvmeSmartLog smart;
> -
> -    if (nsid && nsid != 0xffffffff) {
> -        return NVME_INVALID_FIELD | NVME_DNR;
> -    }
> 
>      if (off >= sizeof(smart)) {
>          return NVME_INVALID_FIELD | NVME_DNR;
>      }
> 
> -    for (int i = 1; i <= n->num_namespaces; i++) {
> -        NvmeNamespace *ns = nvme_ns(n, i);
> -        if (!ns) {
> -            continue;
> -        }
> -
> -        BlockAcctStats *s = blk_get_stats(ns->blkconf.blk);
> +    if (nsid != 0xffffffff) {
> +        ns = nvme_ns(n, nsid);
> +        if (!ns)
> +            return NVME_INVALID_NSID | NVME_DNR;

checkpatch will complain about missing curly braces here

> +        nvme_set_blk_stats(ns, &stats);
> +    } else {
> +        int i;
> 
> -        units_read += s->nr_bytes[BLOCK_ACCT_READ] >>
> BDRV_SECTOR_BITS;
> -        units_written += s->nr_bytes[BLOCK_ACCT_WRITE] >>
> BDRV_SECTOR_BITS;
> -        read_commands += s->nr_ops[BLOCK_ACCT_READ];
> -        write_commands += s->nr_ops[BLOCK_ACCT_WRITE];
> +        for (i = 1; i <= n->num_namespaces; i++) {
> +            ns = nvme_ns(n, i);
> +            if (!ns) {
> +                continue;
> +            }
> +            nvme_set_blk_stats(ns, &stats);
> +        }
>      }
> 
>      trans_len = MIN(sizeof(smart) - off, buf_len);
> 
> -    memset(&smart, 0x0, sizeof(smart));
> -
> -    smart.data_units_read[0] = cpu_to_le64(DIV_ROUND_UP(units_read,
> 1000));
> -    smart.data_units_written[0] =
> cpu_to_le64(DIV_ROUND_UP(units_written,
> +    smart.data_units_read[0] =
> cpu_to_le64(DIV_ROUND_UP(stats.units_read,
> +                                                        1000));
> +    smart.data_units_written[0] =
> cpu_to_le64(DIV_ROUND_UP(stats.units_written,
>                                                             1000));
> -    smart.host_read_commands[0] = cpu_to_le64(read_commands);
> -    smart.host_write_commands[0] = cpu_to_le64(write_commands);
> +    smart.host_read_commands[0] = cpu_to_le64(stats.read_commands);
> +    smart.host_write_commands[0] = cpu_to_le64(stats.write_commands);
> 
>      smart.temperature = cpu_to_le16(n->temperature);
> 
> @@ -2708,7 +2722,7 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice
> *pci_dev)
>      id->acl = 3;
>      id->aerl = n->params.aerl;
>      id->frmw = (NVME_NUM_FW_SLOTS << 1) | NVME_FRMW_SLOT1_RO;
> -    id->lpa = NVME_LPA_EXTENDED;
> +    id->lpa = NVME_LPA_NS_SMART | NVME_LPA_EXTENDED;
> 
>      /* recommended default value (~70 C) */
>      id->wctemp = cpu_to_le16(NVME_TEMPERATURE_WARNING);
> diff --git a/include/block/nvme.h b/include/block/nvme.h
> index 58647bcdad..868cf53f0b 100644
> --- a/include/block/nvme.h
> +++ b/include/block/nvme.h
> @@ -849,6 +849,7 @@ enum NvmeIdCtrlFrmw {
>  };
> 
>  enum NvmeIdCtrlLpa {
> +    NVME_LPA_NS_SMART = 1 << 0,
>      NVME_LPA_EXTENDED = 1 << 2,
>  };
> 
> --
> 2.24.1



  parent reply	other threads:[~2020-10-06  1:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-30 22:04 [PATCH 0/9] nvme qemu cleanups and fixes Keith Busch
2020-09-30 22:04 ` [PATCH 1/9] hw/block/nvme: remove pointless rw indirection Keith Busch
2020-10-01  4:05   ` Klaus Jensen
2020-10-01  8:48     ` Klaus Jensen
2020-10-01 15:24       ` Keith Busch
2020-10-01 18:34     ` Klaus Jensen
2020-10-06  1:49   ` Dmitry Fomichev
2020-09-30 22:04 ` [PATCH 2/9] hw/block/nvme: fix log page offset check Keith Busch
2020-09-30 23:18   ` Dmitry Fomichev
2020-10-01  4:05   ` Klaus Jensen
2020-10-01 10:11   ` Philippe Mathieu-Daudé
2020-09-30 22:04 ` [PATCH 3/9] hw/block/nvme: support per-namespace smart log Keith Busch
2020-10-01  4:10   ` Klaus Jensen
2020-10-01 15:20     ` Keith Busch
2020-10-01 17:18       ` Klaus Jensen
2020-10-01 17:30         ` Keith Busch
2020-10-01 17:34           ` Klaus Jensen
2020-10-02  8:48   ` Klaus Jensen
2020-10-06  1:57   ` Dmitry Fomichev [this message]
2020-09-30 22:04 ` [PATCH 4/9] hw/block/nvme: validate command set selected Keith Busch
2020-10-01  4:14   ` Klaus Jensen
2020-09-30 22:04 ` [PATCH 5/9] hw/block/nvme: support for admin-only command set Keith Busch
2020-10-01  0:11   ` Dmitry Fomichev
2020-10-01  4:17   ` Klaus Jensen
2020-09-30 22:04 ` [PATCH 6/9] hw/block/nvme: reject io commands if only admin command set selected Keith Busch
2020-09-30 23:11   ` Dmitry Fomichev
2020-09-30 22:04 ` [PATCH 7/9] hw/block/nvme: add nsid to get/setfeat trace events Keith Busch
2020-09-30 22:04 ` [PATCH 8/9] hw/block/nvme: add trace event for requests with non-zero status code Keith Busch
2020-09-30 23:21   ` Dmitry Fomichev
2020-10-01 15:25   ` Philippe Mathieu-Daudé
2020-09-30 22:04 ` [PATCH 9/9] hw/block/nvme: report actual LBA data shift in LBAF Keith Busch
2020-10-01  9:48   ` Klaus Jensen
2020-10-01 18:46 ` [PATCH 0/9] nvme qemu cleanups and fixes Klaus Jensen
2020-10-13  9:04 ` Klaus Jensen
2020-10-13 17:48   ` Keith Busch
2020-10-13 18:36     ` Klaus Jensen

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=MN2PR04MB59511A76ECDD83C8A41DA61CE10D0@MN2PR04MB5951.namprd04.prod.outlook.com \
    --to=dmitry.fomichev@wdc.com \
    --cc=Niklas.Cassel@wdc.com \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=kwolf@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).