tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c
Extension
.c
Size
26293 bytes
Lines
1059
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

struct test_vcpu_shared_data {
	atomic_t handled;
	atomic_t spurious;
} shared_data;

struct test_args {
	/* Virtual or physical timer and counter tests. */
	enum arch_timer timer;
	/* Delay used for most timer tests. */
	u64 wait_ms;
	/* Delay used in the test_long_timer_delays test. */
	u64 long_wait_ms;
	/* Number of iterations. */
	int iterations;
	/* Whether to test the physical timer. */
	bool test_physical;
	/* Whether to test the virtual timer. */
	bool test_virtual;
};

struct test_args test_args = {
	.wait_ms = WAIT_TEST_MS,
	.long_wait_ms = LONG_WAIT_TEST_MS,
	.iterations = NR_TEST_ITERS_DEF,
	.test_physical = true,
	.test_virtual = true,
};

static int vtimer_irq, ptimer_irq;

enum sync_cmd {
	SET_COUNTER_VALUE,
	USERSPACE_USLEEP,
	USERSPACE_SCHED_YIELD,
	USERSPACE_MIGRATE_SELF,
	NO_USERSPACE_CMD,
};

typedef void (*sleep_method_t)(enum arch_timer timer, u64 usec);

static void sleep_poll(enum arch_timer timer, u64 usec);
static void sleep_sched_poll(enum arch_timer timer, u64 usec);
static void sleep_in_userspace(enum arch_timer timer, u64 usec);
static void sleep_migrate(enum arch_timer timer, u64 usec);

sleep_method_t sleep_method[] = {
	sleep_poll,
	sleep_sched_poll,
	sleep_migrate,
	sleep_in_userspace,
};

typedef void (*irq_wait_method_t)(void);

static void wait_for_non_spurious_irq(void);
static void wait_poll_for_irq(void);
static void wait_sched_poll_for_irq(void);
static void wait_migrate_poll_for_irq(void);

irq_wait_method_t irq_wait_method[] = {
	wait_for_non_spurious_irq,
	wait_poll_for_irq,
	wait_sched_poll_for_irq,
	wait_migrate_poll_for_irq,
};

enum timer_view {
	TIMER_CVAL,
	TIMER_TVAL,
};

static void assert_irqs_handled(u32 n)
{
	int h = atomic_read(&shared_data.handled);

	__GUEST_ASSERT(h == n, "Handled %d IRQS but expected %d", h, n);
}

static void userspace_cmd(u64 cmd)
{
	GUEST_SYNC_ARGS(cmd, 0, 0, 0, 0);
}

static void userspace_migrate_vcpu(void)
{
	userspace_cmd(USERSPACE_MIGRATE_SELF);
}

static void userspace_sleep(u64 usecs)
{

Annotation

Implementation Notes