Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1952350rwb; Thu, 17 Nov 2022 04:40:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf709IrjkzHqBrrP5Uiqh06ccmR5jJpT78eJqlNj0J2BaHvH1iZRRRt8zCCymcNA3dQJDGJM X-Received: by 2002:a17:903:4091:b0:186:da90:5936 with SMTP id z17-20020a170903409100b00186da905936mr2517546plc.158.1668688800315; Thu, 17 Nov 2022 04:40:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668688800; cv=none; d=google.com; s=arc-20160816; b=gOdI35uhBkR1Y6PLBjKgFMntqMNTnvFey9xsOnuEACjzEld3/IrtiDhxn0sSKNA1G8 3zsYJ6Vv52MzFpUl8OiXk9pPrSWZCBJ1Amvl3he0X0oC80MNv26Ab6IXwtnsxN51xoah 4ErluyYlTKspGuogqcClX8oGjls5e0PGTjPCK2X/s3xAbFQrLhSERF8eJKhOcSA0lzsH DYFCj9NfIlMkd55PXED+hQdZEMbBVKDZ0g2h7mcwMvJdFdZlQT1AodAF2aJVMEaKLFgi BoKW2iF0CwnNYAYBzefDiTsFfbt1wZDCkSuSDfY6rARmIHZkQUwDOXGWnKvPCfJNlheo xbeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=azZy4BjGMs2vwfYYg9AXx73vBo982brFqhhAYU3BMdw=; b=QznRh42shqB3phL/iakA5Qf7yGe+JGDojTlK6VQ+HtWRBxBRebICz1PUQgr+cDsc52 oDy5dvXsutv9DV9P1tgWDFnirn8fnMtkka5WcPtAdzd8FpwIIIV0CpWbpjnl37VTO9Dr RyiG6OdhOm33YUkMRd9txPZanp1UDvTmRuB5JuWKQaRJKnRielGfPfsKtxyCrD4F0hSG hszwV0s4C0dLJokGTkkk+llsPlW+PzlT6y4+MQUz30dIJBvYbeNU57XKGCYxSxWDluqv /riXv2as1NsCMIRskO89TPTYvV88G1ZEvDetnCSKAPVBnapk7MAJlRkv/nf81onO61/N zfIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Pf5T+HAX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a170902ecd000b0017e6e415520si915359plh.292.2022.11.17.04.39.48; Thu, 17 Nov 2022 04:40:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Pf5T+HAX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbiKQMOt (ORCPT + 92 others); Thu, 17 Nov 2022 07:14:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239850AbiKQMOm (ORCPT ); Thu, 17 Nov 2022 07:14:42 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03BCF697FD for ; Thu, 17 Nov 2022 04:14:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A9037B81FF8 for ; Thu, 17 Nov 2022 12:14:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14469C433C1; Thu, 17 Nov 2022 12:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668687279; bh=5AGlEfjAH4p4s75U9CBP7W+SmAqweBoH1A780nJMhiE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pf5T+HAXKsKKGjiCy+wijhg8pKq29AzH6VeFTaKNiTLDNelim0u8qwV8eS/hO3VQO lEQKblHAipIX8Z6LOjOFyftzm0VmJwCnz0MvFHrmPLqTG4QrdTeLwRRExQtW7oMtrN 1oJuscIz810ePrSbKwH08Vxr9bBbQpYQKRfdP7h+c/GDoV5LGnBA7tw6YtAhLGMshJ sIbTfGs05lVTsQHNsfVLIDoT3Uyt5aDi91ZvhxTenq9YRtHblGPJdynySXQqWcaKYK x/SilLKxnYT7G1JudnmGNaDljSQut4rXVbb1+E4y5VXqfs+K9aBM8TU639s+nDT/X3 Jb3zHJeNBNCeg== Date: Thu, 17 Nov 2022 13:14:36 +0100 From: Frederic Weisbecker To: Thomas Gleixner Cc: "Zhou, Yun" , "jstultz@google.com" , "sboyd@kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] timers: fix LVL_START macro Message-ID: <20221117121436.GB839309@lothringen> References: <20221115025614.79537-1-yun.zhou@windriver.com> <20221115120239.GA721394@lothringen> <20221115224042.GA722789@lothringen> <877czuo40a.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877czuo40a.ffs@tglx> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 17, 2022 at 12:48:05AM +0100, Thomas Gleixner wrote: > On Tue, Nov 15 2022 at 23:40, Frederic Weisbecker wrote: > > On Tue, Nov 15, 2022 at 01:15:11PM +0000, Zhou, Yun wrote: > >> Hi Frederic, > >> > >> The issue now is that a timer may be thrown into the upper level bucket. For example, expires 4090 and 1000 HZ, it should be in level 2, but now it will be placed in the level 3. Is this expected? > >> > >> * HZ 1000 steps > >> * Level Offset Granularity Range > >> * 0 0 1 ms 0 ms - 63 ms > >> * 1 64 8 ms 64 ms - 511 ms > >> * 2 128 64 ms 512 ms - 4095 ms (512ms - ~4s) > >> * 3 192 512 ms 4096 ms - 32767 ms (~4s - ~32s) > >> * 4 256 4096 ms (~4s) 32768 ms - 262143 ms (~32s - ~4m) > > > > The rule is that a timer is not allowed to expire too early. But it can expire > > a bit late. Hence why it is always rounded up. So in the case of 4090, we have > > the choice between: > > > > 1) expiring at bucket 2 after 4096 - 64 = 4032 ms > > 2) expiring at bucket 3 after 4096 ms > > > > The 1) rounds down and expires too early. The 2) rounds up and expires a bit > > late. So the second solution is preferred. > > It's not only preferred, it's required simply because the timer wheel > has only one guarantee: Not to expire early. > > Timer wheel based timers are fundamentaly not precise unless the timeout > is short and hits the first level. > > But even hrtimers which are designed to be precise have only one real > guarantee: Not to expire early. > > hrtimers do not have the side effect of batching on long timeouts like > timer wheel based timer have, but that's it. > > Timers in the kernel come with a choice: > > - Imprecise and inexpensive to arm and cancel (timer_list) > - Precise and expensive to arm and cancel (hrtimer) > > You can't have both. That's well documented. Actually I'm pretty sure we can manage imprecise and expensive to arm and cancel. It's a matter of willpower! Anyway, thanks for confirming what I thought about timers guarantees. Thanks. > > Thanks, > > tglx