From patchwork Thu Oct 3 15:51:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 175185 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp627388ill; Thu, 3 Oct 2019 10:26:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjvXeCcOE3gq6qUx7M3CYeC5AJdKIYU+Y+YEYrsuwzuIQQ44X+Hx2lkrU/yPFvzDpbz0XL X-Received: by 2002:a50:f603:: with SMTP id c3mr10469804edn.208.1570123586715; Thu, 03 Oct 2019 10:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123586; cv=none; d=google.com; s=arc-20160816; b=OTLmNQvTcExLuieN6b0hUBczaGBKdrtI8y1DuDj4Hiv08xAibMNDbfNUlZvIQQ7zpy SMq2h9DVBww02Ah16aMr43QCr8LEAmBgKKtdUHFa+f5dDCiCvaitDOwAwVpdCshQhLvX PWSny4H2+E7eEQYn3KignxZXAcQWYUxOQxADXJFJdY36BqAjEKculm2/dOuAzbCbfBZd 0gb+awS62gPusPbNUDJ6ixM4olBSGDGbif2+KF5VTB213ZLWrLf3WRh8cW+5FI8Gcnyr 6HgO+uMyu8FSb2SMuwwyDsRAft3BVOurD9mAF5nc2eX6fsw4Dial9c7RBDI/odhz4uDR A86g== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2cBVT5dic84Wu3NU2ZZaXR6q44Id+GDnuiDO5mib/20=; b=al66nfgIxYZaNYOQyj9ysioDSoiIW50suBsVPE0RXBfGJ5M3bu1NES7vRSacYOOD8L k2t/58XOzKTevWKpgFOom4JENc5hEhA2VfnendTlhhflhS95FaRxs5z0r6LP6d1a3/kU w1zM8gltGet44PbmC9ZVOSPDzvv8bUn6ASYezXWCWIy7wOarIS6UnrRTzL6NF8ADT0gZ v4RGkoI6AAohhQlgN+fQmi+9cexUgNVU7KbdoMQOjtVxwurhRCO/1OnwJDUJzpeJvRO8 /OCFTh869gnLIwnFLoC5P0tnzEJ0xpNnsac45ZauYyRqNoMp6Fl73nBswpr71BXhD56f vKbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zZkIU0fy; 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 e31si1983577ede.199.2019.10.03.10.26.26; Thu, 03 Oct 2019 10:26:26 -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=@kernel.org header.s=default header.b=zZkIU0fy; 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 S2388914AbfJCQQG (ORCPT + 27 others); Thu, 3 Oct 2019 12:16:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:40708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbfJCQQD (ORCPT ); Thu, 3 Oct 2019 12:16:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A624721848; Thu, 3 Oct 2019 16:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119363; bh=U4nLDZyW+12AR45NjmA0NOq24LJ8YnQZNzJGzVI+V4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zZkIU0fyxo3hUgEbLuKPtEkoomA8+Vp/NesV8rE7f4RgcK38zyrTtKVrWiXnnU+Wz 3HnyJ6BqfLz5Zv2HeLAm7OcbAZ1lAG3N7Denv4HwOcLcAkHlrNTQqxdIF8zLvyEtAd JtxT7CoYcZ3fKiCim4++78J1xSRvCRSYEWaAbHis= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Guittot , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 038/211] sched/fair: Fix imbalance due to CPU affinity Date: Thu, 3 Oct 2019 17:51:44 +0200 Message-Id: <20191003154456.085032239@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Guittot [ Upstream commit f6cad8df6b30a5d2bbbd2e698f74b4cafb9fb82b ] The load_balance() has a dedicated mecanism to detect when an imbalance is due to CPU affinity and must be handled at parent level. In this case, the imbalance field of the parent's sched_group is set. The description of sg_imbalanced() gives a typical example of two groups of 4 CPUs each and 4 tasks each with a cpumask covering 1 CPU of the first group and 3 CPUs of the second group. Something like: { 0 1 2 3 } { 4 5 6 7 } * * * * But the load_balance fails to fix this UC on my octo cores system made of 2 clusters of quad cores. Whereas the load_balance is able to detect that the imbalanced is due to CPU affinity, it fails to fix it because the imbalance field is cleared before letting parent level a chance to run. In fact, when the imbalance is detected, the load_balance reruns without the CPU with pinned tasks. But there is no other running tasks in the situation described above and everything looks balanced this time so the imbalance field is immediately cleared. The imbalance field should not be cleared if there is no other task to move when the imbalance is detected. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: https://lkml.kernel.org/r/1561996022-28829-1-git-send-email-vincent.guittot@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 49ed38914669b..ad78a15bd5677 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8863,9 +8863,10 @@ static int load_balance(int this_cpu, struct rq *this_rq, out_balanced: /* * We reach balance although we may have faced some affinity - * constraints. Clear the imbalance flag if it was set. + * constraints. Clear the imbalance flag only if other tasks got + * a chance to move and fix the imbalance. */ - if (sd_parent) { + if (sd_parent && !(env.flags & LBF_ALL_PINNED)) { int *group_imbalance = &sd_parent->groups->sgc->imbalance; if (*group_imbalance)