From lada@pc8811.gud.siemens.at  Thu Apr 30 10:18:56 1998
Received: from zwei.siemens.at (zwei.siemens.at [193.81.246.12])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA12131
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Apr 1998 10:18:55 -0700 (PDT)
          (envelope-from lada@pc8811.gud.siemens.at)
Received: from pc8811.gud.siemens.at (root@firix [10.1.143.100])
	by zwei.siemens.at  with ESMTP id TAA10878
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Apr 1998 19:18:22 +0200 (MET DST)
Received: (from lada@localhost)
	by pc8811.gud.siemens.at (8.8.8/8.8.8) id TAA29819;
	Thu, 30 Apr 1998 19:19:36 +0200 (CEST)
	(envelope-from lada)
Message-Id: <199804301719.TAA29819@pc8811.gud.siemens.at>
Date: Thu, 30 Apr 1998 19:19:36 +0200 (CEST)
From: lada@pc8811.gud.siemens.at
Reply-To: lada@pc8811.gud.siemens.at
To: FreeBSD-gnats-submit@freebsd.org
Subject: Thread incremental priority update
X-Send-Pr-Version: 3.2

>Number:         6467
>Category:       bin
>Synopsis:       Thread incremental priority update
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 30 10:20:01 PDT 1998
>Closed-Date:    Thu Apr 30 15:27:34 PDT 1998
>Last-Modified:  Thu Apr 30 15:30:45 PDT 1998
>Originator:     lada@pc8811.gud.siemens.at
>Release:        FreeBSD 2.2.6-RELEASE i386
>Organization:
>Environment:


>Description:
The code in question increased the priority of runnable thread only if
it became inactive after the last priority update.  This means that
the priority boost was added at most once to any inactive thread.

>How-To-Repeat:

the test program (test.c) follows;
it was compiled with 
	cc test.c -o test -lc_r

#define _THREAD_SAFE
#define DO_YIELD
#define DO_YIELD2
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

void *writer( void *arg )
{
	int i = 0;
	int j;

	for (;; i++) 
		switch (i%7) {
		case 0:	puts( "One" );
			break;
		case 1:	puts( "Two" );
			break;
		case 2:	for (j=0; j<10000000;)
				j++;
			puts( "Three" );
			break;
		case 3:	puts( "Four" );
			break;
		case 4:	puts( "Five" );
			break;
		case 5:	puts( "Six" );
			break;
		case 6:	puts( "Seven" );
#ifdef DO_YIELD
			pthread_yield();
			puts( "Yield in writer returned" );
#endif
			break;
		}

	return NULL;
}

void *looper( void *arg )
{
	long int i = 0;

	for (;;) {
		if (i==10000000) {
			puts( "Yielding" );
#ifdef DO_YIELD2
			pthread_yield();
#endif
			puts( "Yield returned" );
			i = 0;
		}
		else 
			i++;
	}

	return NULL;
}

int main (void)
{

	pthread_t	printer, cpu_hog;
	void 		*result;

	pthread_create( &printer, pthread_attr_default, writer, "first" );
 	pthread_create( &cpu_hog, pthread_attr_default, looper, "second" ); 

	pthread_join( printer, &result );

	return 0;
}



>Fix:

This patch seems to fix this (i.e. both threads get to run), but there
are still some other problems: if DO_YIELD's are not defined only one
of the threads seems to be running.  This will require further investigation.
	

--- uthread_kern.c	1998/04/30 16:31:53	1.1
+++ uthread_kern.c	1998/04/30 16:34:33
@@ -349,7 +349,7 @@
 				 * the last incremental priority check was
 				 * made: 
 				 */
-				else if (timercmp(&_thread_run->last_inactive, &kern_inc_prio_time, >)) {
+				else if (timercmp(&_thread_run->last_inactive, &kern_inc_prio_time, <)) {
 					/*
 					 * Increment the incremental priority
 					 * for this thread in the hope that
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: jb 
State-Changed-When: Thu Apr 30 15:27:34 PDT 1998 
State-Changed-Why:  
Patch committed to both -current and RELENG_2_2, tanks. 
>Unformatted:
Marino Ladavac
