tools/testing/selftests/net/io_uring_zerocopy_tx.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/io_uring_zerocopy_tx.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/io_uring_zerocopy_tx.c- Extension
.c- Size
- 7627 bytes
- Lines
- 321
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
assert.herrno.herror.hfcntl.hlimits.hstdbool.hstdint.hstdio.hstdlib.hstring.hunistd.harpa/inet.hlinux/errqueue.hlinux/if_packet.hlinux/io_uring.hlinux/ipv6.hlinux/socket.hlinux/sockios.hnet/ethernet.hnet/if.hnetinet/in.hnetinet/ip.hnetinet/ip6.hnetinet/tcp.hnetinet/udp.hsys/ioctl.hsys/mman.hsys/resource.hsys/socket.hsys/stat.hsys/time.hsys/types.h
Detected Declarations
function gettimeofday_msfunction do_setsockoptfunction do_setup_txfunction do_txfunction do_testfunction usagefunction parse_optsfunction main
Annotated Snippet
if (mode == MODE_NONZC) {
io_uring_prep_send(sqe, fd, payload,
cfg_payload_len, msg_flags);
sqe->user_data = NONZC_TAG;
} else {
io_uring_prep_sendzc(sqe, fd, payload,
cfg_payload_len,
msg_flags, zc_flags);
if (mode == MODE_ZC_FIXED) {
sqe->ioprio |= IORING_RECVSEND_FIXED_BUF;
sqe->buf_index = buf_idx;
}
sqe->user_data = ZC_TAG;
}
}
ret = io_uring_submit(&ring);
if (ret != cfg_nr_reqs)
error(1, -ret, "submit");
if (cfg_cork)
do_setsockopt(fd, IPPROTO_UDP, UDP_CORK, 0);
for (i = 0; i < cfg_nr_reqs; i++) {
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret)
error(1, -ret, "wait cqe");
if (cqe->user_data != NONZC_TAG &&
cqe->user_data != ZC_TAG)
error(1, EINVAL, "invalid cqe->user_data");
if (cqe->flags & IORING_CQE_F_NOTIF) {
if (cqe->flags & IORING_CQE_F_MORE)
error(1, EINVAL, "invalid notif flags");
if (compl_cqes <= 0)
error(1, EINVAL, "notification mismatch");
compl_cqes--;
i--;
io_uring_cqe_seen(&ring);
continue;
}
if (cqe->flags & IORING_CQE_F_MORE) {
if (cqe->user_data != ZC_TAG)
error(1, -cqe->res, "unexpected F_MORE");
compl_cqes++;
}
if (cqe->res >= 0) {
packets++;
bytes += cqe->res;
} else if (cqe->res != -EAGAIN) {
error(1, -cqe->res, "send failed");
}
io_uring_cqe_seen(&ring);
}
} while (gettimeofday_ms() < tstop);
while (compl_cqes) {
ret = io_uring_wait_cqe(&ring, &cqe);
if (ret)
error(1, -ret, "wait cqe");
if (cqe->flags & IORING_CQE_F_MORE)
error(1, EINVAL, "invalid notif flags");
if (!(cqe->flags & IORING_CQE_F_NOTIF))
error(1, EINVAL, "missing notif flag");
io_uring_cqe_seen(&ring);
compl_cqes--;
}
fprintf(stderr, "tx=%lu (MB=%lu), tx/s=%lu (MB/s=%lu)\n",
packets, bytes >> 20,
packets / (cfg_runtime_ms / 1000),
(bytes >> 20) / (cfg_runtime_ms / 1000));
if (close(fd))
error(1, errno, "close");
}
static void do_test(int domain, int type, int protocol)
{
int i;
for (i = 0; i < IP_MAXPACKET; i++)
payload[i] = 'a' + (i % 26);
do_tx(domain, type, protocol);
}
static void usage(const char *filepath)
{
error(1, 0, "Usage: %s (-4|-6) (udp|tcp) -D<dst_ip> [-s<payload size>] "
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `error.h`, `fcntl.h`, `limits.h`, `stdbool.h`, `stdint.h`, `stdio.h`.
- Detected declarations: `function gettimeofday_ms`, `function do_setsockopt`, `function do_setup_tx`, `function do_tx`, `function do_test`, `function usage`, `function parse_opts`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.