tools/testing/vsock/vsock_perf.c
Source file repositories/reference/linux-study-clean/tools/testing/vsock/vsock_perf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/vsock/vsock_perf.c- Extension
.c- Size
- 10444 bytes
- Lines
- 500
- 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
getopt.hstdio.hstdlib.hstdbool.hstring.herrno.hunistd.htime.hstdint.hpoll.hsys/socket.hlinux/vm_sockets.hsys/mman.hmsg_zerocopy_common.h
Detected Declarations
function errorfunction current_nsecfunction memparsefunction vsock_increase_buf_sizefunction vsock_connectfunction get_gbpsfunction run_receiverfunction enable_so_zerocopyfunction run_senderfunction usagefunction strtolxfunction main
Annotated Snippet
if (fds.revents & POLLERR) {
fprintf(stderr, "'poll()' error\n");
exit(EXIT_FAILURE);
}
if (fds.revents & POLLIN) {
ssize_t bytes_read;
time_t t;
t = current_nsec();
bytes_read = read(fds.fd, data, buf_size_bytes);
in_read_ns += (current_nsec() - t);
read_cnt++;
if (!bytes_read)
break;
if (bytes_read < 0) {
perror("read");
exit(EXIT_FAILURE);
}
total_recv += bytes_read;
}
if (fds.revents & (POLLHUP | POLLRDHUP))
break;
}
printf("total bytes received: %zu\n", total_recv);
printf("rx performance: %f Gbits/s\n",
get_gbps(total_recv * 8, current_nsec() - rx_begin_ns));
printf("total time in 'read()': %f sec\n", (float)in_read_ns / NSEC_PER_SEC);
printf("average time in 'read()': %f ns\n", (float)in_read_ns / read_cnt);
printf("POLLIN wakeups: %i\n", read_cnt);
free(data);
close(client_fd);
close(fd);
}
static void enable_so_zerocopy(int fd)
{
int val = 1;
if (setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &val, sizeof(val))) {
perror("setsockopt");
exit(EXIT_FAILURE);
}
}
static void run_sender(int peer_cid, unsigned long to_send_bytes)
{
time_t tx_begin_ns;
time_t tx_total_ns;
size_t total_send;
time_t time_in_send;
void *data;
int fd;
if (zerocopy)
printf("Run as sender MSG_ZEROCOPY\n");
else
printf("Run as sender\n");
printf("Connect to %i:%u\n", peer_cid, port);
printf("Send %lu bytes\n", to_send_bytes);
printf("TX buffer %lu bytes\n", buf_size_bytes);
fd = vsock_connect(peer_cid, port);
if (fd < 0)
exit(EXIT_FAILURE);
if (zerocopy) {
enable_so_zerocopy(fd);
data = mmap(NULL, buf_size_bytes, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (data == MAP_FAILED) {
perror("mmap");
exit(EXIT_FAILURE);
}
} else {
data = malloc(buf_size_bytes);
if (!data) {
fprintf(stderr, "'malloc()' failed\n");
exit(EXIT_FAILURE);
}
Annotation
- Immediate include surface: `getopt.h`, `stdio.h`, `stdlib.h`, `stdbool.h`, `string.h`, `errno.h`, `unistd.h`, `time.h`.
- Detected declarations: `function error`, `function current_nsec`, `function memparse`, `function vsock_increase_buf_size`, `function vsock_connect`, `function get_gbps`, `function run_receiver`, `function enable_so_zerocopy`, `function run_sender`, `function usage`.
- 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.