From owner-freebsd-arch@FreeBSD.ORG Wed Dec 29 08:22:24 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 7E04F106566C; Wed, 29 Dec 2010 08:22:24 +0000 (UTC) (envelope-from davidxu@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 6EDF88FC12; Wed, 29 Dec 2010 08:22:24 +0000 (UTC) Received: from xyf.my.dom (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oBT8MMN3097264; Wed, 29 Dec 2010 08:22:23 GMT (envelope-from davidxu@freebsd.org) Message-ID: <4D1AEFC0.7030400@freebsd.org> Date: Wed, 29 Dec 2010 16:22:24 +0800 From: David Xu User-Agent: Thunderbird 2.0.0.24 (X11/20100630) MIME-Version: 1.0 To: John Baldwin , Julian Elischer , arch@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: 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 08:22:24 -0000 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. Regards, David Xu