Пример #1
0
/*
 * Test pthread creation at different thread priorities.
 */
int main(int argc, char *argv[])
{
	int i, retc, nopi = 0;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(0, &mask);
	setup();

	rt_init("h", parse_args, argc, argv);

	retc = pthread_barrier_init(&barrier, NULL, 5);
	if (retc) {
		printf("pthread_barrier_init failed: %s\n", strerror(retc));
		exit(retc);
	}

	retc = sched_setaffinity(0, sizeof(mask), &mask);
	if (retc < 0) {
		printf("Main Thread: Can't set affinity: %d %s\n", retc,
		       strerror(retc));
		exit(-1);
	}
	for (i = 0; i < argc; i++) {
		if (strcmp(argv[i], "nopi") == 0)
			nopi = 1;
	}

	printf("Start %s\n", argv[0]);

	glob_mutex = malloc(sizeof(pthread_mutex_t));
	if (glob_mutex == NULL) {
		printf("Malloc failed\n");
		exit(errno);
	}

	if (!nopi)
		init_pi_mutex(glob_mutex);

	create_other_thread(func_nonrt, NULL);
	create_rr_thread(func_rt, NULL, 20);
	create_rr_thread(func_rt, NULL, 30);
	create_rr_thread(func_rt, NULL, 40);
	create_rr_thread(func_noise, NULL, 40);

	printf("Joining threads\n");
	join_threads();
	printf("Done\n");

	pthread_mutex_destroy(glob_mutex);
	pthread_mutex_destroy(&cond_mutex);
	pthread_cond_destroy(&cond_var);

	return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	long i;
	int ret;
	setup();

	pass_criteria = THRESHOLD;
	rt_init("hi:n:w:", parse_args, argc, argv);

	if (iterations < 100) {
		printf("Number of iterations cannot be less than 100\n");
		exit(1);
	}

	busy_work_time = low_work_time;
	if (num_busy == -1) {
		/* Number of busy threads = No. of CPUs */
		num_busy = sysconf(_SC_NPROCESSORS_ONLN);
	}

	if ((ret = pthread_barrier_init(&bar1, NULL, (num_busy + 2)))) {
		printf("pthread_barrier_init failed: %s\n", strerror(ret));
		exit(ret);
	}
	if ((ret = pthread_barrier_init(&bar2, NULL, (num_busy + 2)))) {
		printf("pthread_barrier_init failed: %s\n", strerror(ret));
		exit(ret);
	}

	init_pi_mutex(&lock);


	if ((ret = create_fifo_thread(low_prio_thread, (void *)0, LOWPRIO)) < 0)
		exit(ret);
	if ((ret = create_fifo_thread(high_prio_thread, (void *)0, HIGHPRIO)) < 0)
		exit(ret);

	for (i = 0; i < num_busy; i++) {
		if ((ret = create_fifo_thread(busy_thread, (void *)i, BUSYPRIO)) < 0)
			exit(ret);
	}

	join_threads();
	printf("Criteria: High prio lock wait time < "
			"(Low prio lock held time + %d us)\n", (int)pass_criteria);

	ret = 0;
	if (max_pi_delay > pass_criteria)
		ret = 1;

	printf("Result: %s\n", ret ? "FAIL" : "PASS");
	return ret;
}
Пример #3
0
/*
 * Test pthread creation at different thread priorities.
 */
int main(int argc, char *argv[])
{
	int i, retc, nopi = 0;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(0, &mask);
	setup();
	rt_init("h", parse_args, argc, argv);

	retc = pthread_barrier_init(&barrier, NULL, 5);
	if (retc) {
		printf("pthread_barrier_init failed: %s\n", strerror(retc));
		exit(retc);
	}

	retc = sched_setaffinity(0, sizeof(mask), &mask);
	if (retc < 0) {
		printf("Main Thread: Can't set affinity: %d %s\n", retc,\
			strerror(retc));
		exit(-1);
	}

	for (i = 0; i < argc; i++) {
		if (strcmp(argv[i], "nopi") == 0)
			nopi = 1;
	}

	printf("Start %s\n", argv[0]);

	if (!nopi)
		init_pi_mutex(&glob_mutex);

	create_rr_thread(func_lowrt, NULL, 10);
	create_rr_thread(func_rt, NULL, 20);
	create_fifo_thread(func_rt, NULL, 30);
	create_fifo_thread(func_rt, NULL, 40);
	create_rr_thread(func_noise, NULL, 40);

	printf("Joining threads\n");
	join_threads();
	printf("Done\n");
	printf("Criteria: Low Priority Thread and High Priority Thread "\
		"should prempt each other multiple times\n");

	pthread_mutex_destroy(&glob_mutex);
	pthread_mutex_destroy(&cond_mutex);
	pthread_cond_destroy(&cond_var);

	return 0;
}
Пример #4
0
int main(int argc, char *argv[])
{
	init_pi_mutex(&MM);
	init_pi_mutex(&MS);
	init_pi_mutex(&MT);
	setup();

	pthread_cond_init(&CM, NULL);
	pthread_cond_init(&CS, NULL);
	pthread_cond_init(&CT, NULL);

	rt_init("h", parse_args, argc, argv);

	create_other_thread(master_thread, (void *)0);

	// wait for the slaves to quit
	while (atomic_get(&slave_order_c) < NUM_SLAVES)
		usleep(10);

	join_threads();

	return 0;
}
Пример #5
0
int main(int argc, char *argv[])
{
	struct option longopts[] = {
		{"broadcast", 0, NULL, 'a'},
		{"realtime", 0, NULL, 'r'},
		{NULL, 0, NULL, 0},
	};
	setup();

	init_pi_mutex(&child_mutex);
	rt_init_long("ahi:n:r", longopts, parse_args, argc, argv);

	/* Legacy command line arguments support, overrides getopt args. */
	if (optind < argc)
		iterations = strtol(argv[optind++], NULL, 0);
	if (optind < argc)
		nthreads = strtol(argv[optind++], NULL, 0);

	/* Ensure we have the required arguments. */
	if (iterations == 0 || nthreads == 0) {
		usage();
		exit(1);
	}

	child_waiting = (int *)malloc(sizeof(*child_waiting) * nthreads);
	condlist = (pthread_cond_t *) malloc(sizeof(*condlist) * nthreads);
	if ((child_waiting == NULL) || (condlist == NULL)) {
		fprintf(stderr, "Out of memory\n");
		exit(-1);
	}
	test_signal(iterations, nthreads);
	printf("\nCriteria: latencies < %d us\n", PASS_US);
	printf("Result: %s\n", fail ? "FAIL" : "PASS");

	return 0;
}
Пример #6
0
int main(int argc, char* argv[])
{
	int threads_per_prio;
	int numcpus;
	int numprios;
	int prio;
	int i;
	setup();

	rt_init("hn:l:", parse_args, argc, argv);

	if (rt_threads == 0) {
		numcpus = sysconf(_SC_NPROCESSORS_ONLN);
		rt_threads = numcpus;
	}
	wakeup.arr = (int *)malloc(rt_threads * sizeof(int));
	wakeup.counter = 0;
	printf("\n-----------------------\n");
	printf("Priority Ordered Wakeup\n");
	printf("-----------------------\n");
	printf("Worker Threads: %d\n", rt_threads);
	printf("Calling pthread_cond_broadcast() with mutex: %s\n\n",
	       locked_broadcast ? "LOCKED" : "UNLOCKED");

	beginrun = rt_gettime();

	init_pi_mutex(&mutex);

	/* calculate the number of threads per priority */
	/* we get num numprios -1 for the workers, leaving one for the master */
	numprios = sched_get_priority_max(SCHED_FIFO) -
		   sched_get_priority_min(SCHED_FIFO);

	threads_per_prio = rt_threads /	numprios;
	if (rt_threads % numprios)
		threads_per_prio++;

	/* start the worker threads */
	prio = sched_get_priority_min(SCHED_FIFO);
	for (i = rt_threads; i > 0; i--) {
		if ((i != rt_threads && (i % threads_per_prio) == 0))
			prio++;
		create_fifo_thread(worker_thread, (void*)(intptr_t)i, prio);
	}

	/* start the master thread */
	create_fifo_thread(master_thread, (void*)(intptr_t)i, ++prio);

	/* wait for threads to complete */
	join_threads();

	pthread_mutex_destroy(&mutex);

	printf("\nCriteria: Threads should be woken up in priority order\n");

	for (i = 0; i < (wakeup.counter-1); i++) {
		if (wakeup.arr[i] < wakeup.arr[i+1]) {
			printf("FAIL: Thread %d woken before %d\n", wakeup.arr[i], wakeup.arr[i+1]);
			ret++;
		}
	}
	printf("Result: %s\n", ret ? "FAIL" : "PASS");
	return ret;
}