Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5482030ybl; Tue, 27 Aug 2019 05:30:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxy4DVDqiQ9qQnW0QVHUsicO353dq8Wuf1al1WYL1PsW+xGUrhpmsSclUnXiGReLRfM6DUG X-Received: by 2002:a65:690f:: with SMTP id s15mr20471990pgq.432.1566909006281; Tue, 27 Aug 2019 05:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566909006; cv=none; d=google.com; s=arc-20160816; b=iZlPr/18GaWdKZfOpidAtkIyK8Wgtp4esmSVuIW/XMNSZIOFWzLseyFLgBpexZlKRL xU4bXbXl/n7271qS5TBQEpu36v69CC35ZboP6GqYWfqzu1nq7ATDQ3XdUHFGY9fYJXUP LZZCa4m5axFHnqJXPc+TAKxCI1BRswFUqozAZUJ4fEql+8ftLr85Fb3gxwWiuHasT2Ei i/mmXW30ZLe433g5g2naRF4pXLGBJniyto3KFpRtUOXcwmTR/08P40MlG/1MVTXbmhrO hNDaqXz9YQW7Q855DnKa8kmZXN1Luij72zTH58b2AbTpR4rIwSdudQ1Rqbkau1rmnYYU mOfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=IrvTyiP5uOe3nkt4yyBHrThnDSmKFkgXLFlJJeQFR3o=; b=dbbTG7Ca1SOhofj8vb0+NMeOdqyLuKLFzCQ+0j4OZnrnLeWQrQAWdBtmWPyvSECd39 j7KZiOgyZp90bs9n33cjd+rVxjqddJJxoxg0CFUAljKGNN4FsTjXzeBvC0PSVKW3t8B6 XLzm3+JrUsFgP+k3NBX6csFRJaRKjl9CmVXeRAAYJJ2uiQNvwWCfJUIWXmi6QnmsyVbh iPobO+cFGaITT2VzEBymfxhC/5QSc+m/hrlwsFvT+B5QcpKa6CD/fgLN8nrzf5MNmlGf D9gDzZ1p2x6oQZtlKZaXELm2m0Xvn6fVqYPxqMSmWF2sUK0SPTbPtd+s03uOXQvPIF+y VZUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xhA1kkrz; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25si6207109pfi.265.2019.08.27.05.29.49; Tue, 27 Aug 2019 05:30:06 -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=@linaro.org header.s=google header.b=xhA1kkrz; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729706AbfH0M27 (ORCPT + 99 others); Tue, 27 Aug 2019 08:28:59 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41736 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfH0M27 (ORCPT ); Tue, 27 Aug 2019 08:28:59 -0400 Received: by mail-lf1-f67.google.com with SMTP id j4so4129216lfh.8 for ; Tue, 27 Aug 2019 05:28:58 -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=IrvTyiP5uOe3nkt4yyBHrThnDSmKFkgXLFlJJeQFR3o=; b=xhA1kkrz9zuMoZ661z6on04LYIQa+xd0K/cfJXpljR8KT+VLM8k0Jyf7nHDehNy7r/ hiHA2D7Ke/OKsD7/IzFlcKniW4cUMh1tnlCpEUG7FUalFCZae6aq5ekCGEhEXY2SeelY T+HtQZNKY4H25B4PYDAK+MvzvQ+In0p9RsxTWtcTHtOsObWptvWE6R67bA6cdzmYDyLA FnfoElL5s2OUVf6Oi8SnQR3XW5SJU1kq+vIQeg6wf7vcYmBeSOfqiK+2IJ35HKVwNzXb tk2ycU5PYcnQW5dXIaKFHeAbkyh5f+Gh7MlXFyCqnrYVknOrwq74Tbxjhv3NL5cW/mfI I9/w== 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=IrvTyiP5uOe3nkt4yyBHrThnDSmKFkgXLFlJJeQFR3o=; b=nqyFUlQSewpMqwShQsurM224x/9ebf8jHc3LVeYxsCzVNIFES6MANFQcPOabDY4AZ9 OMwwR+hgEad2fshXzTzQOR8wURd0dwrgWp8k6gBWhokA9Ysi/sBTZGAnaBG9jk3pxuyt 7ClYduYKrihxtQOAZx/O4AU0XooSH1mY4CL+UmfUWj71q1eJuccLs4Yszi/SxyCYz/Wl T8CuAwv2daWybIVZ0IQXBeLfQu/h83wISA+RoxU+sRAk04MsDPFHpr/3lkgMNCqwPiFR ZfRqztuTzoidKjJ9NZt7/qhxzBIRi25fFbCOrTXEfIzlVtiSAsTyqhYPW/yniyuoXO2s rpXA== X-Gm-Message-State: APjAAAUlKJ+bT6sSs/G8fPowQjqrzwP6EKahgJaZ5IYf3yd6OmJx46C6 8yCfzXr5u3GUt5ovNZptc5jDCMqPvJE4+bOcd4N3Rw== X-Received: by 2002:a19:f603:: with SMTP id x3mr12851076lfe.125.1566908937534; Tue, 27 Aug 2019 05:28:57 -0700 (PDT) MIME-Version: 1.0 References: <20190815145107.5318-1-valentin.schneider@arm.com> <20190815145107.5318-5-valentin.schneider@arm.com> In-Reply-To: <20190815145107.5318-5-valentin.schneider@arm.com> From: Vincent Guittot Date: Tue, 27 Aug 2019 14:28:46 +0200 Message-ID: Subject: Re: [PATCH v2 4/4] sched/fair: Prevent active LB from preempting higher sched classes To: Valentin Schneider Cc: linux-kernel , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Qais Yousef Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Aug 2019 at 16:52, Valentin Schneider wrote: > > The CFS load balancer can cause the cpu_stopper to run a function to > try and steal a remote rq's running task. However, it so happens > that while only CFS tasks will ever be migrated by that function, we > can end up preempting higher sched class tasks, since it is executed > by the cpu_stopper. > > This can potentially occur whenever a rq's running task is > CFS but > the rq has runnable CFS tasks. > > Check the sched class of the remote rq's running task after we've > grabbed its lock. If it's CFS, carry on, otherwise run > detach_one_task() locally since we don't need the cpu_stopper (that > !CFS task is doing the exact same thing). AFAICT, this doesn't prevent from preempting !CFS task but only reduce the window. As soon as you unlock, !CFS task can preempt CFS before you start stop thread testing busiest->cfs.h_nr_running < 1 and/or busiest->curr->sched_class != &fair_sched_class in need_active_balance() will do almost the same and is much simpler than this patchset IMO. > > Signed-off-by: Valentin Schneider > --- > kernel/sched/fair.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 8f5f6cad5008..bf4f7f43252f 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -8759,6 +8759,7 @@ static inline enum alb_status active_load_balance(struct lb_env *env) > enum alb_status status = cancelled; > struct sched_domain *sd = env->sd; > struct rq *busiest = env->src_rq; > + struct task_struct *p = NULL; > unsigned long flags; > > schedstat_inc(sd->lb_failed[env->idle]); > @@ -8780,6 +8781,16 @@ static inline enum alb_status active_load_balance(struct lb_env *env) > if (busiest->cfs.h_nr_running < 1) > goto unlock; > > + /* > + * If busiest->curr isn't CFS, then there's no point in running the > + * cpu_stopper. We can try to nab one CFS task though, since they're > + * all ready to be plucked. > + */ > + if (busiest->curr->sched_class != &fair_sched_class) { > + p = detach_one_task(env); > + goto unlock; > + } > + > /* > * Don't kick the active_load_balance_cpu_stop, if the curr task on > * busiest CPU can't be moved to dst_cpu: > @@ -8803,7 +8814,9 @@ static inline enum alb_status active_load_balance(struct lb_env *env) > unlock: > raw_spin_unlock_irqrestore(&busiest->lock, flags); > > - if (status == started) > + if (p) > + attach_one_task(env->dst_rq, p); > + else if (status == started) > stop_one_cpu_nowait(cpu_of(busiest), > active_load_balance_cpu_stop, busiest, > &busiest->active_balance_work); > -- > 2.22.0 >