Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1716964ybl; Wed, 28 Aug 2019 20:16:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRjEUThEoXpmFFNWYDsm3pMThVns0xXIut/9ntl933HV8ZlhEP3E2Hn45OimqV7Pl1+Eju X-Received: by 2002:a17:90a:224e:: with SMTP id c72mr7739376pje.9.1567048613034; Wed, 28 Aug 2019 20:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567048613; cv=none; d=google.com; s=arc-20160816; b=PaNU41M+Ivkd8am3oBj2q5oOkRT+HrjcmjHULQ48u4SNtIU+kF8MkAcxfAvX3BzGWR o6pD+VGXiaXVkTRsXwKipVJJPY9NhadJxv7M3AoBIF0ELseyfT06wXJeXnrY0fL8CF91 ezqG628tXaweaSWabOy7YDh++UawVXkNhKDAnxhYbtoVxWzLRTI2F9mmtfy3DFvQtjOm +LrJNmgbtkyYlnzQpmM/Po+gBUjQEcwP9s8ZYwCWIwKkEiMXhh/QWwGUgqdcPe6gQWSG ZFPXm3hvEbu356MV+rp9rGF8DRRW4mefhG2PtX+1O+4SauZg8LNyJYKiP7Gm8XKQFX1N Vqyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=5ufrYwynEZzx5EPLwj53uE38sVnrbD7L+AyECfiIKGM=; b=sgsDwLPJMOL6PhdjcFXE3Z6RXSRtvqeVe55mu3WocgN6uG4ZYjAEOsScYl+alguvDY 3+ADpTesHl5OJfXGDmcYrMSgDpnLvymDxBMCaFSj+4ZYuTWHhvgs/ItKs4Dq9x9mYfv4 l0vnouc2K9Q2VvX7ylDelzHsxUxXoZrCg/ugNo40g6Bc7nck5wAEIKbre5Pu2WJIkpeN ZPaA7dKkPbSoxkdqchEoSrVj+zjLigGexvPz4jpymgN+leWezfQDZAqCLr5w1VTfgyHG QOkbvceJM7txZ/unKyANKZfA5+a5dp8MP9Yu0cMnu2MLsQFA/qwOUwWiDKIeOjEAa3aI 8bGg== 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=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si754354pgb.209.2019.08.28.20.16.37; Wed, 28 Aug 2019 20:16:53 -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=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbfH2DPM (ORCPT + 99 others); Wed, 28 Aug 2019 23:15:12 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:56698 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726081AbfH2DPM (ORCPT ); Wed, 28 Aug 2019 23:15:12 -0400 X-UUID: ed8255095a524db3996276f69a241a2d-20190829 X-UUID: ed8255095a524db3996276f69a241a2d-20190829 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1455996244; Thu, 29 Aug 2019 11:15:06 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 29 Aug 2019 11:15:10 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 29 Aug 2019 11:15:10 +0800 From: Jing-Ting Wu To: Peter Zijlstra , Matthias Brugger CC: , , , , Jing-Ting Wu Subject: [PATCH 1/1] sched/rt: avoid contend with CFS task Date: Thu, 29 Aug 2019 11:15:02 +0800 Message-ID: <1567048502-6064-1-git-send-email-jing-ting.wu@mediatek.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: CF92C9C9AC6572474D62653CE02C724113EE36A30E31A424135181DAEB5C373D2000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); /* @@ -1648,6 +1629,7 @@ static int find_lowest_rq(struct task_struct *task) struct cpumask *lowest_mask = this_cpu_cpumask_var_ptr(local_cpu_mask); int this_cpu = smp_processor_id(); int cpu = task_cpu(task); + int i; /* Make sure the mask is initialized first */ if (unlikely(!lowest_mask)) @@ -1659,6 +1641,16 @@ static int find_lowest_rq(struct task_struct *task) if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask)) return -1; /* No targets found */ + /* Choose previous cpu if it is idle and it fits lowest_mask */ + if (cpumask_test_cpu(cpu, lowest_mask) && idle_cpu(cpu)) + return cpu; + + /* Choose idle_cpu among lowest_mask */ + for_each_cpu(i, lowest_mask) { + if (idle_cpu(i)) + return i; + } + /* * At this point we have built a mask of CPUs representing the * lowest priority tasks in the system. Now we want to elect -- 1.7.9.5