Message ID | 20221115025614.79537-1-yun.zhou@windriver.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2486364wru; Mon, 14 Nov 2022 19:02:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TFKL1FKsnhtLET4SR0c1aijt2axEhHNPQIUICSZv+rT8aOUHcZhP+KxPVp0VEAyhzLJGZ X-Received: by 2002:a17:90a:1a19:b0:20a:6468:9bf0 with SMTP id 25-20020a17090a1a1900b0020a64689bf0mr137873pjk.31.1668481320078; Mon, 14 Nov 2022 19:02:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668481320; cv=none; d=google.com; s=arc-20160816; b=o+o1wse5scRNCd3dxMzAA/07gbRCdl30n9i/zFVHJAJ90XtKI3+DjgxARhbMVVSV91 ze9ROXDuSL/FRWmBGgp6RYgU2U/f+LK4qndHru8ei10oTjeW652TSrTb+e0hh2hInMYS FVj8Nl9Kkn94e7qbOh/iBDgzXX3q7KiR22w1x7ezewofD5z8bQJIaZPcoSYEwQWa7CEO IDI0iZgSzEhJMSpZjrO+1I9y1Cw5u1OlJinjGT+Oy73fOkNf36vZdTsJT49m+YyhqfUf pYTK9q8dOkn5+8IsgzGUpze8VKc/fF8CmDFb0z8adKItDrXkyny71jdK3sCw2Kb65NHG 4LZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/CxmLvqUQR8gZR78/D1hy1TINRUon8HR8i5+i5W8Dyc=; b=n5yKKOgFKlsLv/RmfEh/VBh2pxqHVwcVx+6rngoqAnah0BjY/8ZpLgwS8lmNuofiKr Q/axlkOgFS7LKPU2nJt4IB9ZODhQcqswxetpbPeXoMQaIHOisdcAtNK27vJOVE0bqF4q fhiU9+Ns/mk02nkoGk1MPVcWW/WDj5hSnEheiSacevFe1YdKWUXPr1H7cPS7djOeX0+k fHH/QHEa985qUdRjhQJhIkAe3fnvTKDqG6QjeMCP2urbRbE2PMvEkjROybaDXQVbi+vz E4CQJWPuRS4ZQ0u2LfvlQc0P1keOFkBLhogcR1D3p3Iz6dcmXKV5EnCgUMbqFlEpa/yx jLdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@windriver.com header.s=PPS06212021 header.b=FRvgyFuX; 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=windriver.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pf3-20020a17090b1d8300b002008d0b0838si12228502pjb.178.2022.11.14.19.01.44; Mon, 14 Nov 2022 19:02: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=@windriver.com header.s=PPS06212021 header.b=FRvgyFuX; 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=windriver.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232400AbiKOC7h (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 14 Nov 2022 21:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237857AbiKOC7O (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 14 Nov 2022 21:59:14 -0500 Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2C651C930 for <linux-kernel@vger.kernel.org>; Mon, 14 Nov 2022 18:56:37 -0800 (PST) Received: from pps.filterd (m0250809.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AF2lArQ011244; Mon, 14 Nov 2022 18:56:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=PPS06212021; bh=/CxmLvqUQR8gZR78/D1hy1TINRUon8HR8i5+i5W8Dyc=; b=FRvgyFuXhxVXQldYGTynxaFhRNDnTFHAm4XTLZnXDCfBYN2jcZ7e+G6DjskFp/BXG5IJ T3PDmZ6d+ieYqIkW6ZJbhaalYiPNFcCT8dHM9pLmcAIIduwzeZF34Ub3ngC4cz278I9S jMBD+XHF+Ymz77UZuMqrhGaM5YPvBgry2573O/Kymypc2upetFGxxA7K3WSB32rwFnDZ V7fqblmz38UCZf7FSEi4z5Bk9CgtqQnMDz/qsr2uZXtTycdzbESv2t8YeeXI4kyniC5x 1bWNOQZeQh3OJEjYYh14XCbLClUn+TcQG79swzjcw0K90suiRjRnwpOtsc5R1HwTo4Wt 2g== Received: from ala-exchng02.corp.ad.wrs.com (unknown-82-254.windriver.com [147.11.82.254]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 3ktbvr9tst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 14 Nov 2022 18:56:16 -0800 Received: from ala-exchng01.corp.ad.wrs.com (147.11.82.252) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Mon, 14 Nov 2022 18:56:16 -0800 Received: from pek-lpd-ccm3.wrs.com (147.11.136.210) by ala-exchng01.corp.ad.wrs.com (147.11.82.252) with Microsoft SMTP Server id 15.1.2242.12 via Frontend Transport; Mon, 14 Nov 2022 18:56:15 -0800 From: Yun Zhou <yun.zhou@windriver.com> To: <jstultz@google.com>, <tglx@linutronix.de>, <sboyd@kernel.org> CC: <linux-kernel@vger.kernel.org> Subject: [PATCH] timers: fix LVL_START macro Date: Tue, 15 Nov 2022 10:56:14 +0800 Message-ID: <20221115025614.79537-1-yun.zhou@windriver.com> X-Mailer: git-send-email 2.35.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: ldBEMTSq4fIAaL-TbuTO3fRTgJBvaDEm X-Proofpoint-GUID: ldBEMTSq4fIAaL-TbuTO3fRTgJBvaDEm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_15,2022-11-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 mlxscore=0 clxscore=1011 spamscore=0 bulkscore=0 malwarescore=0 mlxlogscore=825 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211150020 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749529469019911211?= X-GMAIL-MSGID: =?utf-8?q?1749529469019911211?= |
Series |
timers: fix LVL_START macro
|
|
Commit Message
Yun Zhou
Nov. 15, 2022, 2:56 a.m. UTC
The number of buckets per level should be LVL_SIZE, not LVL_SIZE-1.
Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
---
kernel/time/timer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Yun Zhou, On Tue, Nov 15, 2022 at 10:56:14AM +0800, Yun Zhou wrote: > The number of buckets per level should be LVL_SIZE, not LVL_SIZE-1. > > Signed-off-by: Yun Zhou <yun.zhou@windriver.com> > --- > kernel/time/timer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 717fcb9fb14a..1116b208093e 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -161,7 +161,7 @@ EXPORT_SYMBOL(jiffies_64); > * 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)) > +#define LVL_START(n) (LVL_SIZE << (((n) - 1) * LVL_CLK_SHIFT)) See the comment above: "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())." Thanks. > > /* Size of each clock level */ > #define LVL_BITS 6 > -- > 2.35.2 >
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. Thanks.
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. Thanks, tglx
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
diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 717fcb9fb14a..1116b208093e 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -161,7 +161,7 @@ EXPORT_SYMBOL(jiffies_64); * 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)) +#define LVL_START(n) (LVL_SIZE << (((n) - 1) * LVL_CLK_SHIFT)) /* Size of each clock level */ #define LVL_BITS 6