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

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/timer.c
Extension
.c
Size
8148 bytes
Lines
352
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) {
			printf("SKIP:no PERF_COUNT_HW_CPU_CYCLES\n");
			test__skip();
			ret = EOPNOTSUPP;
			goto cleanup;
		}
		ASSERT_GE(pe_fd, 0, "perf_event_open");
		goto cleanup;
	}

	link = bpf_program__attach_perf_event(prog, pe_fd);
	if (!ASSERT_OK_PTR(link, "attach_perf_event"))
		goto cleanup;
	pe_fd = -1;  /* Ownership transferred to link */

	/* Signal child to start CPU work */
	close(pipefd[0]);
	pipefd[0] = -1;
	write(pipefd[1], &buf, 1);
	close(pipefd[1]);
	pipefd[1] = -1;

	waitpid(pid, &status, 0);
	pid = 0;

	/* Verify NMI context was hit */
	ASSERT_GT(timer_skel->bss->test_hits, 0, "test_hits");
	ret = 0;

cleanup:
	bpf_link__destroy(link);
	if (pe_fd >= 0)
		close(pe_fd);
	if (pid > 0) {
		write(pipefd[1], &buf, 1);
		waitpid(pid, &status, 0);
	}
	if (pipefd[0] >= 0)
		close(pipefd[0]);
	if (pipefd[1] >= 0)
		close(pipefd[1]);
	return ret;
}

static int timer_stress_nmi_race(struct timer *timer_skel)
{
	int err;

	err = run_nmi_test(timer_skel, timer_skel->progs.nmi_race);
	if (err == EOPNOTSUPP)
		return 0;
	return err;
}

static int timer_stress_nmi_update(struct timer *timer_skel)
{
	int err;

	err = run_nmi_test(timer_skel, timer_skel->progs.nmi_update);
	if (err == EOPNOTSUPP)
		return 0;
	if (err)
		return err;
	ASSERT_GT(timer_skel->bss->update_hits, 0, "update_hits");
	return 0;
}

static int timer_stress_nmi_cancel(struct timer *timer_skel)
{
	int err;

	err = run_nmi_test(timer_skel, timer_skel->progs.nmi_cancel);
	if (err == EOPNOTSUPP)
		return 0;
	if (err)
		return err;
	ASSERT_GT(timer_skel->bss->cancel_hits, 0, "cancel_hits");
	return 0;
}

static int timer(struct timer *timer_skel)
{
	int err, prog_fd;
	LIBBPF_OPTS(bpf_test_run_opts, topts);

	err = timer__attach(timer_skel);
	if (!ASSERT_OK(err, "timer_attach"))
		return err;

	ASSERT_EQ(timer_skel->data->callback_check, 52, "callback_check1");

Annotation

Implementation Notes