qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: Jinhao Fan <fanjinhao21s@ict.ac.cn>
Cc: qemu-devel <qemu-devel@nongnu.org>,
	Keith Busch <kbusch@kernel.org>,
	"open list:nvme" <qemu-block@nongnu.org>
Subject: Re: [PATCH] hw/nvme: Add helper functions for qid-db conversion
Date: Tue, 2 Aug 2022 12:05:41 +0200	[thread overview]
Message-ID: <Yuj29dyTTdRug1iu@apples> (raw)
In-Reply-To: <YujmUfXpFXSO8eU5@apples>

[-- Attachment #1: Type: text/plain, Size: 2255 bytes --]

On Aug  2 10:54, Klaus Jensen wrote:
> On Aug  2 16:31, Jinhao Fan wrote:
> > at 2:02 PM, Klaus Jensen <its@irrelevant.dk> wrote:
> > 
> > > On Jul 28 16:07, Jinhao Fan wrote:
> > >> With the introduction of shadow doorbell and ioeventfd, we need to do
> > >> frequent conversion between qid and its doorbell offset. The original
> > >> hard-coded calculation is confusing and error-prone. Add several helper
> > >> functions to do this task.
> > >> 
> > >> Signed-off-by: Jinhao Fan <fanjinhao21s@ict.ac.cn>
> > >> ---
> > >> hw/nvme/ctrl.c | 61 ++++++++++++++++++++++++++++++++------------------
> > >> 1 file changed, 39 insertions(+), 22 deletions(-)
> > >> 
> > >> diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
> > >> index 533ad14e7a..6116c0e660 100644
> > >> --- a/hw/nvme/ctrl.c
> > >> +++ b/hw/nvme/ctrl.c
> > >> @@ -487,6 +487,29 @@ static int nvme_check_cqid(NvmeCtrl *n, uint16_t cqid)
> > >> {
> > >>     return cqid < n->conf_ioqpairs + 1 && n->cq[cqid] != NULL ? 0 : -1;
> > >> }
> > >> +static inline bool nvme_db_offset_is_cq(NvmeCtrl *n, hwaddr offset)
> > >> +{
> > >> +    hwaddr stride = 4 << NVME_CAP_DSTRD(ldq_le_p(&n->bar.cap));
> > >> +    return (offset / stride) & 1;
> > >> +}
> > > 
> > > This can be changed morphed into `(offset >> (2 + dstrd)) & 1` if I am not
> > > mistaken.
> > > 
> > 
> > Yes. But my current code looks more readable to me. Is it necessary to
> > change to `(offset >> (2 + dstrd)) & 1`.
> > 
> 
> I am unsure if the compiler will transform that division into the shift
> if it can infer that the divisor is a power of two (it most likely
> will be able to).
> 
> But I see no reason to have a potential division here when we can do
> without and to me it is just as readable when you know the definition of
> DSTRD is `2 ^ (2 + DSTRD)`.
> 
> > >> +
> > >> +static inline uint16_t nvme_db_offset_to_qid(NvmeCtrl *n, hwaddr offset)
> > >> +{
> > >> +    hwaddr stride = 4 << NVME_CAP_DSTRD(ldq_le_p(&n->bar.cap));
> > >> +    return offset / (2 * stride);
> > >> +}
> > > 
> > > Same, should be able to do `offset >> (2 * dstrd + 1)`, no?
> > 
> > Same as above.
> > 
> 

I meant `offset >> (2 + dstrd + 1)` ('+', not '*') like above of course.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-08-02 10:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28  8:07 [PATCH] hw/nvme: Add helper functions for qid-db conversion Jinhao Fan
2022-08-02  3:46 ` Jinhao Fan
2022-08-02  6:02 ` Klaus Jensen
2022-08-02  8:31   ` Jinhao Fan
2022-08-02  8:54     ` Klaus Jensen
2022-08-02 10:05       ` Klaus Jensen [this message]
2022-08-03  1:46       ` Jinhao Fan
2022-08-03  2:36         ` Keith Busch

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=Yuj29dyTTdRug1iu@apples \
    --to=its@irrelevant.dk \
    --cc=fanjinhao21s@ict.ac.cn \
    --cc=kbusch@kernel.org \
    --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).