Received: by 10.192.165.156 with SMTP id m28csp1821335imm; Thu, 12 Apr 2018 04:13:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Bv8HxTScjnc6DjkP4X8epDLd5tglxOwFS27Eejx4Mym/rq2eXxPtvs1AlMrJlaqcXTeyd X-Received: by 10.101.64.7 with SMTP id f7mr387384pgp.216.1523531608122; Thu, 12 Apr 2018 04:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531608; cv=none; d=google.com; s=arc-20160816; b=EYRWajkoqmTZ7GmysMZt+2OVlcOeI0PHiGdgxetjHG+m+qNLUxjj1ANo5oEFjt45ej kx2XwQY+ae/srZ7AuZQm0KXa95+K2Z0+AvQYc8uaNCmzyC8ukGF2+H0EUv9Lgidp193U OL8+a0ydZ5L17V6vvq3GUdx8ik1hFCaBxfCKMBGswiiPI6ysTFae/KzexypYHAY00urj dwNj92olysBA8Yra5F1TMYZfEvLulzYwTNmzpjQrZVZim+HwqRyklEmWaN0WH/MTRpuW QSyyVOo37NaHdg65y9DH0jaZUc0fX/F3qhbKgxKAtt8qN+5WyLfj6rO2XsLcrd8nApJm QxYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=PgMLti38R4c+gNFLplD+I2dxsf2zMqPnCWS6lYQ6XF4=; b=kJOYXhEPH7+/7t/ykqoXyWVkYMK0zbMu8IfUmmW57iYpMMfF0rLNYKSMG2zBBmhGnp 4mvDu1ll2VyszATzc00faq0yD61dyRPHS/UZkT6HL4/RuxUUsYZlOKrwOB92FEaFCgBG jvRjv3VX1+15bZzA/Tz9pql5qriFsCMA6a2YT5jBr4qLHNMGT7UPEMANanKdRJnlPiwx THF3AKnfzp2Mo7aC1hDATjumDnoc8C9b9kTfiQjj37B7iHsNp8iolQ9DQ5fYha653rXD o/LnYVYeRXBSK+P+FUqwtYNavVxgHxshvwJcgdhqjAZO0CtcnFPoMyq4YDqZzKn3eBZU r33w== 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 b15-v6si1238337plm.590.2018.04.12.04.12.51; Thu, 12 Apr 2018 04:13:28 -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 S1752831AbeDLLJF (ORCPT + 99 others); Thu, 12 Apr 2018 07:09:05 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:48263 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752793AbeDLLJC (ORCPT ); Thu, 12 Apr 2018 07:09:02 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 432AC68431379; Thu, 12 Apr 2018 19:08:58 +0800 (CST) Received: from huawei.com (10.175.102.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.361.1; Thu, 12 Apr 2018 19:08:49 +0800 From: Li Bin To: , , CC: , , Subject: [PATCH 2/2] sched/deadline.c: pick and check task if double_lock_balance() unlock the rq Date: Thu, 12 Apr 2018 18:58:55 +0800 Message-ID: <1523530735-20011-3-git-send-email-huawei.libin@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1523530735-20011-1-git-send-email-huawei.libin@huawei.com> References: <1523530735-20011-1-git-send-email-huawei.libin@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org push_dl_task() pick the first pushable task and find an eligible later_rq, then double_lock_balance(rq, lowest_rq). So if double_lock_balance() unlock the rq (when double_lock_balance() return 1), we have to check if this task is still on the rq. The problem is that the check conditions are not sufficient: if (unlikely(task_rq(task) != rq || !cpumask_test_cpu(later_rq->cpu, &task->cpus_allowed) || task_running(rq, task) || !dl_task(task) || !task_on_rq_queued(task))) { cpu2 cpu1 cpu0 push_dl_task(rq1) pick task_A on rq1 find rq0 double_lock_balance(rq1, rq0) unlock(rq1) rq1 __schedule pick task_A run task_A sleep (dequeued) lock(rq0) lock(rq1) do_above_check(task_A) task_rq(task_A) == rq1 cpus_allowed unchanged task_running == false dl_task(task_A) == true try_to_wake_up(task_A) select_cpu = cpu3 enqueue(rq3, task_A) task_A->on_rq = 1 task_on_rq_queued(task_A) above_check passed, return rq0 ... migrate task_A from rq1 to rq0 So we can't rely on these checks of task_A to make sure the task_A is still on the rq1, even though we hold the rq1->lock. This patch will repick the first pushable task to be sure the task is still on the rq. Signed-off-by: Li Bin --- kernel/sched/deadline.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 9df0978..87cd7ca 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1936,6 +1936,26 @@ static int find_later_rq(struct task_struct *task) return -1; } +static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) +{ + struct task_struct *p; + + if (!has_pushable_dl_tasks(rq)) + return NULL; + + p = rb_entry(rq->dl.pushable_dl_tasks_root.rb_leftmost, + struct task_struct, pushable_dl_tasks); + + BUG_ON(rq->cpu != task_cpu(p)); + BUG_ON(task_current(rq, p)); + BUG_ON(p->nr_cpus_allowed <= 1); + + BUG_ON(!task_on_rq_queued(p)); + BUG_ON(!dl_task(p)); + + return p; +} + /* Locks the rq it finds */ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) { @@ -1965,11 +1985,9 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) /* Retry if something changed. */ if (double_lock_balance(rq, later_rq)) { - if (unlikely(task_rq(task) != rq || - !cpumask_test_cpu(later_rq->cpu, &task->cpus_allowed) || - task_running(rq, task) || - !dl_task(task) || - !task_on_rq_queued(task))) { + struct task_struct *next_task = pick_next_pushable_dl_task(rq); + if (unlikely(next_task != task || + !cpumask_test_cpu(later_rq->cpu, &task->cpus_allowed))) { double_unlock_balance(rq, later_rq); later_rq = NULL; break; @@ -1994,26 +2012,6 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq) return later_rq; } -static struct task_struct *pick_next_pushable_dl_task(struct rq *rq) -{ - struct task_struct *p; - - if (!has_pushable_dl_tasks(rq)) - return NULL; - - p = rb_entry(rq->dl.pushable_dl_tasks_root.rb_leftmost, - struct task_struct, pushable_dl_tasks); - - BUG_ON(rq->cpu != task_cpu(p)); - BUG_ON(task_current(rq, p)); - BUG_ON(p->nr_cpus_allowed <= 1); - - BUG_ON(!task_on_rq_queued(p)); - BUG_ON(!dl_task(p)); - - return p; -} - /* * See if the non running -deadline tasks on this rq * can be sent to some other CPU where they can preempt -- 1.7.12.4