Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752178AbcDUN1x (ORCPT ); Thu, 21 Apr 2016 09:27:53 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:54927 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751904AbcDUN1v (ORCPT ); Thu, 21 Apr 2016 09:27:51 -0400 Date: Thu, 21 Apr 2016 15:27:43 +0200 From: Peter Zijlstra To: Minfei Huang Cc: mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Remove useless test during exchanging values Message-ID: <20160421132743.GL3408@twins.programming.kicks-ass.net> References: <1461241708-812-1-git-send-email-mnghuan@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1461241708-812-1-git-send-email-mnghuan@gmail.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1092 Lines: 30 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 > --- > 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.