Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1188771iol; Fri, 10 Jun 2022 02:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDzHSvh2kHQ97IcJQNJhIChR6D3+ed//jSqY9CqSGnaX3t1wBll5aMSF49b8KEzVBriNdA X-Received: by 2002:a05:6402:40c9:b0:42d:da4a:9a72 with SMTP id z9-20020a05640240c900b0042dda4a9a72mr50452346edb.380.1654852065442; Fri, 10 Jun 2022 02:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654852065; cv=none; d=google.com; s=arc-20160816; b=SnVg4iSGvuNT44uCjvn15xde2bpSFCWvEEGMe6M2K+rszPLJEXSufzeVCSJvx53m1d FVPD8M45wX2edJcxv7zeJvcCQUxtQse4peeC15waob8SjHGZvjYhQojTYEbYaRhNn11Z nBhAfxdC6JJUiLxL7i2BzwTKPb7IgSXb8G1j5Nb4OCh7ddcPfFZPF5Qj2l0dLUOaVpGg emNlBQVs46P+1pBbHyIuSH+0SyEhymAG2ZPI/ANN4//RouxNiHN7ywZjhp1xqpJ97qG8 7ni/GXjV2Zn9BMDSNIK41X1Bjp7p2vG+/I4Bn7tSEzpCcdwJTRrEwZTM3PjAREdbyICn myBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7bdR1YHa7YgmZUPKy2qQkHy7vQLxG7NreiHak78/QtQ=; b=Z+69FZg0EwxHdE5+OD7dbaa2GBcb7ENhxiSEStrXTpIm/iGGRsr9VrEfdRbb1bmZ+4 GXxUatBaccTxHtFssCuVvuORSEW+g6LLyjs23x98bUhiGC1cJrnEci0xTQ4RExfXyO/3 yUmBJwF5XenoJF/L27M4D8yolCX6S9RE1HtuVZVBmPTCcTL9mMdYqMjpNT4OS4n5J93e cyfzBH39Oxzw7NP45ECGpKiLvVWmJ5mwYVCSjvJMkKr4PLHyJgDupRkdGdDs2ekzZb2C Prq+xV9jJUfz8jmfkBCZt6sdNuip/cVRRPJZ1C4AEv9dYjRxcVhGN5NJeBZlRahZgb1p mp3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QLCRkdqX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a170906414400b006ff1e01c729si10889265ejk.1009.2022.06.10.02.07.18; Fri, 10 Jun 2022 02:07:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QLCRkdqX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1347164AbiFJIKn (ORCPT + 99 others); Fri, 10 Jun 2022 04:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243411AbiFJIKl (ORCPT ); Fri, 10 Jun 2022 04:10:41 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE4921E0EF for ; Fri, 10 Jun 2022 01:10:38 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id m14so2244895ybm.2 for ; Fri, 10 Jun 2022 01:10:38 -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=7bdR1YHa7YgmZUPKy2qQkHy7vQLxG7NreiHak78/QtQ=; b=QLCRkdqX5BuO5jjWVwqHoDAbZSlWUMtDF2QsKc+A92RKb2PVtFbOk6uKHrKtSZqHNS +aXbr5c5hzZUgiGH863uiQ/c6qMPZubPbIPWbFIp5DHvL+vefBPJ0x9MCaWF+QmIvERF Ssr6PMxqChyARcq7EE/uG3eyHTO/8glHxS5x9XIYN6sKyOl0QimoPrgptp5QL+T7PR9a EY+QNF5hOX2awdkDeAGprTxkE6LXsiBIu+lFEB/QY8lABm8DeFQMZ2bh4cTM56z8E8Um MldM9tYuVNi8FqSfqzTAVSxFETKxW9D6xvvhO21jEqVfyrq61uG4+lk2jfISh0uIbTNP 4ljw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7bdR1YHa7YgmZUPKy2qQkHy7vQLxG7NreiHak78/QtQ=; b=tQ6RBuNhUR5DLE7XX7EPt3YHeb46jZJynQSv28s9LXE4ICo1bpf8k0FSLDdnJ8vxYT YyADXhBDbLyiB82Q6bEcI9hV9pM27ZM75wyUokTy0Rx1Q/rv5BfdsjfQs3wVVRSA8MOK 9CCNsBWxVgwu0bRyaj5S8aS7h+4pFANgUCKsscGbTqe7isSJA/W6Maxfs2q+dUx2zA25 UFWX4T3rafbH5EpyiOni73ZJ7RoEZuY90+hLscNwDO0d+FK4sSeAbk1ZbuSZkpoOAQKR DyDV+rGYBH/vRSa+p7qcvTBO7Ocehvm5hHKLCCFXi7HYd6qq+yJwZWpOEIHIYfhUjELx w0cg== X-Gm-Message-State: AOAM533Z9pjsOi1XcqQxv47iGiqC7cWSrD44mn58krHX6ivVXqaHLmoz bQW1Unh3R+A19cnM4sx0391cimkWnVHpZi7kAc3Gcg== X-Received: by 2002:a25:24c1:0:b0:663:f537:2dc2 with SMTP id k184-20020a2524c1000000b00663f5372dc2mr13426648ybk.241.1654848637915; Fri, 10 Jun 2022 01:10:37 -0700 (PDT) MIME-Version: 1.0 References: <20220609025515.2086253-1-joshdon@google.com> In-Reply-To: From: Vincent Guittot Date: Fri, 10 Jun 2022 10:10:25 +0200 Message-ID: Subject: Re: [PATCH] sched: allow newidle balancing to bail out of load_balance To: Josh Don Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 9 Jun 2022 at 21:40, Josh Don wrote: > > Thanks Vincent, > > On Thu, Jun 9, 2022 at 6:42 AM Vincent Guittot > wrote: > > > > On Thu, 9 Jun 2022 at 04:55, Josh Don wrote: > > > > > > While doing newidle load balancing, it is possible for new tasks to > > > arrive, such as with pending wakeups. newidle_balance() already accounts > > > for this by exiting the sched_domain load_balance() iteration if it > > > detects these cases. This is very important for minimizing wakeup > > > latency. > > > > > > However, if we are already in load_balance(), we may stay there for a > > > while before returning back to newidle_balance(). This is most > > > exacerbated if we enter a 'goto redo' loop in the LBF_ALL_PINNED case. A > > > very straightforward workaround to this is to adjust should_we_balance() > > > to bail out if we're doing a CPU_NEWLY_IDLE balance and new tasks are > > > detected. > > > > This one is close to the other tests and I wonder if it should be > > better placed before taking the busiest rq lock and detaching some > > tasks. > > > > Beside your use case where all other threads can't move in local cpu > > and load_balance() loops and clears other cpus, most of the time is > > probably spent in fbg() and fbq() so there are more chance that a task > > woke in this meantime and I imagine that it becomes useless to take > > lock and move tasks from another cpu if the local cpu is no more newly > > idle. > > > > Have you tried other places in load_balance() and does this one > > provide the lowest wakeup latency ? > > > > That being said, the current patch makes sense. > > I tested with another check after fbg/fbq and there wasn't any > noticeable improvement to observed wakeup latency (not totally > unexpected, since it only helps for wakeups that come during fbg/fbq). ok. so IIUC the wakeup has already happened when we start load_balance() in your case so the additional test is useless in your case > However, I don't think there's any harm in having that extra check in > the CPU_NEWLY_IDLE case; might as well avoid bouncing the rq lock if > we can. fbq+fbg are together taking ~3-4us per iteration in my repro. > > If there are no objections I can send a v2 with the added delta: Would be good to get figures that show some benefits of this additional check for some benchmarks So I think that we can stay with your current proposal for now > > @@ -9906,6 +9906,16 @@ static int load_balance(int this_cpu, struct rq *this_rq, > goto out_balanced; > } > > + /* > + * fbg/fbq can take a while. In the newly idle case, recheck whether > + * we should continue with balancing, since it is possible that a > + * task woke up in the interim. > + */ > + if (env.idle == CPU_NEWLY_IDLE && !should_we_balance(&env)) { > + *continue_balancing = 0; > + goto out_balanced; > + } > + > BUG_ON(busiest == env.dst_rq); > > schedstat_add(sd->lb_imbalance[idle], env.imbalance);