From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA6ABC606BD for ; Mon, 8 Jul 2019 14:15:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBC6B21670 for ; Mon, 8 Jul 2019 14:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731668AbfGHOPA (ORCPT ); Mon, 8 Jul 2019 10:15:00 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:39489 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728596AbfGHOO7 (ORCPT ); Mon, 8 Jul 2019 10:14:59 -0400 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1hkUPi-0001Ht-7E; Mon, 08 Jul 2019 16:14:42 +0200 Date: Mon, 8 Jul 2019 16:14:41 +0200 (CEST) From: Thomas Gleixner To: Zhiqiang Liu cc: corbet@lwn.net, mcgrof@kernel.org, Kees Cook , akpm@linux-foundation.org, manfred@colorfullife.com, jwilk@jwilk.net, dvyukov@google.com, feng.tang@intel.com, sunilmut@microsoft.com, quentin.perret@arm.com, linux@leemhuis.info, alex.popov@linux.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "wangxiaogang (F)" , "Zhoukang (A)" , Mingfangsen , tedheadster@gmail.com, Eric Dumazet Subject: Re: [PATCH next] softirq: enable MAX_SOFTIRQ_TIME tuning with sysctl max_softirq_time_usecs In-Reply-To: Message-ID: References: <0099726a-ead3-bdbe-4c66-c8adc9a4f11b@huawei.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zhiqiang, On Tue, 25 Jun 2019, Zhiqiang Liu wrote: > I have a doubt about _msecs_to_jiffies funcs, especially when input m is > equal to 0. > > For different HZ setttings, different _msecs_to_jiffies funcs will be > chosen for msecs_to_jiffies func. However, the performance of different > _msecs_to_jiffies is inconsistent with input m is equal to 0. > > If HZ satisfies the condition: HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % > HZ), the return value of _msecs_to_jiffies func with m=0 is different > with different HZ setting. > ------------------------------------ > | HZ | MSEC_PER_SEC / HZ | return | > ------------------------------------ > |1000| 1 | 0 | > |500 | 2 | 1 | > |200 | 5 | 1 | > |100 | 10 | 1 | > ------------------------------------ > > Why only the return value of HZ=1000 is equal to 0 with m=0 ? I don't know how you tested that, but obviously all four HZ values use this variant: > #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) > static inline unsigned long _msecs_to_jiffies(const unsigned int m) > { > return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ); > } and for all four HZ values the result is 0. Why? For m = 0 the calculation reduces to: ((MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ) i.e. (x - 1) / x where x = [1, 2, 5, 10] which is guaranteed to be 0 for integer math. If not, you have a compiler problem. Thanks, tglx