From patchwork Fri Oct 18 13:26:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 176837 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp861723ill; Fri, 18 Oct 2019 06:27:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVyLojxTGXHbQQO5lYQzPjB7dmqjOWvDAKhnOl4xjgaVVW8ATdkJ0eGMkhAHesXjl8a1zj X-Received: by 2002:a05:6402:19bd:: with SMTP id o29mr9478402edz.42.1571405232292; Fri, 18 Oct 2019 06:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571405232; cv=none; d=google.com; s=arc-20160816; b=SUkI20MULkI7jevUEuyvL6iI9/ppGc43AFOVR68plxXvXtj8IyItvqbckn4hC9R917 coTnigZ43WgaACEG1NCYLOqlnIsRDDQT3O7YFq91owLaBF7dZ5+u8BSGCMwcQz0y66I2 Vwgvf2BxbusyvySIHOiNd88oOKH6kfEzuxrR6u1g+3odaGabTX0I8tCwmBpwMrmFKwS7 NODvKazKSQ5Z7ih/9ft35s1JyXtQkD2KcM/YfWHKx8peLRml98wt96+GpOoXfVp7VGnb CDbDWl6fBbYuPKDbX4L77UfbS8qFtMLwrBBEpjCe5Lr3zpq4TwPUMyP1HK24fKQXoCc4 oqdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=rF17NfzVuoPQDjrV4B8MSfUDRkdA/P46N9yA+eCB77U=; b=SvgKpA3hbhn+XZl83WzotEtpd53YbWi2qieaDhtHjeRP3GTDiPgV5+NvVzThhNKmA5 kAPn+UrmNN+fg+x3w71BFq1FJvwbpUyVkV5j86eY2NTpQGMMjw6rPnOev/C8/H2jTKso 7YZYG+GOr6hTdzDAl2brHgFv0lgBVj71GBbIb2s5thCPuauLvDGIFybpxy2r0NvK2O15 Bn8w7LCXCLSLRc13M6XvWnzpL/wHPcKSv2LHDdHhYR8SE6lWxWPObdvDtnGy+yD4Mnkq 6Tx8+arkWxfTxlnHtudU5NSoLasmwdVQfftnSP/J8dX9cGw/mOoNotcnEMAO2Lea69D4 qaqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G0oDhG1t; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x62si4011677ede.352.2019.10.18.06.27.12; Fri, 18 Oct 2019 06:27:12 -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; dkim=pass header.i=@linaro.org header.s=google header.b=G0oDhG1t; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442845AbfJRN1H (ORCPT + 26 others); Fri, 18 Oct 2019 09:27:07 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55007 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438919AbfJRN1E (ORCPT ); Fri, 18 Oct 2019 09:27:04 -0400 Received: by mail-wm1-f65.google.com with SMTP id p7so6193216wmp.4 for ; Fri, 18 Oct 2019 06:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rF17NfzVuoPQDjrV4B8MSfUDRkdA/P46N9yA+eCB77U=; b=G0oDhG1tp21hqgoc0Wftnssc9hxoXtNaWmw+rX4yhbE0TfCUsLCUi2lUibmsO/dO+R ZAeKslXiKdUvQNF5+/tWf8z9YDwDNh6iP0kqNAH1W7mjk3OIIDkR25vTWoJeiXryGQz6 CiTA0HSae02uTYsH1CtxaxiWGKU6dikwaGiWNLbOlebv82W4MPTw/9aOJKRbnidMVfeA Edeo7C2SnFT5Q3TH25FB1bmiIn4sAIFVK0vMDtEm3krbAKip3CQ9qFFs0X7/Il3cQIrx 65F2uNoLKYHNl6GoBI/NfYUfqLUT+Mb/g1cOXMKKY6xumD9nWHZhvz1+B80kCITNjZRm ysYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rF17NfzVuoPQDjrV4B8MSfUDRkdA/P46N9yA+eCB77U=; b=WhrzCnH9Uzd9PTCSlpWmeaRs+6XZCBCzoW4qm1a6nAnaMWYEnQB59BC4PPMFPXTT0M VlEM/2ZW570TEfRGRbZfzrIJ06Lk1SX6HFXHaX4QQv83xC2KtBgDh1UW1bMdnns6WNRd Phpq6zMvGb7eqWWJ691lMuYZJb8JUT/PeSIFX6Ir7daPci0PBjrHesSRzV1QsLVITYQC s3NH114Y/PtJwFtpBfn5ePzuda1pZcWp72etLjbtatC49sqURXuSSSEv4f16a0X0Z4FY oslzxadSRrLBfaQEF6ojeDhOzB7JW9UBNqREaDSY0I6KaAs07zEuzLti6c0lJPc3+Mwv u3/A== X-Gm-Message-State: APjAAAVW5ilrALn/gTZsmZREvgOWYTe9vS3UMNcNMy/tmqKXRRC8DwIo QFlFsQQUNS9a53AUvZThx9MJvYLO2KY= X-Received: by 2002:a1c:9c0c:: with SMTP id f12mr1836748wme.133.1571405222144; Fri, 18 Oct 2019 06:27:02 -0700 (PDT) Received: from localhost.localdomain (91-160-61-128.subs.proxad.net. [91.160.61.128]) by smtp.gmail.com with ESMTPSA id p15sm5870123wrs.94.2019.10.18.06.27.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Oct 2019 06:27:00 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Cc: pauld@redhat.com, valentin.schneider@arm.com, srikar@linux.vnet.ibm.com, quentin.perret@arm.com, dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, hdanton@sina.com, parth@linux.ibm.com, riel@surriel.com, Vincent Guittot Subject: [PATCH v4 10/11] sched/fair: optimize find_idlest_group Date: Fri, 18 Oct 2019 15:26:37 +0200 Message-Id: <1571405198-27570-11-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1571405198-27570-1-git-send-email-vincent.guittot@linaro.org> References: <1571405198-27570-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org find_idlest_group() now reads CPU's load_avg in 2 different ways. Consolidate the function to read and use load_avg only once and simplify the algorithm to only look for the group with lowest load_avg. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 50 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 36 deletions(-) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6203e71..ed1800d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5560,16 +5560,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, { struct sched_group *idlest = NULL, *group = sd->groups; struct sched_group *most_spare_sg = NULL; - unsigned long min_runnable_load = ULONG_MAX; - unsigned long this_runnable_load = ULONG_MAX; - unsigned long min_avg_load = ULONG_MAX, this_avg_load = ULONG_MAX; + unsigned long min_load = ULONG_MAX, this_load = ULONG_MAX; unsigned long most_spare = 0, this_spare = 0; int imbalance_scale = 100 + (sd->imbalance_pct-100)/2; unsigned long imbalance = scale_load_down(NICE_0_LOAD) * (sd->imbalance_pct-100) / 100; do { - unsigned long load, avg_load, runnable_load; + unsigned long load; unsigned long spare_cap, max_spare_cap; int local_group; int i; @@ -5586,15 +5584,11 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, * Tally up the load of all CPUs in the group and find * the group containing the CPU with most spare capacity. */ - avg_load = 0; - runnable_load = 0; + load = 0; max_spare_cap = 0; for_each_cpu(i, sched_group_span(group)) { - load = cpu_load(cpu_rq(i)); - runnable_load += load; - - avg_load += cfs_rq_load_avg(&cpu_rq(i)->cfs); + load += cpu_load(cpu_rq(i)); spare_cap = capacity_spare_without(i, p); @@ -5603,31 +5597,15 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, } /* Adjust by relative CPU capacity of the group */ - avg_load = (avg_load * SCHED_CAPACITY_SCALE) / - group->sgc->capacity; - runnable_load = (runnable_load * SCHED_CAPACITY_SCALE) / + load = (load * SCHED_CAPACITY_SCALE) / group->sgc->capacity; if (local_group) { - this_runnable_load = runnable_load; - this_avg_load = avg_load; + this_load = load; this_spare = max_spare_cap; } else { - if (min_runnable_load > (runnable_load + imbalance)) { - /* - * The runnable load is significantly smaller - * so we can pick this new CPU: - */ - min_runnable_load = runnable_load; - min_avg_load = avg_load; - idlest = group; - } else if ((runnable_load < (min_runnable_load + imbalance)) && - (100*min_avg_load > imbalance_scale*avg_load)) { - /* - * The runnable loads are close so take the - * blocked load into account through avg_load: - */ - min_avg_load = avg_load; + if (load < min_load) { + min_load = load; idlest = group; } @@ -5668,18 +5646,18 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, * local domain to be very lightly loaded relative to the remote * domains but "imbalance" skews the comparison making remote CPUs * look much more favourable. When considering cross-domain, add - * imbalance to the runnable load on the remote node and consider - * staying local. + * imbalance to the load on the remote node and consider staying + * local. */ if ((sd->flags & SD_NUMA) && - min_runnable_load + imbalance >= this_runnable_load) + min_load + imbalance >= this_load) return NULL; - if (min_runnable_load > (this_runnable_load + imbalance)) + if (min_load >= this_load + imbalance) return NULL; - if ((this_runnable_load < (min_runnable_load + imbalance)) && - (100*this_avg_load < imbalance_scale*min_avg_load)) + if ((this_load < (min_load + imbalance)) && + (100*this_load < imbalance_scale*min_load)) return NULL; return idlest;