Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp626957ybt; Mon, 6 Jul 2020 18:37:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7xppld5i9Y9VG3uhL3Inqxx9ZzUo5yAoBcF+5GFOUTB7giA1PIS5fFUFNdIg0HVdFhWHs X-Received: by 2002:a17:906:a058:: with SMTP id bg24mr46966397ejb.370.1594085858149; Mon, 06 Jul 2020 18:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594085858; cv=none; d=google.com; s=arc-20160816; b=vQs5RmVJBZ+7/pqWsQOkK1S0Pzlz5v6f+uPSEoMflJCjAwqVH+vUk/4/t/1jatT88g WvV6XSwu/PJfHslCT1HU3hsHucNntSVT/OL/QqFEX+UD0QtLgk+dP8fkIIkNly9jIZXV aFEpgZ0h90Fxw2eX9KRVuhNiIdp0OGOkre890dyQFeei5lTJGYDrHdoslOfYjZfEUjZH 6T9O3xceHN1UiOlov5c7ads6s1MnXOeMIlAa++EIi1rt/bPDRDrpkFsmshpM8HMg8JY1 RLJpDy+2eEmqPHJSK3ZcyVezvtjUSY8ZWwaCJlR4fvPTHQPg6kuIoPTWuyE9J6nsTzN8 i7kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HclmHjq3aJjcuFmbRfzbV3pD+S6yUyYubDq6Z2DUnXE=; b=ZSzm+Fv/2jph4bJu9IGDcM876khNy1ea06QTwlxHtiF5iKpnxzgvDAK/nyBCpHL5Yl 6fzGFbucYsoOfCaB1KjG0FNTlL0IRRhQ+eZzEXxBP/TY1KH5Myq1t83N6XthkdSz/YVj UAfmLDcUJc00LePKq8sCuwBvWz9cIJGxiNaIQV4iOGh9kHdZzQlbs4mRFzbI663HsAa1 Y4gxdmirO/4vxOfmIwFO/74hYzM5MVT9koLkBiTznm4tZ2vNv7H2sSeIJdRHEpdInF+R /qtF5TjbgJ0EkLLgiMFaSBuRwscYIBjs8fNZCseuMGqpLks/IcI7ifoSuyind7fe+5zF L5IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=USNXXaTR; 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 h5si13833143ejq.249.2020.07.06.18.37.14; Mon, 06 Jul 2020 18:37:38 -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=USNXXaTR; 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 S1727945AbgGGBdM (ORCPT + 99 others); Mon, 6 Jul 2020 21:33:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:38598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbgGGBdJ (ORCPT ); Mon, 6 Jul 2020 21:33:09 -0400 Received: from lenoir.home (lfbn-ncy-1-317-216.w83-196.abo.wanadoo.fr [83.196.152.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D51120719; Tue, 7 Jul 2020 01:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594085589; bh=UogAco9ta0WJk43bNzsuzyB1AsXk0IHvfcexwJ/oSds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=USNXXaTR/with0/E2Nmkdm7TIiDdZlwDnkhVSCjw2Q+P6oITf3k+47CgzqW9fwBLk QykWevpgGgEbAGePddZ2Hgx/cBx+pYBD+n42I2/9KXtVFt8iZ8Cr3d2NTJ+qsr4OnB kjhr5T6YtGjPw3gW+F79vhWD8TUJl6aLTxr569oU= From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Anna-Maria Gleixner , Peter Zijlstra , Juri Lelli Subject: [PATCH 2/9] timer: Add comments about calc_index() ceiling work Date: Tue, 7 Jul 2020 03:32:46 +0200 Message-Id: <20200707013253.26770-3-frederic@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200707013253.26770-1-frederic@kernel.org> References: <20200707013253.26770-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org calc_index() adds 1 unit of the level granularity to the expiry passed in parameter to ensure that the timer doesn't expire too early. Add a comment to explain that and the resulting layout in the wheel. Signed-off-by: Frederic Weisbecker Cc: Peter Zijlstra Cc: Anna-Maria Gleixner Cc: Juri Lelli --- kernel/time/timer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 4c977df3610b..ae1259f67486 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -156,7 +156,8 @@ EXPORT_SYMBOL(jiffies_64); /* * The time start value for each level to select the bucket at enqueue - * time. + * time. We start from the last possible delta of the previous level + * so that we can later add an extra LVL_GRAN(n) to n (see calc_index()). */ #define LVL_START(n) ((LVL_SIZE - 1) << (((n) - 1) * LVL_CLK_SHIFT)) @@ -489,6 +490,13 @@ static inline void timer_set_idx(struct timer_list *timer, unsigned int idx) */ static inline unsigned calc_index(unsigned expires, unsigned lvl) { + /* + * Time may have past since the clock last reached an index of + * this @lvl. And that time, below LVL_GRAN(@lvl), is going to + * be substracted from the delta until we reach @expires. To + * fix that we must add one level granularity unit to make sure + * we rather expire late than early. Prefer ceil over floor. + */ expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl); return LVL_OFFS(lvl) + (expires & LVL_MASK); } -- 2.26.2