tools/perf/tests/perf-time-to-tsc.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/perf-time-to-tsc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/perf-time-to-tsc.c- Extension
.c- Size
- 5606 bytes
- Lines
- 222
- 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
errno.hinttypes.hlimits.hstdbool.hstdio.hunistd.hlinux/types.hsys/prctl.hperf/cpumap.hperf/evlist.hperf/mmap.hdebug.hparse-events.hevlist.hevsel.hthread_map.hrecord.htsc.hmmap.htests.hutil/sample.h
Detected Declarations
function test__tsc_is_supportedfunction test__perf_time_to_tsc
Annotated Snippet
if (ret == -EOPNOTSUPP) {
pr_debug("perf_read_tsc_conversion is not supported in current kernel\n");
err = TEST_SKIP;
}
goto out_err;
}
evlist__enable(evlist);
comm1 = "Test COMM 1";
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm1, 0, 0, 0));
test_tsc = rdtsc();
comm2 = "Test COMM 2";
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm2, 0, 0, 0));
evlist__disable(evlist);
for (i = 0; i < evlist->core.nr_mmaps; i++) {
md = &evlist->mmap[i];
if (perf_mmap__read_init(&md->core) < 0)
continue;
while ((event = perf_mmap__read_event(&md->core)) != NULL) {
struct perf_sample sample;
perf_sample__init(&sample, /*all=*/false);
if (event->header.type != PERF_RECORD_COMM ||
(pid_t)event->comm.pid != getpid() ||
(pid_t)event->comm.tid != getpid())
goto next_event;
if (strcmp(event->comm.comm, comm1) == 0) {
CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
CHECK__(evsel__parse_sample(evsel, event, &sample));
comm1_time = sample.time;
}
if (strcmp(event->comm.comm, comm2) == 0) {
CHECK_NOT_NULL__(evsel = evlist__event2evsel(evlist, event));
CHECK__(evsel__parse_sample(evsel, event, &sample));
comm2_time = sample.time;
}
next_event:
perf_mmap__consume(&md->core);
perf_sample__exit(&sample);
}
perf_mmap__read_done(&md->core);
}
if (!comm1_time || !comm2_time)
goto out_err;
test_time = tsc_to_perf_time(test_tsc, &tc);
comm1_tsc = perf_time_to_tsc(comm1_time, &tc);
comm2_tsc = perf_time_to_tsc(comm2_time, &tc);
pr_debug("1st event perf time %"PRIu64" tsc %"PRIu64"\n",
comm1_time, comm1_tsc);
pr_debug("rdtsc time %"PRIu64" tsc %"PRIu64"\n",
test_time, test_tsc);
pr_debug("2nd event perf time %"PRIu64" tsc %"PRIu64"\n",
comm2_time, comm2_tsc);
if (test_time <= comm1_time ||
test_time >= comm2_time)
goto out_err;
if (test_tsc <= comm1_tsc ||
test_tsc >= comm2_tsc)
goto out_err;
err = TEST_OK;
out_err:
evlist__delete(evlist);
perf_cpu_map__put(cpus);
perf_thread_map__put(threads);
return err;
}
static struct test_case time_to_tsc_tests[] = {
TEST_CASE_REASON("TSC support", tsc_is_supported,
"This architecture does not support"),
TEST_CASE_REASON("Perf time to TSC", perf_time_to_tsc,
"perf_read_tsc_conversion is not supported"),
{ .name = NULL, }
};
struct test_suite suite__perf_time_to_tsc = {
Annotation
- Immediate include surface: `errno.h`, `inttypes.h`, `limits.h`, `stdbool.h`, `stdio.h`, `unistd.h`, `linux/types.h`, `sys/prctl.h`.
- Detected declarations: `function test__tsc_is_supported`, `function test__perf_time_to_tsc`.
- 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.