Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, Apr 10, 2018 at 08:14:54AM -0700, Joe Perches wrote: > Whinging about bool : seems entirely sensible > and straightforward to do. > > I'm not so sure about bool in structs as a patch context > could be adding a bool to local stack definitions and > there's no real ability to determine if the bool is in a > struct or on the stack. > > Also, I think there's nothing really wrong with using > bool in structs. Steven Rostedt's rationale in > https://lkml.org/lkml/2017/11/21/207 isn't really right > as sizeof(int) is 4 not 1 and sizeof(bool) is 1 on arches > without alignment issues. I believe when using gcc, > sizeof(bool) is always 1 and there may be alignment padding > added on some arches. Dunno. C std simply does not define sizeof(_Bool) and leaves it up to architecture ABI, therefore I refuse to use _Bool in composite types, because I care about layout. Also, not all architectures can do byte addressing, see Alpha But I think the battle is already lost anyway. > > git grep -P '(? 1543 Yes I know, doesn't mean we shouldn't discourage it for new code; also Linus.
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, Apr 10, 2018 at 08:14:54AM -0700, Joe Perches wrote: > Whinging about bool : seems entirely sensible > and straightforward to do. > > I'm not so sure about bool in structs as a patch context > could be adding a bool to local stack definitions and > there's no real ability to determine if the bool is in a > struct or on the stack. > > Also, I think there's nothing really wrong with using > bool in structs. Steven Rostedt's rationale in > https://lkml.org/lkml/2017/11/21/207 isn't really right > as sizeof(int) is 4 not 1 and sizeof(bool) is 1 on arches > without alignment issues. I believe when using gcc, > sizeof(bool) is always 1 and there may be alignment padding > added on some arches. Dunno. C std simply does not define sizeof(_Bool) and leaves it up to architecture ABI, therefore I refuse to use _Bool in composite types, because I care about layout. Also, not all architectures can do byte addressing, see Alpha But I think the battle is already lost anyway. > > git grep -P '(? 1543 Yes I know, doesn't mean we shouldn't discourage it for new code; also Linus.
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 2018-04-10 at 14:33 +0200, Peter Zijlstra wrote: > On Tue, Apr 10, 2018 at 10:00:01AM +0200, Rafael J. Wysocki wrote: > > On Tue, Apr 10, 2018 at 9:33 AM,wrote: > > > +++ b/kernel/time/tick-sched.h > > > @@ -48,8 +48,8 @@ struct tick_sched { > > > unsigned long check_clocks; > > > enum tick_nohz_mode nohz_mode; > > > > > > + booltick_stopped: 1; > > > unsigned intinidle : 1; > > > - unsigned inttick_stopped: 1; > > > unsigned intidle_active : 1; > > > unsigned intdo_timer_last : 1; > > > unsigned intgot_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. > > Joe, apw, could we get Checkpatch to whinge about _Bool in composite > types? That should immediately also disqualify using it as the base type > of bitfields. Whinging about bool : seems entirely sensible and straightforward to do. I'm not so sure about bool in structs as a patch context could be adding a bool to local stack definitions and there's no real ability to determine if the bool is in a struct or on the stack. Also, I think there's nothing really wrong with using bool in structs. Steven Rostedt's rationale in https://lkml.org/lkml/2017/11/21/207 isn't really right as sizeof(int) is 4 not 1 and sizeof(bool) is 1 on arches without alignment issues. I believe when using gcc, sizeof(bool) is always 1 and there may be alignment padding added on some arches. Dunno. But I think the battle is already lost anyway. git grep -P '(?
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 2018-04-10 at 14:33 +0200, Peter Zijlstra wrote: > On Tue, Apr 10, 2018 at 10:00:01AM +0200, Rafael J. Wysocki wrote: > > On Tue, Apr 10, 2018 at 9:33 AM, wrote: > > > +++ b/kernel/time/tick-sched.h > > > @@ -48,8 +48,8 @@ struct tick_sched { > > > unsigned long check_clocks; > > > enum tick_nohz_mode nohz_mode; > > > > > > + booltick_stopped: 1; > > > unsigned intinidle : 1; > > > - unsigned inttick_stopped: 1; > > > unsigned intidle_active : 1; > > > unsigned intdo_timer_last : 1; > > > unsigned intgot_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. > > Joe, apw, could we get Checkpatch to whinge about _Bool in composite > types? That should immediately also disqualify using it as the base type > of bitfields. Whinging about bool : seems entirely sensible and straightforward to do. I'm not so sure about bool in structs as a patch context could be adding a bool to local stack definitions and there's no real ability to determine if the bool is in a struct or on the stack. Also, I think there's nothing really wrong with using bool in structs. Steven Rostedt's rationale in https://lkml.org/lkml/2017/11/21/207 isn't really right as sizeof(int) is 4 not 1 and sizeof(bool) is 1 on arches without alignment issues. I believe when using gcc, sizeof(bool) is always 1 and there may be alignment padding added on some arches. Dunno. But I think the battle is already lost anyway. git grep -P '(?
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, Apr 10, 2018 at 10:00:01AM +0200, Rafael J. Wysocki wrote: > On Tue, Apr 10, 2018 at 9:33 AM,wrote: > > +++ b/kernel/time/tick-sched.h > > @@ -48,8 +48,8 @@ struct tick_sched { > > unsigned long check_clocks; > > enum tick_nohz_mode nohz_mode; > > > > + booltick_stopped: 1; > > unsigned intinidle : 1; > > - unsigned inttick_stopped: 1; > > unsigned intidle_active : 1; > > unsigned intdo_timer_last : 1; > > unsigned intgot_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. Joe, apw, could we get Checkpatch to whinge about _Bool in composite types? That should immediately also disqualify using it as the base type of bitfields.
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, Apr 10, 2018 at 10:00:01AM +0200, Rafael J. Wysocki wrote: > On Tue, Apr 10, 2018 at 9:33 AM, wrote: > > +++ b/kernel/time/tick-sched.h > > @@ -48,8 +48,8 @@ struct tick_sched { > > unsigned long check_clocks; > > enum tick_nohz_mode nohz_mode; > > > > + booltick_stopped: 1; > > unsigned intinidle : 1; > > - unsigned inttick_stopped: 1; > > unsigned intidle_active : 1; > > unsigned intdo_timer_last : 1; > > unsigned intgot_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. Joe, apw, could we get Checkpatch to whinge about _Bool in composite types? That should immediately also disqualify using it as the base type of bitfields.
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 10 Apr 2018, yuank...@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 / forse 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 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; > > > > > > + booltick_stopped: 1; > > > unsigned intinidle : 1; > > > - unsigned inttick_stopped: 1; > > > unsigned intidle_active : 1; > > > unsigned intdo_timer_last : 1; > > > unsigned intgot_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 for no benefit at all. Thanks, tglx
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 10 Apr 2018, yuank...@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 / forse 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 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; > > > > > > + booltick_stopped: 1; > > > unsigned intinidle : 1; > > > - unsigned inttick_stopped: 1; > > > unsigned intidle_active : 1; > > > unsigned intdo_timer_last : 1; > > > unsigned intgot_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 for no benefit at all. Thanks, tglx
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
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 / forse 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_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". Thanks!
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
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 / forse 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_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". Thanks!
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On 2018-04-10 03:55 PM, Thomas Gleixner wrote: On Tue, 10 Apr 2018, yuank...@codeaurora.org wrote: From: John ZhaoVariable tick_stopped returned by tick_nohz_tick_stopped can have only true / forse 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 int. The data type is not int. [ZJ] Yes. Per newest tip in branch of linux-pm-cpuidle, it is unsigned int with 1 bit in width. There is typo in commit message, "int" at here should be "unsigned int" It's part of an integer bitfield and occupies exactly one bit of storage, while bool has an architecture dependend size and is at least 1 byte, i.e. 8 bit. So with alignment effects you grew the size of the data structure and therefore the cache foot print. [ZJ] So, 1 bit in width is specified as: + booltick_stopped: 1; This patch is based on the linux-pm-cpuidle branch which has already gathered available space in the structure of tick_sched. This is not about 'nice to have' Thanks, tglx
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On 2018-04-10 03:55 PM, Thomas Gleixner wrote: On Tue, 10 Apr 2018, yuank...@codeaurora.org wrote: From: John Zhao Variable tick_stopped returned by tick_nohz_tick_stopped can have only true / forse 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 int. The data type is not int. [ZJ] Yes. Per newest tip in branch of linux-pm-cpuidle, it is unsigned int with 1 bit in width. There is typo in commit message, "int" at here should be "unsigned int" It's part of an integer bitfield and occupies exactly one bit of storage, while bool has an architecture dependend size and is at least 1 byte, i.e. 8 bit. So with alignment effects you grew the size of the data structure and therefore the cache foot print. [ZJ] So, 1 bit in width is specified as: + booltick_stopped: 1; This patch is based on the linux-pm-cpuidle branch which has already gathered available space in the structure of tick_sched. This is not about 'nice to have' Thanks, tglx
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
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 / forse 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 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; > > + booltick_stopped: 1; > unsigned intinidle : 1; > - unsigned inttick_stopped: 1; > unsigned intidle_active : 1; > unsigned intdo_timer_last : 1; > unsigned intgot_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. Thanks!
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
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 / forse 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 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; > > + booltick_stopped: 1; > unsigned intinidle : 1; > - unsigned inttick_stopped: 1; > unsigned intidle_active : 1; > unsigned intdo_timer_last : 1; > unsigned intgot_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. Thanks!
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 10 Apr 2018, yuank...@codeaurora.org wrote: > From: John Zhao> > Variable tick_stopped returned by tick_nohz_tick_stopped > can have only true / forse 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 int. The data type is not int. It's part of an integer bitfield and occupies exactly one bit of storage, while bool has an architecture dependend size and is at least 1 byte, i.e. 8 bit. So with alignment effects you grew the size of the data structure and therefore the cache foot print. This is not about 'nice to have' Thanks, tglx
Re: Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
On Tue, 10 Apr 2018, yuank...@codeaurora.org wrote: > From: John Zhao > > Variable tick_stopped returned by tick_nohz_tick_stopped > can have only true / forse 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 int. The data type is not int. It's part of an integer bitfield and occupies exactly one bit of storage, while bool has an architecture dependend size and is at least 1 byte, i.e. 8 bit. So with alignment effects you grew the size of the data structure and therefore the cache foot print. This is not about 'nice to have' Thanks, tglx
[PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
From: John ZhaoVariable tick_stopped returned by tick_nohz_tick_stopped can only be 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_idle_tick : 1;
[PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
From: John Zhao Variable tick_stopped returned by tick_nohz_tick_stopped can only be 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_idle_tick : 1;
Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
From: John ZhaoVariable tick_stopped returned by tick_nohz_tick_stopped can have only true / forse 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_idle_tick : 1;
Subject: [PATCH] [PATCH] time: tick-sched: use bool for tick_stopped
From: John Zhao Variable tick_stopped returned by tick_nohz_tick_stopped can have only true / forse 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 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; + booltick_stopped: 1; unsigned intinidle : 1; - unsigned inttick_stopped: 1; unsigned intidle_active : 1; unsigned intdo_timer_last : 1; unsigned intgot_idle_tick : 1;