Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp17993ybz; Tue, 21 Apr 2020 03:53:42 -0700 (PDT) X-Google-Smtp-Source: APiQypJZgbYueYAfSZoMl7qMYshTg/T5jKrfWLL2afqjN4VhTHkI0+TDB3oFkDiuim6ZF53FecG9 X-Received: by 2002:a17:906:6856:: with SMTP id a22mr16531252ejs.115.1587466422496; Tue, 21 Apr 2020 03:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587466422; cv=none; d=google.com; s=arc-20160816; b=HxIeOtuRjHQ5m3bxFgmRmaYtNemJOsaHDx0e7LXNqg1d+O19WeiPCDgFhvvHM945Li WYjon+otyPcCxEXzv2cGXf8qV3KYg/VmKs3mVGArNRTySRiO0mDoBkCWQkgZ9/KcaUiB 0JsvT3Rb/vYF2b8eFdfnamqnABZQaUCA/QQJt5RpV+8nzy5QeKYA0ainBNYcnwBJ1R2b BadelBr4cn8uWWqFABKzGeQ18RsCm7I5xX1ndu4Y14RpU5V8SVPHiVy9NI5HQ/KKxR53 AExQ/COUkHqN9hpw0Z0DRgz5MWAivYG9WTVGhLKeJgXDaWT2XuORxf9j44il4sEGXRRG +VSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=1Kzf3+FgAqpoBxR2TEse42mk+/ZA5DDGuxRiDPo1VUU=; b=h0n7hZe1T+cYPAHyMXw4DtXO3pkCNiGSXFlNRfUP9mjBHcXtrrBkDMrFINUhmGKjzg ceTDGIDFot2Ww0CYXjM8jc8KOOP21QKHhVQrMa7VwN4TWBIIrqR0Z/KY5gbfnZy3EYjH pgiKGB79brr48Ned+q9coxXMO4in6cqz+EmHXBIDoWEJT5XLNInWCr3kZmgkdIcwo7nI eayfDocZq+bCaXeccJz3RKp0kl+xk5QJVRcbKeFdDhSOv0LSwfa0lKvR5BwWLszhe4kQ UiSChvfcJ+Y6eR53n6gqbHtWca5ttNzbChYUitWkjab/7NNc73xE+LEggY4gI5lOccDe llEA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si1336391ejt.267.2020.04.21.03.53.19; Tue, 21 Apr 2020 03:53:42 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728592AbgDUKuS (ORCPT + 99 others); Tue, 21 Apr 2020 06:50:18 -0400 Received: from mga07.intel.com ([134.134.136.100]:22658 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726741AbgDUKuR (ORCPT ); Tue, 21 Apr 2020 06:50:17 -0400 IronPort-SDR: Xmb6aiz7XMAis+pfDYhD1qcJwwlz1UKwY3pOH/ewBfmV6AWGVE3ZEhW4lJLgTvEqgPVFXJgl4X W5mdD/ptvGHw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 03:50:17 -0700 IronPort-SDR: 1/7uHZJs+ksuoPYOpbP3jEsnt+fB9q2u4GE7YI0HccD9ma8xvDqB98w96Lefg3XXDrj5rXutF8 w+FVaCZlqTSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,410,1580803200"; d="scan'208";a="247146052" Received: from chenyu-office.sh.intel.com ([10.239.158.173]) by fmsmga008.fm.intel.com with ESMTP; 21 Apr 2020 03:50:14 -0700 From: Chen Yu To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Vincent Guittot , Steven Rostedt , Valentin Schneider , Ingo Molnar , Juri Lelli , Dietmar Eggemann , Mel Gorman , Ben Segall , Chen Yu Subject: [PATCH 2/2][v3] sched: Extract the task putting code from pick_next_task() Date: Tue, 21 Apr 2020 18:50:43 +0800 Message-Id: <5a99860cf66293db58a397d6248bcb2eee326776.1587464698.git.yu.c.chen@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a new function put_prev_task_balance() to do the balance when necessary, and then put previous task back to the run queue. This function is extracted from pick_next_task() to prepare for future usage by other type of task picking logic. No functional change. Suggested-by: Peter Zijlstra Reviewed-by: Valentin Schneider Signed-off-by: Chen Yu --- v3: According to Steven's suggestion, fix the comment to change put_next_task() to put_prev_task() Rename finish_prev_task() to put_prev_task_balance() as this reflects what we do before picking a new task. Per Valentin's suggestion, put the declaration of struct sched_class within the ifdef, given it isn't used outside of it. --- kernel/sched/core.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3a61a3b8eaa9..c9d7880f6bf2 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3904,6 +3904,28 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt) schedstat_inc(this_rq()->sched_count); } +static void put_prev_task_balance(struct rq *rq, struct task_struct *prev, + struct rq_flags *rf) +{ +#ifdef CONFIG_SMP + const struct sched_class *class; + /* + * We must do the balancing pass before put_prev_task(), such + * that when we release the rq->lock the task is in the same + * state as before we took rq->lock. + * + * We can terminate the balance pass as soon as we know there is + * a runnable task of @class priority or higher. + */ + for_class_range(class, prev->sched_class, &idle_sched_class) { + if (class->balance(rq, prev, rf)) + break; + } +#endif + + put_prev_task(rq, prev); +} + /* * Pick up the highest-prio task: */ @@ -3937,22 +3959,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) } restart: -#ifdef CONFIG_SMP - /* - * We must do the balancing pass before put_next_task(), such - * that when we release the rq->lock the task is in the same - * state as before we took rq->lock. - * - * We can terminate the balance pass as soon as we know there is - * a runnable task of @class priority or higher. - */ - for_class_range(class, prev->sched_class, &idle_sched_class) { - if (class->balance(rq, prev, rf)) - break; - } -#endif - - put_prev_task(rq, prev); + put_prev_task_balance(rq, prev, rf); for_each_class(class) { p = class->pick_next_task(rq); -- 2.17.1