- lower buzy_process priority below timer interrupt priority to prevent
uninterruptible while(1); loop on RT systems
- synchronize thread start to run test properly

-- 
Stefan Assmann          | SUSE LINUX Products GmbH
Software Engineer       | Maxfeldstr. 5, D-90409 Nuernberg
Mail : [EMAIL PROTECTED] | GF: Markus Rex, HRB 16746 (AG Nuernberg)

Index: ltp-full-20061017/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
===================================================================
--- ltp-full-20061017.orig/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
+++ ltp-full-20061017/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
@@ -50,6 +50,9 @@
 #define LOOP 1000     /* Shall be >= 1 */
 
 
+static pthread_mutex_t start_spinner;
+static pthread_cond_t start_cond;
+static int ready;
 volatile int nb_call = 0;
 
 /* Get the number of CPUs */
@@ -131,11 +134,12 @@ int set_thread_affinity(int cpu)
 void * runner(void * arg) {
 	int i=0, nc;
 	long result = 0;
+
 #ifdef LINUX        
         set_thread_affinity(*(int *)arg);
         fprintf(stderr, "%ld bind to cpu: %d\n", pthread_self(), *(int*)arg);
 #endif
-	
+
 	for(;i<LOOP;i++){
 		nc = nb_call;
 		sched_yield();
@@ -154,11 +158,17 @@ void * runner(void * arg) {
 }
 
 void * busy_thread(void *arg){
+
 #ifdef LINUX        
         set_thread_affinity(*(int *)arg);
         fprintf(stderr, "%ld bind to cpu: %d\n", pthread_self(), *(int*)arg);
 #endif
-        while(1){ 
+
+	pthread_mutex_lock(&start_spinner);
+	ready=1;
+	pthread_cond_signal(&start_cond);
+	pthread_mutex_unlock(&start_spinner);
+	while(1){
                 nb_call++;
 		sched_yield();
 	}
@@ -175,7 +185,9 @@ void buzy_process(int cpu){
         set_process_affinity(cpu);
         fprintf(stderr, "%d bind to cpu: %d\n", getpid(), cpu);
 #endif
-        param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+	/* this priority should be below the priority of the timer
+	 * interrupt to avoid an uninterruptible while(1); loop */
+        param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 2;
         if(sched_setscheduler(getpid(), SCHED_FIFO, &param) != 0) {
                 perror("An error occurs when calling sched_setparam()");
                 return;
@@ -198,6 +210,8 @@ int main() {
         struct sched_param param;
         int thread_cpu;
 
+	pthread_cond_init(&start_cond, NULL);
+	pthread_mutex_init(&start_spinner, NULL);
 
 	ncpu = get_ncpu();
 	if(ncpu == -1) {
@@ -242,6 +256,11 @@ int main() {
 		perror("An error occurs when calling pthread_create()");
 		return PTS_UNRESOLVED;
 	}
+
+	pthread_mutex_lock(&start_spinner);
+	while(!ready)
+		pthread_cond_wait(&start_cond, &start_spinner);
+	pthread_mutex_unlock(&start_spinner);
 	
 	if(pthread_create(&tid_runner, &attr, runner, &thread_cpu) != 0) {
 		perror("An error occurs when calling pthread_create()");
@@ -257,6 +276,10 @@ int main() {
                 waitpid(child_pid[i], NULL, 0);
 	
         result = (long)tmpresult;
+
+        pthread_cond_destroy(&start_cond);
+        pthread_mutex_destroy(&start_spinner);
+
 	if(result){
 		printf("A thread does not relinquish the processor.\n");
 		return PTS_FAIL;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to