Skip to contentSkip to conversation

providers/rxe: Replace '%' with '&' in check_qp_queue_full()

PATCH Superseded Xiao Yang 4 participants 5 messages Jan 11, 2022 – Jan 17, 2022 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 providers/rxe: Replace '%' with '&' in check_qp_queue_full()

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when qp->cur_index is equal to "maximum - 1" (maximum is correct).

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +1 -1
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))
 		qp->err = ENOSPC;
 err:
 	return qp->err;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when qp->cur_index is equal to "maximum - 1" (maximum is correct).

Hi All,

The commit message seems inappropriate so I will resend this patch.

Best Regards,
Xiao Yang

Quoted 23 lines

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +1 -1
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))
 		qp->err = ENOSPC;
 err:
 	return qp->err;
#2 lore raw
Quoted 28 lines · On 1/10/22 20:22, [email protected] wrote:
Quoted 3 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when qp->cur_index is equal to "maximum - 1" (maximum is correct).

Hi All,

The commit message seems inappropriate so I will resend this patch.

Best Regards,
Xiao Yang

Quoted 18 lines

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")
---
 providers/rxe/rxe_queue.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
Quoted 5 lines

providers/rxe/rxe_queue.h static inline int check_qp_queue_full(struct rxe_qp *qp) · line 211

Quoted 5 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))
 		qp->err = ENOSPC;
 err:
 	return qp->err;

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

prod = cons = 0 and is empty and is *not* full

Adding one entry gives

slot[0] = value, prod = 1, cons = 0 and is full and not empty

After reading this value

slot[0] = old value, prod = cons = 1 and queue is empty again.

Writing a new value

slot[1] = new value, slot[0] = old value, prod = 0 and cons = 1 and queue is full again.

The expression full = (cons == ((qp->cur_index + 1) % q->index_mask)) is correct.

Please do not make this change.

Bob

#3 lore raw
Quoted 33 lines · Bob Pearson
Quoted 28 lines · On 1/10/22 20:22, [email protected] wrote:
Quoted 3 lines · Xiao Yang

The expression "cons == ((qp->cur_index + 1) % q->index_mask)" mistakenly assumes the queue is full when qp->cur_index is equal to "maximum - 1" (maximum is correct).

Hi All,

The commit message seems inappropriate so I will resend this patch.

Best Regards,
Xiao Yang

Quoted 18 lines

For example:
If cons and qp->cur_index are 0 and q->index_mask is 1, check_qp_queue_full() reports ENOSPC.

Fixes 1a894ca10105 ("Providers/rxe: Implement ibv_create_qp_ex verb")

---
providers/rxe/rxe_queue.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
providers/rxe/rxe_queue.h +0 -0
index 6de8140c..708e76ac 100644
@@ -205,7 +205,7 @@ static inline int check_qp_queue_full(struct rxe_qp *qp)
 	if (qp->err)
 		goto err;
 
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
providers/rxe/rxe_queue.h +1 -1
-	if (cons == ((qp->cur_index + 1) % q->index_mask))
+	if (cons == ((qp->cur_index + 1) & q->index_mask))
 		qp->err = ENOSPC;

err:

	return qp->err;

The way these queues work they can only hold 2^n - 1 entries. The reason for this is to distinguish empty and full.

You can simply mitigate that by having free-running counters, right?

Thxs, Håkon

Quoted 21 lines

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

prod = cons = 0 and is empty and is *not* full

Adding one entry gives

slot[0] = value, prod = 1, cons = 0 and is full and not empty

After reading this value

slot[0] = old value, prod = cons = 1 and queue is empty again.

Writing a new value

slot[1] = new value, slot[0] = old value, prod = 0 and cons = 1 and queue is full again.

The expression full = (cons == ((qp->cur_index + 1) % q->index_mask)) is correct.

Please do not make this change.

Bob

#4 lore raw
Quoted 4 lines · Haakon Bugge
Quoted 2 lines

The way these queues work they can only hold 2^n - 1 entries. The reason for this is to distinguish empty and full.

You can simply mitigate that by having free-running counters, right?

That is generally the best design, with the cost of doing the & on every use of queue data vs only on ++

Jason