From owner-freebsd-current Sun Jan 31 03:39:40 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id DAA16006 for freebsd-current-outgoing; Sun, 31 Jan 1999 03:39:40 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from hda.hda.com (hda-bicnet.bicnet.net [209.244.238.132] (may be forged)) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id DAA16000 for ; Sun, 31 Jan 1999 03:39:36 -0800 (PST) (envelope-from dufault@hda.hda.com) Received: (from dufault@localhost) by hda.hda.com (8.8.5/8.8.5) id GAA21441; Sun, 31 Jan 1999 06:33:41 -0500 (EST) From: Peter Dufault Message-Id: <199901311133.GAA21441@hda.hda.com> Subject: Re: more about yield() versus sched_yield() In-Reply-To: <199901311057.VAA08719@godzilla.zeta.org.au> from Bruce Evans at "Jan 31, 99 09:57:07 pm" To: bde@zeta.org.au (Bruce Evans) Date: Sun, 31 Jan 1999 06:33:40 -0500 (EST) Cc: current@FreeBSD.ORG, dufault@hda.com, bde@zeta.org.au X-Mailer: ELM [version 2.4ME+ PL25 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Another difference is that it correctly counts context switches as voluntary. Good point. The patched version calls maybe_resched(), and I'm adding the line at "<<<". (This also will let people who haven't looked at that code complain about the function interface - it doesn't bother me, macros could come later.) /* * prioritize: Compute a priority based on the type of scheduler. */ static priority_type prioritize(struct proc *p) { priority_type priority; int class = RTP_PRIO_BASE(p->p_rtprio.type); if (class == RTP_PRIO_NORMAL) { priority = (RTP_PRIO_NORMAL << 8) | (p->p_priority / PPQ); } else priority = (class << 8) | p->p_rtprio.prio; return priority; } /* * curpriority_set: Set the current process priority to that of the process * in the call. */ void curpriority_set(struct proc *p) { newcurpriority = prioritize(p); } /* * curpriority_cmp: Compare the priorities. Return: * <0: p < curpriority * 0: p == curpriority * >0: p > curpriority */ static int curpriority_cmp(struct proc *p) { priority_type prio = prioritize(p); return prio - newcurpriority; } /* * maybe_resched: Decide if you need to reschedule or not, * taking the priorities and schedulers into account. * * This function needs to be call AFTER chk->p_priority has * been updated. */ static void maybe_resched(struct proc *chk) { if (curproc == 0) need_resched(); else if (chk == curproc) { /* * If chk is curproc, we may need to preempt if * we're making our priority less favorable. */ if (curpriority_cmp(chk) > 0) { chk->p_stats->p_ru.ru_nvcsw++; /* <<< Adding */ need_resched(); } } /* * If chk is not the curproc, we want to preempt if chk has * a more favorable priority than curproc. * * We shouldn't preempt the current process because of the * priority of a sleeping or stopped process. * */ else if ((chk->p_flag & P_INMEM) && chk->p_stat == SRUN && curpriority_cmp(chk) < 0) { need_resched(); } } -- Peter Dufault (dufault@hda.com) Realtime development, Machine control, HD Associates, Inc. Safety critical systems, Agency approval To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message