Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Fri, Nov 13, 2015 at 02:46:43PM +0100, Christoph Hellwig wrote: > This adds an abstraction that allows ULP to simply pass a completion > object and completion callback with each submitted WR and let the RDMA > core handle the nitty gritty details of how to handle completion > interrupts and poll the CQ. This looks pretty nice, I'd really like to look it over carefully after SC|15.. I know Bart and others have attempted to have switching between event and polling driven operation, but there were problems resolving the races. Would be nice to review that conversation.. Do you remember the details Bart? > +static int __ib_process_cq(struct ib_cq *cq, int budget) > +{ > + int i, n, completed = 0; > + > + while ((n = ib_poll_cq(cq, IB_POLL_BATCH, cq->wc)) > 0) { > + completed += n; > + if (completed >= budget) > + break; For instance, like this, not fulling draining the cq and then doing: > + completed = __ib_process_cq(cq, budget); > + if (completed < budget) { > + irq_poll_complete(&cq->iop); > + if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) { Doesn't seem entirely right? There is no point in calling ib_req_notify_cq if the code knows there is still stuff in the CQ and has already, independently, arranged for ib_poll_hander to be guarenteed called. > + if (!irq_poll_sched_prep(&cq->iop)) > + irq_poll_sched(&cq->iop); Which, it seems, is what this is doing. Assuming irq_poll_sched is safe to call from a hard irq context, this looks sane, at first glance. > + completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE); > + if (completed >= IB_POLL_BUDGET_WORKQUEUE || > + ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) > + queue_work(ib_comp_wq, &cq->work); Same comment here.. > +static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) > +{ > + queue_work(ib_comp_wq, &cq->work); > + switch (cq->poll_ctx) { > + case IB_POLL_DIRECT: > + cq->comp_handler = ib_cq_completion_direct; > + break; > + case IB_POLL_SOFTIRQ: > + cq->comp_handler = ib_cq_completion_softirq; > + > + irq_poll_init(&cq->iop, IB_POLL_BUDGET_IRQ, ib_poll_handler); > + irq_poll_enable(&cq->iop); > + ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); > + break; I understand several drivers are not using a hard irq context for the comp_handler call back. Is there any way to exploit that in this new API so we don't have to do so many context switches? Ie if the driver already is using a softirq when calling comp_handler can we somehow just rig ib_poll_handler directly and avoid the overhead? (Future) At first glance this seems so much saner than what we have.. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/13/2015 10:25 AM, Jason Gunthorpe wrote: On Fri, Nov 13, 2015 at 02:46:43PM +0100, Christoph Hellwig wrote: This adds an abstraction that allows ULP to simply pass a completion object and completion callback with each submitted WR and let the RDMA core handle the nitty gritty details of how to handle completion interrupts and poll the CQ. This looks pretty nice, I'd really like to look it over carefully after SC|15.. I know Bart and others have attempted to have switching between event and polling driven operation, but there were problems resolving the races. Would be nice to review that conversation.. Do you remember the details Bart? Hello Jason, I think this is the conversation you are referring to: "About a shortcoming of the verbs API" (http://thread.gmane.org/gmane.linux.drivers.rdma/5028). That conversation occurred five years ago, which means that you have an excellent memory :-) I doesn't seem to me like Christoph wanted to support dynamic switching between the IB_POLL_DIRECT, IB_POLL_SOFTIRQ and IB_POLL_WORKQUEUE polling modes. I think this should have been mentioned in the patch description. The implementation of this patch makes it clear that it is essential that all polling is serialized. The WC array that is used for polling is embedded in the CQ and is not protected against concurrent access. This means that it is essential that _ib_process_cq() calls are serialized. I need some more time to verify whether such serialization is always guaranteed by this patch. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Fri, Nov 13, 2015 at 11:57:56AM -0800, Bart Van Assche wrote: > I think this is the conversation you are referring to: "About a shortcoming > of the verbs API" (http://thread.gmane.org/gmane.linux.drivers.rdma/5028). > That conversation occurred five years ago, which means that you have an > excellent memory :-) Heh, the whole thread is interesting, but this message is what I was thinking of http://thread.gmane.org/gmane.linux.drivers.rdma/5028 And it looks like this patch is OK relative to that discussion. > I doesn't seem to me like Christoph wanted to support dynamic switching > between the IB_POLL_DIRECT, IB_POLL_SOFTIRQ and IB_POLL_WORKQUEUE polling > modes. I think this should have been mentioned in the patch description. Indeed. Which is probably OK. > The implementation of this patch makes it clear that it is essential that > all polling is serialized. The WC array that is used for polling is embedded > in the CQ and is not protected against concurrent access. This means that it > is essential that _ib_process_cq() calls are serialized. I need some more > time to verify whether such serialization is always guaranteed by this > patch. Yes, the two big design/review checks - ib_process_cq is fully serialized/etc - All re-arm cases are done properly - rearm is only called when the CQ is empty and all cases where it is not empty guarentee that the polling loop happens again. Looking at that thread and then at the patch a bit more.. +void ib_process_cq_direct(struct ib_cq *cq) [..] + __ib_process_cq(cq, INT_MAX); INT_MAX is not enough, it needs to loop. This is missing a ib_req_notify also. And this structure: +static int __ib_process_cq(struct ib_cq *cq, int budget) + while ((n = ib_poll_cq(cq, IB_POLL_BATCH, cq->wc)) > 0) { Does an unnecessary ib_poll_cq call in common cases. I'd suggest change the result to bool and do: // true return means the caller should attempt ib_req_notify_cq while ((n = ib_poll_cq(cq, IB_POLL_BATCH, cq->wc)) > 0) { for (...) if (n != IB_POLL_BATCH) return true; completed += n; if (completed > budget) return false; } return true; And then change call site like: static void ib_cq_poll_work(struct work_struct *work) { if (__ib_process_cq(...)) if (ib_req_notify_cq(cq, IB_POLL_FLAGS) == 0) return; // Else we need to loop again. queue_work(ib_comp_wq, &cq->work); } Which avoids the rearm. void ib_process_cq_direct(struct ib_cq *cq) { while (1) { if (__ib_process_cq(..) && ib_req_notify_cq(cq, IB_POLL_FLAGS) == 0) return; } } Which adds the inf loop and rearm. etc for softirq Perhaps ib_req_notify_cq should be folded into __ib_process_cq, then it can trivially honour the budget on additional loops from IB_CQ_REPORT_MISSED_EVENTS. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Fri, Nov 13, 2015 at 11:25:13AM -0700, Jason Gunthorpe wrote: > For instance, like this, not fulling draining the cq and then doing: > > > + completed = __ib_process_cq(cq, budget); > > + if (completed < budget) { > > + irq_poll_complete(&cq->iop); > > + if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) { > > Doesn't seem entirely right? There is no point in calling > ib_req_notify_cq if the code knows there is still stuff in the CQ and > has already, independently, arranged for ib_poll_hander to be > guarenteed called. The code only calls ib_req_notify_cq if it knowns we finished earlier than our budget. > > + completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE); > > + if (completed >= IB_POLL_BUDGET_WORKQUEUE || > > + ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) > > + queue_work(ib_comp_wq, &cq->work); > > Same comment here.. Same here - we only requeue the work item if either we processed all of our budget, or ib_req_notify_cq with IB_CQ_REPORT_MISSED_EVENTS told us that we need to poll again. > I understand several drivers are not using a hard irq context for the > comp_handler call back. Is there any way to exploit that in this new > API so we don't have to do so many context switches? Ie if the driver > already is using a softirq when calling comp_handler can we somehow > just rig ib_poll_handler directly and avoid the overhead? (Future) Let's say this API makes it possible. I still don't think moving the whole budget and rearm logic into the LLD is necessarily a good idea if we can avoid it. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Fri, Nov 13, 2015 at 03:06:36PM -0700, Jason Gunthorpe wrote: > Looking at that thread and then at the patch a bit more.. > > +void ib_process_cq_direct(struct ib_cq *cq) > [..] > + __ib_process_cq(cq, INT_MAX); > > INT_MAX is not enough, it needs to loop. > This is missing a ib_req_notify also. No. Direct cases _never_ calls ib_req_notify. Its for the case where the SRP case polls the send CQ only from the same context it sends for without any interrupt notification at al. > +static int __ib_process_cq(struct ib_cq *cq, int budget) > + while ((n = ib_poll_cq(cq, IB_POLL_BATCH, cq->wc)) > 0) { > > Does an unnecessary ib_poll_cq call in common cases. I'd suggest > change the result to bool and do: > > // true return means the caller should attempt ib_req_notify_cq > while ((n = ib_poll_cq(cq, IB_POLL_BATCH, cq->wc)) > 0) { > for (...) > if (n != IB_POLL_BATCH) >return true; > completed += n; > if (completed > budget) > return false; > } > return true; > > And then change call site like: > > static void ib_cq_poll_work(struct work_struct *work) > { > if (__ib_process_cq(...)) > if (ib_req_notify_cq(cq, IB_POLL_FLAGS) == 0) > return; > // Else we need to loop again. > queue_work(ib_comp_wq, &cq->work); > } > > Which avoids the rearm. > > void ib_process_cq_direct(struct ib_cq *cq) > { >while (1) { >if (__ib_process_cq(..) && >ib_req_notify_cq(cq, IB_POLL_FLAGS) == 0) >return; >} > } > > Which adds the inf loop and rearm. > > etc for softirq For the workqueue and softirq cases this looks reasonable. For the direct case there is no rearming, though. > Perhaps ib_req_notify_cq should be folded into __ib_process_cq, then > it can trivially honour the budget on additional loops from > IB_CQ_REPORT_MISSED_EVENTS. Which also defeats this proposal. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
+/** + * ib_process_direct_cq - process a CQ in caller context + * @cq:CQ to process + * + * 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 from completion interrupts from the HCA. + */ +void ib_process_cq_direct(struct ib_cq *cq) +{ + WARN_ON_ONCE(cq->poll_ctx != IB_POLL_DIRECT); + + __ib_process_cq(cq, INT_MAX); +} I doubt INT_MAX is useful as a budget in any use-case. it can easily hog the CPU. If the consumer is given access to poll a CQ, it must be able to provide some way to budget it. Why not expose a budget argument to the consumer? -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Sun, Nov 15, 2015 at 11:40:02AM +0200, Sagi Grimberg wrote: > I doubt INT_MAX is useful as a budget in any use-case. it can easily > hog the CPU. If the consumer is given access to poll a CQ, it must be > able to provide some way to budget it. Why not expose a budget argument > to the consumer? Because in theory we could have a lot of sends completing before we finally need to reap them. I think that's more of a theoretical than real issue. My preference would be to simply kill this mode though. Allocate a IU to each block request in SRP and only use the free_tx list for task management and AEN/req_limit calls. Then we can use a single CQ and mark the regular I/O requests as unsignalled. AFAICS no other driver wants a similar polling mode as the SRP initiator does for it's send queue. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 15/11/2015 14:55, Christoph Hellwig wrote: On Sun, Nov 15, 2015 at 11:40:02AM +0200, Sagi Grimberg wrote: I doubt INT_MAX is useful as a budget in any use-case. it can easily hog the CPU. If the consumer is given access to poll a CQ, it must be able to provide some way to budget it. Why not expose a budget argument to the consumer? Because in theory we could have a lot of sends completing before we finally need to reap them. I think that's more of a theoretical than real issue. Still, processing a CQ possibly forever is not something we'd want to enable in an API, if a caller wants to do that anyway, it should loop this call... My preference would be to simply kill this mode though. Allocate a IU to each block request in SRP and only use the free_tx list for task management and AEN/req_limit calls. Then we can use a single CQ and mark the regular I/O requests as unsignalled. It might be better. I'd say that we keep this API and let Bart decide if he wants to do that in srp. If he wants to convert srp, we can always drop it. AFAICS no other driver wants a similar polling mode as the SRP initiator does for it's send queue. iser worked in this mode in the past. But we changed that. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/13/2015 05:46 AM, Christoph Hellwig wrote: + * context and does not ask from completion interrupts from the HCA. Should this perhaps be changed into "for" ? + */ +void ib_process_cq_direct(struct ib_cq *cq) +{ + WARN_ON_ONCE(cq->poll_ctx != IB_POLL_DIRECT); + + __ib_process_cq(cq, INT_MAX); +} +EXPORT_SYMBOL(ib_process_cq_direct); My proposal is to drop this function and to export __ib_process_cq() instead (with or without renaming). That will allow callers of this function to compare the poll budget with the number of completions that have been processed and use that information to decide whether or not to call this function again. +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); + if (completed >= IB_POLL_BUDGET_WORKQUEUE || + ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) + queue_work(ib_comp_wq, &cq->work); +} + +static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) +{ + queue_work(ib_comp_wq, &cq->work); +} The above code will cause all polling to occur on the context of the CPU that received the completion interrupt. This approach is not powerful enough. For certain workloads throughput is higher if work completions are processed by another CPU core on the same CPU socket. Has it been considered to make the CPU core on which work completions are processed configurable ? diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 62b6cba..3027824 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -457,10 +457,11 @@ static struct srp_fr_pool *srp_alloc_fr_pool(struct srp_target_port *target) static void srp_destroy_qp(struct srp_rdma_ch *ch) { static struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; - static struct ib_recv_wr wr = { .wr_id = SRP_LAST_WR_ID }; + static struct ib_recv_wr wr = { 0 }; struct ib_recv_wr *bad_wr; int ret; Since the 'wr' structure is static I don't think it needs to be zero-initialized explicitly. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
Hi Bart, + */ +void ib_process_cq_direct(struct ib_cq *cq) +{ +WARN_ON_ONCE(cq->poll_ctx != IB_POLL_DIRECT); + +__ib_process_cq(cq, INT_MAX); +} +EXPORT_SYMBOL(ib_process_cq_direct); My proposal is to drop this function and to export __ib_process_cq() instead (with or without renaming). That will allow callers of this function to compare the poll budget with the number of completions that have been processed and use that information to decide whether or not to call this function again. I agree with that. +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); +if (completed >= IB_POLL_BUDGET_WORKQUEUE || +ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) +queue_work(ib_comp_wq, &cq->work); +} + +static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) +{ +queue_work(ib_comp_wq, &cq->work); +} The above code will cause all polling to occur on the context of the CPU that received the completion interrupt. This approach is not powerful enough. For certain workloads throughput is higher if work completions are processed by another CPU core on the same CPU socket. Has it been considered to make the CPU core on which work completions are processed configurable ? The workqueue is unbound. This means that the functionality you are you are asking for exists. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Tue, Nov 17, 2015 at 09:52:58AM -0800, Bart Van Assche wrote: > On 11/13/2015 05:46 AM, Christoph Hellwig wrote: >> + * context and does not ask from completion interrupts from the HCA. > > Should this perhaps be changed into "for" ? Yes. > >> + */ >> +void ib_process_cq_direct(struct ib_cq *cq) >> +{ >> +WARN_ON_ONCE(cq->poll_ctx != IB_POLL_DIRECT); >> + >> +__ib_process_cq(cq, INT_MAX); >> +} >> +EXPORT_SYMBOL(ib_process_cq_direct); > > My proposal is to drop this function and to export __ib_process_cq() > instead (with or without renaming). That will allow callers of this > function to compare the poll budget with the number of completions that > have been processed and use that information to decide whether or not to > call this function again. I'd like to keep the WARN_ON, but we can export the same signature. Then again my preference would be to remove the direct mode entirely. >> +static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) >> +{ >> +queue_work(ib_comp_wq, &cq->work); >> +} > > The above code will cause all polling to occur on the context of the CPU > that received the completion interrupt. This approach is not powerful > enough. For certain workloads throughput is higher if work completions are > processed by another CPU core on the same CPU socket. Has it been > considered to make the CPU core on which work completions are processed > configurable ? It's an unbound workqueue, so it's not tied to the specific CPU. However we'll only run the work_struct once so it's still tied to a single CPU at a time, but that's not different from the kthread use previously. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/17/2015 11:55 PM, Sagi Grimberg wrote: +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); +if (completed >= IB_POLL_BUDGET_WORKQUEUE || +ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) +queue_work(ib_comp_wq, &cq->work); +} + +static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) +{ +queue_work(ib_comp_wq, &cq->work); +} The above code will cause all polling to occur on the context of the CPU that received the completion interrupt. This approach is not powerful enough. For certain workloads throughput is higher if work completions are processed by another CPU core on the same CPU socket. Has it been considered to make the CPU core on which work completions are processed configurable ? The workqueue is unbound. This means that the functionality you are you are asking for exists. Hello Sagi, Are you perhaps referring to the sysfs CPU mask that allows to control workqueue affinity ? I expect that setting the CPU mask for an entire pool through sysfs will lead to suboptimal results. What I have learned by tuning target systems is that there is a significant performance difference (> 30% IOPS) between a configuration where each completion thread is pinned to exactly one CPU compared to allowing the scheduler to choose a CPU. Controlling the CPU affinity of worker threads with the taskset command is not possible since the function create_worker() in kernel/workqueue.c calls kthread_bind_mask(). That function sets PF_NO_SETAFFINITY. From sched.h: #define PF_NO_SETAFFINITY 0x0400 /* Userland is not allowed to meddle with cpus_allowed */ Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Wed, Nov 18, 2015 at 10:20:14AM -0800, Bart Van Assche wrote: > Are you perhaps referring to the sysfs CPU mask that allows to control > workqueue affinity ? I think he is referring to the defintion of WQ_UNBOUND: WQ_UNBOUND Work items queued to an unbound wq are served by the special woker-pools which host workers which are not bound to any specific CPU. This makes the wq behave as a simple execution context provider without concurrency management. The unbound worker-pools try to start execution of work items as soon as possible. Unbound wq sacrifices locality but is useful for the following cases. * Wide fluctuation in the concurrency level requirement is expected and using bound wq may end up creating large number of mostly unused workers across different CPUs as the issuer hops through different CPUs. * Long running CPU intensive workloads which can be better managed by the system scheduler. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/20/2015 02:16 AM, Christoph Hellwig wrote: > On Wed, Nov 18, 2015 at 10:20:14AM -0800, Bart Van Assche wrote: >> Are you perhaps referring to the sysfs CPU mask that allows to control >> workqueue affinity ? > > I think he is referring to the defintion of WQ_UNBOUND: > >WQ_UNBOUND > > Work items queued to an unbound wq are served by the special > woker-pools which host workers which are not bound to any > specific CPU. This makes the wq behave as a simple execution > context provider without concurrency management. The unbound > worker-pools try to start execution of work items as soon as > possible. Unbound wq sacrifices locality but is useful for > the following cases. > > * Wide fluctuation in the concurrency level requirement is > expected and using bound wq may end up creating large number > of mostly unused workers across different CPUs as the issuer > hops through different CPUs. > > * Long running CPU intensive workloads which can be better > managed by the system scheduler. Hello Christoph, The comment about locality in the above quote is interesting. How about modifying patch 2/9 as indicated below ? The modification below does not change the behavior of this patch if ib_cq.w.cpu is not modified. And it allows users who care about locality and who want to skip the scheduler overhead by setting ib_cq.w.cpu to the index of the CPU they want the work to be processed on. Thanks, Bart. --- drivers/infiniband/core/cq.c | 11 ++- include/rdma/ib_verbs.h | 5 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c index bf2a079..4d80d8c 100644 --- a/drivers/infiniband/core/cq.c +++ b/drivers/infiniband/core/cq.c @@ -94,18 +94,18 @@ static void ib_cq_completion_softirq(struct ib_cq *cq, void *private) static void ib_cq_poll_work(struct work_struct *work) { - struct ib_cq *cq = container_of(work, struct ib_cq, work); + struct ib_cq *cq = container_of(work, struct ib_cq, w.work); int completed; completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE); if (completed >= IB_POLL_BUDGET_WORKQUEUE || ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) - queue_work(ib_comp_wq, &cq->work); + queue_work_on(cq->w.cpu, ib_comp_wq, &cq->w.work); } static void ib_cq_completion_workqueue(struct ib_cq *cq, void *private) { - queue_work(ib_comp_wq, &cq->work); + queue_work_on(cq->w.cpu, ib_comp_wq, &cq->w.work); } /** @@ -159,7 +159,8 @@ struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private, break; case IB_POLL_WORKQUEUE: cq->comp_handler = ib_cq_completion_workqueue; - INIT_WORK(&cq->work, ib_cq_poll_work); + INIT_WORK(&cq->w.work, ib_cq_poll_work); + cq->w.cpu = WORK_CPU_UNBOUND; ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); break; default: @@ -195,7 +196,7 @@ void ib_free_cq(struct ib_cq *cq) irq_poll_disable(&cq->iop); break; case IB_POLL_WORKQUEUE: - flush_work(&cq->work); + flush_work(&cq->w.work); break; default: WARN_ON_ONCE(1); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index f59a8d3..b1344f8 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1291,7 +1291,10 @@ struct ib_cq { struct ib_wc*wc; union { struct irq_poll iop; - struct work_struct work; + struct { + struct work_struct work; + int cpu; + } w; }; }; -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
Hello Christoph, The comment about locality in the above quote is interesting. How about modifying patch 2/9 as indicated below ? The modification below does not change the behavior of this patch if ib_cq.w.cpu is not modified. And it allows users who care about locality and who want to skip the scheduler overhead by setting ib_cq.w.cpu to the index of the CPU they want the work to be processed on. That sounds acceptable... -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Sun, Nov 22, 2015 at 11:51:13AM +0200, Sagi Grimberg wrote: > >> Hello Christoph, >> >> The comment about locality in the above quote is interesting. How about >> modifying patch 2/9 as indicated below ? The modification below does not >> change the behavior of this patch if ib_cq.w.cpu is not modified. And it >> allows users who care about locality and who want to skip the scheduler >> overhead by setting ib_cq.w.cpu to the index of the CPU they want the >> work to be processed on. > > That sounds acceptable... Wouldn't it be a better idea to set the WQ_SYSFS interface and use the standard sysfs interface for specifying cpumasks or node affinity? -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
Wouldn't it be a better idea to set the WQ_SYSFS interface and use the standard sysfs interface for specifying cpumasks or node affinity? I think that bart wants to allow the caller to select cpu affinity per CQ. In this case ib_alloc_cq in workqueue mode would need to accept a affinity_hint from the caller (default to wild-card WORK_CPU_UNBOUND). -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Sun, Nov 22, 2015 at 12:36:00PM +0200, Sagi Grimberg wrote: > >> Wouldn't it be a better idea to set the WQ_SYSFS interface and use >> the standard sysfs interface for specifying cpumasks or node affinity? > > I think that bart wants to allow the caller to select cpu affinity > per CQ. In this case ib_alloc_cq in workqueue mode would need to > accept a affinity_hint from the caller (default to wild-card > WORK_CPU_UNBOUND). Hmm, true. How would be set that hint from userspace? I'd really prefer to see a practical justification for it first. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
I think that bart wants to allow the caller to select cpu affinity per CQ. In this case ib_alloc_cq in workqueue mode would need to accept a affinity_hint from the caller (default to wild-card WORK_CPU_UNBOUND). Hmm, true. How would be set that hint from userspace? I'd really prefer to see a practical justification for it first. In order to assign CPUs from user-space we'd need an ethtool like interface for isert/srpt/. Given that this is something we don't want to get into right now, I assumed that Bart meant that srpt would take a "least used" approach from srpt driver (which isn't better taking the wild-card option I'd say), So I'll let Bart answer... -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/22/15 06:57, Sagi Grimberg wrote: I think that bart wants to allow the caller to select cpu affinity per CQ. In this case ib_alloc_cq in workqueue mode would need to accept a affinity_hint from the caller (default to wild-card WORK_CPU_UNBOUND). Hmm, true. How would be set that hint from userspace? I'd really prefer to see a practical justification for it first. In order to assign CPUs from user-space we'd need an ethtool like interface for isert/srpt/. Given that this is something we don't want to get into right now, I assumed that Bart meant that srpt would take a "least used" approach from srpt driver (which isn't better taking the wild-card option I'd say), So I'll let Bart answer... Hello Christoph and Sagi, My intention is indeed to allow to control CPU affinity per CQ. One use case is to implement a least-used policy in RDMA drivers that use multiple completion queues. Another use case is to make CPU affinity configurable from user space through something similar to ethtool or via sysfs. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Sat, Nov 14, 2015 at 08:08:49AM +0100, Christoph Hellwig wrote: > On Fri, Nov 13, 2015 at 11:25:13AM -0700, Jason Gunthorpe wrote: > > For instance, like this, not fulling draining the cq and then doing: > > > > > + completed = __ib_process_cq(cq, budget); > > > + if (completed < budget) { > > > + irq_poll_complete(&cq->iop); > > > + if (ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) { > > > > Doesn't seem entirely right? There is no point in calling > > ib_req_notify_cq if the code knows there is still stuff in the CQ and > > has already, independently, arranged for ib_poll_hander to be > > guarenteed called. > > The code only calls ib_req_notify_cq if it knowns we finished earlier than > our budget. Okay, having now read the whole thing, I think I see the flow now. I don't see any holes in the above, other than it is doing a bit more work than it needs in some edges cases because it doesn't know if the CQ is actually empty or not. > > > + completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE); > > > + if (completed >= IB_POLL_BUDGET_WORKQUEUE || > > > + ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) > > > + queue_work(ib_comp_wq, &cq->work); > > > > Same comment here.. > > Same here - we only requeue the work item if either we processed all of > our budget, or ib_req_notify_cq with IB_CQ_REPORT_MISSED_EVENTS told > us that we need to poll again. I find the if construction hard to read, but yes, it looks OK. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Sat, Nov 14, 2015 at 08:13:44AM +0100, Christoph Hellwig wrote: > On Fri, Nov 13, 2015 at 03:06:36PM -0700, Jason Gunthorpe wrote: > > Looking at that thread and then at the patch a bit more.. > > > > +void ib_process_cq_direct(struct ib_cq *cq) > > [..] > > + __ib_process_cq(cq, INT_MAX); > > > > INT_MAX is not enough, it needs to loop. > > This is missing a ib_req_notify also. > > No. Direct cases _never_ calls ib_req_notify. Its for the case where > the SRP case polls the send CQ only from the same context it sends for > without any interrupt notification at al. Hurm, okay, that is not at all what I was thinking this was for.. So the only use of this function is to drain a send cq, in a state where it is guarenteed no new entries can be added, and only if the cq is not already event driven. I'd stick those notes in the comment.. Hum. I wonder if this is even a reasonable way to run a ULP. It is important that rx completions are not used to drive reaping of resources that are still committed to the send queue. ie do not trigger send buffer reuse based on a rx completion. So, if a ULP uses this API, how does it handle the sendq becoming full? As above, a ULP cannot use recvs to infer available sendq space. It must directly reap the sendq. So a correct ULP would have to spin calling ib_process_direct_cq until it makes enough progress to add more things to the sendq. I don't obviously see that in SRP - so I'm guessing it has buggered up sendq flow control? NFS had similar problems lately too, I wrote a long explanation to Chuck on this subject. That said, the demand poll almost seems like a reasonable way for a ULP to run the sendq, do the polls on send occasionally or when more space is needed to better amortize the reaping overhead at the cost of send latency. But API wise it needs to be able to switch over to a sleep if enough progress hasn't been made. So.. maybe also add to the comment that ib_process_cq_direct is deprecated and should not be used in new code until SRP gets sorted? > > Perhaps ib_req_notify_cq should be folded into __ib_process_cq, then > > it can trivially honour the budget on additional loops from > > IB_CQ_REPORT_MISSED_EVENTS. > > Which also defeats this proposal. Just ignore my remarks here, someone should do a benchmark to see if we are hitting the edge cases of extra spins around the various loops before reworking this. Can't trivially hoist ib_req_notify_cq into __ib_process_cq because of how it needs to be ordered with irq_poll_complete Reviewed-by: Jason Gunthorpe Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 01:01:36PM -0700, Jason Gunthorpe wrote: > Okay, having now read the whole thing, I think I see the flow now. I don't > see any holes in the above, other than it is doing a bit more work > than it needs in some edges cases because it doesn't know if the CQ is > actually empty or not. > > > > > + completed = __ib_process_cq(cq, IB_POLL_BUDGET_WORKQUEUE); > > > > + if (completed >= IB_POLL_BUDGET_WORKQUEUE || > > > > + ib_req_notify_cq(cq, IB_POLL_FLAGS) > 0) > > > > + queue_work(ib_comp_wq, &cq->work); > > > > > > Same comment here.. > > > > Same here - we only requeue the work item if either we processed all of > > our budget, or ib_req_notify_cq with IB_CQ_REPORT_MISSED_EVENTS told > > us that we need to poll again. > > I find the if construction hard to read, but yes, it looks OK. If you're got suggestions to improve the flow please send them my way. I'm not entirely happy with it, but couldn't come up with a better idea. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/23/2015 12:37 PM, Jason Gunthorpe wrote: On Sat, Nov 14, 2015 at 08:13:44AM +0100, Christoph Hellwig wrote: On Fri, Nov 13, 2015 at 03:06:36PM -0700, Jason Gunthorpe wrote: Looking at that thread and then at the patch a bit more.. +void ib_process_cq_direct(struct ib_cq *cq) [..] + __ib_process_cq(cq, INT_MAX); INT_MAX is not enough, it needs to loop. This is missing a ib_req_notify also. No. Direct cases _never_ calls ib_req_notify. Its for the case where the SRP case polls the send CQ only from the same context it sends for without any interrupt notification at al. Hurm, okay, that is not at all what I was thinking this was for.. So the only use of this function is to drain a send cq, in a state where it is guarenteed no new entries can be added, and only if the cq is not already event driven. I'd stick those notes in the comment.. Hum. I wonder if this is even a reasonable way to run a ULP. It is important that rx completions are not used to drive reaping of resources that are still committed to the send queue. ie do not trigger send buffer reuse based on a rx completion. So, if a ULP uses this API, how does it handle the sendq becoming full? As above, a ULP cannot use recvs to infer available sendq space. It must directly reap the sendq. So a correct ULP would have to spin calling ib_process_direct_cq until it makes enough progress to add more things to the sendq. I don't obviously see that in SRP - so I'm guessing it has buggered up sendq flow control? NFS had similar problems lately too, I wrote a long explanation to Chuck on this subject. That said, the demand poll almost seems like a reasonable way for a ULP to run the sendq, do the polls on send occasionally or when more space is needed to better amortize the reaping overhead at the cost of send latency. But API wise it needs to be able to switch over to a sleep if enough progress hasn't been made. So.. maybe also add to the comment that ib_process_cq_direct is deprecated and should not be used in new code until SRP gets sorted? Hello Jason, Considerable time ago the send queue in the SRP initiator driver was modified from signaled to non-signaled to reduce the number of interrupts triggered by the SRP initiator driver. The SRP initiator driver polls the send queue every time before a SCSI command is sent to the target. I think this is a pattern that is also useful for other ULP's so I'm not convinced that ib_process_cq_direct() should be deprecated :-) Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 01:04:25PM -0800, Bart Van Assche wrote: > Considerable time ago the send queue in the SRP initiator driver was > modified from signaled to non-signaled to reduce the number of interrupts > triggered by the SRP initiator driver. The SRP initiator driver polls the > send queue every time before a SCSI command is sent to the target. I think > this is a pattern that is also useful for other ULP's so I'm not convinced > that ib_process_cq_direct() should be deprecated :-) As I explained, that is a fine idea, but I can't see how SRP is able to correctly do sendq flow control without spinning on the poll, which it does not do. I'm guessing SRP is trying to drive sendq flow control from the recv side, like NFS was. This is wrong and should not be part of the common API. Does that make sense? Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/23/2015 01:28 PM, Jason Gunthorpe wrote: On Mon, Nov 23, 2015 at 01:04:25PM -0800, Bart Van Assche wrote: Considerable time ago the send queue in the SRP initiator driver was modified from signaled to non-signaled to reduce the number of interrupts triggered by the SRP initiator driver. The SRP initiator driver polls the send queue every time before a SCSI command is sent to the target. I think this is a pattern that is also useful for other ULP's so I'm not convinced that ib_process_cq_direct() should be deprecated :-) As I explained, that is a fine idea, but I can't see how SRP is able to correctly do sendq flow control without spinning on the poll, which it does not do. I'm guessing SRP is trying to drive sendq flow control from the recv side, like NFS was. This is wrong and should not be part of the common API. Does that make sense? Not really ... Please have a look at the SRP initiator source code. What the SRP initiator does is to poll the send queue before sending a new SCSI command to the target system starts. I think this approach could also be used in other ULP drivers if the send queue poll frequency is such that no send queue overflow occurs. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 01:54:05PM -0800, Bart Van Assche wrote: > Not really ... Please have a look at the SRP initiator source code. What the > SRP initiator does is to poll the send queue before sending a new > SCSI I see that. What I don't see is how SRP handles things when the sendq fills up, ie the case where __srp_get_tx_iu() == NULL. It looks like the driver starts to panic and generates printks. I can't tell if it can survive that, but it doesn't look very good.. It would be a lot better if this wasn't allowed to happen, the polling loop can run until a sendq becomes available, and never return null from __srp_get_tx_iu(). Ie, __srp_get_tx_iu should look more like ib_poll_cq_until(..., !list_empty(&ch->free_tx)); Which would be a fairly sane core API for this direct usage.. Ideally the core code would sleep if possible and not just spin. Maybe also protect it with a timer. > command to the target system starts. I think this approach could also be > used in other ULP drivers if the send queue poll frequency is such that no > send queue overflow occurs. Yes, I agree, but it has to be done properly :) Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/23/2015 02:18 PM, Jason Gunthorpe wrote: On Mon, Nov 23, 2015 at 01:54:05PM -0800, Bart Van Assche wrote: What I don't see is how SRP handles things when the sendq fills up, ie the case where __srp_get_tx_iu() == NULL. It looks like the driver starts to panic and generates printks. I can't tell if it can survive that, but it doesn't look very good.. Hello Jason, From srp_cm_rep_handler(): target->scsi_host->can_queue = min(ch->req_lim - SRP_TSK_MGMT_SQ_SIZE, target->scsi_host->can_queue); In other words, the SCSI core is told to ensure that the number of outstanding SCSI commands is one less than the number of elements in the ch->free_tx list. And since the SRP initiator serializes task management requests it is guaranteed that __srp_get_tx_iu() won't fail due to ch->free_tx being empty. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 02:33:05PM -0800, Bart Van Assche wrote: > On 11/23/2015 02:18 PM, Jason Gunthorpe wrote: > >On Mon, Nov 23, 2015 at 01:54:05PM -0800, Bart Van Assche wrote: > >What I don't see is how SRP handles things when the > >sendq fills up, ie the case where __srp_get_tx_iu() == NULL. It looks > >like the driver starts to panic and generates printks. I can't tell if > >it can survive that, but it doesn't look very good.. > > Hello Jason, > > From srp_cm_rep_handler(): > > target->scsi_host->can_queue > = min(ch->req_lim - SRP_TSK_MGMT_SQ_SIZE, > target->scsi_host->can_queue); > > In other words, the SCSI core is told to ensure that the number of > outstanding SCSI commands is one less than the number of elements in the > ch->free_tx list. And since the SRP initiator serializes task management > requests it is guaranteed that __srp_get_tx_iu() won't fail due to > ch->free_tx being empty. I realize that, and as I already explained, SRP cannot drive the sendq flow control from the recv side. The SCSI core considers the command complete and will issue a new command as soon as the recv completion associated with the command is returned. (ie when the remote responds) This *DOES NOT* say anything about the state of the sendq, it does not guarantee there is send CQ entry available for the associated send, it does not guarantee there is available space in the sendq. Verbs DOES NOT make ordering guarentees between queues, even if the queues are causally related. This is an important point in verbs and it is commonly done wrong. So, yes, __srp_get_tx_iu absolutely can fail due to ch->free_tx being empty, even though by observing the recv side SRP has inferred that the sendq should have space. Every ULP has to cope with this, and a direct poll API that doesn't account for the need to block on a predicate is broken by design. This is why I object. 'ib_poll_cq_until' would correct all of this. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 03:30:42PM -0800, Caitlin Bestler wrote: >The receive completion can be safely assumed to indicate transmit >completion over a reliable connection unless your peer has gone >completely bonkers and is replying to a command that it did not >receive. Perhaps iWarp is different and does specify this ordering but IB does not. The issue with IB is how the ACK protocol is designed. There is not strong ordering between ACKs and data transfers. A HCA can send ACK,DATA and the network could drop the ACK. The recevier side does not know the ACK was lost and goes ahead to process DATA. Since only ACK advances the sendq and DATA advances the recvq it is trivial to get a case where the recvq is advanced with a reply while the sendq continues to wait for the ACK to be resent. Further IB allows ACK coalescing and has no rules for how an ACK is placed. It is entirely valid for a HCA to RECV,REPLY,ACK - for instance. >I actually had a bug in an early iWARP emulation where the simulated >peer, because it was simulated, responded >instantly. The result was a TCP segment that both acked the >transmission *and* contained the reply. The bug was >that the code processed the reception before the transmission ack, >causing the receive completion to be placed >on the completion queue before transmit completion. I don't know if iWARP has the same lax ordering as IB, but certainly, what you describe is legal for IB verbs to do, and our kernel ULPs have to cope with it. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/23/2015 7:00 PM, Jason Gunthorpe wrote: On Mon, Nov 23, 2015 at 03:30:42PM -0800, Caitlin Bestler wrote: The receive completion can be safely assumed to indicate transmit completion over a reliable connection unless your peer has gone completely bonkers and is replying to a command that it did not receive. Perhaps iWarp is different and does specify this ordering but IB does not. iWARP is not different. The situation you (Jason) describe has nothing to do with the transport. It has everything to do with as you point out the lack of causality between send and receive completions. It is entirely possible for the reply to be received before the send is fully processed. For example, the send might be issued on one core, and that core scheduled away before the completion for the send is ready. In the meantime, the request goes on the wire, the target processes it and replies, and the reply is processed. Boom, the send queue completion is still pending. Been there, seen that. Bluescreened on it, mysteriously. A really good way to see this is with software providers, btw. Try it with soft{roce,iwarp}, under heavy load. Tom. The issue with IB is how the ACK protocol is designed. There is not strong ordering between ACKs and data transfers. A HCA can send ACK,DATA and the network could drop the ACK. The recevier side does not know the ACK was lost and goes ahead to process DATA. Since only ACK advances the sendq and DATA advances the recvq it is trivial to get a case where the recvq is advanced with a reply while the sendq continues to wait for the ACK to be resent. Further IB allows ACK coalescing and has no rules for how an ACK is placed. It is entirely valid for a HCA to RECV,REPLY,ACK - for instance. I actually had a bug in an early iWARP emulation where the simulated peer, because it was simulated, responded instantly. The result was a TCP segment that both acked the transmission *and* contained the reply. The bug was that the code processed the reception before the transmission ack, causing the receive completion to be placed on the completion queue before transmit completion. I don't know if iWARP has the same lax ordering as IB, but certainly, what you describe is legal for IB verbs to do, and our kernel ULPs have to cope with it. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 07:34:53PM -0500, Tom Talpey wrote: > Been there, seen that. Bluescreened on it, mysteriously. Yes, me too :( Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/23/2015 4:00 PM, Jason Gunthorpe wrote: On Mon, Nov 23, 2015 at 03:30:42PM -0800, Caitlin Bestler wrote: The receive completion can be safely assumed to indicate transmit completion over a reliable connection unless your peer has gone completely bonkers and is replying to a command that it did not receive. Perhaps iWarp is different and does specify this ordering but IB does not. The issue with IB is how the ACK protocol is designed. There is not strong ordering between ACKs and data transfers. A HCA can send ACK,DATA and the network could drop the ACK. The recevier side does not know the ACK was lost and goes ahead to process DATA. Since only ACK advances the sendq and DATA advances the recvq it is trivial to get a case where the recvq is advanced with a reply while the sendq continues to wait for the ACK to be resent. Further IB allows ACK coalescing and has no rules for how an ACK is placed. It is entirely valid for a HCA to RECV,REPLY,ACK - for instance. Is it possible for an IB HCA to transmit a response on a QP and not in that packet or a previous packet acknowledge something that it has delivered to the user? My recollection of the IB verbs is that they were unlikely to have overlooked something like that. If it did slip through then there should be an errata. But regardless of specification lawyering, is this an implementation issue. Are there actual HCAs that make this mistake? -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Mon, Nov 23, 2015 at 06:35:28PM -0800, Caitlin Bestler wrote: > Is it possible for an IB HCA to transmit a response on a QP and not > in that packet or a previous packet acknowledge something that it > has delivered to the user? AFAIK, the rules of ack coalescing do not interact with the send side. Even if they did, that is the wrong place to look at. We must look at the receiver. Ordered ack,data on the wire may suffer a packet loss and the ack may not reach the reciever. In this case can the reciever detect the lost ack and not progress the data? For IB, it cannot. The ack sequencing is part of the transmitters recv FSM, and does not interact with the send FSM. I feel this a deliberate IB design choice to be simple and efficient in hardware. > My recollection of the IB verbs is that they were unlikely to have > overlooked something like that. If it did slip through then there > should be an errata. verbs reflects the wire protocol and the wire protocol has no way to create a linkage between the send and recv sides of a RC QP. It is not a spec bug, there is no errata. > But regardless of specification lawyering, is this an implementation > issue. All IB implementations have no choice but to act this way - the wire protocol provides no way to guarentee ack vs data sequencing at the receiver, so there is simply no way to guarentee the sendq advances strictly causally with the recvq. > Are there actual HCAs that make this mistake? All IB HCAs have this behavior and require apps to see a send CQ completion before making any statements about the state of the send Q or buffers handed over to the HCA. Tom and I have seen this in real systems under proper stress conditions. [Which is why I am so certain about this, because when I first hit it years ago I dug into the spec and figured out it was not a HW bug I was looking at] This is a direct consequence of how IB runs the ACK protocol. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On 11/24/2015 2:03 AM, Jason Gunthorpe wrote: On Mon, Nov 23, 2015 at 06:35:28PM -0800, Caitlin Bestler wrote: Are there actual HCAs that make this mistake? All IB HCAs have this behavior and require apps to see a send CQ completion before making any statements about the state of the send Q or buffers handed over to the HCA. Tom and I have seen this in real systems under proper stress conditions. [Which is why I am so certain about this, because when I first hit it years ago I dug into the spec and figured out it was not a HW bug I was looking at] To be clear, I saw the reply-completion-before-request-completion on Windows, not Linux, but the principle is identical. It's simply a fact of life on a multiprocessor, unless you want to throw in locks and synchronization rules that drivers have to follow to enforce ordered completions across queues. Which trust me, you don't. In Windows SMB Direct, we added reference counts around pretty much every verb interaction associated with each upper layer operation, and did not retire them until all refcounts went to zero. It is excruciatingly correct yet performs incredibly well. Tom. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Tue, Nov 24, 2015 at 10:08:39AM -0700, c...@asomi.com wrote: >>> My recollection of the IB verbs is that they were unlikely to have >>> overlooked something like that. If it did slip through then there >>> should be an errata. >>verbs reflects the wire protocol and the wire protocol has no way to >>create a linkage between the send and recv sides of a RC QP. It is not >>a spec bug, there is no errata. > >No, verbs do not reflect the link layer. Verbs fulfill the contract >with the end user - especially when the hardware cannot. Are you serious? You think verbs should specify things that cannot actually be implemented? IB verbs doesn't do that. >Reporting a completion of a receive without having guaranteed >that the acknowledgement will be sent before anything >subsequently submitted is failing to implement a reliable >connection. As I've said repeatedly, the side receiving the request has no impact on this issue. Requiring it to generate an ack before delivering the recv completion *does nothing* to guarantee ordering on the other side in IB. The network can always drop the ack, and the receiver cannot tell. I disagree that RC has anything to do with this causal ordering issue, this is not a property described in the IB spec for RC. >One of the hardware designs I worked with over a decade ago >actually had *two* completion queues, one from the left brain (receive) >and the other from the right brain (transmit). Nevertheless we >presented All verbs hardware has to have these two flows. >a unified completion queue that followed ordering rules. We were not >"reflecting" the hardware, we were implementing an interface in a >combination of hardware and software. And how did you detect lost acks at the reciever to make this an actual guarentee? Maybe TCP can do this but IB cannot. I honestly don't know why you think verbs has this requirement. It is not in the IB spec, and can't be implemented by IB hardware. If one of the other flavours of verbs has this, then fine, but it is not part of the *Linux* verbs flavour. > I cannot think of a reason why that would not work here. Simply do > not report a completion to the user before guaranteeing that the > acks will be transmitted. I've already explained three times why this is not enough for IB. >What would you do if the next user action had been to close the >connection? Would the acks have been lost? No acks will be lost. The IB termination process requires the closing side to drain it's sendq and stop injecting new traffic before sending the CM close message. The other must also drain the sendq before replying. This handshake ensures the QP is quiescent and all in flight traffic completed before the QP is destroyed. IB basically shifts the lingering close into the CM arena, where it costs less, and allows the QP and associated HW resources to be destroyed quickly. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/9] IB: add a proper completion queue abstraction
On Tue, Nov 24, 2015 at 06:47:14PM -0800, Caitlin Bestler wrote: > Acknowledge packet for the last packet of the request has been > committed to the wire (including the appropriate fields for RDMA > READ response). > The target side cannot generate a response before it receives the request. > The target side verbs cannot generate the completion before the acknowledge > packet has been > committed to the wire. Sure, but, I keep saying this, the responder behavior is largely irrelevant to what the target is able/required to do. > Therefore the initiating side cannot receive a response before the write > operation has completed. Wrong. The ladder diagram would be Requestor Responder Responder Verbs SEND1 ---> Process X- ACK (lost) > recv1 CQ <--- send2 WQE recv2 CQE < SEND2 Packet [..] send1 CQE < ACK (resent) The Ack may be lost, causing the send CQE to arrive after the recv CQE, even though the responder did everything in a specific order. The fundamental issue is that the responder cannot detect the lost ACK. The PSN of the ACK packet is part of the Requestor's PSN space, not part of the Responders: 9.7.5.1.1 GENERATING PSNs FOR ACKNOWLEDGE MESSAGES C9-95: For responses to SEND requests or RDMA WRITE requests the responder shall insert in the PSN field of the response the PSN of the most recent request packet being acknowledged. Or stated another way, the value of the AckReq bit in SEND1 has no impact on the contents of the SEND2 packet - thus there is no way for the requestor to detect the loss of the ACK and hold off delivering recv2 CQE. Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html