Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6678573ybh; Thu, 8 Aug 2019 04:01:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzn+bubqm2yos1wPnnGU8vEuDePEsYWm3U2YkIg5RjlqvsJzFM4TGJXD6yR35AC73vgx8F3 X-Received: by 2002:a63:f941:: with SMTP id q1mr12270869pgk.350.1565262095827; Thu, 08 Aug 2019 04:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565262095; cv=none; d=google.com; s=arc-20160816; b=YQMiTCT6FBCdwHg8xSj7h+OqE2TtQIJqbkDpim2jhjiEHc770ukEVJZbVQcrp4tfCS D/kTwAjTYWp1rmZE0DbcQbOrKYX/xFwNcyUOIf6TR/R3F5HUi8nfbvMd5us54vBEnZWc CSurPKQYwqifjtvrwTOLnOjwpMme+Vo1dRG43nSkbm5G2naJ//a0V0Hhh6WLl6mNGMSS fF4xWB9jkTDWTQowthyfM0EHgLGlkkE+MrlWVOsAvudFTsgXQ9FRvWQR8hmsy/AE6wDB eXJnVJ/+yj3JUNPRkZX91FIln21Vwhqnswfo+Kraum7vQaL08uBAsEtZ75i9YUERfQ6z nhBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=NJSJma+mK9+wqBvelA3hphNOwL4DNEshM/EJHZ+DEBI=; b=zgHRBxne+giUMfYObMjBddBUGPe239pJEzDUh+Szy0XdxngcM+Svwpk9ZkK6KF8L9o xzuT0e1h1HDJ4riLMyuUKtgOsumcjQOEvVeTOu+AR+OcUkN/1BfdQWFUdzIFyc2dp4pU 5AI1K7EFbRkaAsr6MCC416jdLqZev9gY6lgxXyGTgEzqQWtXGJ+sQ9yMNc9M1qAGY12T 1Ogere6jWNV9dhzdWcOYZ2L05rkQ5g1i7VskBFGozQl1Pug04Q59DcV6IkNgkhAEj3eQ eL6XkpKfj/zrdYf91TT8uTdg+JzdMRohgn9xDSFMlCWGGMwT40XmEvh89A6rrAB2kEyJ cB/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=urB6Hv2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a14si51779852pfo.37.2019.08.08.04.01.17; Thu, 08 Aug 2019 04:01:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019071901 header.b=urB6Hv2i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732037AbfHHK7A (ORCPT + 99 others); Thu, 8 Aug 2019 06:59:00 -0400 Received: from terminus.zytor.com ([198.137.202.136]:47523 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728289AbfHHK7A (ORCPT ); Thu, 8 Aug 2019 06:59:00 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x78AwjiY3127973 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 8 Aug 2019 03:58:45 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x78AwjiY3127973 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019071901; t=1565261925; bh=NJSJma+mK9+wqBvelA3hphNOwL4DNEshM/EJHZ+DEBI=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=urB6Hv2iZU7mQsKSIcEQsq1JvKvXcxVLeDPs1lZO8axIz/agiFDjjJu5zzmgO8Smp yCL3DQknW6Yt4OQJ/iJKgeFasNNnqHmH06VjS+VnVjj5dT7FTsn4WtIDZvZLNd9j4H CuIzBFUwQ7dbk+RZK4bxqat5rinSNq9/qGulyT0R5vTdTaOi1XAHOqT+0fQFOu3T42 PnMxQ1ZV270Tz+m0GGzHPHRvhOeYkpTqeTeRNewbKQxAjVzNvvTqbRz6D31UD6oQto YYlT6LQ/oS5MP0CNWXhwRfxrVd96nvNmfF8Q2TPGDngCvau51pzcc72R4UrdsEjocJ muLTTvyDIEa7w== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x78Awj8E3127970; Thu, 8 Aug 2019 03:58:45 -0700 Date: Thu, 8 Aug 2019 03:58:45 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Peter Zijlstra Message-ID: Cc: aaron.lwe@gmail.com, naravamudan@digitalocean.com, pauld@redhat.com, mingo@kernel.org, valentin.schneider@arm.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, jdesfossez@digitalocean.com Reply-To: pauld@redhat.com, valentin.schneider@arm.com, mingo@kernel.org, naravamudan@digitalocean.com, aaron.lwe@gmail.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, jdesfossez@digitalocean.com In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/core] sched: Allow put_prev_task() to drop rq->lock Git-Commit-ID: 5f2a45fc9e89e022233085e6f0f352eb6ff770bb X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5f2a45fc9e89e022233085e6f0f352eb6ff770bb Gitweb: https://git.kernel.org/tip/5f2a45fc9e89e022233085e6f0f352eb6ff770bb Author: Peter Zijlstra AuthorDate: Wed, 29 May 2019 20:36:43 +0000 Committer: Peter Zijlstra CommitDate: Thu, 8 Aug 2019 09:09:31 +0200 sched: Allow put_prev_task() to drop rq->lock Currently the pick_next_task() loop is convoluted and ugly because of how it can drop the rq->lock and needs to restart the picking. For the RT/Deadline classes, it is put_prev_task() where we do balancing, and we could do this before the picking loop. Make this possible. Signed-off-by: Peter Zijlstra (Intel) Cc: Valentin Schneider Cc: Aaron Lu Cc: mingo@kernel.org Cc: Phil Auld Cc: Julien Desfossez Cc: Nishanth Aravamudan Link: https://lkml.kernel.org/r/e4519f6850477ab7f3d257062796e6425ee4ba7c.1559129225.git.vpillai@digitalocean.com --- kernel/sched/core.c | 2 +- kernel/sched/deadline.c | 14 +++++++++++++- kernel/sched/fair.c | 2 +- kernel/sched/idle.c | 2 +- kernel/sched/rt.c | 14 +++++++++++++- kernel/sched/sched.h | 4 ++-- kernel/sched/stop_task.c | 2 +- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0c4220789092..7bbe78a31ba5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6090,7 +6090,7 @@ static struct task_struct *__pick_migrate_task(struct rq *rq) for_each_class(class) { next = class->pick_next_task(rq, NULL, NULL); if (next) { - next->sched_class->put_prev_task(rq, next); + next->sched_class->put_prev_task(rq, next, NULL); return next; } } diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 6eae79350303..2872e15a87cd 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1804,13 +1804,25 @@ pick_next_task_dl(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) return p; } -static void put_prev_task_dl(struct rq *rq, struct task_struct *p) +static void put_prev_task_dl(struct rq *rq, struct task_struct *p, struct rq_flags *rf) { update_curr_dl(rq); update_dl_rq_load_avg(rq_clock_pelt(rq), rq, 1); if (on_dl_rq(&p->dl) && p->nr_cpus_allowed > 1) enqueue_pushable_dl_task(rq, p); + + if (rf && !on_dl_rq(&p->dl) && need_pull_dl_task(rq, p)) { + /* + * This is OK, because current is on_cpu, which avoids it being + * picked for load-balance and preemption/IRQs are still + * disabled avoiding further scheduler activity on it and we've + * not yet started the picking loop. + */ + rq_unpin_lock(rq, rf); + pull_dl_task(rq); + rq_repin_lock(rq, rf); + } } /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e7c27eda9f24..4418c1998e69 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6901,7 +6901,7 @@ idle: /* * Account for a descheduled task: */ -static void put_prev_task_fair(struct rq *rq, struct task_struct *prev) +static void put_prev_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { struct sched_entity *se = &prev->se; struct cfs_rq *cfs_rq; diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 54194d41035c..8d59de2e4a6e 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -374,7 +374,7 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl resched_curr(rq); } -static void put_prev_task_idle(struct rq *rq, struct task_struct *prev) +static void put_prev_task_idle(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { } diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index f71bcbe1a00c..dbdabd76f192 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1592,7 +1592,7 @@ pick_next_task_rt(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) return p; } -static void put_prev_task_rt(struct rq *rq, struct task_struct *p) +static void put_prev_task_rt(struct rq *rq, struct task_struct *p, struct rq_flags *rf) { update_curr_rt(rq); @@ -1604,6 +1604,18 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) */ if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) enqueue_pushable_task(rq, p); + + if (rf && !on_rt_rq(&p->rt) && need_pull_rt_task(rq, p)) { + /* + * This is OK, because current is on_cpu, which avoids it being + * picked for load-balance and preemption/IRQs are still + * disabled avoiding further scheduler activity on it and we've + * not yet started the picking loop. + */ + rq_unpin_lock(rq, rf); + pull_rt_task(rq); + rq_repin_lock(rq, rf); + } } #ifdef CONFIG_SMP diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 304d98e712bf..e085cffb8004 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1710,7 +1710,7 @@ struct sched_class { struct task_struct * (*pick_next_task)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf); - void (*put_prev_task)(struct rq *rq, struct task_struct *p); + void (*put_prev_task)(struct rq *rq, struct task_struct *p, struct rq_flags *rf); void (*set_next_task)(struct rq *rq, struct task_struct *p); #ifdef CONFIG_SMP @@ -1756,7 +1756,7 @@ struct sched_class { static inline void put_prev_task(struct rq *rq, struct task_struct *prev) { WARN_ON_ONCE(rq->curr != prev); - prev->sched_class->put_prev_task(rq, prev); + prev->sched_class->put_prev_task(rq, prev, NULL); } static inline void set_next_task(struct rq *rq, struct task_struct *next) diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c index 47a3d2a18a9a..8f414018d5e0 100644 --- a/kernel/sched/stop_task.c +++ b/kernel/sched/stop_task.c @@ -59,7 +59,7 @@ static void yield_task_stop(struct rq *rq) BUG(); /* the stop task should never yield, its pointless. */ } -static void put_prev_task_stop(struct rq *rq, struct task_struct *prev) +static void put_prev_task_stop(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) { struct task_struct *curr = rq->curr; u64 delta_exec;