Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jun 2002 11:01:26 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        David Xu <bsddiy@yahoo.com>
Cc:        FreeBSD current users <current@freebsd.org>
Subject:   Re: Seeking OK to commit KSE MIII
Message-ID:  <Pine.BSF.4.21.0206031046380.43219-100000@InterJet.elischer.org>
In-Reply-To: <20020602070855.73453.qmail@web20905.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Thanks for looking at it....

This is not offtopic.. 

the answer is:
No, the code is correct..

here is the logic..

If there are N processors, then there are at most N KSEs (kernel
schedulable entities) working to process threads that belong to this
KSEGOUP. (kg). If there are N or more threads runnable, the top N threads
(by priority) are 'preassigned' to the N KSEs. The KSEs take their
priority from those threads and are put on the run queue.

The last thread that had a priority high enough to have a KSE associated
with it, AND IS ON THE RUN QUEUE is pointed to by
kg->kg_last_assigned. Therefore when a KSE is
removed from the run queue to become runnable, if it is the last assigned,
that pointer must be removed from it. 
Since it was removed, we know that it was teh highest priority KSE
available, and since it was teh last assigned, we know there were no more
KSEs available, and since we are not FREEING our KSE but using it, we know
there are STILL no more KSEs available, we can prove that the next thread
in the ksegrp list will not have a KSE to assign to it, so we can show
that the pointer must be made 'invalid' because there aer now NO threads
on the list that are assigned a KSE.

The pointer exists so that when a new threasd is maid runnable, it can
have it's priority compared with the last assigned thread to see if
it should 'steal' it's KSE or not.. i.e. is it 'earlier'
on the list than that thread or later.. If it's earlier, then th e KSE is
removed from the last assigned (which is now not assigned a KSE)
and reassigned to the new thread, which is placed earlier inthe list.
The pointer is then backed up to teh previous thread (which may or may not
be the new thread.

I will try add more comments to explain what we are doing..

On Sun, 2 Jun 2002, David Xu wrote:

> Sorry for this OT, I found a point in kern_switch.c, when choosethread() runs, 
> you reset kg_last_assigned to NULL, I suspect it is incorrect, should it be:
> 
> --- kern_switch.c.orig	Sun Jun  2 14:52:24 2002
> +++ kern_switch.c	Sun Jun  2 14:53:28 2002
> @@ -67,7 +67,9 @@
>  			kg = ke->ke_ksegrp;
>  			TAILQ_REMOVE(&kg->kg_runq, td, td_runq);
>  			if (kg->kg_last_assigned == td) 
> -				kg->kg_last_assigned = NULL;
> +				kg->kg_last_assigned =
> +					TAILQ_PREV(td,
> +					    threadlist_head, td_runq);
>  		}
>  		CTR2(KTR_RUNQ, "choosethread: td=%p pri=%d",
>  		    td, td->td_priority);
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0206031046380.43219-100000>