Debian Codegraph @

libibverbs/man/ibv_get_cq_event.3

raw
1 .\" -*- nroff -*-
2 .\" Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md
3 .\"
4 .TH IBV_GET_CQ_EVENT 3 2006-10-31 libibverbs "Libibverbs Programmer's Manual"
5 .SH "NAME"
6 ibv_get_cq_event, ibv_ack_cq_events \- get and acknowledge completion queue (CQ) events
7
8 .SH "SYNOPSIS"
9 .nf
10 .B #include <infiniband/verbs.h>
11 .sp
12 .BI "int ibv_get_cq_event(struct ibv_comp_channel " "*channel" ,
13 .BI " struct ibv_cq " "**cq" ", void " "**cq_context" );
14 .sp
15 .BI "void ibv_ack_cq_events(struct ibv_cq " "*cq" ", unsigned int " "nevents" );
16 .fi
17
18 .SH "DESCRIPTION"
19 .B ibv_get_cq_event()
20 waits for the next completion event in the completion event channel
21 .I channel\fR.
22 Fills the arguments
23 .I cq
24 with the CQ that got the event and
25 .I cq_context
26 with the CQ's context\fR.
27 .PP
28 .B ibv_ack_cq_events()
29 acknowledges
30 .I nevents
31 events on the CQ
32 .I cq\fR.
33
34 .SH "RETURN VALUE"
35 .B ibv_get_cq_event()
36 returns 0 on success, and \-1 on error.
37 .PP
38 .B ibv_ack_cq_events()
39 returns no value.
40 .SH "NOTES"
41 All completion events that
42 .B ibv_get_cq_event()
43 returns must be acknowledged using
44 .B ibv_ack_cq_events()\fR.
45 To avoid races, destroying a CQ will wait for all completion events to
46 be acknowledged; this guarantees a one-to-one correspondence between
47 acks and successful gets.
48 .PP
49 Calling
50 .B ibv_ack_cq_events()
51 may be relatively expensive in the datapath, since it must take a
52 mutex. Therefore it may be better to amortize this cost by
53 keeping a count of the number of events needing acknowledgement and
54 acking several completion events in one call to
55 .B ibv_ack_cq_events()\fR.
56 .SH "EXAMPLES"
57 The following code example demonstrates one possible way to work with
58 completion events. It performs the following steps:
59 .PP
60 Stage I: Preparation
61 .br
62 1. Creates a CQ
63 .br
64 2. Requests for notification upon a new (first) completion event
65 .PP
66 Stage II: Completion Handling Routine
67 .br
68 3. Wait for the completion event and ack it
69 .br
70 4. Request for notification upon the next completion event
71 .br
72 5. Empty the CQ
73 .PP
74 Note that an extra event may be triggered without having a
75 corresponding completion entry in the CQ. This occurs if a completion
76 entry is added to the CQ between Step 4 and Step 5, and the CQ is then
77 emptied (polled) in Step 5.
78 .PP
79 .nf
80 cq = ibv_create_cq(ctx, 1, ev_ctx, channel, 0);
81 if (!cq) {
82 fprintf(stderr, "Failed to create CQ\en");
83 return 1;
84 }
85 .PP
86 /* Request notification before any completion can be created */
87 if (ibv_req_notify_cq(cq, 0)) {
88 fprintf(stderr, "Couldn't request CQ notification\en");
89 return 1;
90 }
91 .PP
92 \&.
93 \&.
94 \&.
95 .PP
96 /* Wait for the completion event */
97 if (ibv_get_cq_event(channel, &ev_cq, &ev_ctx)) {
98 fprintf(stderr, "Failed to get cq_event\en");
99 return 1;
100 }
101
102 /* Ack the event */
103 ibv_ack_cq_events(ev_cq, 1);
104 .PP
105 /* Request notification upon the next completion event */
106 if (ibv_req_notify_cq(ev_cq, 0)) {
107 fprintf(stderr, "Couldn't request CQ notification\en");
108 return 1;
109 }
110 .PP
111 /* Empty the CQ: poll all of the completions from the CQ (if any exist) */
112 do {
113 ne = ibv_poll_cq(cq, 1, &wc);
114 if (ne < 0) {
115 fprintf(stderr, "Failed to poll completions from the CQ\en");
116 return 1;
117 }
118
119 /* there may be an extra event with no completion in the CQ */
120 if (ne == 0)
121 continue;
122 .PP
123 if (wc.status != IBV_WC_SUCCESS) {
124 fprintf(stderr, "Completion with status 0x%x was found\en", wc.status);
125 return 1;
126 }
127 } while (ne);
128 .fi
129
130 The following code example demonstrates one possible way to work with
131 completion events in non-blocking mode. It performs the following
132 steps:
133 .PP
134 1. Set the completion event channel to be non-blocked
135 .br
136 2. Poll the channel until there it has a completion event
137 .br
138 3. Get the completion event and ack it
139 .PP
140 .nf
141 /* change the blocking mode of the completion channel */
142 flags = fcntl(channel->fd, F_GETFL);
143 rc = fcntl(channel->fd, F_SETFL, flags | O_NONBLOCK);
144 if (rc < 0) {
145 fprintf(stderr, "Failed to change file descriptor of completion event channel\en");
146 return 1;
147 }
148
149
150 /*
151 * poll the channel until it has an event and sleep ms_timeout
152 * milliseconds between any iteration
153 */
154 my_pollfd.fd = channel->fd;
155 my_pollfd.events = POLLIN;
156 my_pollfd.revents = 0;
157
158 do {
159 rc = poll(&my_pollfd, 1, ms_timeout);
160 } while (rc == 0);
161 if (rc < 0) {
162 fprintf(stderr, "poll failed\en");
163 return 1;
164 }
165 ev_cq = cq;
166
167 /* Wait for the completion event */
168 if (ibv_get_cq_event(channel, &ev_cq, &ev_ctx)) {
169 fprintf(stderr, "Failed to get cq_event\en");
170 return 1;
171 }
172
173 /* Ack the event */
174 ibv_ack_cq_events(ev_cq, 1);
175
176 .fi
177 .SH "SEE ALSO"
178 .BR ibv_create_comp_channel (3),
179 .BR ibv_create_cq (3),
180 .BR ibv_req_notify_cq (3),
181 .BR ibv_poll_cq (3)
182
183 .SH "AUTHORS"
184 .TP
185 Dotan Barak
186 .RI < [email protected] >