Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18664580ybl; Fri, 3 Jan 2020 06:46:05 -0800 (PST) X-Google-Smtp-Source: APXvYqyLpPBnsnvUKLAxoGEmARNY5r8Q1WkGzo5bRWPlWe37wCPButVKIKhoO4JAUhbXP5DEdryr X-Received: by 2002:a05:6830:1401:: with SMTP id v1mr67713026otp.360.1578062765568; Fri, 03 Jan 2020 06:46:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578062765; cv=none; d=google.com; s=arc-20160816; b=fhhT8nxJoIj15sInoC5E498aPdvygPsmG1aqzVTy0vAJdybos/BT67tgMJ/3nyrVA9 4zaZs9Y87CdRi625ICR04rFc6gowULSzY1nUgfeIzu3QZDVpINjtSO3Y104ZdiL6v5J1 B+yAvCHoRuzC+OOlq1Cxui+FYRLMaV0XvAwyx5jcjP57QQg+bOCFRPXO6CEE3z7QtzLB 5TwqqzNBFkRDKIDLhJOTiiVKxYNWb5MOW2rlsByd+E/nLCvExeiByTOi/MflrJ7L9/Db mEaOLeNarntyUIHU1gZXKRkPplJQFMKPp+magXGM37CvWDrLNmb2i8CPFEEiFvaHK9TG Kr5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=d1Yb6URz/QiCAQUrTxVrQKXjUpONJEkT9H8N0EXNSP0=; b=vpdhKd1oVXJJgniXC7re58Hc06+PBlytkvb44p4pQ0DofbHkCzXBmohuaEQwLvmW0A qnfMUgtf3Hul1jtBDH1biKLPt6j8nu1jWoGR13neKJP+TwToMdyWR2Ir9Gos/JxExzFx Dk0ePo/u87tw+qLLuK5H1V0NdUjERT8zsOYiLA7F9TcAsnhrEJAYGZ63pRLNxUAB1cMK Bb/uhRV5B4h0txCjsfea+2R2r6jXnAIBpQ6TdSObYEZK2woCpQkziRba+KxPyVt5ShyX 6JnWZVNl9fHKQ54Lxu1QweQAWfix5n2KJB2kAwbCeurdQ/pCK0JQt2aLu7Xx35ozxtDQ fvgA== 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 t82si27353049oif.45.2020.01.03.06.45.53; Fri, 03 Jan 2020 06:46:05 -0800 (PST) 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 S1727887AbgACOoE (ORCPT + 99 others); Fri, 3 Jan 2020 09:44:04 -0500 Received: from foss.arm.com ([217.140.110.172]:55976 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbgACOoD (ORCPT ); Fri, 3 Jan 2020 09:44:03 -0500 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 D1A6E328; Fri, 3 Jan 2020 06:44:02 -0800 (PST) Received: from [10.1.194.46] (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64AB03F237; Fri, 3 Jan 2020 06:44:01 -0800 (PST) Subject: Re: [PATCH] sched/fair: fix sgc->{min,max}_capacity miscalculate To: Peng Liu , linux-kernel@vger.kernel.org Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, qais.yousef@arm.com, morten.rasmussen@arm.com References: <20191231035122.GA10020@iZj6chx1xj0e0buvshuecpZ> <20200101141329.GA12809@iZj6chx1xj0e0buvshuecpZ> <20200103142152.GA4551@iZj6chx1xj0e0buvshuecpZ> From: Valentin Schneider Message-ID: <7370a631-1e9a-90ba-dcbe-f714ecb0fb26@arm.com> Date: Fri, 3 Jan 2020 14:44:00 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200103142152.GA4551@iZj6chx1xj0e0buvshuecpZ> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/01/2020 14:21, Peng Liu wrote: > Thanks for your patient explanation, and the picture is intuitive > and clear. Indeed, the group in lowest domain only contains one CPU, and > the only CPU in the first group should be the rq's CPU. So, I wonder if > we can do like this? > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 2d170b5da0e3..c9d7613c74d2 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7793,9 +7793,6 @@ void update_group_capacity(struct sched_domain *sd, int cpu) > */ > > for_each_cpu(cpu, sched_group_span(sdg)) { > - struct sched_group_capacity *sgc; > - struct rq *rq = cpu_rq(cpu); > - > /* > * build_sched_domains() -> init_sched_groups_capacity() > * gets here before we've attached the domains to the > @@ -7807,15 +7804,11 @@ void update_group_capacity(struct sched_domain *sd, int cpu) > * This avoids capacity from being 0 and > * causing divide-by-zero issues on boot. > */ > - if (unlikely(!rq->sd)) { > - capacity += capacity_of(cpu); > - } else { > - sgc = rq->sd->groups->sgc; > - capacity += sgc->capacity; > - } > + unsigned long cpu_cap = capacity_of(cpu); > > - min_capacity = min(capacity, min_capacity); > - max_capacity = max(capacity, max_capacity); > + min_capacity = min(cpu_cap, min_capacity); > + max_capacity = max(cpu_cap, max_capacity); > + capacity += cpu_cap; > } > } else { > /* > Yep, if we refactor it to always use capacity_of() we'd end up with something like this. The comment block could be updated (or removed) as well. There must be (or have been) a reason to use the sched_group_capacity structure, but I'm not aware of it and I don't have time right now to dig through the git history to figure it out. I didn't see anyone suggesting or talking about this simplification in the discussion thread of 9abf24d46518 ("sched: Check sched_domain before computing group power") What you can try is sending that as the v2, and see if anyone screams. FWIW you can add this to it too: Reviewed-by: Valentin Schneider