---
name: "ibv_create_counters"
section: "3"
platform: "linux"
package: "rdma-core"
version: "65.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ibv_create_counters"
---

# ibv\_create\_counters(3)

Create or destroy a counters handle

## NAME

**ibv\_create\_counters**, **ibv\_destroy\_counters** - Create or destroy a counters handle

## SYNOPSIS

-

  ```
  #include <infiniband/verbs.h>
  struct ibv_counters *
  ibv_create_counters(struct ibv_context *context,
                      struct ibv_counters_init_attr *init_attr);
  int ibv_destroy_counters(struct ibv_counters *counters);
  ```

## DESCRIPTION

**ibv\_create\_counters**() creates a new counters handle for the RDMA device context.

An ibv\_counters handle can be attached to a verbs resource (e.g.: QP, WQ, Flow) statically when these are created.

For example attach an ibv\_counters statically to a Flow (struct ibv\_flow) during creation of a new Flow by calling **ibv\_create\_flow()**.

Counters are cleared upon creation and values will be monotonically increasing.

**ibv\_destroy\_counters**() releases the counters handle, user should detach the counters object before destroying it.

## ARGUMENTS

- *context*

  RDMA device context to create the counters on.

- *init\_attr*

  Is an ibv\_counters\_init\_attr struct, as defined in verbs.h.

### *init\_attr* Argument

-

  ```
  struct ibv_counters_init_attr {
      int comp_mask;
  };
  ```

- *comp\_mask*

  Bitmask specifying what fields in the structure are valid.

## RETURN VALUE

**ibv\_create\_counters**() returns a pointer to the allocated ibv\_counters object, or NULL if the request fails (and sets errno to indicate the failure reason)

**ibv\_destroy\_counters**() returns 0 on success, or the value of errno on failure (which indicates the failure reason)

## ERRORS

- EOPNOTSUPP

  **ibv\_create\_counters**() is not currently supported on this device (ENOSYS may sometimes be returned by old versions of libibverbs).

- ENOMEM

  **ibv\_create\_counters**() could not create ibv\_counters object, not enough memory

- EINVAL

  invalid parameter supplied **ibv\_destroy\_counters**()

## EXAMPLE

An example of use of ibv\_counters is shown in **ibv\_read\_counters**

## SEE ALSO

**ibv\_attach\_counters\_point\_flow**, **ibv\_read\_counters**, **ibv\_create\_flow**

## AUTHORS

Raed Salem ⟨raeds@mellanox.com⟩\\c

Alex Rosenbaum ⟨alexr@mellanox.com⟩\\c
