From owner-freebsd-hackers@FreeBSD.ORG Sat Oct 1 09:52:14 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 A9A4F1065677 for ; Sat, 1 Oct 2011 09:52:14 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx1.freebsd.org (Postfix) with ESMTP id 3B07A8FC1C for ; Sat, 1 Oct 2011 09:52:13 +0000 (UTC) Received: by eyg7 with SMTP id 7so2201440eyg.13 for ; Sat, 01 Oct 2011 02:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=NUpJaoxHRenew1Bs/f4/xDgWwTSmlGeycqXefNpKGKQ=; b=lh1OBRIplx4d3zk01O5u9Fb/FsfuW5qwxCTdCIoVmmbIuvb9ucVa83ac5h2V9sPBKt VmYKYjI3tHdeSuQPtcdN7M8x85q88tquDaGw0crRaZuKupIAh3od2Db3zQ1An/v30b16 1orW4i+JrSdm5cmlR//OoFXfLiQyzGKi17Fds= Received: by 10.223.58.198 with SMTP id i6mr16221405fah.91.1317461141412; Sat, 01 Oct 2011 02:25:41 -0700 (PDT) Received: from mavbook2.mavhome.dp.ua (pc.mavhome.dp.ua. [212.86.226.226]) by mx.google.com with ESMTPS id w14sm10670282fae.13.2011.10.01.02.25.39 (version=SSLv3 cipher=OTHER); Sat, 01 Oct 2011 02:25:40 -0700 (PDT) Sender: Alexander Motin Message-ID: <4E86DC86.3040204@FreeBSD.org> Date: Sat, 01 Oct 2011 12:25:26 +0300 From: Alexander Motin User-Agent: Thunderbird 2.0.0.23 (X11/20091212) MIME-Version: 1.0 To: Adrian Chadd References: In-Reply-To: X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: how are callouts handled in cpu_idle() ? 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: Sat, 01 Oct 2011 09:52:14 -0000 Hi. Adrian Chadd wrote: > What happens if this occurs: > > * cpu_idle() is entered > * you enter critical_enter() and call cpu_idleclock() > * an interrupt occurs, scheduling an immediate callout > * .. but you've already set the clock register, so it won't be > serviced until the wait returns. > > Perhaps interrupts have to be disabled before critical_enter() and > cpu_idletick() to ensure an interrupt-driven callout doesn't get > delayed? Use of critical section in cpu_idle() from the beginning was based on number of assumptions about filter interrupt handler's limitations. These handlers are not guarantied to get updated system time/ticks and they are discouraged to use callouts. If callout scheduled from interrupt filter during system wake up, system has no ticks counter updated yet and you may get callout scheduled into the past (it will be run immediately) or at least much earlier (up to 250ms) then requested. In your case callout indeed may get delayed (up to the same 250ms). All that is not a problem for regular interrupt threaded interrupts -- interrupt thread execution will be delayed until all stuff get updated. On some platforms and CPUs it is possible to enter/exit sleep with interrupts disabled. That would allow to cover all kinds of problems, but that support is very selective, so it is not used for this purpose now. We may want to get cpu_idle() rewritten again at some time to handle that and possibly make code choosing sleep state and measuring sleep time more MI, like Linux does it, but that is another project. So, if you really need to use callout() in interrupt filter, we could disable interrupts before calling cpu_idleclock(), as you have told. But that is only a partial solution and you should be ready for the second half of the problems. Depending on your needs I am not sure it will satisfy you. -- Alexander Motin