【verbs】ibv_create_cq()

原文:https://www.rdmamojo.com/2012/11/03/ibv_create_cq/

描述


ibv_create_cq()为RDMA设备上下文创建完成队列(CQ)。
当发送或接收队列中的未完成工作请求完成时,会将【工作完成】添加到该工作队列的CQ中。此【工作完成】指示未完成的工作请求已完成(不再视为未完成),并提供有关此请求的详细信息(状态,方向,操作码等)。
一个CQ 可以在多个QP之间共享用于发送和接收。WC(工作完成)保存 QP编号以及它来自的(发送或接收)队列。
用户可以定义CQ的最小尺寸。实际创建的大小可以等于或大于此值。

 

参数

context入参

从ibv_open_device()返回的RDMA设备上下文

cqe入参

The minimum requested capacity of the CQ, value can be [1..dev_cap.max_cqe]

CQ的最小请求容量值可以是[1..dev_cap.max_cqe]

cq_context入参

(可选)用户定义的值,将在cq-> cq_context中可用。在使用ibv_get_cq_event()等待完成事件通知时,将返回此值

channel入参

(可选)完成事件通道,将用于指示新的WC(工作完成)已添加到此CQ。 NULL表示将不使用任何完成事件通道

comp_vector入参

MSI-X完成向量,将用于发信号通知完成事件。如果这些中断的IRQ关联掩码已配置为将要由不同内核处理每个MSI-X中断,则可以使用此参数在多个内核上 配置工作负载。值可以是[0..context-> num_comp_vectors)。

(MSI-X completion vector that will be used for signaling Completion events. If the IRQ affinity masks of these interrupts have been configured to spread each MSI-X interrupt to be handled by a different core, this parameter can be used to spread the completion workload over multiple cores. Value can be [0..context->num_comp_vectors).)

 

返回值

ValueDescription
CQ

指向新分配的完成队列(CQ)的指针。
该指针还包含以下字段:

 

cq_context提供给ibv_create_cq()的值cq_context
cqeCQ的实际大小
NULL

 

发生错误时,errno指示错误原因:

 

EINVAL

无效的cqe,channel 或comp_vector

ENOMEM

没有足够的资源来完成此操作

例子

 

  • 创建一个包含100个entry的CQ并将其销毁:
struct ibv_cq *cq;
 
cq = ibv_create_cq(context, 100, NULL, NULL, 0);
if (!cq) {
	fprintf(stderr, "Error, ibv_create_cq() failed\n");
	return -1;
}
 
if (ibv_destroy_cq(cq)) {
	fprintf(stderr, "Error, ibv_destroy_cq() failed\n");
	return -1;
}

创建一个带有100个与“完成”事件通道相关联的entry的CQ:
(在此示例中,我们假设完成事件通道之前已经创建):

struct ibv_cq *cq;
struct ibv_comp_channel *channel;
 
cq = ibv_create_cq(context, 100, NULL, channel, 0);
if (!cq) {
	fprintf(stderr, "Error, ibv_create_cq() failed\n");
	return -1;
} 

 

 

常见问题

  • 为何CQ有益呢?

CQ用于为已完成的任何工作请求保留WC(工作完成,WC能提供详细信息)。

  • 我可以在同一QP中对发送/接收队列使用不同的CQ吗?

是的。在任何QP中,发送队列的CQ和接收队列的CQ可以相同或不同。这是灵活的,由用户决定。

  • 几个QP可以与同一个CQ相关联吗?

是的。多个QP可以在它们的发送或接收队列中或在两个队列中与同一个CQ相关联。

  • CQ大小应该是多少?

A CQ should have enough room to hold all of Work Completions of the Outstanding Work Requests of the Queues that are associated with that CQ, so the CQ size shouldn't be less than the total number of Work Request that may be outstanding.

一个CQ应该有足够的空间来容纳与该CQ相关的队列中未完成的工作请求的所有工作完成,因此CQ的大小不应小于可能未完成的工作请求的总数。

  • 如果我选择的CQ尺寸太小会发生什么?

If there will be a case that the CQ will be full and a new Work Completion is going to be added to that CQ, there will be a CQ overrun. A Completion with error will be added to the CQ and an asynchronous event IBV_EVENT_CQ_ERR will be generated.

如果可能出现CQ满的情况,并且要向该CQ添加新的工作完成,则CQ会超支。有错误的完成将添加到CQ中,并生成一个异步事件IBV_EVENT_CQ_ERR。

  • 我可以将哪个值用作cq_context?

由于cq_context  void*,因此您使用任何值。

 

posted on 2022-10-04 01:23  bdy  阅读(32)  评论(0编辑  收藏  举报

导航