[BUG -rt] -rt16 hang w/ realtime thread test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Ingo,
	I've been hunting a report that lower priority realtime threads are not
preempting higher priority realtime threads. However, in generating test
cases, I found I was locking the system quite frequently.

The attached test runs to completion on 2.6.15, but with 2.6.15-rt16, it
hangs the box. It could very well be a test issue, but I'm not sure I
see where the problem is.

thanks
-john

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
#include <sched.h>
#include <errno.h>
#include <sys/syscall.h>


#define MAXTHREADS 256
#define TEST_LENGTH 5

volatile int test_finished;
volatile int running_count;

pthread_mutex_t     mutex = PTHREAD_MUTEX_INITIALIZER;


void *busy(void* arg)
{
	struct timeval start, now;

    	pthread_mutex_lock(&mutex);
	running_count = running_count + 1;
    	pthread_mutex_unlock(&mutex);

	gettimeofday(&start,0);
	while (!test_finished){
		gettimeofday(&now,0);
		if (now.tv_sec - start.tv_sec > 10) {
			printf("Something is broken\n");
			break;
		}
		sched_yield();
	}
    	pthread_mutex_lock(&mutex);
	running_count--;
    	pthread_mutex_unlock(&mutex);

}

void create_thread(pthread_t *thread, void*(*func)(void*), int prio)
{
	pthread_attr_t attr;
	struct sched_param param;

	param.sched_priority = sched_get_priority_min(SCHED_FIFO) + prio;

	pthread_attr_init(&attr);
	pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
	pthread_attr_setschedparam(&attr, &param);
	pthread_attr_setschedpolicy(&attr, SCHED_FIFO);

	if (pthread_create(thread, &attr, func, (void *)0)) {
		perror("pthread_create failed");
	}

	pthread_attr_destroy(&attr);
}

int main(int argc, char* argv[])
{
	struct sched_param param;
	int num_threads;
	int priority;
	int thread_count = 0;
	pthread_t thread_id[MAXTHREADS];
	int i;

	if (argc != 2) {
		printf("Usage: %s num_threads\n", argv[0]);
		exit(1);
	}

	num_threads = atoi(argv[1]);


	param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 80;
	sched_setscheduler(0, SCHED_FIFO, &param);

	priority = 30;
	for (i = 0; i < num_threads; i++)
		create_thread(&thread_id[thread_count++],
				busy, priority);
	while (running_count < num_threads)
		usleep(100);


	sleep(TEST_LENGTH);
	test_finished = 1;

	for (i = 0; i < thread_count; i++)
		pthread_join(thread_id[i], 0);

	return 0;
}


[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux