#include <infiniband/verbs.h> int ibv_get_async_event(struct ibv_context *context, struct ibv_async_event *event); void ibv_ack_async_event(struct ibv_async_event *event);
struct ibv_async_event {
union {
struct ibv_cq *cq; /* CQ that got the event */
struct ibv_qp *qp; /* QP that got the event */
struct ibv_srq *srq; /* SRQ that got the event */
int port_num; /* port number that got the event */
} element;
enum ibv_event_type event_type; /* type of the event */
};
One member of the element union will be valid, depending on the event_type member of the structure. event_type will be one of the following events:
QP events:
CQ events:
SRQ events:
Port events:
CA events:
ibv_ack_async_event() acknowledge the async event event.
ibv_ack_async_event() returns no value.
ibv_get_async_event() is a blocking function. If multiple threads call this function simultaneously, then when an async event occurs, only one thread will receive it, and it is not possible to predict which thread will receive it.
1. Set the async events queue work mode to be non-blocked
2. Poll the queue until it has an async event
3. Get the async event and ack it
/* change the blocking mode of the async event queue */
flags = fcntl(ctx->async_fd, F_GETFL);
rc = fcntl(ctx->async_fd, F_SETFL, flags | O_NONBLOCK);
if (rc < 0) {
fprintf(stderr, "Failed to change file descriptor of async event queue\n");
return 1;
}
/*
* poll the queue until it has an event and sleep ms_timeout
* milliseconds between any iteration
*/
my_pollfd.fd = ctx->async_fd;
my_pollfd.events = POLLIN;
my_pollfd.revents = 0;
do {
rc = poll(&my_pollfd, 1, ms_timeout);
} while (rc == 0);
if (rc < 0) {
fprintf(stderr, "poll failed\n");
return 1;
}
/* Get the async event */
if (ibv_get_async_event(ctx, &async_event)) {
fprintf(stderr, "Failed to get async_event\n");
return 1;
}
/* Ack the event */
ibv_ack_async_event(&async_event);