tools/testing/selftests/bpf/prog_tests/perf_branches.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/perf_branches.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/perf_branches.c
Extension
.c
Size
5541 bytes
Lines
183
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.

Dependency Surface

Detected Declarations

Annotated Snippet

if (errno == ENOENT || errno == EOPNOTSUPP || errno == EINVAL) {
			printf("%s:SKIP:no PERF_SAMPLE_BRANCH_STACK\n",
			       __func__);
			test__skip();
			return;
		}
		if (CHECK(pfd < 0, "perf_event_open", "err %d errno %d\n",
			  pfd, errno))
			return;
	}

	test_perf_branches_common(pfd, check_good_sample);

	close(pfd);
}

/*
 * Tests negative case -- run bpf_read_branch_records() on improperly configured
 * perf event.
 */
static void test_perf_branches_no_hw(void)
{
	struct perf_event_attr attr = {0};
	int duration = 0;
	int pfd;

	/* create perf event */
	attr.size = sizeof(attr);
	attr.type = PERF_TYPE_SOFTWARE;
	attr.config = PERF_COUNT_SW_CPU_CLOCK;
	attr.freq = 1;
	attr.sample_freq = 1000;
	pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
	if (CHECK(pfd < 0, "perf_event_open", "err %d\n", pfd))
		return;

	test_perf_branches_common(pfd, check_bad_sample);

	close(pfd);
}

void test_perf_branches(void)
{
	if (test__start_subtest("perf_branches_hw"))
		test_perf_branches_hw();
	if (test__start_subtest("perf_branches_no_hw"))
		test_perf_branches_no_hw();
}

Annotation

Implementation Notes