ibv_qp_a...comp_cntr(3)
π ibv_qp_attach_comp_cntr β NAME β¨
okay so bestie, welcome to the ibv_qp_attach_comp_cntr page from the Libibverbs Programmer's Manual (yes, that's the manual name, we're fancy here π). The whole vibe of this function? Attach a completion counter to a QP. That's it, that's the tweet. π¦
πΈ SYNOPSIS πΈ
#include <infiniband/verbs.h>
int ibv_qp_attach_comp_cntr(struct ibv_qp *qp,
struct ibv_comp_cntr *comp_cntr,
struct ibv_qp_attach_comp_cntr_attr *attr);
β¨ DESCRIPTION β¨
So ibv_qp_attach_comp_cntr() does exactly what it says on the tin: it attaches the completion counter comp_cntr to the queue pair qp. And the attr argument? That's the little icon that tells it which operation types should update the counter. iykyk π
π¨ vibe check on the QP state, bestie: the QP must be inIBV_QPS_RESETorIBV_QPS_INITstate when you attach a completion counter. Try to attach to a QP in literally any other state and it will fail withEINVAL. no cap, it's not gonna work π
The completion counter starts collecting values for the specified QP once attached. And here's the cute part β attaching the same completion counter to multiple QPs will accumulate values from all attached QPs into the same counter. it's giving "sharing is caring" π«Ά
The op_mask field is the main character here β it controls which operation completions get counted:
- Local operations β
IBV_QP_ATTACH_COMP_CNTR_OP_SEND,IBV_QP_ATTACH_COMP_CNTR_OP_RECV,IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_READ,IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_WRITEβ count completions initiated by the local QP. - Remote operations β
IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_READ,IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_WRITEβ count completions of incoming RDMA operations initiated by the remote side. π
Supported op_mask values may vary by device and can be queried using ibv_query_comp_cntr_caps(3); unsupported values will result in an ENOTSUP error. so like, check before you commit, bestie π
Multiple completion counters can be attached to the same QP β provided their op_mask values do not overlap. Each QP and operation type pair can be associated with at most one completion counter. Attempting to attach a counter with an op_mask that conflicts with an already attached counter will fail. π
And the tea on detaching: there is no explicit detach operation. A completion counter is implicitly detached when the QP it is attached to is destroyed. Also β a completion counter cannot be destroyed while it is still attached to any QP. The QP must be destroyed first. periodt. π
π ARGUMENTS π
qpβ The queue pair to attach the completion counter to. your fave QP πcomp_cntrβ The completion counter to attach, previously created withibv_create_comp_cntr(). gotta make it first, babe β¨attrβ Attach attributes specifying which operation types update the counter.
π§ ibv_qp_attach_comp_cntr_attr π§
enum ibv_qp_attach_comp_cntr_op {
IBV_QP_ATTACH_COMP_CNTR_OP_SEND = 1 << 0,
IBV_QP_ATTACH_COMP_CNTR_OP_RECV = 1 << 1,
IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_READ = 1 << 2,
IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_READ = 1 << 3,
IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_WRITE = 1 << 4,
IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_WRITE = 1 << 5,
};
struct ibv_qp_attach_comp_cntr_attr {
uint32_t comp_mask;
uint32_t op_mask;
};
comp_maskβ Bitmask specifying what fields in the structure are valid. It's used for extensibility, so it should be set to0. keep it zero, bestie, it's not that deep πop_maskβ Bitmask ofibv_qp_attach_comp_cntr_opvalues specifying which operation types should update the counter. the important one π
β RETURN VALUE β
ibv_qp_attach_comp_cntr() returns 0 on success, or the value of errno on failure (which indicates the failure reason). slay when it's 0 π
π₯ ERRORS π₯
EINVALβ Invalid argument(s) passed. πENOTSUPβ Requested operation is not supported on this device. your device said "not today" πEBUSYβ Theop_maskoverlaps with a completion counter already attached to this QP. someone else got there first π
π SEE ALSO π
ibv_create_comp_cntr(3), ibv_query_comp_cntr_caps(3), ibv_create_qp(3)
π¦ AUTHORS π¦
Michael Margolin mrgolin@amazon.com
okay that's the whole page, bestie, you ate that π«Άβ¨ shoutout to libibverbs, dated 2026-02-09 β and yes, the footer says ibv_qp_a...comp_cntr(3) too, we love a consistent icon π
π
π¦ where this page comes from
- arch rolling: rdma-core 65.0-1 Β· GPL-2.0-or-later OR LicenseRef-OpenIB.org-BSD-MIT AND GPL-2.0-or-later OR LicenseRef-OpenIB.org-BSD-FreeBSD AND GPL-2.0-or-later OR LicenseRef-Intel-BSD-3-Clause AND GPL-2.0-or-later OR LicenseRef-PathScale-BSD-Patent-License AND CC0-1.0 AND MIT AND BSD-2-Clause AND CPL-1.0 OR BSD-2-Clause OR GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms