/* * Except x86_64/i386 and Arm64, other archs don't support TSC in perf. Just * enable the test for x86_64/i386 and Arm64 archs.
*/ #ifdefined(__x86_64__) || defined(__i386__) || defined(__aarch64__) #define TSC_IS_SUPPORTED 1 #else #define TSC_IS_SUPPORTED 0 #endif
staticint test__tsc_is_supported(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{ if (!TSC_IS_SUPPORTED) {
pr_debug("Test not supported on this architecture\n"); return TEST_SKIP;
}
return TEST_OK;
}
/** * test__perf_time_to_tsc - test converting perf time to TSC. * * This function implements a test that checks that the conversion of perf time * to and from TSC is consistent with the order of events. If the test passes * %0 is returned, otherwise %-1 is returned. If TSC conversion is not * supported then the test passes but " (not supported)" is printed.
*/ staticint test__perf_time_to_tsc(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
{ struct record_opts opts = {
.mmap_pages = UINT_MAX,
.user_freq = UINT_MAX,
.user_interval = ULLONG_MAX,
.target = {
.uses_mmap = true,
},
.sample_time = true,
}; struct perf_thread_map *threads = NULL; struct perf_cpu_map *cpus = NULL; struct evlist *evlist = NULL; struct evsel *evsel = NULL; int err = TEST_FAIL, ret, i; constchar *comm1, *comm2; struct perf_tsc_conversion tc; struct perf_event_mmap_page *pc; union perf_event *event;
u64 test_tsc, comm1_tsc, comm2_tsc;
u64 test_time, comm1_time = 0, comm2_time = 0; struct mmap *md;
/* For hybrid "cycles:u", it creates two events */
evlist__for_each_entry(evlist, evsel) {
evsel->core.attr.comm = 1;
evsel->core.attr.disabled = 1;
evsel->core.attr.enable_on_exec = 0;
}
ret = evlist__open(evlist); if (ret < 0) { if (ret == -ENOENT)
err = TEST_SKIP; else
pr_debug("evlist__open() failed\n"); goto out_err;
}
CHECK__(evlist__mmap(evlist, UINT_MAX));
pc = evlist->mmap[0].core.base;
ret = perf_read_tsc_conversion(pc, &tc); if (ret) { 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, (unsignedlong)comm1, 0, 0, 0));
test_tsc = rdtsc();
comm2 = "Test COMM 2";
CHECK__(prctl(PR_SET_NAME, (unsignedlong)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;
staticstruct 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 = {
.desc = "Convert perf time to TSC",
.test_cases = time_to_tsc_tests,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.