Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1660211iol; Fri, 10 Jun 2022 12:02:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZeoaOIM9z94lY8KlHG5AtXTlVEomHmBf/k7tI5JIIuD3eTIwXH9bkX5Jah5cVdEZ6aAkz X-Received: by 2002:a65:6e0b:0:b0:3aa:6146:15a8 with SMTP id bd11-20020a656e0b000000b003aa614615a8mr40289704pgb.181.1654887722913; Fri, 10 Jun 2022 12:02:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654887722; cv=none; d=google.com; s=arc-20160816; b=RH9QioUCjSgR5Xhs6bQPn+6BIFN4yKZ3V1E5vvAVZ1SF442SUpilGK7Up3clKSvSBA 1t/mFx7icAAZt0A6oF+SR/2Ehzi5RZfw9MDwQIx0B6mBGIZQOwWqHOEJNsl15bqsBYbQ fP964I/b7zu+vvvU47LYsFUbePMSvb2Jxdny/8BUaTmWlZsyDihGJ5nQfWWhzeNE5f42 envFsl4cPOdjPAUXzOqZ9QEtrp26c9FbZBISvtO4K8IS6ze2N1KjAHjveoAMWbt9ezRK jVKdWDPs7/Xi60AoJQh3c6cRlsLf8qHyJDHcptEAMAODZKhyPC1Wb01cELYJoss2wAJr m7Iw== 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=QckDBPSwpnz2yiVzfF53cZ+SpuqEwRglZc9JnM2/2zs=; b=oUAy7f0osS7c8IuBYpp7H87vjbNLLe/Bh4sbemmF8YlkP9RsVYjdaV/D1aEn57VBGy r7pTlsPt39r9PM6ykQ6sflcyZwCQ6uApAotRMW6mMSgamf3zqPm9MvYonCBcUSTQKora uN0A7iXv9VkmU6uxf8xRiI5Zu0wa9LjKUc9RUETbo7UwKqbTrRpMPQJT72P76CuroSzJ xhuM6JRCY4A1t0NH/de/Bihocgo3q7iIxqMQFoYmROLUZRL3ppb41C86iyD2Fe26O+mV nuw7tPTYTrugZyJNfFp6VJVndVjSUWYqStC89jAcaR67bDh0XvINPLla983zpO0U2GBx oPhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AdSNAkn6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a056a000ac900b005206b82a13esi1986645pfl.127.2022.06.10.12.01.49; Fri, 10 Jun 2022 12:02:02 -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=@google.com header.s=20210112 header.b=AdSNAkn6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348077AbiFJSq0 (ORCPT + 99 others); Fri, 10 Jun 2022 14:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347817AbiFJSqY (ORCPT ); Fri, 10 Jun 2022 14:46:24 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34FA8277FA0 for ; Fri, 10 Jun 2022 11:46:23 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id t32so64874ybt.12 for ; Fri, 10 Jun 2022 11:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QckDBPSwpnz2yiVzfF53cZ+SpuqEwRglZc9JnM2/2zs=; b=AdSNAkn6KcLWIHl/b2zcbW+/xKnsmsR4YJfiYh2v6WHCatiIEzbOPSkTWjO6MOqbDO xcKIYk+tECJFxtnueGS9wfy/F40V/M+wIGzC9GDaSOZDfGHPdEqvVQcpfqpHL+rKpccn SiQve+NdZnR3CyBJeFNep3L57WHkLpl5NIMdXDvJsPqJATW6tWg3pABkwgMUUt5H9mJw hLgvAJ18nZ3Zt/su2UdEqWCnmhbRvBZpqrVuFX4NQgvqG3X7JCN376OSOMOVxm67IcLs RckGnl8hDripRYXYWultMaM4HDTeZPTkrnVjJUH/j7z2Bzxi+DArpJ1A4y/pvytIbbal fE4Q== 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=QckDBPSwpnz2yiVzfF53cZ+SpuqEwRglZc9JnM2/2zs=; b=J1vL3uMZTNPG/xqI5HGBbtP8fmQhp4rC/XeUmELVsbcnmkJaSfkxRZaczfpsog7yY9 nFvwnC33HPZIe4n/+AOxjIKsT/7IAsT2cwuWSeM6cGaQqiXwjgX/YKZoCwZG2tfQFU8K axUj6n6eEaT5hR7hKcnw//A33eWLepFlYyiyxmbG+o7+JRcJAHBLeYUrGXoBVpB8bLUh qc7JIRUgrJ2jyuhVwQDlsanSlLEYiK4p897cWvR6Mx22EotHhMNcdQneQP5fnqpUY55x iZf1eRSW0WfeaWhGukNBkyQ3Rz7DmWeOHi4kVuaSBw1vc+KX+Oxpqewx9QybktF+zjZS Q78w== X-Gm-Message-State: AOAM530jfPyAuSuFs5b18fY9oMFFFJqGn5pETP8vJXpP0O78dwjvgaiN 8WEtPQ9KSsO9gfrfLThuai40Jb0Re5iXUmmIquq5SQ== X-Received: by 2002:a25:cb8a:0:b0:65c:a718:475c with SMTP id b132-20020a25cb8a000000b0065ca718475cmr47863832ybg.352.1654886781855; Fri, 10 Jun 2022 11:46:21 -0700 (PDT) MIME-Version: 1.0 References: <20220609025515.2086253-1-joshdon@google.com> In-Reply-To: From: Josh Don Date: Fri, 10 Jun 2022 11:46:10 -0700 Message-ID: Subject: Re: [PATCH] sched: allow newidle balancing to bail out of load_balance To: Vincent Guittot 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Jun 10, 2022 at 1:10 AM Vincent Guittot wrote: > > 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 Not necessarily; the wakeup could also happen while we're in the ALL_PINNED redo loop (this lasts ~100us), but the added check doesn't meaningfully affect latency for my specific repro. > > 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 Sounds good, thanks for taking a look! > > > > @@ -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);