All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] IB/core: postpone WR initialization during queue drain
@ 2018-01-14 15:07 Max Gurtovoy
       [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Max Gurtovoy @ 2018-01-14 15:07 UTC (permalink / raw)
  To: jgg-VPRAkNaXOzVWk0Htik3J/w, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA, sagi-NQWnxTmZq1alnMjI0IkVqw
  Cc: Max Gurtovoy

No need to initialize completion and WR in case we fail
during QP modification.

Signed-off-by: Max Gurtovoy <maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 drivers/infiniband/core/verbs.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index e36d27e..7868727 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -2156,16 +2156,16 @@ static void __ib_drain_sq(struct ib_qp *qp)
 	struct ib_send_wr swr = {}, *bad_swr;
 	int ret;
 
-	swr.wr_cqe = &sdrain.cqe;
-	sdrain.cqe.done = ib_drain_qp_done;
-	init_completion(&sdrain.done);
-
 	ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
 	if (ret) {
 		WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
 		return;
 	}
 
+	swr.wr_cqe = &sdrain.cqe;
+	sdrain.cqe.done = ib_drain_qp_done;
+	init_completion(&sdrain.done);
+
 	ret = ib_post_send(qp, &swr, &bad_swr);
 	if (ret) {
 		WARN_ONCE(ret, "failed to drain send queue: %d\n", ret);
@@ -2190,16 +2190,16 @@ static void __ib_drain_rq(struct ib_qp *qp)
 	struct ib_recv_wr rwr = {}, *bad_rwr;
 	int ret;
 
-	rwr.wr_cqe = &rdrain.cqe;
-	rdrain.cqe.done = ib_drain_qp_done;
-	init_completion(&rdrain.done);
-
 	ret = ib_modify_qp(qp, &attr, IB_QP_STATE);
 	if (ret) {
 		WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret);
 		return;
 	}
 
+	rwr.wr_cqe = &rdrain.cqe;
+	rdrain.cqe.done = ib_drain_qp_done;
+	init_completion(&rdrain.done);
+
 	ret = ib_post_recv(qp, &rwr, &bad_rwr);
 	if (ret) {
 		WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] IB/core: allocate wc array statically
       [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2018-01-14 15:07   ` Max Gurtovoy
       [not found]     ` <1515942470-11461-2-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  2018-01-14 15:07   ` [PATCH 3/3] IB/cq: Don't force IB_POLL_DIRECT poll context for ib_process_cq_direct Max Gurtovoy
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Max Gurtovoy @ 2018-01-14 15:07 UTC (permalink / raw)
  To: jgg-VPRAkNaXOzVWk0Htik3J/w, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA, sagi-NQWnxTmZq1alnMjI0IkVqw
  Cc: Max Gurtovoy

The poll batch is small and known at pre-proccessing time.
No need to allocate it dynamically.

Signed-off-by: Max Gurtovoy <maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 drivers/infiniband/core/cq.c | 12 +-----------
 include/rdma/ib_verbs.h      |  5 ++++-
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c
index f2ae75f..637c999 100644
--- a/drivers/infiniband/core/cq.c
+++ b/drivers/infiniband/core/cq.c
@@ -15,9 +15,6 @@
 #include <linux/slab.h>
 #include <rdma/ib_verbs.h>
 
-/* # of WCs to poll for with a single call to ib_poll_cq */
-#define IB_POLL_BATCH			16
-
 /* # of WCs to iterate over before yielding */
 #define IB_POLL_BUDGET_IRQ		256
 #define IB_POLL_BUDGET_WORKQUEUE	65536
@@ -150,10 +147,6 @@ struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
 	cq->poll_ctx = poll_ctx;
 	atomic_set(&cq->usecnt, 0);
 
-	cq->wc = kmalloc_array(IB_POLL_BATCH, sizeof(*cq->wc), GFP_KERNEL);
-	if (!cq->wc)
-		goto out_destroy_cq;
-
 	switch (cq->poll_ctx) {
 	case IB_POLL_DIRECT:
 		cq->comp_handler = ib_cq_completion_direct;
@@ -171,13 +164,11 @@ struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
 		break;
 	default:
 		ret = -EINVAL;
-		goto out_free_wc;
+		goto out_destroy_cq;
 	}
 
 	return cq;
 
-out_free_wc:
-	kfree(cq->wc);
 out_destroy_cq:
 	cq->device->destroy_cq(cq);
 	return ERR_PTR(ret);
@@ -208,7 +199,6 @@ void ib_free_cq(struct ib_cq *cq)
 		WARN_ON_ONCE(1);
 	}
 
-	kfree(cq->wc);
 	ret = cq->device->destroy_cq(cq);
 	WARN_ON_ONCE(ret);
 }
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index fd84cda..3538add 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1549,6 +1549,9 @@ struct ib_ah {
 
 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
 
+/* # of WCs to poll for with a single call to ib_poll_cq */
+#define IB_POLL_BATCH			16
+
 enum ib_poll_context {
 	IB_POLL_DIRECT,		/* caller context, no hw completions */
 	IB_POLL_SOFTIRQ,	/* poll from softirq context */
@@ -1564,7 +1567,7 @@ struct ib_cq {
 	int               	cqe;
 	atomic_t          	usecnt; /* count number of work queues */
 	enum ib_poll_context	poll_ctx;
-	struct ib_wc		*wc;
+	struct ib_wc		wc[IB_POLL_BATCH];
 	union {
 		struct irq_poll		iop;
 		struct work_struct	work;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] IB/cq: Don't force IB_POLL_DIRECT poll context for ib_process_cq_direct
       [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  2018-01-14 15:07   ` [PATCH 2/3] IB/core: allocate wc array statically Max Gurtovoy
@ 2018-01-14 15:07   ` Max Gurtovoy
  2018-01-14 16:20   ` [PATCH 1/3] IB/core: postpone WR initialization during queue drain Sagi Grimberg
  2018-01-17 21:10   ` Doug Ledford
  3 siblings, 0 replies; 8+ messages in thread
From: Max Gurtovoy @ 2018-01-14 15:07 UTC (permalink / raw)
  To: jgg-VPRAkNaXOzVWk0Htik3J/w, linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA, sagi-NQWnxTmZq1alnMjI0IkVqw
  Cc: Bart Van Assche, Max Gurtovoy

From: Sagi Grimberg <sagi-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>

polling the completion queue directly does not interfere
with the existing polling logic, hence drop the requirement.
Be aware that running ib_process_cq_direct with non IB_POLL_DIRECT
CQ may trigger concurrent CQ processing.

This can be used for polling mode ULPs.

Cc: Bart Van Assche <bart.vanassche-Sjgp3cTcYWE@public.gmane.org>
Reported-by: Steve Wise <swise-7bPotxP6k4+P2YhJcF5u+vpXobYPEAuW@public.gmane.org>
Signed-off-by: Sagi Grimberg <sagi-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
[maxg: added wcs array argument to __ib_process_cq]
Signed-off-by: Max Gurtovoy <maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 drivers/infiniband/core/cq.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c
index 637c999..0519130 100644
--- a/drivers/infiniband/core/cq.c
+++ b/drivers/infiniband/core/cq.c
@@ -22,9 +22,10 @@
 #define IB_POLL_FLAGS \
 	(IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS)
 
-static int __ib_process_cq(struct ib_cq *cq, int budget)
+static int __ib_process_cq(struct ib_cq *cq, int budget, struct ib_wc *poll_wc)
 {
 	int i, n, completed = 0;
+	struct ib_wc *wcs = poll_wc ? : cq->wc;
 
 	/*
 	 * budget might be (-1) if the caller does not
@@ -32,9 +33,9 @@ static int __ib_process_cq(struct ib_cq *cq, int budget)
 	 * minimum here.
 	 */
 	while ((n = ib_poll_cq(cq, min_t(u32, IB_POLL_BATCH,
-			budget - completed), cq->wc)) > 0) {
+			budget - completed), wcs)) > 0) {
 		for (i = 0; i < n; i++) {
-			struct ib_wc *wc = &cq->wc[i];
+			struct ib_wc *wc = &wcs[i];
 
 			if (wc->wr_cqe)
 				wc->wr_cqe->done(cq, wc);
@@ -57,18 +58,20 @@ static int __ib_process_cq(struct ib_cq *cq, int budget)
  * @cq:		CQ to process
  * @budget:	number of CQEs to poll for
  *
- * This function is used to process all outstanding CQ entries on a
- * %IB_POLL_DIRECT CQ.  It does not offload CQ processing to a different
- * context and does not ask for completion interrupts from the HCA.
+ * This function is used to process all outstanding CQ entries.
+ * It does not offload CQ processing to a different context and does
+ * not ask for completion interrupts from the HCA.
+ * Using direct processing on CQ with non IB_POLL_DIRECT type may trigger
+ * concurrent processing.
  *
  * Note: do not pass -1 as %budget unless it is guaranteed that the number
  * of completions that will be processed is small.
  */
 int ib_process_cq_direct(struct ib_cq *cq, int budget)
 {
-	WARN_ON_ONCE(cq->poll_ctx != IB_POLL_DIRECT);
+	struct ib_wc wcs[IB_POLL_BATCH];
 
-	return __ib_process_cq(cq, budget);
+	return __ib_process_cq(cq, budget, wcs);
 }
 EXPORT_SYMBOL(ib_process_cq_direct);
 
@@ -82,7 +85,7 @@ static int ib_poll_handler(struct irq_poll *iop, int budget)
 	struct ib_cq *cq = container_of(iop, struct ib_cq, iop);
 	int completed;
 
-	completed = __ib_process_cq(cq, budget);
+	completed = __ib_process_cq(cq, budget, NULL);
 	if (completed < budget) {
 		irq_poll_complete(&cq->iop);
 		if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0)
@@ -102,7 +105,7 @@ static void ib_cq_poll_work(struct work_struct *work)
 	struct ib_cq *cq = container_of(work, struct ib_cq, work);
 	int completed;
 
-	completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE);
+	completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE, NULL);
 	if (completed >= IB_POLL_BUDGET_WORKQUEUE ||
 	    ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0)
 		queue_work(ib_comp_wq, &cq->work);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] IB/core: postpone WR initialization during queue drain
       [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  2018-01-14 15:07   ` [PATCH 2/3] IB/core: allocate wc array statically Max Gurtovoy
  2018-01-14 15:07   ` [PATCH 3/3] IB/cq: Don't force IB_POLL_DIRECT poll context for ib_process_cq_direct Max Gurtovoy
@ 2018-01-14 16:20   ` Sagi Grimberg
  2018-01-17 21:10   ` Doug Ledford
  3 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2018-01-14 16:20 UTC (permalink / raw)
  To: Max Gurtovoy, jgg-VPRAkNaXOzVWk0Htik3J/w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA

OK...

> No need to initialize completion and WR in case we fail
> during QP modification.

Acked-by: Sagi Grimberg <sagi-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] IB/core: allocate wc array statically
       [not found]     ` <1515942470-11461-2-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2018-01-14 16:22       ` Sagi Grimberg
       [not found]         ` <70221289-a8a7-91cf-7975-cf0ad60c9018-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Sagi Grimberg @ 2018-01-14 16:22 UTC (permalink / raw)
  To: Max Gurtovoy, jgg-VPRAkNaXOzVWk0Htik3J/w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA


> The poll batch is small and known at pre-proccessing time.
> No need to allocate it dynamically.

Any specific reason why all CQ allocators (including userspace)
should allocate this array (as small as it is...)
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] IB/core: allocate wc array statically
       [not found]         ` <70221289-a8a7-91cf-7975-cf0ad60c9018-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
@ 2018-01-15 11:00           ` Max Gurtovoy
       [not found]             ` <5b245fae-5696-3fa6-2b51-be263d8b9684-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Max Gurtovoy @ 2018-01-15 11:00 UTC (permalink / raw)
  To: Sagi Grimberg, jgg-VPRAkNaXOzVWk0Htik3J/w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA



On 1/14/2018 6:22 PM, Sagi Grimberg wrote:
> 
>> The poll batch is small and known at pre-proccessing time.
>> No need to allocate it dynamically.
> 
> Any specific reason why all CQ allocators (including userspace)
> should allocate this array (as small as it is...)

For kernel allocators, I think we're ok with this approach since we 
allocate it dynamically anyway.
I guess you're right regarding the user space, so we can ignore this 
patch and push the other 2 or we can live with this allocation and save 
few lines of code for dynamic alloc/free of wcs.

I'm good with both approaches.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] IB/core: allocate wc array statically
       [not found]             ` <5b245fae-5696-3fa6-2b51-be263d8b9684-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
@ 2018-01-17  8:28               ` Sagi Grimberg
  0 siblings, 0 replies; 8+ messages in thread
From: Sagi Grimberg @ 2018-01-17  8:28 UTC (permalink / raw)
  To: Max Gurtovoy, jgg-VPRAkNaXOzVWk0Htik3J/w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA,
	dledford-H+wXaHxf7aLQT0dZR+AlfA


> so we can ignore this patch and push the other 2

Sounds fine,

Jason, can you pick it up?
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] IB/core: postpone WR initialization during queue drain
       [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2018-01-14 16:20   ` [PATCH 1/3] IB/core: postpone WR initialization during queue drain Sagi Grimberg
@ 2018-01-17 21:10   ` Doug Ledford
  3 siblings, 0 replies; 8+ messages in thread
From: Doug Ledford @ 2018-01-17 21:10 UTC (permalink / raw)
  To: Max Gurtovoy, jgg-VPRAkNaXOzVWk0Htik3J/w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA, sagi-NQWnxTmZq1alnMjI0IkVqw

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

On Sun, 2018-01-14 at 17:07 +0200, Max Gurtovoy wrote:
> No need to initialize completion and WR in case we fail
> during QP modification.
> 
> Signed-off-by: Max Gurtovoy <maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> ---

Patch 1 and 3 applied, 2 dropped.  Thanks.

-- 
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-01-17 21:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-14 15:07 [PATCH 1/3] IB/core: postpone WR initialization during queue drain Max Gurtovoy
     [not found] ` <1515942470-11461-1-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-14 15:07   ` [PATCH 2/3] IB/core: allocate wc array statically Max Gurtovoy
     [not found]     ` <1515942470-11461-2-git-send-email-maxg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-14 16:22       ` Sagi Grimberg
     [not found]         ` <70221289-a8a7-91cf-7975-cf0ad60c9018-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2018-01-15 11:00           ` Max Gurtovoy
     [not found]             ` <5b245fae-5696-3fa6-2b51-be263d8b9684-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-17  8:28               ` Sagi Grimberg
2018-01-14 15:07   ` [PATCH 3/3] IB/cq: Don't force IB_POLL_DIRECT poll context for ib_process_cq_direct Max Gurtovoy
2018-01-14 16:20   ` [PATCH 1/3] IB/core: postpone WR initialization during queue drain Sagi Grimberg
2018-01-17 21:10   ` Doug Ledford

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.