Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp10638ybp; Thu, 3 Oct 2019 09:28:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSJ5hA70Zpnwc1LnAwDauUMaPEMkp2bQci5N7/6frEc/GIxRnQob79Y4NdWq33Lb2pUBL6 X-Received: by 2002:a17:906:8246:: with SMTP id f6mr8464473ejx.179.1570120092130; Thu, 03 Oct 2019 09:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570120092; cv=none; d=google.com; s=arc-20160816; b=TXPBht/OQCmvQdccMhV4WpPdCyXT0pcUJqtMA4nc9n0d+Ee5N9TZpgkqc5WOcZSKgW 4ONtDwUx6NXrN4LIcAglw6qlZqu9MPbx1ykPUOtZfqVMt9KPZbNmlTJJbHLQuup7LXkI o4+AjvE30cpz8JsfDAYOaPazWtOien1/bWzKtCHygVw2tYa390EGC8pmHylyfY5S7uKz iQZJXVxdqb+ChDkFgU97Y56Z66+q+8rsVNHP5u2n6UtHYTgqt0WCOibLZKuo1fudwgsq Cdc7nZP6ZMhnrI7TewXpNaHbCpBN4mUuxrrKfs2K/15kL94V2fybXFqhcQEelZJJjumV uSCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ysshzu7lh6f87j5fL21OLEMQXhkQ39ragJr8z/wrmFw=; b=nB2Ir4hW8tLWuvRJ0IQd6stpbCyCskRuk6exY20S/UmMdO7qpmytSbZ64vPZ88mC82 HbeJLVJqlGnSbjJFoQU0k9mLdO5bhd6Q5AVxnhKL0saXgulNeIR4stKZ7mVBbCtXsxmd DZ0echGgOh6iErAN3fUGO3o6S4aUaazq6MMm95gIQh3exITYb4dLx3nJ6KPbKw8NG2Rv cSSyUtcgGtXrhWmnQeVas5Wd8O/0HmojWewONPvqJKB8/aLHiv5Wk7EiHg2eYyi1gLQd VZGidlthy0EAGL8lEXJ//o/NWjI2usq/uIX/m1JpHkWUwLHyeBd/3XoagaMra5L7v2T+ fxrg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si2012430edi.410.2019.10.03.09.27.48; Thu, 03 Oct 2019 09:28:12 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391024AbfJCQ0I (ORCPT + 99 others); Thu, 3 Oct 2019 12:26:08 -0400 Received: from foss.arm.com ([217.140.110.172]:48920 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390979AbfJCQZy (ORCPT ); Thu, 3 Oct 2019 12:25:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0722D1000; Thu, 3 Oct 2019 09:25:54 -0700 (PDT) Received: from [192.168.0.9] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B2C883F739; Thu, 3 Oct 2019 09:25:52 -0700 (PDT) Subject: Re: [PATCH 1/1] sched/rt: avoid contend with CFS task To: Jing-Ting Wu , Peter Zijlstra , Matthias Brugger Cc: wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Steven Rostedt References: <1567048502-6064-1-git-send-email-jing-ting.wu@mediatek.com> From: Dietmar Eggemann Message-ID: <7bd9506b-9930-0bf8-a024-8c7d7d8bf86e@arm.com> Date: Thu, 3 Oct 2019 18:25:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <1567048502-6064-1-git-send-email-jing-ting.wu@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+ Steven Rostedt ] On 29/08/2019 05:15, Jing-Ting Wu wrote: > At original linux design, RT & CFS scheduler are independent. > Current RT task placement policy will select the first cpu in > lowest_mask, even if the first CPU is running a CFS task. > This may put RT task to a running cpu and let CFS task runnable. > > So we select idle cpu in lowest_mask first to avoid preempting > CFS task. > > Signed-off-by: Jing-Ting Wu > --- > kernel/sched/rt.c | 42 +++++++++++++++++------------------------- > 1 file changed, 17 insertions(+), 25 deletions(-) > > diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c > index a532558..626ca27 100644 > --- a/kernel/sched/rt.c > +++ b/kernel/sched/rt.c > @@ -1388,7 +1388,6 @@ static void yield_task_rt(struct rq *rq) > static int > select_task_rq_rt(struct task_struct *p, int cpu, int sd_flag, int flags) > { > - struct task_struct *curr; > struct rq *rq; > > /* For anything but wake ups, just return the task_cpu */ > @@ -1398,33 +1397,15 @@ static void yield_task_rt(struct rq *rq) > rq = cpu_rq(cpu); > > rcu_read_lock(); > - curr = READ_ONCE(rq->curr); /* unlocked access */ > > /* > - * If the current task on @p's runqueue is an RT task, then > - * try to see if we can wake this RT task up on another > - * runqueue. Otherwise simply start this RT task > - * on its current runqueue. > - * > - * We want to avoid overloading runqueues. If the woken > - * task is a higher priority, then it will stay on this CPU > - * and the lower prio task should be moved to another CPU. > - * Even though this will probably make the lower prio task > - * lose its cache, we do not want to bounce a higher task > - * around just because it gave up its CPU, perhaps for a > - * lock? > - * > - * For equal prio tasks, we just let the scheduler sort it out. > - * > - * Otherwise, just let it ride on the affined RQ and the > - * post-schedule router will push the preempted task away > - * > - * This test is optimistic, if we get it wrong the load-balancer > - * will have to sort it out. > + * If the task p is allowed to put more than one CPU or > + * it is not allowed to put on this CPU. > + * Let p use find_lowest_rq to choose other idle CPU first, > + * instead of choose this cpu and preempt curr cfs task. > */ > - if (curr && unlikely(rt_task(curr)) && > - (curr->nr_cpus_allowed < 2 || > - curr->prio <= p->prio)) { > + if ((p->nr_cpus_allowed > 1) || > + (!cpumask_test_cpu(cpu, p->cpus_ptr))) { > int target = find_lowest_rq(p); I'm sure RT folks don't like the idea to change this condition. I remember a similar approach and Steven Rostedt NAKed the idea back: https://lore.kernel.org/r/1415099585-31174-2-git-send-email-pang.xunlei@linaro.org Back then, Xunlei Pang even tried to create a lower mask of idle CPUs, for find_lower_mask() to return: https://lore.kernel.org/r/1415099585-31174-1-git-send-email-pang.xunlei@linaro.org [...]