/*
 * DF-5568 — vktimer reload pressure generator (INSIDE the vkernel).
 *
 * Loops clock_nanosleep(2ms) for <secs> seconds, arming dense one-shot
 * timeouts.  Each timeout re-arms the per-cpu one-shot systimer on the
 * current vcpu, which calls vktimer_intr_reload() — the function whose
 * dead CAS loop we are instrumenting.  Run two of these (2 vcpus) to
 * also exercise the cothread->vcpu SIGURG forwarding.
 *
 * build: cc -static -O2 -o hog hog.c
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char **argv)
{
	int secs = argc > 1 ? atoi(argv[1]) : 20;
	struct timespec rq;

	rq.tv_sec = 0;
	rq.tv_nsec = 2 * 1000 * 1000;	/* 2 ms */
	while (secs-- > 0) {
		int n = 500;		/* 500 * 2ms ~= 1s */
		while (n--)
			clock_nanosleep(CLOCK_MONOTONIC, 0, &rq, NULL);
	}
	printf("HOG_DONE\n");
	return 0;
}
