tools/testing/selftests/net/txtimestamp.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/txtimestamp.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/txtimestamp.c- Extension
.c- Size
- 23087 bytes
- Lines
- 952
- 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.hasm/types.herror.herrno.hinttypes.hlinux/errqueue.hlinux/if_ether.hlinux/if_packet.hlinux/ipv6.hlinux/net_tstamp.hnetdb.hnet/if.hnetinet/in.hnetinet/ip.hnetinet/udp.hnetinet/tcp.hpoll.hstdarg.hstdbool.hstdio.hstdlib.hstring.hsys/epoll.hsys/ioctl.hsys/select.hsys/socket.hsys/time.hsys/types.htime.hunistd.h
Detected Declarations
struct timing_eventfunction timespec_to_ns64function timespec_to_us64function init_timing_eventfunction add_timing_eventfunction validate_keyfunction validate_timestampfunction __print_ts_delta_formattedfunction __print_timestampfunction record_timestamp_usrfunction print_timestampfunction print_timing_eventfunction print_payloadfunction print_pktinfofunction __epollfunction __pollfunction __recv_errmsg_cmsgfunction recv_errmsgfunction get_ip_csumfunction get_udp_csumfunction fill_header_ipv4function fill_header_ipv6function fill_header_udpfunction do_testfunction __attribute__function parse_optfunction resolve_hostnamefunction do_listenfunction connectfunction main
Annotated Snippet
struct timing_event {
int64_t min;
int64_t max;
int64_t total;
int count;
};
static struct timing_event usr_enq;
static struct timing_event usr_snd;
static struct timing_event usr_ack;
static bool test_failed;
static int64_t timespec_to_ns64(struct timespec *ts)
{
return ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec;
}
static int64_t timespec_to_us64(struct timespec *ts)
{
return ts->tv_sec * USEC_PER_SEC + ts->tv_nsec / NSEC_PER_USEC;
}
static void init_timing_event(struct timing_event *te)
{
te->min = INT64_MAX;
te->max = 0;
te->total = 0;
te->count = 0;
}
static void add_timing_event(struct timing_event *te,
struct timespec *t_start, struct timespec *t_end)
{
int64_t ts_delta = timespec_to_ns64(t_end) - timespec_to_ns64(t_start);
te->count++;
if (ts_delta < te->min)
te->min = ts_delta;
if (ts_delta > te->max)
te->max = ts_delta;
te->total += ts_delta;
}
static void validate_key(int tskey, int tstype)
{
int stepsize;
/* compare key for each subsequent request
* must only test for one type, the first one requested
*/
if (saved_tskey == -1 || cfg_use_cmsg_opt_id)
saved_tskey_type = tstype;
else if (saved_tskey_type != tstype)
return;
stepsize = cfg_proto == SOCK_STREAM ? cfg_payload_len : 1;
stepsize = cfg_use_cmsg_opt_id ? 0 : stepsize;
if (tskey != saved_tskey + stepsize) {
fprintf(stderr, "ERROR: key %d, expected %d\n",
tskey, saved_tskey + stepsize);
test_failed = true;
}
saved_tskey = tskey;
}
static void validate_timestamp(struct timespec *cur, int min_delay)
{
int64_t cur64, start64;
int max_delay;
cur64 = timespec_to_us64(cur);
start64 = timespec_to_us64(&ts_usr);
max_delay = min_delay + cfg_delay_tolerance_usec;
if (cur64 < start64 + min_delay || cur64 > start64 + max_delay) {
fprintf(stderr, "ERROR: %" PRId64 " us expected between %d and %d\n",
cur64 - start64, min_delay, max_delay);
if (!getenv("KSFT_MACHINE_SLOW"))
test_failed = true;
}
}
static void __print_ts_delta_formatted(int64_t ts_delta)
{
if (cfg_print_nsec)
fprintf(stderr, "%" PRId64 " ns", ts_delta);
else
fprintf(stderr, "%" PRId64 " us", ts_delta / NSEC_PER_USEC);
Annotation
- Immediate include surface: `arpa/inet.h`, `asm/types.h`, `error.h`, `errno.h`, `inttypes.h`, `linux/errqueue.h`, `linux/if_ether.h`, `linux/if_packet.h`.
- Detected declarations: `struct timing_event`, `function timespec_to_ns64`, `function timespec_to_us64`, `function init_timing_event`, `function add_timing_event`, `function validate_key`, `function validate_timestamp`, `function __print_ts_delta_formatted`, `function __print_timestamp`, `function record_timestamp_usr`.
- 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.