Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2409541pxb; Mon, 19 Apr 2021 05:13:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJvuiGE+SE22xYNs/ieWlekW+IUegVU2MMtULLUMO2IRInGlPXOHUNvOQoNwxBxTzZgzUD X-Received: by 2002:a17:906:170d:: with SMTP id c13mr21260581eje.491.1618834418510; Mon, 19 Apr 2021 05:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618834418; cv=none; d=google.com; s=arc-20160816; b=L/x1W2glVx7vfFxGFveqz4h9OFncT7zIxAcWJZG8JyMU4yHKTpoyxhrpHdhCwIo4p0 OQzvP2ZqcSV5YWRicsGqy+q6SRux09sHBwNQlDvjO/bxo4fIPAU7AK/kGFlFxz6YCHTN F0AnWGpVnX68WLuAwUTXxiJVTqojqxpmCpIvjUdQtJDRtD6cjbh0Q7zA6bWbh6YqPIul lvP2vwaLzJY9hOTrk424TT6S9JG9o4NNhQuyy7LFcANpJy4oxdtcok4PYgQ8w97ksRjL vl99lO7RwgfDgKUv4y2EI5bRlNHkZU4Hh4x/wzxXTf7tXb8w1nss2AItsVpN556VZOei d84g== 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=Jk8cUESaS2PhVsxT1qv4OEiuADnSJdzp/1nAVuneZ4w=; b=TKAPcTll2P58gdZEpuSx+bb5mggbzeTv7orx0gQyWyUo+4sov1xr61muY7x4wXszkh TRPU1HmVyCM7QXrOmrv7BtTA3ns1qemP0e5F4OtO8yJP9i95vFkMTHB2TBAOkJCZQcIn sAOxUf5YgCefHCnMc3ODPzrM1ZQGYxALqyqEPVtZV1Ofz9vbVhpp8IB4/j8vSHSAHfud 7yux6tKhRuxC8oTGDsV7DNAfq3YWZoWcMPAIr6tKm7n3O8vOTkkCJ5JiLRbEK04w6jFc vwm+msfRuUE9shWsmj0DOIY7SzOCIAtXCkHVeQfkZUuZnV9A8f79L+wQAoUlYyulRxV4 IFcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LRXX0Ypm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id cr12si11983046ejc.735.2021.04.19.05.13.11; Mon, 19 Apr 2021 05:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LRXX0Ypm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238190AbhDSMMq (ORCPT + 99 others); Mon, 19 Apr 2021 08:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237650AbhDSMMo (ORCPT ); Mon, 19 Apr 2021 08:12:44 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F847C06174A for ; Mon, 19 Apr 2021 05:12:14 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id x19so25153744lfa.2 for ; Mon, 19 Apr 2021 05:12:14 -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=Jk8cUESaS2PhVsxT1qv4OEiuADnSJdzp/1nAVuneZ4w=; b=LRXX0Ypm6HKXqidAnD3jouMvuRBI7OADh9UGKK2esvIoz/t844O61CkGySvyMfqsPF CebNiHk0PeVAHBhD+nyRQ0WSIsqTbauQ2yyWmCl6c63YAX6tf5s2HJNLu8QoxG0oIZPD BNXT2rnb1OxXp/xh5JwaKJmJUM9Fjz3C8yyDt2xwfaquNfK2bT8esFX0yKobMiG2at4m 4AxCN4JeCoTCakbHzdFFXb7v8ZjATPlSGMteo8vNy/tl4us6k1TrOxhvyNB4Ewt4TAH6 jHJQ/W/Po9Cgoa82GAr6xqgK5XkRsXO9qulQrHZzjfHCeLbHNW7PFfWpDGCZ6ZtJmky0 ym0A== 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=Jk8cUESaS2PhVsxT1qv4OEiuADnSJdzp/1nAVuneZ4w=; b=idqSSEo9DlWDaI28INH5fONL3t8vnFR0FRUusVJ078JpWggn5ooP//BB74kilNWUXk 4eKrSe0Gxg6oGEiZxRpRzmBBc+JVnlgPRsVh3Bu0ZmkPAX+MQaI8+CJvU1AZGY1wlkP0 1DZI4GqIvnXZa9cIG+qy80dx1xNAKBTLOFNXPWC6Ehs10Wj4vO3tnl66OydNGMlijyY3 WHTUXZQTqmXbzDg6BudTfhuFfOAdbMHXbt5h9g4dO84duIZBBlYBmdp97uOACYzpHUXh 2HryiepB+1+NI/gzfljE0BiA9DmD0bfgywz+TccZca8pNX+7V3uZLuKgnkUffHZwz0IV jFpw== X-Gm-Message-State: AOAM533iL/j0uvKglq61ORwwmGg+NFtMkIEhshuds5E3DazlmK3yjKUo Okc7IHpJQ/TfXa5Whqoj5Gj9SIy7P9RyPMaIzPkIyQ== X-Received: by 2002:a19:4082:: with SMTP id n124mr12211144lfa.154.1618834332805; Mon, 19 Apr 2021 05:12:12 -0700 (PDT) MIME-Version: 1.0 References: <20210418221751.7edfc03b@imladris.surriel.com> In-Reply-To: <20210418221751.7edfc03b@imladris.surriel.com> From: Vincent Guittot Date: Mon, 19 Apr 2021 14:12:01 +0200 Message-ID: Subject: Re: [PATCH] sched,fair: skip newidle_balance if a wakeup is pending To: Rik van Riel Cc: linux-kernel , Kernel Team , Peter Zijlstra , Ingo Molnar , Dietmar Eggemann , Mel Gorman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Apr 2021 at 04:18, Rik van Riel wrote: > > The try_to_wake_up function has an optimization where it can queue > a task for wakeup on its previous CPU, if the task is still in the > middle of going to sleep inside schedule(). > > Once schedule() re-enables IRQs, the task will be woken up with an > IPI, and placed back on the runqueue. > > If we have such a wakeup pending, there is no need to search other > CPUs for runnable tasks. Just skip (or bail out early from) newidle > balancing, and run the just woken up task. > > For a memcache like workload test, this reduces total CPU use by > about 2%, proportionally split between user and system time, > and p99 and p95 application response time by 2-3% on average. > The schedstats run_delay number shows a similar improvement. > > Signed-off-by: Rik van Riel > --- > kernel/sched/fair.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 69680158963f..19a92c48939f 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7163,6 +7163,14 @@ done: __maybe_unused; > if (!rf) > return NULL; > > + /* > + * We have a woken up task pending here. No need to search for ones > + * elsewhere. This task will be enqueued the moment we unblock irqs > + * upon exiting the scheduler. > + */ > + if (rq->ttwu_pending) > + return NULL; Would it be better to put this check at the beg of newidle_balance() ? If prev is not a cfs task, we never reach this point but instead use the path: class->balance => balance_fair => newidle_balance and we will not check for rq->ttwu_pending > + > new_tasks = newidle_balance(rq, rf); > > /* > @@ -10661,7 +10669,8 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) > * Stop searching for tasks to pull if there are > * now runnable tasks on this rq. > */ > - if (pulled_task || this_rq->nr_running > 0) > + if (pulled_task || this_rq->nr_running > 0 || > + this_rq->ttwu_pending) > break; > } > rcu_read_unlock(); > -- > 2.25.4 > >