From patchwork Thu Apr 9 03:27:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 46901 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B52C21416 for ; Thu, 9 Apr 2015 03:30:11 +0000 (UTC) Received: by wiaa2 with SMTP id a2sf14330893wia.1 for ; Wed, 08 Apr 2015 20:30:10 -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=8dRS9oKwQ7l1sfasyNNI61IN+5TJ/kDM67BdIfFh1BY=; b=PLD5eiK5crADiXwPaSwgjfhsZalOOW3rVxcPzWzbOh/tQhSvJ2c2rxJ818uwIedqwS jpDilY9wznJmaHfmcNUx8nkdWz11ppJ1J92KnCPKuZ/Y1C0OSOqgW0NZ17tUVdCtgNHh 6fv9cR4kgH79DvyloarxyxJlkhoVq+xpDHavNS5+VYHTsM4V833NI3dqgj4ZZllX5q6a Vmdm/+rRJ/w4KHaR3q+ETuXaD0P2fYNP3X3HGu/SSGxbCasF9qabjBkfhjze1xddUWaA /1SYbGrJfkwcrNC6e9IVSYUM2ArT5Cf5/yVgwqI5QgmPzzktlNQIZHFkP0du+yhI4Hlg 3/hA== X-Gm-Message-State: ALoCoQma7fNbqs+v43SD37hIXwQYYrpeFYxVUFi4YWC6Evvt6PoTevYEs2yEc2fRuNo2DLVr4lpn X-Received: by 10.180.81.134 with SMTP id a6mr198765wiy.1.1428550210701; Wed, 08 Apr 2015 20:30:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.137 with SMTP id o9ls207653lal.16.gmail; Wed, 08 Apr 2015 20:30:10 -0700 (PDT) X-Received: by 10.112.119.234 with SMTP id kx10mr22681941lbb.35.1428550210375; Wed, 08 Apr 2015 20:30:10 -0700 (PDT) Received: from mail-lb0-x229.google.com (mail-lb0-x229.google.com. [2a00:1450:4010:c04::229]) by mx.google.com with ESMTPS id dg6si10349473lac.105.2015.04.08.20.30.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 20:30:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::229 as permitted sender) client-ip=2a00:1450:4010:c04::229; Received: by lbbzk7 with SMTP id zk7so81563123lbb.0 for ; Wed, 08 Apr 2015 20:30:10 -0700 (PDT) X-Received: by 10.152.206.75 with SMTP id lm11mr2646457lac.41.1428550210246; Wed, 08 Apr 2015 20:30:10 -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.67.65 with SMTP id l1csp221353lbt; Wed, 8 Apr 2015 20:30:09 -0700 (PDT) X-Received: by 10.68.172.3 with SMTP id ay3mr39165118pbc.94.1428550208405; Wed, 08 Apr 2015 20:30:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fo3si19457730pad.17.2015.04.08.20.30.06; Wed, 08 Apr 2015 20:30:08 -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 S1754961AbbDIDaD (ORCPT + 27 others); Wed, 8 Apr 2015 23:30:03 -0400 Received: from m15-112.126.com ([220.181.15.112]:40003 "EHLO m15-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754530AbbDID3p (ORCPT ); Wed, 8 Apr 2015 23:29:45 -0400 Received: from localhost.localdomain (unknown [210.21.223.3]) by smtp2 (Coremail) with SMTP id DMmowEDJvlOa8SVVTV0aAQ--.926S3; Thu, 09 Apr 2015 11:27:29 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Dan Streetman , Xunlei Pang Subject: [PATCH v5 2/3] sched/rt: Fix wrong SMP scheduler behavior for equal prio cases Date: Thu, 9 Apr 2015 11:27:17 +0800 Message-Id: <1428550038-13619-2-git-send-email-xlpang@126.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428550038-13619-1-git-send-email-xlpang@126.com> References: <1428550038-13619-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DMmowEDJvlOa8SVVTV0aAQ--.926S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWrZr4kur48Gw4xXF13Jwb_yoW5Kr13pa 4rJw1jya1kJa9Fgrn7Xr48Zr43G3sYq3y5Jrn5t3yrKa15tFW8XFnYyryftFWSyr1vqa13 tFWDtrsxGr1UZFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jRXdbUUUUU= X-Originating-IP: [210.21.223.3] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiJwHWv01sBHgn-QAAsI 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::229 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. Suggested-by: Steven Rostedt Signed-off-by: Xunlei Pang --- kernel/sched/rt.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 575da76..402162a 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -359,11 +359,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) @@ -385,7 +389,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) { } @@ -1260,7 +1265,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) @@ -1507,7 +1512,16 @@ static void put_prev_task_rt(struct rq *rq, struct task_struct *p) * if it is still active */ if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1) - enqueue_pushable_task(rq, p); + /* + * put_prev_task_rt() is called by many functions, + * pick_next_task_rt() is the only one may have + * PREEMPT_ACTIVE set. So if detecting p(current + * task) is preempted in such case, we should + * enqueue it to the front of the pushable plist, + * as there may be multiple tasks with the same + * priority as p. + */ + enqueue_pushable_task(rq, p, !!(preempt_count() & PREEMPT_ACTIVE)); } #ifdef CONFIG_SMP @@ -2091,7 +2105,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++; }