How it works
ntprof turns timestamps taken on two machines into stage times, without changing the kernel and without synchronizing clocks. Four pieces do it.
1. Hooks on what the kernel already has
ntprof attaches eBPF programs to tracepoints and to functions the compiler kept out of line, on both sides:
- Block layer and NVMe core: the
nvme_setup_cmd,nvme_complete_rq,block_rq_issue,block_rq_complete,nvmet_req_initandnvmet_req_completetracepoints. - NVMe/TCP: the host's send functions and
nvme_tcp_recv_skb, with the receive time of each packet; the target's queue-response and socket-send paths. Where a kernel build inlines the host's send functions, ntprof watches their caller and the socket sends it makes instead. - NVMe/RDMA: posting and completion handlers on both sides (
nvme_rdma_post_send,nvme_rdma_recv_done,nvmet_rdma_recv_done,nvmet_rdma_read_data_done,nvmet_rdma_queue_response,nvmet_rdma_send_done). - SPDK (NVMe/TCP and NVMe/RDMA): a few USDT probes added by a small patch; SPDK keeps the stage times itself and reports them once per command and side. SPDK's I/O never enters the kernel, so hooking it from outside would trap into the kernel at every hook; why a patch for SPDK, and none for the kernel.
Every function hook exists as fentry/fexit and as kprobe/kretprobe. fentry costs less per call and is preferred; kprobes are used where a module has no BTF of its own, or where a busy CPU would make attaching fentry wait.
2. The same commands on both sides
ntprof records one command in N on each machine (-s N). For the two records of a command to meet later, the host
and the target must keep the same commands, although neither tells the other which.
What the first ntprof did. The NSDI'25 artifact changed the drivers: the host decided which commands to sample and marked them with a tag in the command's message, and the target read the tag; the target's times then travelled back inside the response. An eBPF program cannot add a field to a message without changing the drivers and the wire format, so today's ntprof sends nothing at all. Instead, both machines make the same decision on their own.
The rule. A command is sampled when
hash(cid, slba, nlb) mod N == 0
where cid is the command's identifier, slba its starting block and nlb its number of blocks. All three are
fields of the 64-byte NVMe command itself, which crosses the network unchanged: the same bytes go into the same
function on both machines, so both get the same answer. The hash is a short mix of shifts and multiplications
(splitmix64's finaliser), computed for every command on both sides.
A worked example, with N = 100 (-s 100) and three consecutive 4 KiB reads on one queue (a 4 KiB read is 8
blocks of 512 bytes; the field counts from 0, so nlb is 7):
| cid | slba | nlb | hash | hash mod 100 | Host | Target |
|---|---|---|---|---|---|---|
| 37 | 1718280 | 7 | 17529531532818101500 | 0 | records it | records it |
| 37 | 1718288 | 7 | 1449998766250991225 | 25 | skips it | skips it |
| 37 | 1718296 | 7 | 14263320587697034239 | 39 | skips it | skips it |
Neither side asks the other: each computes the same number from the same command and comes to the same decision.
Where each side decides. The decision is taken at the first point where the command exists in full on that side:
| Host | Target | |
|---|---|---|
| Linux drivers | the nvme_setup_cmd tracepoint: the host driver has just built the command, its cid assigned | the nvmet_req_init tracepoint: the target driver has just received the command |
| SPDK | SPDK's host driver submitting the command (nvme_tcp or nvme_rdma) | SPDK's target taking the received command |
In the kernel, the eBPF program at that tracepoint reads the three fields from the command and applies the rule. In SPDK, ntprof's patch contains the same function, line for line, and applies it in SPDK's own code; ntprof gives SPDK the value of N by writing it into a variable of the running process when it starts, and 0 when it stops, after which SPDK samples nothing. Because the rule is the same everywhere, a Linux host and an SPDK target, or the reverse, also keep the same commands.
Why these three fields. The command ID alone would not do: it repeats every few commands (the Linux host driver
folds a 4-bit counter into it, so at queue depth 1 a queue's cid comes back every 16 commands). A hash of the
cid alone would keep the same few IDs forever, or none at all. The starting block changes from one command to
the next, so the choice spreads evenly: with one cid and random blocks, the rule keeps 1.00 % of the commands at
N = 100.
- The same N on both sides. With different values, the two machines keep different commands.
- Start the target first and stop it last, so that the target records every command the host samples. (On one
machine,
-r bothtakes care of this.) - A workload that reads the same few blocks again and again gives the hash little to vary: those commands are then always kept or never. fio's random and sequential patterns move through the blocks.
3. The join
Each side writes one record per sampled command when the command leaves that side, with the times of its own
clock, into its own file; nothing is exchanged while recording. ntprof report host.ntp target.ntp then pairs them.
The key is (controller ID, queue ID, command ID), which both sides know: the controller ID is the number the target gave the host's connection when it was set up (the host reads it from its controller, the target from its own), the queue ID is the queue the command travelled on, and the command ID is the one above.
The checks. Since a command ID comes back every few commands, the key alone is not unique over a run. The target's records under one key wait in the order they arrived, and a host record takes the oldest one that is also the same command: the same opcode, namespace, starting block and length.
What is left over. A target record without a host partner is a command the host did not record: the target recorded longer than the host, or the command came from another host. A host record without a partner is counted, and the report's last line says how many matched:
records: 2298 host, 3508 target; 2298 matched (100 % of the host's)
That line is from the tutorial. In our validation runs, Linux and SPDK on either side, reads and writes of 4 and 128 KiB, every host record found its target record at queue depth 1 and 32; with 4 jobs at queue depth 32 on our servers, at least 99.97 % did.
The clocks never meet: ntprof only subtracts two times taken on the same machine, so the host's and the target's clocks need no synchronization (section 4).
4. The stage model
For each round trip, the host waits from handing its message to the network until the answer reaches its network stack; the target is busy from the message's arrival until it hands its answer back. The host's wait minus the target's residence is the time in the wire, the NICs and the network-stack work that neither driver sees. With the two receive paths (from a packet's arrival to the driver handling it), it forms the network stage. The other components come from one side's timestamps each, and all of them add up exactly to the end-to-end latency. ntprof sums them into five stages: host block layer, host driver, network, target driver and storage.
A large NVMe/TCP read arrives in many packets, and the host copies each one while later ones are still on their way, so receiving and copying overlap. ntprof times the host driver's own work on the read's data, every call that copies it, and counts the rest of the time from the first copy to the last data processed as the host waiting for the rest of the data: network time. A large write after R2T is timed the same way on the target, from each copy of its data into the command's buffer. The wait is never negative, and a transfer whose copying never pauses has none.
Each stage's occupancy (avg QD) is its mean time times the command rate, by Little's law. With
--exact-queues, ntprof instead counts the commands in each queue on every I/O, which costs map operations on
every command.
Accuracy and its limits
- Validated on real hardware: on two servers over 400 GbE RoCE, every sampled command joined across host and target; the storage stage matched the drive measured alone on the target (4 KiB read: 60.0 vs 61.2 µs; 128 KiB read: 93.7 vs 93.7 µs); a busy drive appeared only in storage and a saturated link only in the network stage.
- Sampling follows commands, not time: a run needs enough sampled commands per group for its percentiles.
- The hooks run for every command, sampled or not: on the two servers they added 0.8 µs (NVMe/RDMA) and 1.3 µs (NVMe/TCP) to a 4 KiB read at queue depth 1 (Overhead). A sampled command does a little more work for its own timestamps, which its stage times include.
- A kprobe can miss a command under heavy load: on an NVMe/RDMA target running kprobes, about 10 % of the sampled commands at queue depth 32 lacked the time their response was posted. ntprof closes such a record instead of letting the next command on the same request structure write into it, uses the time the command completed in the NVMe target instead (a difference under a microsecond when both are seen), and the report says how many records this concerns.
- Over loopback the network share is close to 0 and can be slightly negative.
The paper describes the model; the repository's DESIGN.md documents every hook.