From owner-freebsd-arch@FreeBSD.ORG Tue Mar 5 08:41:23 2013 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E108B927; Tue, 5 Mar 2013 08:41:23 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-la0-x232.google.com (mail-la0-x232.google.com [IPv6:2a00:1450:4010:c03::232]) by mx1.freebsd.org (Postfix) with ESMTP id 464C298A; Tue, 5 Mar 2013 08:41:23 +0000 (UTC) Received: by mail-la0-f50.google.com with SMTP id ec20so5926879lab.9 for ; Tue, 05 Mar 2013 00:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=27T89Kx2jq1t+783vkzb6QFAAVGLrwrnqkT2HcWY/Qs=; b=tax2eehFmqF2oVEsTcmP0vN8aVjQXE+hE2yZwRufkGUXXG7Y/TZe5qa25YZaOP2r9A B4fltVNDjesbfd3EqwS8KQ38KMSwVxafqa/NcdmtYQzFLRiMSuigv4/aUiJzQG2QJn89 A+t6LwlDhs2wQw3yCH6BAyaQhXa9ZX0mWUXVvjPbXKnzoEvat8/1GaBLFO1hPAniD0/1 dzekBhX5g5Ra5qBnuMpkToPLW1cYB4GPn04AOGynBs+RhkfjfCZvxgFhdCbNOxoJSHB1 YUr8FzcVmIaEjqurf3KPS61JWaQJJhGPo8MGWyQVMwjIJmWTzamBOpTCF0RUm2zuDM7J xTPA== X-Received: by 10.112.28.41 with SMTP id y9mr5635575lbg.133.1362472881436; Tue, 05 Mar 2013 00:41:21 -0800 (PST) Received: from mavbook.mavhome.dp.ua (mavhome.mavhome.dp.ua. [213.227.240.37]) by mx.google.com with ESMTPS id q9sm8265986lbz.3.2013.03.05.00.41.18 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Mar 2013 00:41:20 -0800 (PST) Sender: Alexander Motin Message-ID: <5135AFAD.70408@FreeBSD.org> Date: Tue, 05 Mar 2013 10:41:17 +0200 From: Alexander Motin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130125 Thunderbird/17.0.2 MIME-Version: 1.0 To: Luigi Rizzo Subject: Re: tickless design guidelines References: <20130305080134.GC13187@onelab2.iet.unipi.it> In-Reply-To: <20130305080134.GC13187@onelab2.iet.unipi.it> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Davide Italiano , arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Mar 2013 08:41:23 -0000 On 05.03.2013 10:01, Luigi Rizzo wrote: > Hi, > i would like a bit of advice on how to get coarse time estimates > (such as "no need to do anything unless at least X msec have elapsed") > in a tickless kernel. > > In the past (and I mean a distant one, i got this habit back in 2.x), > rather than calling get*time(), i used to look at "ticks" to > see if it had changed, and only fetch the actual time accordingly. > > This worked well with HZ=1000 or above, when my required accuracy > a few milliseconds. With tickless kernels, i am not sure anymore > how often ticks gets updated. > > I may need to do this tests quite frequently (e.g. up to a million > times per second), so I'd rather have some lightweight function. At this point each active CPU still executes hardclock() with HZ rate as before, skipping only ticks when CPU is idle. As result, both ticks and getbinuptime() are working as before. First -- giving resolution of 1/HZ, second -- min(1/HZ, 1ms). The only place where it is unreliable to use them is hardware interrupt handlers (not interrupt threads), as if they fire during a long idle period timers may not be updated yet. Another way that may be better then polling is to let callout(9) manage time events. You can specify desired time and precision, and depending on precision it will use either binuptime(), or getbinuptime(), or fast custom way equivalent to ticks. Recent tests show that on x86 with LAPIC timer and TSC timecounter present code can handle up to 600K event per second from user-level on one core. From kernel I think rate could be even higher. -- Alexander Motin