tools/testing/selftests/net/fin_ack_lat.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/fin_ack_lat.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/fin_ack_lat.c- Extension
.c- Size
- 3397 bytes
- Lines
- 152
- 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
arpa/inet.herrno.herror.hnetinet/in.hnetinet/tcp.hsignal.hstdio.hstdlib.hsys/socket.hsys/time.hunistd.h
Detected Declarations
function timedifffunction clientfunction serverfunction sig_handlerfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <arpa/inet.h>
#include <errno.h>
#include <error.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
static int child_pid;
static unsigned long timediff(struct timeval s, struct timeval e)
{
unsigned long s_us, e_us;
s_us = s.tv_sec * 1000000 + s.tv_usec;
e_us = e.tv_sec * 1000000 + e.tv_usec;
if (s_us > e_us)
return 0;
return e_us - s_us;
}
static void client(int port)
{
int sock = 0;
struct sockaddr_in addr, laddr;
socklen_t len = sizeof(laddr);
struct linger sl;
int flag = 1;
int buffer;
struct timeval start, end;
unsigned long lat, sum_lat = 0, nr_lat = 0;
while (1) {
gettimeofday(&start, NULL);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
error(-1, errno, "socket creation");
sl.l_onoff = 1;
sl.l_linger = 0;
if (setsockopt(sock, SOL_SOCKET, SO_LINGER, &sl, sizeof(sl)))
error(-1, errno, "setsockopt(linger)");
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
&flag, sizeof(flag)))
error(-1, errno, "setsockopt(nodelay)");
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) <= 0)
error(-1, errno, "inet_pton");
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
error(-1, errno, "connect");
send(sock, &buffer, sizeof(buffer), 0);
if (read(sock, &buffer, sizeof(buffer)) == -1)
error(-1, errno, "waiting read");
gettimeofday(&end, NULL);
lat = timediff(start, end);
sum_lat += lat;
nr_lat++;
if (lat < 100000)
goto close;
if (getsockname(sock, (struct sockaddr *)&laddr, &len) == -1)
error(-1, errno, "getsockname");
printf("port: %d, lat: %lu, avg: %lu, nr: %lu\n",
ntohs(laddr.sin_port), lat,
sum_lat / nr_lat, nr_lat);
close:
fflush(stdout);
close(sock);
}
}
static void server(int sock, struct sockaddr_in address)
{
int accepted;
int addrlen = sizeof(address);
int buffer;
Annotation
- Immediate include surface: `arpa/inet.h`, `errno.h`, `error.h`, `netinet/in.h`, `netinet/tcp.h`, `signal.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `function timediff`, `function client`, `function server`, `function sig_handler`, `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.