Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1007574ybl; Wed, 21 Aug 2019 08:44:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQvdLWVNTdJs9HO7wwqR86Tr09uzT5oFDoDW5JlgcERzP/lzXAiGfNgZlIlHDiwc8i19Eo X-Received: by 2002:a17:90a:3b4f:: with SMTP id t15mr640950pjf.45.1566402298204; Wed, 21 Aug 2019 08:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566402298; cv=none; d=google.com; s=arc-20160816; b=JgBNpjWsiaJ3MToxtySMIJiUPH/UAhC3RsotjommS5thF/M5SQ2CJ1KnaUr53wKkgl aDwik1N219oMROyCoMOIZidnY1iFZI0Wtx4KJecy5KjQh1CPgD3Nxv4Stiti0lwKpD2r iQVA7wuOX/UjomUqJ7HBo2pLu4G4yzRkB6aSzdRPVTN71oo26ld4XGZyCUMbjydGmOdX fZSmztwvlaZ/IqVO+MTwLyDi+2PhukCwswaPSVK093AqbZiEFtAdF+6u9FMvXtDEz5bt ky8djbDRYRvs5cQjmOROE/Wuq1RoNuW4HgCiegweEVOlAMSIfkDTyeJ+DlXCbgiBseQw pXNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=l6WCJwQkLh8qrjckxjjcebdd8bJkp2W3qsa/Xc2aDa0=; b=E0e7OwIbI/MkmDHcP5zW1YtcbiNU3BMeaIzwUj0onQpq3EH5GVxsAniM/Y6KpAi40W Pr+GvJZ76MGN8qQwnEorrvpZncc/zOUlvBKW+e2HyxijReZF1hiGqf8Qvhop+Icjkslo hoNheF4eu0zpmgCulz2pPJlYHOGQfISYpmxvUs4M5IySwKjDEgTwooANKLBxRpC5Hswk /18CqiefadOa2RM3QcGJRczK+TyaPHHLwjF9CN3U5YPrjkPJkQxzY13o2Fr6qfQjMEF9 TPoxkUpzCJ6fTLcWKqICRSxeQo4erlFnyYbvu33HTRPr4DMYadSLDlny1r8EtjOVoCLV 3o4g== ARC-Authentication-Results: i=1; mx.google.com; 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 n3si14498633pgb.68.2019.08.21.08.44.42; Wed, 21 Aug 2019 08:44: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; 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 S1729907AbfHUPP2 (ORCPT + 99 others); Wed, 21 Aug 2019 11:15:28 -0400 Received: from foss.arm.com ([217.140.110.172]:59808 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727395AbfHUPP1 (ORCPT ); Wed, 21 Aug 2019 11:15:27 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3BD10337; Wed, 21 Aug 2019 08:15:27 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.194.52]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 89F1D3F718; Wed, 21 Aug 2019 08:15:26 -0700 (PDT) Date: Wed, 21 Aug 2019 16:15:24 +0100 From: Qais Yousef To: Peng Liu Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com Subject: Re: [PATCH] sched/fair: eliminate redundant code in sched_slice() Message-ID: <20190821151523.lwazjd2d6rp5otdh@e107158-lin.cambridge.arm.com> References: <20190816141202.GA3135@iZj6chx1xj0e0buvshuecpZ> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190816141202.GA3135@iZj6chx1xj0e0buvshuecpZ> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/16/19 22:12, Peng Liu wrote: > Since sched_slice() is used in high frequency, > small change should also make sense. > > Signed-off-by: Peng Liu > --- > kernel/sched/fair.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 1054d2cf6aaa..6ae2a507aac0 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -694,19 +694,16 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) > u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); > > for_each_sched_entity(se) { > - struct load_weight *load; > struct load_weight lw; > > cfs_rq = cfs_rq_of(se); > - load = &cfs_rq->load; > + lw = cfs_rq->load; > > - if (unlikely(!se->on_rq)) { > + if (unlikely(!se->on_rq)) > lw = cfs_rq->load; > > - update_load_add(&lw, se->load.weight); > - load = &lw; > - } > - slice = __calc_delta(slice, se->load.weight, load); > + update_load_add(&lw, se->load.weight); > + slice = __calc_delta(slice, se->load.weight, &lw); Unless I misread the diff, you changed the behavior. update_load_add() is only called if (unlikely(!se->on_rq)), but with your change it is called unconditionally. And lw is set twice. I think what you intended is this? diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bc9cfeaac8bd..6bbe17d5943f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -694,19 +694,15 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); for_each_sched_entity(se) { - struct load_weight *load; struct load_weight lw; cfs_rq = cfs_rq_of(se); - load = &cfs_rq->load; - - if (unlikely(!se->on_rq)) { - lw = cfs_rq->load; + lw = cfs_rq->load; + if (unlikely(!se->on_rq)) update_load_add(&lw, se->load.weight); - load = &lw; - } - slice = __calc_delta(slice, se->load.weight, load); + + slice = __calc_delta(slice, se->load.weight, &lw); } return slice; } Cheers -- Qais Yousef