Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4019431pxj; Tue, 15 Jun 2021 13:38:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdlcw7nw/4hass0+c1zZKDVvoPO6Fjd0iPPfYRI/X6qj2CPwd69snFWS6tf4aQss5RzGaw X-Received: by 2002:aa7:c64e:: with SMTP id z14mr8170edr.119.1623789520972; Tue, 15 Jun 2021 13:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623789520; cv=none; d=google.com; s=arc-20160816; b=GtKLcCx2tXl4/NFV/vbBsn5tlCte+WtxkJemv7Jch5EBV0OYYcDui6r0uvey4GozV3 d0aF57ruK+asEVT4JK5iUq8b5bL5TWdZmgtDgwQvbpEvd3S+wKANUIfQLyd9wamiInmT CfR+eKrd3oae4ie57wcqSBA9BDnkvt2F9lxwjFpK4jUejZk14mwO4vdeWCUHEk38DAOT 4L50ePmw54VMlhpuotF6su01o/QVcTUII0nG+RD2eb7bq5TadCEfOqxb5en1JzsiK0v/ ZejbTYhNUG0xWYOqZPJwxTFThpKqhtTNpAFnJwUyYkWi37pCCKLN+xdG2RWNtkZtLKce BVUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=y9Ixb/cYf5RX0Tp/tP70zOnE6mzcN4QC3xP7A4EcpOM=; b=vX4AVUvCGXfgIGXwz76f+ExgYWEBpZNV27CR6ah0R3ZydpAaFeB0Q5EY9S68LApywD xJMhSAZaQ1Ai24C7hZJbpdng/QFUx2jg0tLjhD8o09sZZ5NVAbhpiAsYdU+QxgjFydOj s6yp90hFvGBKG/bl5hWA4x0kptTbxTLjVp1xH0jADHcaSiQZaTphZe4q5l69/V3GkdLB F3W1uRtg0AehDd5CHk67ArR/FmHFfBXWXvQOAGAthOviEnyYf/hyyr9XGSqT0CtvmKjQ 5fxyn2SH/Sd4Mqtn5OZzygF619FQbKfSorcRJme54PN9jS+IEbhjkZeBmqtc5KmSXG0q 9yAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=psQSCREA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si17142ejl.676.2021.06.15.13.38.17; Tue, 15 Jun 2021 13:38:40 -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=@infradead.org header.s=desiato.20200630 header.b=psQSCREA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhFOUh6 (ORCPT + 99 others); Tue, 15 Jun 2021 16:37:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbhFOUh6 (ORCPT ); Tue, 15 Jun 2021 16:37:58 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E25CC061574 for ; Tue, 15 Jun 2021 13:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=y9Ixb/cYf5RX0Tp/tP70zOnE6mzcN4QC3xP7A4EcpOM=; b=psQSCREALaH4CR8APq/w7wq4ZT SDD6PylWn6G44+BiGmH+K1rw+0LYRxRo8TaSDCaoWUBbMVPqPhA2r82oYtpY3jrVWTWSkg1k5cBQ9 Gv8IPuE50SnrrQ3ddZATNhlEQK+eUJkOSqXIIIwGmghgc/qdtBV86ng57rYRxO9iaiUFyle8iO8gi go+6+KLknvAYmWtgeT4b+joVSSwRgjXiqqr5A9kY56f33QwuHK3LrAU1cX7NQ1b7yByPzQMUbHNfF ljwrApZ1DaK1VX2v3QaoBQGBXL6huvM6zFsbucMFN634KyJxD1owN2Wu7zONxdRe+PTZnZwqwi8xn VKQ0HpZw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltFmT-00865s-8r; Tue, 15 Jun 2021 20:35:36 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id AA61B9863C9; Tue, 15 Jun 2021 22:35:34 +0200 (CEST) Date: Tue, 15 Jun 2021 22:35:34 +0200 From: Peter Zijlstra To: Yafang Shao Cc: vincent.guittot@linaro.org, mingo@redhat.com, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, Valentin Schneider , Thomas Gleixner Subject: Re: [PATCH] sched, fair: try to prevent migration thread from preempting non-cfs task Message-ID: <20210615203534.GA4272@worktop.programming.kicks-ass.net> References: <20210615121551.31138-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210615121551.31138-1-laoar.shao@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 08:15:51PM +0800, Yafang Shao wrote: > --- > kernel/sched/fair.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 3248e24a90b0..597c7a940746 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -9797,6 +9797,20 @@ static int load_balance(int this_cpu, struct rq *this_rq, > /* Record that we found at least one task that could run on this_cpu */ > env.flags &= ~LBF_ALL_PINNED; > > + /* > + * There may be a race between load balance starting migration > + * thread to pull the cfs running thread and the RT thread > + * waking up and preempting cfs task before migration threads > + * which then preempt the RT thread. > + * We'd better do the last minute check before starting > + * migration thread to avoid preempting latency-sensitive thread. > + */ > + if (busiest->curr->sched_class != &fair_sched_class) { > + raw_spin_unlock_irqrestore(&busiest->lock, > + flags); This won't apply. Also, there's still a race window, you've just shrunk it, not fixed it. Busiest can reschedule between the mandatory rq unlock and doing the stopper wakeup. An actual fix might be to have the active migration done by a FIFO-1 task, instead of stopper. The obvious down-side is that that would mean spawning yet another per-cpu kthread. How much do we care?