From owner-svn-src-all@FreeBSD.ORG Tue Oct 16 03:01:52 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2FEDDE4A; Tue, 16 Oct 2012 03:01:52 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from fallbackmx06.syd.optusnet.com.au (fallbackmx06.syd.optusnet.com.au [211.29.132.8]) by mx1.freebsd.org (Postfix) with ESMTP id AACB88FC12; Tue, 16 Oct 2012 03:01:50 +0000 (UTC) Received: from mail27.syd.optusnet.com.au (mail27.syd.optusnet.com.au [211.29.133.168]) by fallbackmx06.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q9G31mjR027241; Tue, 16 Oct 2012 14:01:48 +1100 Received: from c122-106-175-26.carlnfd1.nsw.optusnet.com.au (c122-106-175-26.carlnfd1.nsw.optusnet.com.au [122.106.175.26]) by mail27.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q9G31VqE018357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 16 Oct 2012 14:01:33 +1100 Date: Tue, 16 Oct 2012 14:01:31 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Ian Lepore Subject: Re: svn commit: r241576 - in head/usr.sbin/cron: cron crontab lib In-Reply-To: <1350335891.1123.160.camel@revolution.hippie.lan> Message-ID: <20121016133233.I1358@besplex.bde.org> References: <201210150821.q9F8Lobc047576@svn.freebsd.org> <20121015202615.GJ1383@garage.freebsd.pl> <1350333885.1123.153.camel@revolution.hippie.lan> <1350335891.1123.160.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-CMAE-Score: 0 X-CMAE-Analysis: v=2.0 cv=f7kQn5OM c=1 sm=1 a=l03AIqCZp40A:10 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=QofNcMrMajQA:10 a=vGqK-bROAAAA:8 a=VBVLp-hbcsnfAaLx1pQA:9 a=CjuIK1q_8ugA:10 a=bxQHXO5Py4tHmhUgaywp5w==:117 Cc: Maxim Sobolev , src-committers@freebsd.org, Pawel Jakub Dawidek , Garrett Cooper , svn-src-all@freebsd.org, svn-src-head@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Oct 2012 03:01:52 -0000 On Mon, 15 Oct 2012, Ian Lepore wrote: > On Mon, 2012-10-15 at 13:52 -0700, Garrett Cooper wrote: >> On Mon, Oct 15, 2012 at 1:44 PM, Ian Lepore >> wrote: >>> On Mon, 2012-10-15 at 22:26 +0200, Pawel Jakub Dawidek wrote: >>>> On Mon, Oct 15, 2012 at 08:21:50AM +0000, Maxim Sobolev wrote: >>>>> ... >>>>> >>>>> Log: >>>>> Add per-second scheduling into the cron(8). Right now it's >>>>> only available via the new @every_second shortcut. ENOTIME to >>>>> implement crontab(5) format extensions to allow more flexible >>>>> scheduling. >>>>> ... >>>> >>>> Do I read the code correctly and the cron deamon will wake up every >>>> second now even if @every_second is not used at all? >>> >>> It appears to, which I don't think is a bad thing at all. But the way >>> it waits is to wake up, do some work, and go back to sleep for an >>> integer 1 second. That will occasionally lead to a second in which no >>> wakeup happens, as the "do some work" part always takes some fraction of >>> a second. >> >> This is silly. It should be waking up at the lowest common >> denominator of time quanta, not every second; this could be determined >> via the crontab its managing. > > In 1987 I would have been outraged at waking up at 1hz needlessly. > Sitting here typing on a machine that's doing 12,000 interrupts/sec just > to maintain clocks, and top shows interrupts using 0.0% cpu, it's hard > to get too upset about a 1hz loop anymore. It's more outrageous now, since there are more battery-powered systems and even mains power is much more expensive. In 1987 I didn't worry about kernel clock interrupts at 60 Hz, but they are outrageous now too :-). Clock interrupts normally aren't accounted for properly. With proper accounting, I've seen them taking 1-10% on bad systems in 1987 and 2007, but 0.1% is more normal. Even a fast x86 probably takes 1 microsecond per clock interrupt to do almost nothing, so the bad default of HZ = 1000 costs 0.1%, and HZ = 10000 costs 1%. > On the other hand, if people are going to rely on this new feature of > being able to execute something every second, then the integer sleep > needs to be changed to a nanosleep() calculated to truly wake up at a > 1hz rate without eliding seconds now and then. My version of ping does this so as to send out packets every second instead of drifting at a rate of approximately 2/HZ per second (normal ping sends a packet and then tries to wait for 1 second but actually waits for 1 second plus the scheduling granularity (rounded up) plus any scheduling delay. Then it has a minor delay sending the next packet before trying to wait for 1 second again). The drift is very noticable if the scheduling granularity is large. I use select timeouts for this (ping already uses select timeouts and I just calculate the time to the next second instead of always using 1), but I now think this would be better implemented as a periodic itimer. Old versions of ping used non-periodic alarms and had significant (at least in 1987-1997) system overheads from this (for restarting the alarms), so ping was changed to use select timeouts. It still has to restart the timeouts but this now happens in the same syscall that waits for a packet to come back. cron should care more about waking up at exact seconds boundaries. Periodic itimers aren't accurate enough for this (they drift, but at a constant rate). Except high resolution timers might "fix" this using lots more clock interrupts and outrageous slowness to get precise timing. Bruce