diff mbox

sched/idle: Drop !! while calculating 'broadcast'

Message ID 0dfbe2976aa108c53e08d3477ea90f6360c1f54c.1403584026.git.viresh.kumar@linaro.org
State Accepted
Commit 89abb5ad10ae8ac3405e635ac80815f781c8b8e9
Headers show

Commit Message

Viresh Kumar June 24, 2014, 4:31 a.m. UTC
We don't need 'broadcast' to be set to 'zero or one', but to 'zero or non-zero'
and so the extra operation to convert it to 'zero or one' can be skipped.

Also change type of 'broadcast' to unsigned int, i.e. type of
drv->states[*].flags.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Rebased over: 3.16-rc2.

 kernel/sched/idle.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Peter Zijlstra June 24, 2014, 8:03 a.m. UTC | #1
On Tue, Jun 24, 2014 at 10:01:01AM +0530, Viresh Kumar wrote:
> We don't need 'broadcast' to be set to 'zero or one', but to 'zero or non-zero'
> and so the extra operation to convert it to 'zero or one' can be skipped.
> 
> Also change type of 'broadcast' to unsigned int, i.e. type of
> drv->states[*].flags.

All true; but does it change anything? That is, does your compiler
generate better code because of this?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Viresh Kumar June 24, 2014, 10:48 a.m. UTC | #2
On 24 June 2014 13:33, Peter Zijlstra <peterz@infradead.org> wrote:
> All true; but does it change anything? That is, does your compiler
> generate better code because of this?

Compilers are smart enough now a days and may not  perform !!
at all I believe.. And so this patch is more about code clarity ..

I tried comparing results for ARM and got this with/without
this patch ..

$ size ../bexynos/kernel/sched/idle.o
   text   data    bss    dec    hex filename
    690     30      0    720    2d0 ../bexynos/kernel/sched/idle.o

Don't know if some architectures are using somewhat dumb
compilers which might result in better code with this patch :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Mike Galbraith June 24, 2014, 12:18 p.m. UTC | #3
On Tue, 2014-06-24 at 10:03 +0200, Peter Zijlstra wrote: 
> On Tue, Jun 24, 2014 at 10:01:01AM +0530, Viresh Kumar wrote:
> > We don't need 'broadcast' to be set to 'zero or one', but to 'zero or non-zero'
> > and so the extra operation to convert it to 'zero or one' can be skipped.
> > 
> > Also change type of 'broadcast' to unsigned int, i.e. type of
> > drv->states[*].flags.
> 
> All true; but does it change anything? That is, does your compiler
> generate better code because of this?

x86_64 gcc-4.8.3 made 1 less instruction, a shift.

-Mike

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Viresh Kumar June 24, 2014, 12:35 p.m. UTC | #4
On 24 June 2014 17:48, Mike Galbraith <umgwanakikbuti@gmail.com> wrote:
> x86_64 gcc-4.8.3 made 1 less instruction, a shift.

I thought about doing this test for x86 as well, and over-estimated
compilers intelligence. I must have done it :)

And finally this patch is worth more than I originally estimated :)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index cf009fb..9f1608f 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -79,7 +79,7 @@  static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	bool broadcast;
+	unsigned int broadcast;
 
 	/*
 	 * Check if the idle task must be rescheduled. If it is the
@@ -135,7 +135,7 @@  use_default:
 		goto exit_idle;
 	}
 
-	broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP);
+	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
 
 	/*
 	 * Tell the time framework to switch to a broadcast timer