From owner-freebsd-arch@FreeBSD.ORG Wed Dec 29 14:04:44 2010 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B7F9B1065748; Wed, 29 Dec 2010 14:04:44 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 881018FC21; Wed, 29 Dec 2010 14:04:44 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 1BF5046B03; Wed, 29 Dec 2010 09:04:44 -0500 (EST) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 5B52D8A027; Wed, 29 Dec 2010 09:04:43 -0500 (EST) From: John Baldwin To: David Xu Date: Wed, 29 Dec 2010 08:43:52 -0500 User-Agent: KMail/1.13.5 (FreeBSD/7.3-CBSD-20101102; KDE/4.4.5; amd64; ; ) References: <4D1AEFC0.7030400@freebsd.org> In-Reply-To: <4D1AEFC0.7030400@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201012290843.52677.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Wed, 29 Dec 2010 09:04:43 -0500 (EST) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-1.9 required=4.2 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: arch@freebsd.org, Julian Elischer Subject: Re: TDF_NEEDRESCHED (was: Realtime thread priorities) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Dec 2010 14:04:44 -0000 On Wednesday, December 29, 2010 3:22:24 am David Xu wrote: > Hi all, > > I think flag TDF_NEEDRESCHED should not be cleared by sched_switch() in > ULE or 4BSD, instead it should only be cleared by ast() in subr_trap.c. > The reason is that the flag indicates thread should reset its priority > and switch context at user boundary because its user mode priority is > lowered or there is higher priority thread wants to run. > Kernel needs to use this flag to reset its priority to td_user_pri > before a thread returns to user mode, in current code, if an interrupt > thread preempts a user thread, sched_switch() clears the flag for > preempted thread and then switches to preempting thread, this causes > preempted thread to forget resetting its current priority to td_user_pri > this becauses assemble language code doreti() can not find the flag, > and ast() is not called, the thread ends up running user mode code > at very high level priority. Fix me, if I am wrong. Hmm, I think you are correct in which case I broke this many years ago. :( I think it might have worked originally because TDF_NEEDRESCHED triggered the preemption itself in ast(). The bug was probably introduced when I moved preemption into setrunqueue() itself (now sched_add() / critical_exit()). I think originally we also set TDF_NEEDRESCHED more often than we needed to, but now we probably don't (though we should check that it is now only set when we need to run that particular bit of code in ast() and nowhere else). -- John Baldwin