Received: by 10.192.165.148 with SMTP id m20csp358052imm; Thu, 19 Apr 2018 23:45:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx48wT2owHEfEAAh+7rQH1Z387k+Xjqy4ky94MUoCZ7A62O7e6CdI8/SI5Gzf0Wqisne1Z9X3 X-Received: by 10.101.73.68 with SMTP id q4mr7718859pgs.424.1524206759038; Thu, 19 Apr 2018 23:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524206759; cv=none; d=google.com; s=arc-20160816; b=cV6NN+t9T5LDsi/uTmEYrF38+13sWUQxZSuCYQwGdj54aObZrdBSsyTXtbB+xZ5xMr U8CxkeZUsweX3hX/uSJHJlTPSSoEiME/XAQzw2/gYqDB651P49b0QF3wDWmX27PjCkgO AtFRKcaytE8oCU6FUrCAqmg7paUS0kiN5IU2gEQlvsOvTOGz2IgdJGtBENjlEB05Dys0 5LAxczjVDfweJ7r1f7mXDBEdjD9HiiiY+c4R7BPOy49sIQE6EMgt/ID7BD60jaPV1CtK OD61hANh7SOfi/sL1NL8goN2hULhBV9wequKcrBpoiW/Mx+h6PIguIiKMe9VfiF5XupC pg9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=TEEuP9ivqLbmM/WLHd5z22VhJiA+tWZHDC7w8UUduDg=; b=NcIq4E3O/TUHjou7+eYOZp2IUZBwBU0w9jsgnV5ucxi6oNK4aXIDc/rKyi1floyNq3 j1IgbyHF2+ONOYCGfZEcPi8s0IqwG0/ub6qQ/7GJMLwHnnunCt+bF6QRs4c6EIBnDl/7 uG9kH9E/Q4Oe8V2a9E8iu8HUBd8d8GHWmuDcmfLZK+u/uDCpe1dBdvcHO+vLYVDFsVzM n4O+a1InuJDvLXNi4qXVtKymKIcYfSKZiA040dHMP7satwJRUpizWZpMUZ33/VKrLl09 pj5FDlZ3PlCLiQ/uGGDdqrzVFHtRgptQXTEKDtQTj9D3rOiSZpqdexBinA0DY1XnczpP +QSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Yflk9pfd; dkim=pass header.i=@codeaurora.org header.s=default header.b=BWIje7QV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w24-v6si4754723plq.481.2018.04.19.23.45.43; Thu, 19 Apr 2018 23:45:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Yflk9pfd; dkim=pass header.i=@codeaurora.org header.s=default header.b=BWIje7QV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753524AbeDTGoY (ORCPT + 99 others); Fri, 20 Apr 2018 02:44:24 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:60724 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751254AbeDTGoX (ORCPT ); Fri, 20 Apr 2018 02:44:23 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AA91D60FEE; Fri, 20 Apr 2018 06:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524206662; bh=AoZS74gCPV6kP2kOPdDCjMw8Kip1Eh9tzz/gBxoOClE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Yflk9pfdW9/DsNcAfq8xCYGza++285/2FWisAHR66MsATdS/nJBLrCxdBGCyHRE9z r6HrmXZO+AdXghG7xZBzWUXJ4iAemaCBU52gZnviDkNrM2Bek5hQJvDpd/yJzx5RpV lxe11nmc1/oPItDQAbCsLr1/hv/UwVCY+Opzfbsc= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 05E786030D; Fri, 20 Apr 2018 06:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524206661; bh=AoZS74gCPV6kP2kOPdDCjMw8Kip1Eh9tzz/gBxoOClE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BWIje7QVvt6Vc6oCm+22hG3c7x/F+KcN0xs0F8Qi6WASTrymZ1oorUdDHCPM96eoZ ofB19+ciPxZ6ZI5g7yDpxaU8aZg8cGsjtevb1ySP2uN0Bx1P52ab07dzERhX6ri5Cg TyFy9yjkfrz4grcpPOnJUMQ8IqosbPRNf/Vp3g9E= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 20 Apr 2018 14:44:20 +0800 From: yuankuiz@codeaurora.org To: Thomas Gleixner Cc: "Rafael J. Wysocki" , Linux PM , "Rafael J. Wysocki" , Frederic Weisbecker , Peter Zijlstra , Ingo Molnar , Len Brown , Linux Kernel Mailing List , linux-pm-owner@vger.kernel.org, akpm@linux-foundation.org, joe@perches.com Subject: Re: [PATCH] time: tick-sched: use bool for tick_stopped In-Reply-To: References: <891d4f632fbff5052e11f2d0b6fac35d@codeaurora.org> <2f7755fae34bb65ef0a4b5a11c67f431@codeaurora.org> Message-ID: <41aec3337f05316de118357fcbd9d175@codeaurora.org> X-Sender: yuankuiz@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-04-20 09:47 AM, yuankuiz@codeaurora.org wrote: > On 2018-04-11 07:20 AM, yuankuiz@codeaurora.org wrote: >> ++ >> On 2018-04-11 07:09 AM, yuankuiz@codeaurora.org wrote: >>> ++ >>> >>> On 2018-04-10 10:49 PM, yuankuiz@codeaurora.org wrote: >>>> Typo... >>>> >>>> On 2018-04-10 10:08 PM, yuankuiz@codeaurora.org wrote: >>>>> On 2018-04-10 07:06 PM, Thomas Gleixner wrote: >>>>>> On Tue, 10 Apr 2018, yuankuiz@codeaurora.org wrote: >>>>>>> On 2018-04-10 05:10 PM, Thomas Gleixner wrote: >>>>>>> > On Tue, 10 Apr 2018, yuankuiz@codeaurora.org wrote: >>>>>>> > > On 2018-04-10 04:00 PM, Rafael J. Wysocki wrote: >>>>>>> > > > On Tue, Apr 10, 2018 at 9:33 AM, wrote: >>>>>>> > > > > From: John Zhao >>>>>>> > > > > >>>>>>> > > > > Variable tick_stopped returned by tick_nohz_tick_stopped >>>>>>> > > > > can have only true / false values. Since the return type >>>>>>> > > > > of the tick_nohz_tick_stopped is also bool, variable >>>>>>> > > > > tick_stopped nice to have data type as bool in place of unsigned int. >>>>>>> > > > > Moreover, the executed instructions cost could be minimal >>>>>>> > > > > without potiential data type conversion. >>>>>>> > > > > >>>>>>> > > > > Signed-off-by: John Zhao >>>>>>> > > > > --- >>>>>>> > > > > kernel/time/tick-sched.h | 2 +- >>>>>>> > > > > 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>>> > > > > >>>>>>> > > > > diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h >>>>>>> > > > > index 6de959a..4d34309 100644 >>>>>>> > > > > --- a/kernel/time/tick-sched.h >>>>>>> > > > > +++ b/kernel/time/tick-sched.h >>>>>>> > > > > @@ -48,8 +48,8 @@ struct tick_sched { >>>>>>> > > > > unsigned long check_clocks; >>>>>>> > > > > enum tick_nohz_mode nohz_mode; >>>>>>> > > > > >>>>>>> > > > > + bool tick_stopped : 1; >>>>>>> > > > > unsigned int inidle : 1; >>>>>>> > > > > - unsigned int tick_stopped : 1; >>>>>>> > > > > unsigned int idle_active : 1; >>>>>>> > > > > unsigned int do_timer_last : 1; >>>>>>> > > > > unsigned int got_idle_tick : 1; >>>>>>> > > > >>>>>>> > > > I don't think this is a good idea at all. >>>>>>> > > > >>>>>>> > > > Please see https://lkml.org/lkml/2017/11/21/384 for example. >>>>>>> > > [ZJ] Thanks for this sharing. Looks like, this patch fall into the case of >>>>>>> > > "Maybe". >>>>>>> > >>>>>>> > This patch falls into the case 'pointless' because it adds extra storage >>>>>>> [ZJ] 1 bit vs 1 bit. no more. >>>>>> >>>>>> Groan. No. Care to look at the data structure? You create a new >>>>>> storage, >>>>> [ZJ] Say, {unsigned int, unsigned int, unsigned int, unsigned int, >>>>> unsigned int} becomes >>>>> {bool , unsigned int, unsigned int, unsigned int, >>>>> unsigned int} >>>>> As specified by the rule No.10 at the section 6.7.2.1 of C99 TC2 >>>>> as: >>>>> "If enough space remains, a bit-field that immediately follows >>>>> another >>>>> bit-field in a >>>>> structure shall be packed into adjacent bits of the same unit." >>>>> What >>>>> is the new storage so far? > [ZJ] Further prototyping has been given based on gcc for both of > x86_64 and armv8-a, > unsigned int and bool share the same 1 bytes without the > addtional storage for sure. > Open this and welcome if any other difference behaviour could be > captured. [ZJ] Typo.. change 4 bytes above to 1 byte actually. >>>>> >>>>>> which is incidentally merged into the other bitfield by the >>>>>> compiler at a >>>>>> different bit position, but there is no guarantee that a compiler >>>>>> does >>>>>> that. It's free to use distinct storage for that bool based bit. >>>>> [ZJ] Per the rule No.10 at section 6.7.2.1 of C99 TC2 as: >>>>> " If insufficient space remains, whether a bit-field that does >>>>> not fit is put into >>>>> the next unit or overlaps adjacent units is >>>>> implementation-defined." >>>>> So, implementation is never mind which type will be stored if any. >>>>> >>>>>> >> > for no benefit at all. >>>>>>> [ZJ] tick_stopped is returned by the tick_nohz_tick_stopped() >>>>>>> which is bool. >>>>>>> The benefit is no any potiential type conversion could be minded. >>>>>> >>>>>> A bit stays a bit. 'bool foo : 1;' or 'unsigned int foo : 1' has >>>>>> to be >>>>>> evaluated as a bit. So there is a type conversion from BIT to bool >>>>>> required >>>>>> because BIT != bool. >>>>> [ZJ] Per the rule No.9 at section 6.7.2.1 of C99 TC2 as: >>>>> "If the value 0 or 1 is stored into a nonzero-width >>>>> bit-field of types >>>>> _Bool, the value of the bit-field shall compare equal to the value >>>>> stored." >>>>> Obviously, it is nothing related to type conversion actually. >>>>>> >>>>>> By chance the evaluation can be done by evaluating the byte in >>>>>> which the >>>>>> bit is placed just because the compiler knows that the remaining >>>>>> bits are >>>>>> not used. There is no guarantee that this is done, it happens to >>>>>> be true >>>>>> for a particular compiler. >>>>> [ZJ] Actually, such as GCC owe that kind of guarantee to be >>>>> promised by ABI. [ZJ] "-mone-byte-bool" could be used by alpha-linux-gcc to override the default bool size to become 1 byte for even Darwin / powerPC from it's manual. >>>>>> >>>>>> But that does not make it any more interesting. It just makes the >>>>>> code >>>>>> harder to read and eventually leads to bigger storage. >>>>> [ZJ] To get the benctifit to be profiled, it is given as: >>>>> number of instructions of function tick_nohz_tick_stopped(): >>>> [ZJ] Here, I used is not the tick_nohz_tick_stopped(), but an >>>> evaluation() as: >>>> #include >>>> #include >>>> >>>> struct tick_sched { >>>> unsigned int inidle : 1; >>>> unsigned int tick_stopped : 1; >>>> }; >>>> >>>> bool get_status() >>>> { >>>> struct tick_sched *ts; >>>> ts->tick_stopped = 1; >>>> return ts->tick_stopped; >>>> } >>>> >>>> int main() >>>> { >>>> if (get_status()) return 0; >>>> return 0; >>>> } >>>> >>>> [ZJ] Toggle the declaration of tick_stopped in side of the >>>> tick_sched >>>> structure for comparison. >>>> >>>> >>>>> original: 17 >>>>> patched: 14 >>>>> Which was saved is: >>>>> movzbl %al, %eax >>>>> testl %eax, %eax >>>>> setne %al >>>>> Say, 3 / 17 = 17 % could be gained in the instruction executed >>>>> for this function can be evaluated. >>>>> >>>>> Note: >>>>> The environment I used is: >>>>> OS : Ubuntu Desktop 16.04 LTS >>>>> gcc: 6.3.0 (without >>>>> optimization >>>>> for in general purpose) >>>>> >>>>>> >>>> >>>> Just FYI. >>>> >>>> Thanks, >>>> ZJ