From patchwork Mon Jan 19 04:49:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 43288 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EADE72034D for ; Mon, 19 Jan 2015 04:52:27 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf1659167eek.1 for ; Sun, 18 Jan 2015 20:52:26 -0800 (PST) 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=6nwjbpwZBFnI9vdDKEc92mzQZYD5nRDVD2qtmXf3RW8=; b=E5DDNNT7E6nUMW4pQ7XnXTdvI2lBR+SjpkZb3BSSRVS/MiO9+ziJeak0EWAJv98Vit EaKWjik0TF5Bqv2OFXgj2h79YXsJgR4G1+1eF39rynPl5ZU9PcHOvQVOsYyRMHEUPReD cz2l1S/1VjDMX/bIqsSHHFBw0fXf3WpjciKB31XQd7wbdmyU1b/a71G8S9TCqBBKyTnk 3I14a9fbcw4VyCqb85hEwuopRTddGJ6oMlhredixLaLrIX4ONykx2IGj5ExZfhq0jOvv 9b75MYGFsFou1XJlV4rN/95euVjMvHfB4j+unJ+IvowkuSYtZQzFJkmZW8064QOrIMLe BoGg== X-Gm-Message-State: ALoCoQlTS/GqdNvbcBTNtYNz3666i32uDz12I6SJm92mwMeHIfA82DP0tjBID+sb0rkTDhgxX13v X-Received: by 10.152.43.50 with SMTP id t18mr437480lal.3.1421643146718; Sun, 18 Jan 2015 20:52:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.225 with SMTP id i1ls540389lae.19.gmail; Sun, 18 Jan 2015 20:52:26 -0800 (PST) X-Received: by 10.152.5.101 with SMTP id r5mr15368294lar.33.1421643146417; Sun, 18 Jan 2015 20:52:26 -0800 (PST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id oe5si9965987lbb.2.2015.01.18.20.52.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 18 Jan 2015 20:52:26 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id p9so2934134lbv.8 for ; Sun, 18 Jan 2015 20:52:26 -0800 (PST) X-Received: by 10.152.8.11 with SMTP id n11mr27157939laa.38.1421643146324; Sun, 18 Jan 2015 20:52:26 -0800 (PST) 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.9.200 with SMTP id c8csp972660lbb; Sun, 18 Jan 2015 20:52:25 -0800 (PST) X-Received: by 10.70.134.97 with SMTP id pj1mr40929942pdb.125.1421643142296; Sun, 18 Jan 2015 20:52:22 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ao1si14334868pad.182.2015.01.18.20.52.21; Sun, 18 Jan 2015 20:52:22 -0800 (PST) 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 S1751797AbbASEwR (ORCPT + 28 others); Sun, 18 Jan 2015 23:52:17 -0500 Received: from mail-qc0-f171.google.com ([209.85.216.171]:39800 "EHLO mail-qc0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751221AbbASEv5 (ORCPT ); Sun, 18 Jan 2015 23:51:57 -0500 Received: by mail-qc0-f171.google.com with SMTP id s11so5795887qcv.2 for ; Sun, 18 Jan 2015 20:51:56 -0800 (PST) X-Received: by 10.140.97.102 with SMTP id l93mr31786287qge.48.1421643116809; Sun, 18 Jan 2015 20:51:56 -0800 (PST) Received: from ip-10-181-65-231.ec2.internal ([54.235.93.228]) by mx.google.com with ESMTPSA id k91sm4332434qgf.48.2015.01.18.20.51.56 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 18 Jan 2015 20:51:56 -0800 (PST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Juri Lelli , Xunlei Pang Subject: [PATCH 4/5] sched/rt: Consider deadline tasks in cpupri_find() Date: Mon, 19 Jan 2015 04:49:39 +0000 Message-Id: <1421642980-10045-4-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1421642980-10045-1-git-send-email-pang.xunlei@linaro.org> References: <1421642980-10045-1-git-send-email-pang.xunlei@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org 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: , Currently, RT global scheduling doesn't factor deadline tasks, this may cause some problems. See a case below: On a 3 CPU system, CPU0 has one running deadline task, CPU1 has one running low priority RT task or idle, CPU3 has one running high priority RT task. When another mid priority RT task is woken on CPU3, it will be pushed to CPU0(this also disturbs the deadline task on CPU0), while it is reasonable to put it on CPU1. This patch eliminates this issue by filtering CPUs that have runnable deadline tasks, using cpudl->free_cpus in cpupri_find(). NOTE: We want to make the most use of percpu local_cpu_mask to save an extra mask allocation, so always passing a non-NULL lowest_mask to cpupri_find(). Signed-off-by: Xunlei Pang --- kernel/sched/core.c | 2 ++ kernel/sched/cpupri.c | 22 +++++----------------- kernel/sched/cpupri.h | 1 + kernel/sched/rt.c | 9 +++++---- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ade2958..48c9576 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5652,6 +5652,8 @@ static int init_rootdomain(struct root_domain *rd) if (cpupri_init(&rd->cpupri) != 0) goto free_rto_mask; + + rd->cpupri.cpudl = &rd->cpudl; return 0; free_rto_mask: diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c index 981fcd7..40b8e81 100644 --- a/kernel/sched/cpupri.c +++ b/kernel/sched/cpupri.c @@ -32,6 +32,7 @@ #include #include #include "cpupri.h" +#include "cpudeadline.h" /* Convert between a 140 based task->prio, and our 102 based cpupri */ static int convert_prio(int prio) @@ -54,7 +55,7 @@ static int convert_prio(int prio) * cpupri_find - find the best (lowest-pri) CPU in the system * @cp: The cpupri context * @p: The task - * @lowest_mask: A mask to fill in with selected CPUs (or NULL) + * @lowest_mask: A mask to fill in with selected CPUs (not NULL) * * Note: This function returns the recommended CPUs as calculated during the * current invocation. By the time the call returns, the CPUs may have in @@ -103,24 +104,11 @@ int cpupri_find(struct cpupri *cp, struct task_struct *p, if (skip) continue; - if (cpumask_any_and(&p->cpus_allowed, vec->mask) >= nr_cpu_ids) + cpumask_and(lowest_mask, &p->cpus_allowed, vec->mask); + cpumask_and(lowest_mask, lowest_mask, cp->cpudl->free_cpus); + if (cpumask_any(lowest_mask) >= nr_cpu_ids) continue; - if (lowest_mask) { - cpumask_and(lowest_mask, &p->cpus_allowed, vec->mask); - - /* - * We have to ensure that we have at least one bit - * still set in the array, since the map could have - * been concurrently emptied between the first and - * second reads of vec->mask. If we hit this - * condition, simply act as though we never hit this - * priority level and continue on. - */ - if (cpumask_any(lowest_mask) >= nr_cpu_ids) - continue; - } - return 1; } diff --git a/kernel/sched/cpupri.h b/kernel/sched/cpupri.h index 63cbb9c..acd7ccf 100644 --- a/kernel/sched/cpupri.h +++ b/kernel/sched/cpupri.h @@ -18,6 +18,7 @@ struct cpupri_vec { struct cpupri { struct cpupri_vec pri_to_cpu[CPUPRI_NR_PRIORITIES]; int *cpu_to_pri; + struct cpudl *cpudl; }; #ifdef CONFIG_SMP diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 6725e3c..d28cfa4 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1349,14 +1349,17 @@ out: return cpu; } +static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask); static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) { + struct cpumask *lowest_mask = this_cpu_cpumask_var_ptr(local_cpu_mask); + /* * Current can't be migrated, useless to reschedule, * let's hope p can move out. */ if (rq->curr->nr_cpus_allowed == 1 || - !cpupri_find(&rq->rd->cpupri, rq->curr, NULL)) + !cpupri_find(&rq->rd->cpupri, rq->curr, lowest_mask)) return; /* @@ -1364,7 +1367,7 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) * see if it is pushed or pulled somewhere else. */ if (p->nr_cpus_allowed != 1 - && cpupri_find(&rq->rd->cpupri, p, NULL)) + && cpupri_find(&rq->rd->cpupri, p, lowest_mask)) return; /* @@ -1526,8 +1529,6 @@ static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu) return NULL; } -static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask); - static int find_lowest_rq(struct task_struct *task) { struct sched_domain *sd;