From patchwork Mon Jul 1 15:39:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 168214 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3072157ilk; Mon, 1 Jul 2019 08:39:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhCY/DZKUkCXwq5ezI7H4mKQZ++tVhsMxQ4BHobMfxuSCdrvtJ1njOEIwHffWU1CYjes5l X-Received: by 2002:a63:f346:: with SMTP id t6mr26415364pgj.203.1561995579100; Mon, 01 Jul 2019 08:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561995579; cv=none; d=google.com; s=arc-20160816; b=o1UwkhKKgggNAxPkLccICTf+Z/HRLo8I7YCqZrs3k8JuXTgUHWC6ewPBW5jx+PFwJM S0wfrujHiSxbJ2C/Bp21eE+5OHsSJ1crbHcVU01OqNUqrxtI8MqfALrcBAUNDZNAyhEv mNUXBwkTlXHySa3NpnCFo2FokhBhVRvpjvjX06ihnNYK4Dn1bSzHoXqSxvv/jJ5bSznM pzluSS1rJYFGJ+Jl5qojHc79bZYcorpIT55IUrv4pQkZpvuq+ROQzEr7IfudqDzHDeB1 9T2C9j5WMSsImLSsPEVizLVYVnbpudrGJr03STeBwGiGW9HisCkU/fDTRvZuGfPNrysC ztNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=SIA/BH+2QfVgtLDV+7t8/NDCiCsFsJMI64czIqxEO2w=; b=Iw5cKcWzlP/sY9J3jhUSvE3XleOprBuje2CWckKgoqadlRkB1F9zmFwawWAau4k7K6 Mcc4TobBQIT0rROLZISkjwkDuHofjl7IvwxAJHbsZmd3KoAh74UK5bxZXTYtXVRnmOd7 GqBq4AFC9mUFQX4+Yz8Dzxnd1yexn37sPVZOSLV3E8auTpplxEDINxsxcnMQz68h4szb l/3nhnCJPDD82FsFz201kWcc4gurumfbEo7IHjjWNzd5BWAbqPD+wnIdK5SXVGiZ5hIU bcdkG+ZwJ6Mb/GjDFuZL8aLgI3RauHKwosWqPpf6TO/LY6RvM5/bRvkFRgEF9eS/nnr6 J3hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K49Wiqd5; 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 v24si7368509pgn.64.2019.07.01.08.39.38; Mon, 01 Jul 2019 08:39:39 -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=K49Wiqd5; 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 S1729683AbfGAPjg (ORCPT + 30 others); Mon, 1 Jul 2019 11:39:36 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40033 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728618AbfGAPjg (ORCPT ); Mon, 1 Jul 2019 11:39:36 -0400 Received: by mail-wr1-f65.google.com with SMTP id p11so14384259wre.7 for ; Mon, 01 Jul 2019 08:39:35 -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; bh=SIA/BH+2QfVgtLDV+7t8/NDCiCsFsJMI64czIqxEO2w=; b=K49Wiqd5PUgHUnpgeJrSUWKnZWne1SYdlv8UTUrB/dHAp/tP9ZRDPLTiM0rq/vGqX6 VT7cpdX4uIFtrOQ6N3dSZDizmV4o4myEqF0SAaDXy6YFMcNOIuZUCpXs2AuSsDEBc69o 5Ngr+ZortMt4UwpsJNanskDTGEz7tA4Oy5hUVfKVl/VGrrDbpMdEMUYnutfgfRd9uDUh oOp17VPIiAWhKLY+9AenwZxlVB7iDhSU65uffbqAEnG9ccOvuuc59TIohfB/RcoRKCI1 1G2eaG1B8CWrsw0kKKmToCPLlTBOCpo13aIbNCVsyH8doDCxaRwkgct76G+mawqlSGlS lRXA== 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; bh=SIA/BH+2QfVgtLDV+7t8/NDCiCsFsJMI64czIqxEO2w=; b=Wsspw/P/i7Seo0uA/OPbL5DwQ9g6WzkcwX3ZjB+MxlsHjMYZ735VtSLENypW+EtE+q CPDV2yMJEkabdNUeHSq6aIxDMeMmCuX8Gb3rdEPIJdTnEWtUyQNig/211NyuxU55cR3X ++IlEnedzJx7ogxv8l2xPBYnZX5uQVQbgcIJc9J+wnjN9drXCNHVMZ5alPWN3jfKZ5uY joG4JlQhPJs6WF04x4wySNAEry2FpCi49ant7PUqXkwlS16pj51ll6MMyYYbBdUJJQ7g nXyyvnWyuBm6+IYeDsLeFXRBkhM5KWB4aQbC8LJ/bWwnfsO/lChlSEzkyPqgn3pAs4Fi ivzA== X-Gm-Message-State: APjAAAWEpSByBrBxkhw2hW6sznXSFFvBhwajLeo/HaSo8icf/0I8GgD8 6pLsvdRrfs0t4GPHc8hzsomO4/PqA0c= X-Received: by 2002:adf:dfc4:: with SMTP id q4mr19122183wrn.54.1561995574117; Mon, 01 Jul 2019 08:39:34 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:5dbd:30b:8a71:a020]) by smtp.gmail.com with ESMTPSA id w25sm6292276wmk.18.2019.07.01.08.39.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jul 2019 08:39:33 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Cc: Vincent Guittot Subject: [PATCH] sched/fair: fix imbalance due to CPU affinity Date: Mon, 1 Jul 2019 17:39:26 +0200 Message-Id: <1561995566-27200-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/sched/fair.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9f9dcb1..bd94171 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9032,9 +9032,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 get + * 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)