diff options
author | Roland Dreier <rolandd@cisco.com> | 2007-05-07 00:02:48 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2007-05-07 00:18:11 -0400 |
commit | ed23a72778f3dbd465e55b06fe31629e7e1dd2f3 (patch) | |
tree | 99ab8b4cf7c51ae64b4d3d9108e82b31db2b3465 /drivers/infiniband/hw/amso1100 | |
parent | f4fd0b224d60044d2da5ca02f8f2b5150c1d8731 (diff) |
IB: Return "maybe missed event" hint from ib_req_notify_cq()
The semantics defined by the InfiniBand specification say that
completion events are only generated when a completions is added to a
completion queue (CQ) after completion notification is requested. In
other words, this means that the following race is possible:
while (CQ is not empty)
ib_poll_cq(CQ);
// new completion is added after while loop is exited
ib_req_notify_cq(CQ);
// no event is generated for the existing completion
To close this race, the IB spec recommends doing another poll of the
CQ after requesting notification.
However, it is not always possible to arrange code this way (for
example, we have found that NAPI for IPoIB cannot poll after
requesting notification). Also, some hardware (eg Mellanox HCAs)
actually will generate an event for completions added before the call
to ib_req_notify_cq() -- which is allowed by the spec, since there's
no way for any upper-layer consumer to know exactly when a completion
was really added -- so the extra poll of the CQ is just a waste.
Motivated by this, we add a new flag "IB_CQ_REPORT_MISSED_EVENTS" for
ib_req_notify_cq() so that it can return a hint about whether the a
completion may have been added before the request for notification.
The return value of ib_req_notify_cq() is extended so:
< 0 means an error occurred while requesting notification
== 0 means notification was requested successfully, and if
IB_CQ_REPORT_MISSED_EVENTS was passed in, then no
events were missed and it is safe to wait for another
event.
> 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was
passed in. It means that the consumer must poll the
CQ again to make sure it is empty to avoid the race
described above.
We add a flag to enable this behavior rather than turning it on
unconditionally, because checking for missed events may incur
significant overhead for some low-level drivers, and consumers that
don't care about the results of this test shouldn't be forced to pay
for the test.
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband/hw/amso1100')
-rw-r--r-- | drivers/infiniband/hw/amso1100/c2.h | 2 | ||||
-rw-r--r-- | drivers/infiniband/hw/amso1100/c2_cq.c | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/drivers/infiniband/hw/amso1100/c2.h b/drivers/infiniband/hw/amso1100/c2.h index 04a9db5de881..fa58200217a1 100644 --- a/drivers/infiniband/hw/amso1100/c2.h +++ b/drivers/infiniband/hw/amso1100/c2.h | |||
@@ -519,7 +519,7 @@ extern void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq); | |||
519 | extern void c2_cq_event(struct c2_dev *c2dev, u32 mq_index); | 519 | extern void c2_cq_event(struct c2_dev *c2dev, u32 mq_index); |
520 | extern void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index); | 520 | extern void c2_cq_clean(struct c2_dev *c2dev, struct c2_qp *qp, u32 mq_index); |
521 | extern int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry); | 521 | extern int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry); |
522 | extern int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify); | 522 | extern int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); |
523 | 523 | ||
524 | /* CM */ | 524 | /* CM */ |
525 | extern int c2_llp_connect(struct iw_cm_id *cm_id, | 525 | extern int c2_llp_connect(struct iw_cm_id *cm_id, |
diff --git a/drivers/infiniband/hw/amso1100/c2_cq.c b/drivers/infiniband/hw/amso1100/c2_cq.c index 5175c99ee586..d2b3366786d6 100644 --- a/drivers/infiniband/hw/amso1100/c2_cq.c +++ b/drivers/infiniband/hw/amso1100/c2_cq.c | |||
@@ -217,17 +217,19 @@ int c2_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry) | |||
217 | return npolled; | 217 | return npolled; |
218 | } | 218 | } |
219 | 219 | ||
220 | int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify) | 220 | int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags) |
221 | { | 221 | { |
222 | struct c2_mq_shared __iomem *shared; | 222 | struct c2_mq_shared __iomem *shared; |
223 | struct c2_cq *cq; | 223 | struct c2_cq *cq; |
224 | unsigned long flags; | ||
225 | int ret = 0; | ||
224 | 226 | ||
225 | cq = to_c2cq(ibcq); | 227 | cq = to_c2cq(ibcq); |
226 | shared = cq->mq.peer; | 228 | shared = cq->mq.peer; |
227 | 229 | ||
228 | if (notify == IB_CQ_NEXT_COMP) | 230 | if ((notify_flags & IB_CQ_SOLICITED_MASK) == IB_CQ_NEXT_COMP) |
229 | writeb(C2_CQ_NOTIFICATION_TYPE_NEXT, &shared->notification_type); | 231 | writeb(C2_CQ_NOTIFICATION_TYPE_NEXT, &shared->notification_type); |
230 | else if (notify == IB_CQ_SOLICITED) | 232 | else if ((notify_flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED) |
231 | writeb(C2_CQ_NOTIFICATION_TYPE_NEXT_SE, &shared->notification_type); | 233 | writeb(C2_CQ_NOTIFICATION_TYPE_NEXT_SE, &shared->notification_type); |
232 | else | 234 | else |
233 | return -EINVAL; | 235 | return -EINVAL; |
@@ -241,7 +243,13 @@ int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify) | |||
241 | */ | 243 | */ |
242 | readb(&shared->armed); | 244 | readb(&shared->armed); |
243 | 245 | ||
244 | return 0; | 246 | if (notify_flags & IB_CQ_REPORT_MISSED_EVENTS) { |
247 | spin_lock_irqsave(&cq->lock, flags); | ||
248 | ret = !c2_mq_empty(&cq->mq); | ||
249 | spin_unlock_irqrestore(&cq->lock, flags); | ||
250 | } | ||
251 | |||
252 | return ret; | ||
245 | } | 253 | } |
246 | 254 | ||
247 | static void c2_free_cq_buf(struct c2_dev *c2dev, struct c2_mq *mq) | 255 | static void c2_free_cq_buf(struct c2_dev *c2dev, struct c2_mq *mq) |