Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3171225pxb; Tue, 20 Apr 2021 02:07:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlIFDbWrrsIK4KL0BgfVtwjk/KDBncrOiu5TSdriCulQv3QB8w/utKAB75lZLEU3PS/4mP X-Received: by 2002:a17:90a:540c:: with SMTP id z12mr3876997pjh.42.1618909624806; Tue, 20 Apr 2021 02:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618909624; cv=none; d=google.com; s=arc-20160816; b=hjf4xbzFpuYOzwC5A4Au9CLuprS5PE8QAYPvnV0Y5nV8LgChO5LQA6U0QNS3A08sgF G0GW7TEP51ShlBSC9KZNLhwcAWysSm3yTY3/0z4+6QE2VlHeo9KhQw2jNbi+gaq27emI zv+tMsn1ctJe41hdLFf0kILBD9beWuAA3fxunRpgZ6OG4lrxoCHItbFF/d3kxjrAMSP7 eCeFI1ZlOrVx2vOSygRRXnqE0bNa0foqppNaGM3It1oxWYPqdMqYGYxkZ3Kk/1EbyLUX qjN3ud7Co7b4V5Cs/3r36smR7wv04enWfdqw56zNK2nwz4u+N1mwltRsL9tCKwSm9uiJ sDBA== 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=dTfebTCdkJsfaBHlBAbb2gOwkmWwTivYnNWsMmybnGM=; b=eGdd8E/Lslrzz3Jt4x2dqOpzVA5Z8hlDbeyRvpMXelhvWBo6pAJN70cfLhHIKcXULu L3zzcHEHRtIO1Sr9GG7E9aRDxMPv3nZgdhk1J9wwfMVsLMBvd8b8k2MVN5JkvFU01GHX uS0j016UxM5GHtsR3dyZ+FzWxfBCVvtJXq44P6iJ276TpzTJPa854f2b644rSn4dTpuj KDg4nAvshHs/TYbvzgnQNzhPF/p1XVu3b8uBUlf1D1W5wVSLax39WkfQGczlf/M/iShG 1WfbL6byBo6DrkDeyeFXp6butBiLDlaF/58QrM2S8+VKIaAOGM0zkHcgXBl34VS43r8a P7DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MkajPfAV; 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 102si21647946pla.240.2021.04.20.02.06.52; Tue, 20 Apr 2021 02:07:04 -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=MkajPfAV; 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 S231226AbhDTJGt (ORCPT + 99 others); Tue, 20 Apr 2021 05:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbhDTJFn (ORCPT ); Tue, 20 Apr 2021 05:05:43 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA6BC06174A for ; Tue, 20 Apr 2021 02:05:10 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id u20so42642148lja.13 for ; Tue, 20 Apr 2021 02:05:10 -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=dTfebTCdkJsfaBHlBAbb2gOwkmWwTivYnNWsMmybnGM=; b=MkajPfAVIUfmpmnjtH4b+lxj2mrll/yJ9ptk+r9D4cMt49AVd+qutswdDNXlznclvQ gNtE/CRkOsHD5RcmLlLudL1/PFEzEa1al1visZLB8G/hUIA7ZifkQAX2tK+sXGzfu+UU XubcVEOGwJHWxRo5/pY56REnMSZoUVM7DIp9aU8puRtwHQDuH9flCAuhGvL+pDOSZYHh PuYDeevNf7uBW30q1osEZdIhDOdkEAA0v6S/sV5IuE0XROgyf160ZHJxVYzLfXHp8B1m W0OYS6DE9PydaE0Tyf+LDLooYFexWvbthdtswYNy49p+FdNthXn2ftU9kApYAROuNBEs X+gg== 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=dTfebTCdkJsfaBHlBAbb2gOwkmWwTivYnNWsMmybnGM=; b=QA6ZxzxUbDqubwCXOFRNBMUGKy3aq3IqgeEGZnThkbAdyjTvKRXKDz88Q8TgqxaY9c pQiaDgsS5T8zVp7cgzbDhyX1ucBtGkoHEt8OiLuLKmT03uTpNjVPZpFeavX5pSuEzyqZ 6KT4u4rwZs50ESxCFIWD9MOe9JBVo8GDVeEP/Ttq0J1cV2CEfR/FebEsIsWxg2m3+4T8 K+X9E7xFzzJRrExhTQj4FwdOI8VDeEd9zrrPXYqy4OYEvpiKhpSmoyeKS4leY21+NpVA wagEjC4qMLJ31o/FSSUED8i4zDCQBcfZ/0mKda4CpSpx74w3L+EzNR9fsixSU7N7prtR NBug== X-Gm-Message-State: AOAM533QbhGwRHGSYfXH5B//UuAy3R2aNzjfxLFE+hMRGUwHLiRbBIZm r3gkjNl1rmjM+dz0kue0jTIp3AA4gVkJWoDpDp85KQ== X-Received: by 2002:a05:651c:335:: with SMTP id b21mr792258ljp.299.1618909508950; Tue, 20 Apr 2021 02:05:08 -0700 (PDT) MIME-Version: 1.0 References: <20210419125134.5cab12ea@imladris.surriel.com> In-Reply-To: <20210419125134.5cab12ea@imladris.surriel.com> From: Vincent Guittot Date: Tue, 20 Apr 2021 11:04:57 +0200 Message-ID: Subject: Re: [PATCH v2] 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 , Valentin Schneider 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 18:51, 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 > --- > v2: > - fix !SMP build error and prev-not-CFS case by moving check into newidle_balance > - fix formatting of if condition > - audit newidle_balance return value use to make sure we get that right > - reset idle_stamp when breaking out of the loop due to ->ttwu_pending > > kernel/sched/fair.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 69680158963f..5e26f013e182 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -10594,6 +10594,14 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) > u64 curr_cost = 0; > > update_misfit_status(NULL, this_rq); > + > + /* > + * There is a task waiting to run. No need to search for one. > + * Return 0; the task will be enqueued when switching to idle. > + */ > + if (this_rq->ttwu_pending) > + return 0; > + > /* > * We must set idle_stamp _before_ calling idle_balance(), such that we > * measure the duration of idle_balance() as idle time. > @@ -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(); > @@ -10688,7 +10697,7 @@ static int newidle_balance(struct rq *this_rq, struct rq_flags *rf) > if (this_rq->nr_running != this_rq->cfs.h_nr_running) > pulled_task = -1; > > - if (pulled_task) > + if (pulled_task || this_rq->ttwu_pending) This needs at least a comment to explain why we must clear this_rq->idle_stamp when this_rq->ttwu_pending is set whereas it is also done during sched_ttwu_pending() > this_rq->idle_stamp = 0; > > rq_repin_lock(this_rq, rf); > -- > 2.25.4 > >