All of lore.kernel.org
 help / color / mirror / Atom feed
From: "yangx.jy@fujitsu.com" <yangx.jy@fujitsu.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: RDMA mailing list <linux-rdma@vger.kernel.org>
Subject: Re: Fwd: Re: [rdma-core PATCH] providers/rxe: Replace '%' with '&' in check_qp_queue_full()
Date: Fri, 21 Jan 2022 06:20:08 +0000	[thread overview]
Message-ID: <61EA5091.5000504@fujitsu.com> (raw)
In-Reply-To: <b25e4695-000f-0f8f-3e50-184e567132b8@gmail.com>

On 2022/1/20 13:08, Bob Pearson wrote:
> On 1/18/22 03:02, yangx.jy@fujitsu.com wrote:
>> CC: linux-rdma mail list
>>
>> On 2022/1/14 4:51, Bob Pearson wrote:
>>> The way these queues work they can only hold 2^n - 1 entries. The reason for this is
>>> to distinguish empty and full. If you let the last entry be written then producer would advance to equal consumer which is the initial empty condition. So a queue which can hold 1 entry has to have two slots (n=1) but can only hold one entry. It begins with
>> Hi Bob,
>>
>> Thanks for your detailed example.
>>> prod = cons = 0 and is empty and is*not*  full
> full = (cons == ((prod + 1) % 2)) = (0 == 1) = false
> empty = (prod == cons) == (0 == 0) = true
>>> Adding one entry gives
>>>
>>> slot[0] = value, prod = 1, cons = 0 and is full and not empty
> full = (cons == ((prod + 1) % 2)) = (0 == 0) = true
> empty = (prod == cons) == (0 == 1) = false
>>> After reading this value
>>>
>>> slot[0] = old value, prod = cons = 1 and queue is empty again.
> full = (cons == ((prod + 1) % 2)) = (1 == 0) = false
> empty = (prod == cons) = (1 == 1) = true
>>> Writing a new value
>>>
>>> slot[1] = new value, slot[0] = old value, prod = 0 and cons = 1 and queue is full again.
> full = (cons == ((prod + 1) % 2)) = (1 == (0 + 1) % 2) = true
> empty = (prod == cons) = (0 == 1) = false
>
> and x % 2^N is the same as x&  (2^N - 1) or x&  index_mask.
Hi Bob,

Agreed.  either x % 2^N or x & (2^N - 1) is fine, but we use the wrong x 
% (2^N - 1) here.

>>> The expression full = (cons == ((qp->cur_index + 1) % q->index_mask)) is correct.
> Actually you are correct. If you look at queue_full() it uses
> full = (cons == (prod + 1)&  q->index_mask) and queue_empty() uses
> empty = (prod == cons) *but*
> check_qp_queue_full() uses
> full = (cons == ((qp->cur_index + 1) % q->index_mask)) with % instead of&.
> I was so used to looking at the first two I missed the error in the last one.
>
> % should be&  like the others.
I will update the commit message and send v2 patch.

Thanks lot.

Best Regards,
Xiao Yang
> Bob
>
>

      reply	other threads:[~2022-01-21  6:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18  9:02 Fwd: Re: [rdma-core PATCH] providers/rxe: Replace '%' with '&' in check_qp_queue_full() yangx.jy
2022-01-20  5:08 ` Bob Pearson
2022-01-21  6:20   ` yangx.jy [this message]

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=61EA5091.5000504@fujitsu.com \
    --to=yangx.jy@fujitsu.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearsonhpe@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.