Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16679623ybl; Wed, 1 Jan 2020 10:57:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzatbWWGGdf94vDkpOUXkcMIGYXoaxOv7OT+gzfH8G+O0IAngPhI7vsDNsbOZKX/FzwH+PT X-Received: by 2002:a9d:478:: with SMTP id 111mr86275628otc.359.1577905068813; Wed, 01 Jan 2020 10:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577905068; cv=none; d=google.com; s=arc-20160816; b=GcxrY0E8F3J2cHJUDaPa05EztPXti6o/Pz1KvH9BzfEl1jtio3S1XKDUmm4CT8jMIU FLJaNBoScsq3B2Pz6dr6JVx+XCkupDwL4Ria+MfchKfmBRYtPY6FvCV8LfpBVOs8QU3f g2sJyvuGkmUJK3aNuODMwuMfT2iCGqPrnWD0w8vrFPEstnyNfE4u/ZWkM9IgAPTMq8r4 8rR1TGFQTIIBnP88vMtFPeBFmnkc8sQOxdbZDQqwQ+00wqRjRmpv3JfW2FovCDhZ18tL MS/XSIPEL/XeYw85K91lB05PCxIAbzjwas9N7Klhsg0AYDO0y/jMBFFQdcOsrH5jfCVT eZqQ== 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=FNwWMsHaGafb0AIavH6HH+HeK3asMKlBN9tT5DHQ7yA=; b=YUipAATTKjtzU7cyhf7cmfdiX6JhK45wcBNkI9oWjP8OD4gxTJbBKRGm9BIRioPgdH NEEc/bOtRAJNRrz9NoW7/9LrcVJJfBlatyboYmBoB+bnqCsdZ4QM/CctzzL7wRy9uF7l IKOixfDSDxzQMgoSEAucFSvlXanhCefNyRleny4DBgWzcJpXsgIDIErmOXtWz/TuEpRR Vb6YjZUwTSQI24ftySNpXYXNNTJo4srb1TFbyL2s9M3IDsqmwSlwu9mJLXMvOadsgGur FHQSZSWk6cbXecSleAJuLrjHtXieob4z9n/Y2bKuJvf4u5Ev7/GaaohNe30ISmLpfFYC U4cw== 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 t82si23498942oif.45.2020.01.01.10.57.36; Wed, 01 Jan 2020 10:57:48 -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 S1727392AbgAASz7 (ORCPT + 99 others); Wed, 1 Jan 2020 13:55:59 -0500 Received: from foss.arm.com ([217.140.110.172]:41758 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727352AbgAASz7 (ORCPT ); Wed, 1 Jan 2020 13:55:59 -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 8AF9F31B; Wed, 1 Jan 2020 10:55:58 -0800 (PST) Received: from [10.0.2.15] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0BF523F68F; Wed, 1 Jan 2020 10:55:56 -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> From: Valentin Schneider Message-ID: Date: Wed, 1 Jan 2020 18:55:48 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200101141329.GA12809@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 01/01/2020 14:13, Peng Liu wrote: >> --- >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 08a233e97a01..9f6c015639ef 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -7773,8 +7773,8 @@ 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); >> + unsigned long cpu_cap; >> >> /* >> * build_sched_domains() -> init_sched_groups_capacity() >> @@ -7787,15 +7787,15 @@ 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; >> - } >> + if (unlikely(!rq->sd)) >> + cpu_cap = capacity_of(cpu); > > -------------------------------------------------------------- >> + else >> + cpu_cap = rq->sd->groups->sgc->capacity; > > sgc->capacity is the *sum* of all CPU's capacity in that group, right? Right > {min,max}_capacity are per CPU variables(*part* of a group). So we can't > compare *part* to *sum*. Am I overlooking something? Thanks. > AIUI rq->sd->groups->sgc->capacity should be the capacity of the rq's CPU (IOW the groups here should be made of single CPUs). This should be true regardless of overlapping domains, since they sit on top of the regular domains. Let me paint an example with a simple 2-core SMT2 system: MC [ ] SMT [ ][ ] 0 1 2 3 cpu_rq(0)->sd will point to the sched_domain of CPU0 at SMT level (it is the "base domain", IOW the lowest domain in the topology hierarchy). Its groups will be: {0} ----> {1} ^ / `-----' and sd->groups will point at the group spanning the "local" CPU, in our case CPU0, and thus here will be a group containing only CPU0. I do not know why sched_group_capacity is used here however. As I understand things, we could use cpu_capacity() unconditionally. >> + >> + min_capacity = min(cpu_cap, min_capacity); >> + max_capacity = max(cpu_cap, max_capacity); >> >> - min_capacity = min(capacity, min_capacity); >> - max_capacity = max(capacity, max_capacity); >> + capacity += cpu_cap; >> } >> } else { >> /*