Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 May 2002 14:09:34 -0500
From:      "Richard Seaman, Jr." <dick@seaman.org>
To:        freebsd-hackers@freebsd.org
Subject:   Understanding resetpriority() ?
Message-ID:  <20020526140934.D1813@seaman.org>

next in thread | raw e-mail | index | archive | help

I don't understand the resetpriority() function in the file
kern_synch.c in -current.  I'm wondering if someone can help
me?  What I don't understand is the logic for the call(s) to
maybe_resched() in resetpriority().  resetpriority() adjusts
kg->kg_user_pri, but doesn't touch td->td_priority.  Therefore
the call(s) to maybe_resched() seems to be a no-op?

Now, if the callers of resetpriority() are fiddling with 
td->td_priority before calling resetpriority(), then I could 
maybe understand this.  But, in every case I can see, the caller
of resetpriority() either does not change td->td_priority at all,
or it adjusts if _after_ the call to resetpriority().  Therefore,
it seems to me that maybe the call to maybe_resched not only is
a no-op, but perhaps the call should be made later, where needed,
by the callers to resetpriority()?

Thanks for any help.


From kern_synch.c:

void
resetpriority(kg)
	register struct ksegrp *kg;
{
	register unsigned int newpriority;
	struct thread *td;

	mtx_lock_spin(&sched_lock);
	if (kg->kg_pri_class == PRI_TIMESHARE) {
		newpriority = PUSER + kg->kg_estcpu / INVERSE_ESTCPU_WEIGHT +
		    NICE_WEIGHT * (kg->kg_nice - PRIO_MIN);
		newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
		    PRI_MAX_TIMESHARE);
		kg->kg_user_pri = newpriority;
	}
	FOREACH_THREAD_IN_GROUP(kg, td) {         <------ I don't understand
		maybe_resched(td);                <------ these 
	}
	mtx_unlock_spin(&sched_lock);
}

and earlier:

void
maybe_resched(struct thread *td)
{

	mtx_assert(&sched_lock, MA_OWNED);
	if (td->td_priority < curthread->td_priority)
		curthread->td_kse->ke_flags |= KEF_NEEDRESCHED;
}




-- 
Richard Seaman, Jr.        email:    dick@seaman.org
5182 N. Maple Lane         phone:    262-367-5450
Nashotah WI 53058            fax:    262-367-5852

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020526140934.D1813>