Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1434126ybt; Thu, 2 Jul 2020 05:29:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhZ1BopBJUyfBa/RjEUst7KlSc1IjPgqxDnmUkRCGwDKSMv2h9Bl9zhDCqw1a4GIoVnHwy X-Received: by 2002:aa7:ca05:: with SMTP id y5mr7339609eds.204.1593692974326; Thu, 02 Jul 2020 05:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593692974; cv=none; d=google.com; s=arc-20160816; b=SxtcV3OhfdFlLGyY5baWPkkPLiZS/s2MrNMtS6E6+m21IJG3qwUu0Mni60NmLLB2+b 7aKyqFw2dDuJCHP/p5ErWfQCDJKKw028DA8myNrO8/41pYHg0isw3eKQ00D/jVAjBxI9 IU/MrRyUMTtLb9o9DBnmIKf/zClm6+1Cw0AW8cHSduKqF4ehPE2fZzrlMNfKzv56mckk nn8DrNseXC7uyvN3Xd2b6TmsyEgG3gLaEmcSn/S4aTpLFhXyag86wKSwWs7oGokT+sdM 0h3MJTeC6zpfqgdfw1O1g3rZP82xYyQwa3e9KaVAFm+jh0X+Z/s+lv7iaEDGfnJTCCT5 czqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ccozNhbejF2xcUC8ucr7lrsRKzp8guqs/nMD9tmilmM=; b=qWx1QutiDELAItsolgGPinMuLWu0/yS8yCNg1qxv/69LK9BVHDQZVRg1i8cKem27+b +Zkw7muu6eolGHstgqbDEmRCUTLpi28NfHgVrgZPmNvtUdE20SVfR42LO4Zv2BeOm09l FLevA66uFRX+LZTvjr7ZUXvl64sn/sCkhMBR+Heyece0DEMkO+TSzOt9c3UdB/FZcTJI 0WjJQdP/vQKqUJ81L2kHQR7anZ89OggznlfKWWTSbMxytVrzMvEjEmonITlU0eRuRxUF o3B5mUzfmViOsukdZc2iqXtuY8S7peMlcNdtalDYhSpUeQ5QPI6ycIJHxa3GL1p0y9Tm 99iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=caMd6ddO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si5756404edw.49.2020.07.02.05.29.11; Thu, 02 Jul 2020 05:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=caMd6ddO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728854AbgGBM1F (ORCPT + 99 others); Thu, 2 Jul 2020 08:27:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:41524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbgGBM1E (ORCPT ); Thu, 2 Jul 2020 08:27:04 -0400 Received: from localhost (lfbn-ncy-1-317-216.w83-196.abo.wanadoo.fr [83.196.152.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD5A9207CD; Thu, 2 Jul 2020 12:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593692824; bh=uhyzd/UJP5NhJydsQvmRfX9zeMi8dyoLcJsJlsb4nOE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=caMd6ddOSZ7aGenotVJ/5jL2AfHYJHL/BGDG1v/8eEBN15EAOHsYX0GgfdePZTPZ3 idCJYWNwDuxth2Km9OzD8zM0UOfr4nTxqy5pr5cbF/x1dz0PiAXt/1jldPEBEpXBdZ 8W0zNz5JH+KnyySPmT1G3zDKOKN9eEdKvTnUshXQ= Date: Thu, 2 Jul 2020 14:27:01 +0200 From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Anna-Maria Gleixner , Peter Zijlstra , Juri Lelli Subject: Re: [RFC PATCH 03/10] timer: Simplify LVL_START() and calc_index() Message-ID: <20200702122659.GB17670@lenoir> References: <20200701011030.14324-1-frederic@kernel.org> <20200701011030.14324-4-frederic@kernel.org> <87pn9e9lgq.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pn9e9lgq.fsf@nanos.tec.linutronix.de> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 02, 2020 at 01:59:17PM +0200, Thomas Gleixner wrote: > Frederic Weisbecker writes: > > LVL_START() makes the first index of a level to start with what would be > > the value of all bits set of the previous level. > > > > For example level 1 starts at 63 instead of 64. > > > > To cope with that, calc_index() always adds one offset for the level > > granularity to the expiry passed in parameter. > > > > Yet there is no apparent reason for such fixups so simplify the whole > > thing. > > You sure? No :o) > > > @@ -158,7 +158,7 @@ EXPORT_SYMBOL(jiffies_64); > > * The time start value for each level to select the bucket at enqueue > > * time. > > */ > > -#define LVL_START(n) ((LVL_SIZE - 1) << (((n) - 1) * LVL_CLK_SHIFT)) > > +#define LVL_START(n) (LVL_SIZE << (((n) - 1) * LVL_CLK_SHIFT)) > > > /* Size of each clock level */ > > #define LVL_BITS 6 > > @@ -489,7 +489,7 @@ static inline void timer_set_idx(struct timer_list *timer, unsigned int idx) > > */ > > static inline unsigned calc_index(unsigned expires, unsigned lvl) > > { > > - expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl); > > + expires >>= LVL_SHIFT(lvl); > > return LVL_OFFS(lvl) + (expires & LVL_MASK); > > } > > So with that you move the expiry of each timer one jiffie ahead vs. the > original code, which violates the guarantee that a timer sleeps at least > for one jiffie for real and not measured in jiffies. > > base->clk = 1 > jiffies = 0 > local_irq_disable() > -> timer interrupt is raised in HW > timer->expires = 1 > add_timer(timer) > ---> index == 1 > local_irq_enable() > timer interrupt > jiffies++; > softirq() > expire(timer); > > So the off by one has a reason. Fair enough. I didn't know about the one jiffy sleep guarantee. I'll convert this patch to a comment explaining that off by one, using your above example. Thanks!