public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Remove useless test during exchanging values
@ 2016-04-21 12:28 Minfei Huang
  2016-04-21 13:27 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Minfei Huang @ 2016-04-21 12:28 UTC (permalink / raw)
  To: mingo, peterz; +Cc: linux-kernel, Minfei Huang

The value delta is correct as well, although calc_load_idle[idx] is
equal to 0. Remove this useless test to improve performance, since this
function is called more frequently.

Signed-off-by: Minfei Huang <mnghuan@gmail.com>
---
 kernel/sched/loadavg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index ef71590..5a5d7ae 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
 static long calc_load_fold_idle(void)
 {
 	int idx = calc_load_read_idx();
-	long delta = 0;
+	long delta;
 
-	if (atomic_long_read(&calc_load_idle[idx]))
-		delta = atomic_long_xchg(&calc_load_idle[idx], 0);
+	delta = atomic_long_xchg(&calc_load_idle[idx], 0);
 
 	return delta;
 }
-- 
2.6.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Remove useless test during exchanging values
  2016-04-21 12:28 [PATCH] Remove useless test during exchanging values Minfei Huang
@ 2016-04-21 13:27 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2016-04-21 13:27 UTC (permalink / raw)
  To: Minfei Huang; +Cc: mingo, linux-kernel

On Thu, Apr 21, 2016 at 08:28:28PM +0800, Minfei Huang wrote:
> The value delta is correct as well, although calc_load_idle[idx] is
> equal to 0. Remove this useless test to improve performance, since this
> function is called more frequently.
> 
> Signed-off-by: Minfei Huang <mnghuan@gmail.com>
> ---
>  kernel/sched/loadavg.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
> index ef71590..5a5d7ae 100644
> --- a/kernel/sched/loadavg.c
> +++ b/kernel/sched/loadavg.c
> @@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
>  static long calc_load_fold_idle(void)
>  {
>  	int idx = calc_load_read_idx();
> -	long delta = 0;
> +	long delta;
>  
> -	if (atomic_long_read(&calc_load_idle[idx]))
> -		delta = atomic_long_xchg(&calc_load_idle[idx], 0);
> +	delta = atomic_long_xchg(&calc_load_idle[idx], 0);

This will actually degrade performance.

The read can have the cacheline in shared mode, while the xchg will
force it into exclusive mode. Also, the xchg atomic operation is a
really expensive instruction.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-04-21 13:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-21 12:28 [PATCH] Remove useless test during exchanging values Minfei Huang
2016-04-21 13:27 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox