Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp529005ybn; Wed, 2 Oct 2019 01:58:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLRwYMgt7drBru698y9Jw7sfLZ6OqVnqwhpNItun/Xlb+pdXQgDoNWfiBBZs/kbCWThEXz X-Received: by 2002:a17:906:4b41:: with SMTP id j1mr2000711ejv.162.1570006715946; Wed, 02 Oct 2019 01:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570006715; cv=none; d=google.com; s=arc-20160816; b=xQ6xSW+/BpiUJhyJ27gByVrnQPuTSnAuhQqhArm8EbGq6qthoJesHairyZfwI/kQcc JCQ3cOEBmC6HXCrne/iLqrXnPWAXN4cXQ48zojpdX6OBxnex+abSXAGnV2MS948yA+Mm Ob8g+xsU4ksgxcKjFsT7ZexV2h2rgKsQ3F2eIHTjiSCNlRccc7MkXqMV/y8VIjGOrH1D 1hbwlGhg3YqmHe4f4j1FtDKjIpgu73bU/p23Tf2qLpVdk4O6woi6rCPHm2W5X7mN6hi0 OtWwGWY4wsvyDkM5550DE9QgqFsXP4cJ7iq9BUG60V/LKz7gmb6Y2//9kSqM+eZ/Bzdv vpWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=42ZwQ2L8M5MJa5KRQ4XrIfZwc9ii86LEtw7sm/nefwc=; b=hBhjSf36Gegg6xTXOoUfXILVMywJLhZHs1CwYcX1tG6WcSGQhWrOWmoXu39QXYpPOA /QE8zBjwW/x84o4WMgvDCbR0JcwCkrEIJG85qDgnowFpJLGER3n5acYBpfe/hESrcG8w G5I+3F2eOd0c4a3JjZLEKf7OXpFd/C0a7D23hNSdon0R3lwnh+EmqJvJjZtyjJ2VnHtM vlKzxVuaTkEK5BFYf1/kFbx4DSXB8rWwnhp0dAH9aDBKLgNQGKDqI1MraM+6Ec69+E8s ROsVIKX/KZMRlIgDbm3ycbZW5jIT8xHXxB2+BZ5kjbXQ57ZkTzTtC18CTPvudB5uwM8W Lv5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PONKABbo; 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 v13si10754463edy.441.2019.10.02.01.58.11; Wed, 02 Oct 2019 01:58:35 -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=PONKABbo; 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 S1727550AbfJBIbO (ORCPT + 99 others); Wed, 2 Oct 2019 04:31:14 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38901 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727477AbfJBIbO (ORCPT ); Wed, 2 Oct 2019 04:31:14 -0400 Received: by mail-lj1-f194.google.com with SMTP id b20so16193080ljj.5 for ; Wed, 02 Oct 2019 01:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=42ZwQ2L8M5MJa5KRQ4XrIfZwc9ii86LEtw7sm/nefwc=; b=PONKABboRBdjEi9olZIKarJkaAgK8/WETMkf/TppdJPizomPdJl+798WY4nRHCvl6y OE8VdcrHVOXFXO3Yt/nzoJbPe1w7Axhyv7WVMWwYMc/nWEvihcFRwxLoNi4uGwCO3LCA n97pANBnISncCFOXH7JIIyuxVHxhl4+/VZUS+N75iN27wUUgR+ZE4FhGNYfNQGJ+FkQe On+PkEVe2Y/0heRMrEkFGHTUl3QgJqfM9yikCbYko1rScbo+iLOJurYFVp0jgtebLuDN ss+iQJ/c63K8QoZqzdpg7U3GQRbby4HCsuZWubF2KH/aNPQleC27in6mc1tPM9CLCNlx KKwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=42ZwQ2L8M5MJa5KRQ4XrIfZwc9ii86LEtw7sm/nefwc=; b=H9qaiblx2T9htmraKx2dkP2t3HYF7ofhwpmGWIdwchyDBGWgRIIMBfOtD+OH4nMhyU D/N/37RcB8XvCjF8rLn7rTBwK2MaIuftLOH9ApGArkAt9OWoLCZOjrg7JsUz8aMUbVXO AcFN2xABDLEmpxyY4/tYiutyC0oAZrWXL6Sa++VmZXBYIiOsEtG2Lh3vaKx2DwefyxvF z9MDlMbdga28w7u5OGpctVqMu78Apt3QLA3B5ZipVCnkh2X54S82kG/+o7E4RLb7m7ac 85Miu28CxR3rghKZPejGbvYljJVUnjf3RN/qkPlo9bMvMAF/FSoWbHU2PsAuUkLnWzCO FfbA== X-Gm-Message-State: APjAAAX/mnqTR+VzFKl7yWdG5Y7TLRSAJ57QjevLAAxLjhgIYCLYcwsH AQnw3BSmCScqGa7D0MSoR9WxQIvbdlkAbSwJqoHvhQ== X-Received: by 2002:a2e:42c9:: with SMTP id h70mr1538711ljf.88.1570005071461; Wed, 02 Oct 2019 01:31:11 -0700 (PDT) MIME-Version: 1.0 References: <1568878421-12301-1-git-send-email-vincent.guittot@linaro.org> <1568878421-12301-5-git-send-email-vincent.guittot@linaro.org> In-Reply-To: From: Vincent Guittot Date: Wed, 2 Oct 2019 10:30:59 +0200 Message-ID: Subject: Re: [PATCH v3 04/10] sched/fair: rework load_balance To: Valentin Schneider Cc: linux-kernel , Ingo Molnar , Peter Zijlstra , Phil Auld , Srikar Dronamraju , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Hillf Danton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 1 Oct 2019 at 19:47, Valentin Schneider wrote: > > On 19/09/2019 08:33, Vincent Guittot wrote: > > [...] > > > @@ -8283,69 +8363,133 @@ static inline void update_sd_lb_stats(struct lb_env *env, struct sd_lb_stats *sd > > */ > > static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *sds) > > { > > - unsigned long max_pull, load_above_capacity = ~0UL; > > struct sg_lb_stats *local, *busiest; > > > > local = &sds->local_stat; > > busiest = &sds->busiest_stat; > > > > - if (busiest->group_asym_packing) { > > + if (busiest->group_type == group_misfit_task) { > > + /* Set imbalance to allow misfit task to be balanced. */ > > + env->balance_type = migrate_misfit; > > + env->imbalance = busiest->group_misfit_task_load; > > + return; > > + } > > + > > + if (busiest->group_type == group_asym_packing) { > > + /* > > + * In case of asym capacity, we will try to migrate all load to > > + * the preferred CPU. > > + */ > > + env->balance_type = migrate_load; > > env->imbalance = busiest->group_load; > > return; > > } > > > > + if (busiest->group_type == group_imbalanced) { > > + /* > > + * In the group_imb case we cannot rely on group-wide averages > > + * to ensure CPU-load equilibrium, try to move any task to fix > > + * the imbalance. The next load balance will take care of > > + * balancing back the system. > > + */ > > + env->balance_type = migrate_task; > > + env->imbalance = 1; > > + return; > > + } > > + > > /* > > - * Avg load of busiest sg can be less and avg load of local sg can > > - * be greater than avg load across all sgs of sd because avg load > > - * factors in sg capacity and sgs with smaller group_type are > > - * skipped when updating the busiest sg: > > + * Try to use spare capacity of local group without overloading it or > > + * emptying busiest > > */ > > - if (busiest->group_type != group_misfit_task && > > - (busiest->avg_load <= sds->avg_load || > > - local->avg_load >= sds->avg_load)) { > > - env->imbalance = 0; > > + if (local->group_type == group_has_spare) { > > + if (busiest->group_type > group_fully_busy) { > > + /* > > + * If busiest is overloaded, try to fill spare > > + * capacity. This might end up creating spare capacity > > + * in busiest or busiest still being overloaded but > > + * there is no simple way to directly compute the > > + * amount of load to migrate in order to balance the > > + * system. > > + */ > > + env->balance_type = migrate_util; > > + env->imbalance = max(local->group_capacity, local->group_util) - > > + local->group_util; > > + return; > > + } > > + > > + if (busiest->group_weight == 1 || sds->prefer_sibling) { > > + /* > > + * When prefer sibling, evenly spread running tasks on > > + * groups. > > + */ > > + env->balance_type = migrate_task; > > + env->imbalance = (busiest->sum_h_nr_running - local->sum_h_nr_running) >> 1; > > Isn't that one somewhat risky? > > Say both groups are classified group_has_spare and we do prefer_sibling. > We'd select busiest as the one with the maximum number of busy CPUs, but it > could be so that busiest.sum_h_nr_running < local.sum_h_nr_running (because > pinned tasks or wakeup failed to properly spread stuff). > > The thing should be unsigned so at least we save ourselves from right > shifting a negative value, but we still end up with a gygornous imbalance > (which we then store into env.imbalance which *is* signed... Urgh). so it's not clear what happen with a right shift on negative signed value and this seems to be compiler dependent so even max_t(long, 0, (local->idle_cpus - busiest->idle_cpus) >> 1) might be wrong I'm going to update it > > [...]