github ↗
docs menu

Module Rig_mlx5.Qp

A queue pair is a send ring, and a receive ring if it was made with one, connected to one queue pair of a peer.

A send (Rig_mlx5_abi.Entry.op's Send) lands its bytes in the oldest receive the peer posted and has not filled. A send that finds none is retried without end, and lands once the peer posts one. A queue pair of this library asks its peer to retry 0.64 ms later. A message longer than its receive fails the receive, the queue pair and its peer's.

#type t

The type for reliable-connected queue pairs.

#type address =
  1. #| Lid of int
    (*

    An InfiniBand port's local identifier.

    *)
  2. #| Gid of string
    (*

    An Ethernet port's 16-byte RoCE v2 global identifier, an IPv6 address or an IPv4 one mapped into IPv6.

    *)

The type for the addresses of ports.

#type endpoint = {
  1. #qp : int;
    (*

    The queue pair's number.

    *)
  2. #psn : int;
    (*

    The packet sequence number it starts at.

    *)
  3. #address : address;
    (*

    Its port's address.

    *)
  4. #mtu : int;
    (*

    Its port's active MTU, in bytes.

    *)
}

The type for what a peer needs to connect to a queue pair. It is plain data, which a program sends to the peer by any means.

#val make : Cq.t -> receives:int -> int -> (t, string) Stdlib.result

make cq ~receives n is an unconnected queue pair of cq's NIC with room for n entries, n rounded up to a power of two, and for receives receives, rounded up to a power of two no smaller than 4, or no receive ring if receives is 0. Its completions go to cq. It starts at a random packet sequence number. A queue pair with no receive ring takes no messages, so its peer only reads and writes this process's regions through it.

It is Error msg if the rounded n or receives is more than a queue pair of cq's NIC holds, as its kernel driver reports, or more than 215; msg then names the bound. It is also Error msg if the kernel refuses or the process cannot allocate the rings.

Raises Invalid_argument if n < 1, receives < 0, or the queue pairs of cq, each counted at its rounded entries and receives, would hold more than cq.

#val number : t -> int

number qp is qp's number, which completions name.

#val endpoint : t -> endpoint

endpoint qp is what a peer's queue pair connects to qp with.

#val connect : t -> Region.access -> endpoint -> (unit, string) Stdlib.result

connect qp a e connects qp to the peer's queue pair e, at the smaller of both ports' MTUs, and makes it ready to send. The peer may do a to this process's regions through qp (Region.access). A peer that only sends to qp, or that qp only writes, reads and sends to, needs Local. A request of qp that the peer does not acknowledge is retried 7 times, each after an acknowledgement timeout of 1.07 s on InfiniBand or 67 ms on Ethernet, and its entry then fails with Rig_mlx5_abi.Completion.error.Retry_exceeded.

e may be qp's own endpoint. qp is then its own peer, and its writes and reads move bytes between regions of this process, through the NIC, which a must allow.

It is Error msg if the kernel refuses a change of qp's state.

Raises Invalid_argument if qp was connected, e's address is not of qp's link layer, or a Gid is not 16 bytes.

#val room : t -> Rig_mlx5_abi.ring -> int

room qp r is how many entries or receives qp takes before its ring r is full. An entry's slot is free once a completion of it, or of an entry after it, has been polled, and a receive's once its completion has been polled. A completion of an unexpected kind (Rig_mlx5_abi.Completion.status.Unexpected) frees no slot.

#val post : t -> Rig_mlx5_abi.Entry.t -> unit

post qp e writes e in qp's send ring. The NIC runs it after the next ring.

Raises Invalid_argument if qp is not connected, room qp Send is 0, e moves more than max_message bytes, or as Rig_mlx5_abi.Entry.write does, which refuses an entry of 231 bytes a port's max_message may allow.

#val receive : t -> Rig_mlx5_abi.Entry.local -> unit

receive qp l posts the receive of up to l.bytes bytes into l in qp's receive ring. The NIC may fill it as soon as receive returns, with the next message of qp's peer that no earlier receive took.

Raises Invalid_argument if qp is not connected, has no receive ring or room qp Receive is 0, or as Rig_mlx5_abi.Receive.write does.

#val ring : t -> unit

ring qp hands the NIC the entries posted since the last ring. It does nothing if there are none.

#val destroy : t -> (unit, string) Stdlib.result

destroy qp destroys qp and frees its ring. The NIC runs none of its entries and reads and writes no memory for it once destroy returns Ok (). The entries of its peer's queue pair fail once their retries end.

It is Error msg if the kernel refuses. qp then counts as destroyed and its ring is freed all the same, but the kernel's queue pair may still complete its entries, which keep their room in its completion queue (make) until the NIC closes.