* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
@ 2017-06-06 11:27 Marta Rybczynska
2017-06-06 11:59 ` Sagi Grimberg
0 siblings, 1 reply; 6+ messages in thread
From: Marta Rybczynska @ 2017-06-06 11:27 UTC (permalink / raw)
This patch improves the way the RDMA IB signalling is done
by using atomic operations for the signalling variable. This
avoids race conditions on sig_count.
The signalling interval changes slightly and is now the
largest power of two not larger than queue depth / 2.
ilog() usage idea by Bart Van Assche.
Signed-off-by: Marta Rybczynska <marta.rybczynska at kalray.eu>
Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
---
Changes from v1:
* remove nvme_rdma_init_sig_count, put all into
nvme_rdma_queue_sig_limit
---
drivers/nvme/host/rdma.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 28bd255..4eb4846 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -88,7 +88,7 @@ enum nvme_rdma_queue_flags {
struct nvme_rdma_queue {
struct nvme_rdma_qe *rsp_ring;
- u8 sig_count;
+ atomic_t sig_count;
int queue_size;
size_t cmnd_capsule_len;
struct nvme_rdma_ctrl *ctrl;
@@ -554,6 +554,8 @@ static int nvme_rdma_init_queue(struct nvme_rdma_ctrl *ctrl,
queue->queue_size = queue_size;
+ atomic_set(&queue->sig_count, 0);
+
queue->cm_id = rdma_create_id(&init_net, nvme_rdma_cm_handler, queue,
RDMA_PS_TCP, IB_QPT_RC);
if (IS_ERR(queue->cm_id)) {
@@ -1038,17 +1040,18 @@ static void nvme_rdma_send_done(struct ib_cq *cq, struct ib_wc *wc)
nvme_rdma_wr_error(cq, wc, "SEND");
}
-static inline int nvme_rdma_queue_sig_limit(struct nvme_rdma_queue *queue)
+static inline bool nvme_rdma_queue_sig_limit(struct nvme_rdma_queue *queue)
{
- int sig_limit;
+ int limit;
- /*
- * We signal completion every queue depth/2 and also handle the
- * degenerated case of a device with queue_depth=1, where we
- * would need to signal every message.
+ /* We want to signal completion at least every queue depth/2.
+ * This returns the largest power of two that is not above half
+ * of (queue size + 1) to optimize (avoid divisions).
*/
- sig_limit = max(queue->queue_size / 2, 1);
- return (++queue->sig_count % sig_limit) == 0;
+ limit = 1 << ilog2((queue->queue_size + 1) / 2);
+
+ /* Signal if sig_count is a multiple of limit */
+ return (atomic_inc_return(&queue->sig_count) & (limit - 1)) == 0;
}
static int nvme_rdma_post_send(struct nvme_rdma_queue *queue,
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
2017-06-06 11:27 [PATCH v2] nvme-rdma: remove race conditions from IB signalling Marta Rybczynska
@ 2017-06-06 11:59 ` Sagi Grimberg
2017-06-07 8:25 ` Christoph Hellwig
0 siblings, 1 reply; 6+ messages in thread
From: Sagi Grimberg @ 2017-06-06 11:59 UTC (permalink / raw)
Christoph,
Can you place a stable tag on this (4.11+)?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
2017-06-06 11:59 ` Sagi Grimberg
@ 2017-06-07 8:25 ` Christoph Hellwig
2017-06-21 15:14 ` Marta Rybczynska
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2017-06-07 8:25 UTC (permalink / raw)
On Tue, Jun 06, 2017@02:59:43PM +0300, Sagi Grimberg wrote:
> Christoph,
>
> Can you place a stable tag on this (4.11+)?
Added.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
2017-06-07 8:25 ` Christoph Hellwig
@ 2017-06-21 15:14 ` Marta Rybczynska
2017-07-05 17:04 ` Christoph Hellwig
0 siblings, 1 reply; 6+ messages in thread
From: Marta Rybczynska @ 2017-06-21 15:14 UTC (permalink / raw)
> On Tue, Jun 06, 2017@02:59:43PM +0300, Sagi Grimberg wrote:
>> Christoph,
>>
>> Can you place a stable tag on this (4.11+)?
>
> Added.
I do not see this one in nvme-4.13. Can we get it in, please?
We're seeing the races in our setup and this patch fixes it.
Thanks,
Marta
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
2017-06-21 15:14 ` Marta Rybczynska
@ 2017-07-05 17:04 ` Christoph Hellwig
2017-07-06 10:44 ` Marta Rybczynska
0 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2017-07-05 17:04 UTC (permalink / raw)
On Wed, Jun 21, 2017@05:14:41PM +0200, Marta Rybczynska wrote:
> I do not see this one in nvme-4.13. Can we get it in, please?
> We're seeing the races in our setup and this patch fixes it.
I've added it. Note that your mail was whitespace damaged, so I had
to apply it manually. I used that opportunity to also move the comments
around a bit.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] nvme-rdma: remove race conditions from IB signalling
2017-07-05 17:04 ` Christoph Hellwig
@ 2017-07-06 10:44 ` Marta Rybczynska
0 siblings, 0 replies; 6+ messages in thread
From: Marta Rybczynska @ 2017-07-06 10:44 UTC (permalink / raw)
> On Wed, Jun 21, 2017@05:14:41PM +0200, Marta Rybczynska wrote:
>> I do not see this one in nvme-4.13. Can we get it in, please?
>> We're seeing the races in our setup and this patch fixes it.
>
> I've added it. Note that your mail was whitespace damaged, so I had
> to apply it manually. I used that opportunity to also move the comments
> around a bit.
Thank you! And sorry for the issue.
Best regards,
Marta
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-07-06 10:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-06 11:27 [PATCH v2] nvme-rdma: remove race conditions from IB signalling Marta Rybczynska
2017-06-06 11:59 ` Sagi Grimberg
2017-06-07 8:25 ` Christoph Hellwig
2017-06-21 15:14 ` Marta Rybczynska
2017-07-05 17:04 ` Christoph Hellwig
2017-07-06 10:44 ` Marta Rybczynska
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox