From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 11 12:34:16 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2BAEF106566C for ; Tue, 11 Oct 2011 12:34:16 +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 043218FC14 for ; Tue, 11 Oct 2011 12:34:16 +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 AEBBA46B17; Tue, 11 Oct 2011 08:34:15 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 50FD78A02F; Tue, 11 Oct 2011 08:34:15 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 11 Oct 2011 08:26:31 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110617; KDE/4.5.5; amd64; ; ) References: <127B21EE-2730-4463-8921-B79CCE2B5ECB@gmail.com> In-Reply-To: <127B21EE-2730-4463-8921-B79CCE2B5ECB@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201110110826.31499.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 11 Oct 2011 08:34:15 -0400 (EDT) Cc: Riccardo Cattaneo Subject: Re: 4.4BSD timeslice management X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Oct 2011 12:34:16 -0000 On Wednesday, October 05, 2011 12:54:57 pm Riccardo Cattaneo wrote: > Hello, > I'm looking into the code of 4.4BSD scheduler (and related files) of FreeBSD version 7.2-RELEASE on an amd64 machine in order to understand how to manage time slices. I'm trying to dynamically change the length of the time slice on a thread by thread basis to "give more priority" or "less priority" to threads. > In function sched_clock (sched_4bsd.c) I found a piece of code in which thread's flags are added with TDF_NEEDRESCHED when the time slice (quantum) expires but I failed to notice any point in the code that actually preempt the thread. > Adding a per-thread parameter (e.g., in struct thread) I could set TDF_NEEDRESCHED when the dynamic time slice expires but how can I be sure the thread gets preempted? Where can I set a per-thread parameter (maybe after cpu_switch?!)? Is there a timer periodically calling a sort of context switch function or the context switches happen only when triggered by the kernel code? TDF_NEEDRESCHED is checked for in ast() in sys/kern/subr_trap.c. It is called during return to userland from interrupts, traps, and system calls. -- John Baldwin