From patchwork Mon Mar 9 07:32:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 45529 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DB9220285 for ; Mon, 9 Mar 2015 07:38:10 +0000 (UTC) Received: by lbdu14 with SMTP id u14sf21587367lbd.3 for ; Mon, 09 Mar 2015 00:38:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=rrqJMeGEGmq9Yk/594useQ2qNbCGUjl5Xu/ktzbIsDU=; b=dDvqyCzQWcQaF8ammwJPmoOU6JU+K4GJKmC/qQ5jiUZNrOcVtbRmUdZVyq2uaaIF5j p3Dt8RRj6QOkVoTksRjIckb/9ccIEa6DqFfQ/daU1gMoURSoNMEHMJb1bEF/x6feV+YJ rIuPYHKexpcLcLXSsucsZO9SnjWBKv/NVtvC58Hj/odQeWoRRPr0NCxHZ5qL2JYrJDnm d9sAiMXY5kGShwL8/FYJdb5e7fYPYba/3DUcBCOIEwlyoH6zNLig9Jn6fM4cm43mb/go kx39S654Cqy03DaqhkgkuWMMmDzKOt05O7er0yrZdDP28XP5Yn/4qZx46VyyqvqMtZgC i92g== X-Gm-Message-State: ALoCoQl8W7JEwTjFgT6uSpx1WWediCQoo42JnLXqklWWkHJvYtIzyaFFyIB9ZsFvsviFkx9fhs13 X-Received: by 10.112.159.227 with SMTP id xf3mr3747041lbb.11.1425886689262; Mon, 09 Mar 2015 00:38:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.229 with SMTP id ap5ls3052lac.77.gmail; Mon, 09 Mar 2015 00:38:08 -0700 (PDT) X-Received: by 10.152.25.132 with SMTP id c4mr24449256lag.101.1425886688952; Mon, 09 Mar 2015 00:38:08 -0700 (PDT) Received: from mail-lb0-x231.google.com (mail-lb0-x231.google.com. [2a00:1450:4010:c04::231]) by mx.google.com with ESMTPS id d1si13588934laa.39.2015.03.09.00.38.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2015 00:38:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::231 as permitted sender) client-ip=2a00:1450:4010:c04::231; Received: by lbjf15 with SMTP id f15so40973140lbj.2 for ; Mon, 09 Mar 2015 00:38:08 -0700 (PDT) X-Received: by 10.152.178.197 with SMTP id da5mr24934944lac.56.1425886688862; Mon, 09 Mar 2015 00:38:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1309208lbj; Mon, 9 Mar 2015 00:38:08 -0700 (PDT) X-Received: by 10.70.46.230 with SMTP id y6mr50474055pdm.96.1425886687021; Mon, 09 Mar 2015 00:38:07 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ee5si2347768pac.139.2015.03.09.00.38.05; Mon, 09 Mar 2015 00:38:07 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753029AbbCIHiB (ORCPT + 28 others); Mon, 9 Mar 2015 03:38:01 -0400 Received: from m15-111.126.com ([220.181.15.111]:38219 "EHLO m15-111.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbbCIHiA (ORCPT ); Mon, 9 Mar 2015 03:38:00 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp1 (Coremail) with SMTP id C8mowEDJjkaiTP1UiXhUAw--.132S3; Mon, 09 Mar 2015 15:33:16 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Xunlei Pang Subject: [PATCH RESEND v4 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Date: Mon, 9 Mar 2015 15:32:27 +0800 Message-Id: <1425886348-3191-2-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425886348-3191-1-git-send-email-xlpang@126.com> References: <1425886348-3191-1-git-send-email-xlpang@126.com> X-CM-TRANSID: C8mowEDJjkaiTP1UiXhUAw--.132S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWrZr4kur48Gw4xXF13Jwb_yoW5uF43pa ykJw1jya1kJa9Fgrn7Xr4kZr43G3sYq3y7Jrn5t3yrKFs0qF48ZFn5ZryftFW3Kr1vqF43 tFWDtrsxGr1UZF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jlSoJUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiJxa3v01sAqCnhgAAsb Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: xlpang@126.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::231 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=126.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Xunlei Pang Currently, SMP RT scheduler has some trouble in dealing with equal prio cases. For example, in check_preempt_equal_prio(): When RT1(current task) gets preempted by RT2, if there is a migratable RT3 with same prio, RT3 will be pushed away instead of RT1 afterwards, because RT1 will be enqueued to the tail of the pushable list when going through succeeding put_prev_task_rt() triggered by resched. This broke FIFO. Furthermore, this is also problematic for normal preempted cases if there're some rt tasks queued with the same prio as current. Because current will be put behind these tasks in the pushable queue. So, if a task is running and gets preempted by a higher priority task (or even with same priority for migrating), this patch ensures that it is put ahead of any existing task with the same priority in the pushable queue. Signed-off-by: Xunlei Pang --- kernel/sched/rt.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index f4d4b07..86cd79f 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -347,11 +347,15 @@ static inline void set_post_schedule(struct rq *rq) rq->post_schedule = has_pushable_tasks(rq); } -static void enqueue_pushable_task(struct rq *rq, struct task_struct *p) +static void enqueue_pushable_task(struct rq *rq, + struct task_struct *p, bool head) { plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks); plist_node_init(&p->pushable_tasks, p->prio); - plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks); + if (head) + plist_add_head(&p->pushable_tasks, &rq->rt.pushable_tasks); + else + plist_add_tail(&p->pushable_tasks, &rq->rt.pushable_tasks); /* Update the highest prio pushable task */ if (p->prio < rq->rt.highest_prio.next) @@ -373,7 +377,8 @@ static void dequeue_pushable_task(struct rq *rq, struct task_struct *p) #else -static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p) +static inline void enqueue_pushable_task(struct rq *rq, + struct task_struct *p, bool head) { } @@ -1248,7 +1253,7 @@ enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags) enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD); if (!task_current(rq, p) && p->nr_cpus_allowed > 1) - enqueue_pushable_task(rq, p); + enqueue_pushable_task(rq, p, false); } static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags) @@ -1494,8 +1499,12 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) * The previous task needs to be made eligible for pushing * if it is still active */ - if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) - enqueue_pushable_task(rq, p); + if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) { + if (task_running(rq, p) && (preempt_count() & PREEMPT_ACTIVE)) + enqueue_pushable_task(rq, p, true); + else + enqueue_pushable_task(rq, p, false); + } } #ifdef CONFIG_SMP @@ -1914,7 +1923,7 @@ static void set_cpus_allowed_rt(struct task_struct *p, rq->rt.rt_nr_migratory--; } else { if (!task_current(rq, p)) - enqueue_pushable_task(rq, p); + enqueue_pushable_task(rq, p, false); rq->rt.rt_nr_migratory++; }