From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751250AbbDZRMZ (ORCPT ); Sun, 26 Apr 2015 13:12:25 -0400 Received: from m15-114.126.com ([220.181.15.114]:53267 "EHLO m15-114.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750887AbbDZRMW (ORCPT ); Sun, 26 Apr 2015 13:12:22 -0400 From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Ingo Molnar , Xunlei Pang Subject: [RFC PATCH 2/6] sched/rt: Check to push task away when its affinity is changed Date: Mon, 27 Apr 2015 01:10:54 +0800 Message-Id: <1430068258-1960-2-git-send-email-xlpang@126.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430068258-1960-1-git-send-email-xlpang@126.com> References: <1430068258-1960-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DsmowACX+G4iHD1V8BojAA--.830S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFy3Jr13XFykWrWrXrWUJwb_yoW5ZFy5pa ykC345Cw4DJFy2gw1fXw4kur4Yg3s7Zw13JFs5tr1SkFs0gr4FqF4qqF43AF9Igr15CFW2 qrn0gr92gr1jyaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jKYL9UUUUU= X-Originating-IP: [220.166.221.63] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXAvnv1R0V4Y03QAAsX Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xunlei Pang We may suffer from extra rt overload rq due to the affinity, so when the affinity of any runnable rt task is changed, we should check to trigger balancing, otherwise it will cause some unnecessary delayed real-time response. Unfortunately, current RT global scheduler does nothing about this. For example: a 2-cpu system with two runnable FIFO tasks(same rt_priority) bound on CPU0, let's name them rt1(running) and rt2(runnable) respectively; CPU1 has no RTs. Then, someone sets the affinity of rt2 to 0x3(i.e. CPU0 and CPU1), but after this, rt2 still can't be scheduled until rt1 enters schedule(), this definitely causes some/big response latency for rt2. This patch introduces new sched_class::post_set_cpus_allowed() for rt called after set_cpus_allowed_rt(). In this new function, it triggers a push action when detecting such cases. Signed-off-by: Xunlei Pang --- kernel/sched/core.c | 3 +++ kernel/sched/rt.c | 24 ++++++++++++++++++++++++ kernel/sched/sched.h | 1 + 3 files changed, 28 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f9123a8..dc646a6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4769,6 +4769,9 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) cpumask_copy(&p->cpus_allowed, new_mask); p->nr_cpus_allowed = cpumask_weight(new_mask); + + if (p->sched_class->post_set_cpus_allowed) + p->sched_class->post_set_cpus_allowed(p); } /* diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 6b40555..7b76747 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2136,6 +2136,29 @@ static void set_cpus_allowed_rt(struct task_struct *p, update_rt_migration(&rq->rt); } +static void post_set_cpus_allowed_rt(struct task_struct *p) +{ + struct rq *rq; + + if (!task_on_rq_queued(p)) + return; + + rq = task_rq(p); + if (p->nr_cpus_allowed > 1 && + rq->rt.rt_nr_running > 1 && + rt_task(rq->curr) && !test_tsk_need_resched(rq->curr)) { + if (!task_running(rq, p)) { + push_rt_task(rq); + } else if (cpumask_test_cpu(task_cpu(p), &p->cpus_allowed)) { + /* + * p(current) may get migratable due to the change + * of its affinity, let's try to push it away. + */ + check_preempt_equal_prio_common(rq); + } + } +} + /* Assumes rq->lock is held */ static void rq_online_rt(struct rq *rq) { @@ -2350,6 +2373,7 @@ const struct sched_class rt_sched_class = { .select_task_rq = select_task_rq_rt, .set_cpus_allowed = set_cpus_allowed_rt, + .post_set_cpus_allowed = post_set_cpus_allowed_rt, .rq_online = rq_online_rt, .rq_offline = rq_offline_rt, .post_schedule = post_schedule_rt, diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e0e1299..6f90645 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1191,6 +1191,7 @@ struct sched_class { void (*set_cpus_allowed)(struct task_struct *p, const struct cpumask *newmask); + void (*post_set_cpus_allowed)(struct task_struct *p); void (*rq_online)(struct rq *rq); void (*rq_offline)(struct rq *rq); -- 1.9.1