コード例 #1
0
ファイル: semaphore1.c プロジェクト: IRT-SystemX/xvisor-next
static int semaphore1_do_test(struct vmm_chardev *cdev)
{
	int rc, failures = 0;

	/* Initialize semaphores */
	INIT_SEMAPHORE(&s1, 1, 1);
	INIT_SEMAPHORE(&s2, 1, 0);

	/* s1 semaphore should be available */
	if (!vmm_semaphore_avail(&s1)) {
		failures++;
	}

	/* s2 semaphore should not be available */
	if (vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Acquire s1 semaphore */
	rc = vmm_semaphore_down(&s1);
	if (rc) {
		return rc;
	}

	/* Start workers */
	vmm_threads_start(workers[0]);

	/* Wait for worker0 block on s1 semaphore */
	vmm_msleep(SLEEP_MSECS * 10);

	/* s2 semaphore should not be available */
	if (vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Release s1 semaphore */
	rc = vmm_semaphore_up(&s1);
	if (rc) {
		return rc;
	}

	/* Wait for worker0 wakeup and release s2 semaphore */
	vmm_msleep(SLEEP_MSECS * 10);

	/* s2 semaphore should be available */
	if (!vmm_semaphore_avail(&s2)) {
		failures++;
	}

	/* Stop workers */
	vmm_threads_stop(workers[0]);

	return (failures) ? VMM_EFAIL : 0;
}
コード例 #2
0
ファイル: mutex9.c プロジェクト: IRT-SystemX/xvisor-next
static int mutex9_do_test(struct vmm_chardev *cdev)
{
	u64 i, timeout, etimeout, tstamp;
	int rc, failures = 0;

	/* Initialise the shared_data to zero */
	shared_data = 0;

	/* Start worker */
	vmm_threads_start(workers[0]);

	/*
	 * The worker thread has now been started and should take ownership
	 * of the mutex. We wait a while and check that shared_data has been
	 * modified, which proves to us that the thread has taken the mutex.
	 */
	vmm_msleep(SLEEP_MSECS*10);

	/* Check shared data. It should be one. */
	if (shared_data != 1) {
		vmm_cprintf(cdev, "error: shared data unmodified\n");
		failures++;
	}

	/* Try mutex lock with timeout few times */
	for (i = 1; i <= 10; i++) {
		/* Save current timestamp */
		tstamp = vmm_timer_timestamp();

		/* Lock mutex with timeout */
		etimeout = i * SLEEP_MSECS * 1000000ULL;
		timeout = etimeout;
		rc = vmm_mutex_lock_timeout(&mutex1, &timeout);
		if (rc != VMM_ETIMEDOUT) {
			vmm_cprintf(cdev, "error: did not timeout\n");
			failures++;
		}

		/* Check elapsed time */
		tstamp = vmm_timer_timestamp() - tstamp;
		if (tstamp < etimeout) {
			vmm_cprintf(cdev, "error: time elapsed %"PRIu64
				    " nanosecs instead of %"PRIu64" nanosecs",
				    tstamp, etimeout);
			failures++;
		}
	}

	/* Stop worker thread. */
	vmm_threads_stop(workers[0]);

	return (failures) ? VMM_EFAIL : 0;
}
コード例 #3
0
ファイル: mutex4.c プロジェクト: IRT-SystemX/xvisor-next
static int mutex4_do_test(struct vmm_chardev *cdev)
{
	int done_count = 0;

	/* Initialize work done completion */
	INIT_COMPLETION(&work_done);

	/* Acquire mutex1 */
	vmm_mutex_lock(&mutex1);

	/* Start workers */
	vmm_threads_start(workers[0]);
	vmm_threads_start(workers[1]);
	vmm_threads_start(workers[2]);
	vmm_threads_start(workers[3]);
	vmm_msleep(SLEEP_MSECS*40);

	/* Release mutex1 */
	vmm_mutex_unlock(&mutex1);

	/* Wait for workers to complete */
	do {
		if (done_count == NUM_THREADS) {
			break;
		}

		vmm_completion_wait(&work_done);
		done_count++;
	} while (1);

	/* Stop workers */
	vmm_threads_stop(workers[3]);
	vmm_threads_stop(workers[2]);
	vmm_threads_stop(workers[1]);
	vmm_threads_stop(workers[0]);

	return 0;
}
コード例 #4
0
ファイル: mutex7.c プロジェクト: IRT-SystemX/xvisor-next
static int mutex7_do_test(struct vmm_chardev *cdev)
{
	int rc, failures = 0;

	/* Initialise the shared_data to zero */
	shared_data = 0;

	/* Attempt to release the mutex when not owned by any thread */
	rc = vmm_mutex_unlock(&mutex1);
	if (rc == VMM_OK) {
		vmm_cprintf(cdev, "error: unlocking mutex worked\n");
		failures++;
	}

	/* Start worker */
	vmm_threads_start(workers[0]);

	/*
	 * The worker thread has now been started and should take ownership
	 * of the mutex. We wait a while and check that shared_data has been
	 * modified, which proves to us that the thread has taken the mutex.
	 */
	vmm_msleep(SLEEP_MSECS*10);

	/* Attempt to release the mutex when owned by worker thread */
	rc = vmm_mutex_unlock(&mutex1);
	if (rc == VMM_OK) {
		vmm_cprintf(cdev, "error: unlocking mutex worked\n");
		failures++;
	}

	/* Stop worker thread */
	vmm_threads_stop(workers[0]);

	return (failures) ? VMM_EFAIL : 0;
}
コード例 #5
0
ファイル: mterm.c プロジェクト: nmaiti/xvisor
static void daemon_mterm_exit(void)
{
	vmm_threads_stop(mtctrl.thread);

	vmm_threads_destroy(mtctrl.thread);
}