Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4502643ybl; Mon, 26 Aug 2019 11:21:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr1KFtau7YLZSsrWIwXrdfAgWUDLXerzCIXjsgvQdT92X5ot9e0R6tdhOGji6M/ssH75eH X-Received: by 2002:a17:90a:bc06:: with SMTP id w6mr22095796pjr.130.1566843670833; Mon, 26 Aug 2019 11:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566843670; cv=none; d=google.com; s=arc-20160816; b=H8MtAGHHC24UAJ/PNHKzz49+tNo5Cdjg+ZSsWOxWb8CuzqJw7cfK9WIC/RRK++e7Zj bcFJSFRVPamh+ZItCHAW8Dwxl02DWaqe7lCQWMY/+pz9kT4FiiNviR3oF09D/KXokd7l SgmKkiQLie9FTfgvtpZhMW6cIUpNLpNO9kZfDUpM+3CUj0nelyVQzN2QhO4kXaNuGdg7 RgYx5qr6IYGeBnR23JlPVwP8Cz53ixnTMLV+MMtd6+ZibRLK0Xr+++tKRp1bhQfi42IL 9oWv934/o4Ch5UGwrEnN9HYcmF8eU5MuCwih0T/sy6wKLpCUxIWz7GrW5jickgxQRm2p DjzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=Le9JPVVU4vny88u9EiPkItxavGDmRSiG8zPiQ6bCYac=; b=LmvJ7Oxn+03gT/dIMnD5A44OC2IbJ3ynw+Y/5cEnLgxLR2Qej2NE5Bcij9u1R1ow10 DDWwDUiEKc7zJbAa+q6AcVXViSdHSDEQLcjcSNJ1R44/Gum+hcEjY1ViiKd1v4u0KYmf 4G/k7r1i3jr8VJ4ycesGezITY4OkQK4bRbK+t5hN9Lv/WDM2yZSefm1+pajvA8rylvts KEKBVZUn/tgWUqWyP2tIK67JUznQIlpdgENIUp8Wd6Gg7/8SNRI9ICULL7tQJ5xQTUni smUM75Kc1s1XUeu+psamMkVVcA2h1EOTqJ/5kCBlm654NOGJYA/o08VShrE4KhWYc6jD gfIw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b30si10543317pla.299.2019.08.26.11.20.54; Mon, 26 Aug 2019 11:21:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387398AbfHZQvt (ORCPT + 99 others); Mon, 26 Aug 2019 12:51:49 -0400 Received: from mga14.intel.com ([192.55.52.115]:16493 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730248AbfHZQvt (ORCPT ); Mon, 26 Aug 2019 12:51:49 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 09:51:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,433,1559545200"; d="scan'208";a="204647764" Received: from mgross-mobl.amr.corp.intel.com (HELO localhost) ([10.7.198.58]) by fmsmga004.fm.intel.com with ESMTP; 26 Aug 2019 09:51:48 -0700 Date: Mon, 26 Aug 2019 09:51:47 -0700 From: mark gross To: Vineeth Remanan Pillai Cc: Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Tim Chen , mingo@kernel.org, tglx@linutronix.de, pjt@google.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, subhra.mazumdar@oracle.com, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Aaron Lu , Aubrey Li , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini Subject: Re: [RFC PATCH v3 07/16] sched: Allow put_prev_task() to drop rq->lock Message-ID: <20190826165147.GE2680@u1904> Reply-To: mgross@linux.intel.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 29, 2019 at 08:36:43PM +0000, Vineeth Remanan Pillai wrote: > From: Peter Zijlstra > > 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. Maybe explain why adding strtu rq_flags pointers to the function call supports the above commit coment. --mark > > Signed-off-by: Peter Zijlstra (Intel) > --- > 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 32ea79fb8d29..9dfa0c53deb3 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -5595,7 +5595,7 @@ static void calc_load_migrate(struct rq *rq) > atomic_long_add(delta, &calc_load_tasks); > } > > -static void put_prev_task_fake(struct rq *rq, struct task_struct *prev) > +static void put_prev_task_fake(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) > { > } > > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index c02b3229e2c3..45425f971eec 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -1772,13 +1772,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 49707b4797de..8e3eb243fd9f 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -7110,7 +7110,7 @@ done: __maybe_unused; > /* > * 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 dd64be34881d..1b65a4c3683e 100644 > --- a/kernel/sched/idle.c > +++ b/kernel/sched/idle.c > @@ -373,7 +373,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 adec98a94f2b..51ee87c5a28a 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -1593,7 +1593,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); > > @@ -1605,6 +1605,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 bfcbcbb25646..4cbe2bef92e4 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1675,7 +1675,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 > @@ -1721,7 +1721,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; > -- > 2.17.1 >