From patchwork Thu Nov 20 17:28:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 41255 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EDA71241C9 for ; Thu, 20 Nov 2014 17:29:13 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf2330947wib.2 for ; Thu, 20 Nov 2014 09:29:13 -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=0bNpTrCEquIiDz6Nxk8bbcclPOBwxp+hVgT7AH4k3dI=; b=ULOj1SmDXh5JD5ej3s2at4DbsJxfmVPBPMMk7TYxpTeBp3XiapnUratMEO/yfi7YSw GepLpBAl2GlzKRuKMp3A2+6f7sbSWJSnKtVXNwUKNGnvi3Gl0RxZl6E+W/CRIQjMp1zq m0UmV94NXrgGgZYX6ih/pjkKPFMld34aqJ2nciDVAPE23yqcya7YQeFYky8QoV0eezEG Z6gVFGzEU7IrsijEAQYDdikaxUBngMywjdAABWRKd3tRzHHOL7x3OI6YGL/Ke19jzdCS pvm7F/iorB8rQSkOCLhgifwEEefesKYrUov8jpapRTlB9lISW2W3UebT6eZxwJlzFziN X5UA== X-Gm-Message-State: ALoCoQmgtk7LDNrGUdx+OlpP9Rk6bCoBBmeO6B7NJB//SEytdk0aDLPRTJ5t75nSbvWp4qNSLbHR X-Received: by 10.112.138.234 with SMTP id qt10mr5756281lbb.4.1416504553235; Thu, 20 Nov 2014 09:29:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.227 with SMTP id i3ls77424lae.28.gmail; Thu, 20 Nov 2014 09:29:12 -0800 (PST) X-Received: by 10.112.199.40 with SMTP id jh8mr49603635lbc.5.1416504552897; Thu, 20 Nov 2014 09:29:12 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id v4si2644989laj.106.2014.11.20.09.29.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 09:29:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id q1so2857111lam.11 for ; Thu, 20 Nov 2014 09:29:12 -0800 (PST) X-Received: by 10.152.9.7 with SMTP id v7mr427610laa.40.1416504552534; Thu, 20 Nov 2014 09:29:12 -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.184.201 with SMTP id ew9csp303336lbc; Thu, 20 Nov 2014 09:29:11 -0800 (PST) X-Received: by 10.68.218.7 with SMTP id pc7mr8602623pbc.80.1416504550023; Thu, 20 Nov 2014 09:29:10 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ga4si3949146pbb.176.2014.11.20.09.29.09 for ; Thu, 20 Nov 2014 09:29:10 -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 S1757827AbaKTR3G (ORCPT + 26 others); Thu, 20 Nov 2014 12:29:06 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:56223 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751911AbaKTR3C (ORCPT ); Thu, 20 Nov 2014 12:29:02 -0500 Received: by mail-pa0-f50.google.com with SMTP id bj1so2936330pad.23 for ; Thu, 20 Nov 2014 09:29:00 -0800 (PST) X-Received: by 10.70.92.201 with SMTP id co9mr32407703pdb.134.1416504538789; Thu, 20 Nov 2014 09:28:58 -0800 (PST) Received: from vptest-PC.zte.com.cn ([167.160.116.65]) by mx.google.com with ESMTPSA id tv4sm2604342pab.28.2014.11.20.09.28.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 09:28:58 -0800 (PST) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , "pang.xunlei" Subject: [PATCH v3 3/3] sched/deadline: Change the return meaning of cpudl_find() Date: Fri, 21 Nov 2014 01:28:05 +0800 Message-Id: <1416504485-8180-3-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1416504485-8180-1-git-send-email-pang.xunlei@linaro.org> References: <1416504485-8180-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.215.52 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: , cpudl_find() is not a good place to select the best cpu, so leave this role to its call site, currently it is find_later_rq() where we can do the election of the best cpu according to sd topology. This patch tackles cpudl_find() using a trick with its return value: - define macros for the return values of cpudl_find(): then, with return value >=0, means it returns the only available cpu. - In the leg of "if", it can just return CPUDL_FIND_CPUMASK, as we want to select the best_cpu in find_later_rq(). In the leg of "else if", just returns cpudl_maximum(cp), apparently there is no need to set the later_mask, since we will definitely select this cpu as the best_cpu in find_later_rq() . - Convert all its call sites to reflect this return meaning change. Sync find_later_rq()'s processing logic of best cpu election to that of RT find_lowest_rq(). Additionally, this patch avoids the extra cpumask_set_cpu() operation in cpudl_find() as well. Signed-off-by: pang.xunlei --- kernel/sched/cpudeadline.c | 16 +++++++--------- kernel/sched/cpudeadline.h | 3 +++ kernel/sched/deadline.c | 17 ++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c index c01b3aa..f17e6af 100644 --- a/kernel/sched/cpudeadline.c +++ b/kernel/sched/cpudeadline.c @@ -99,28 +99,26 @@ static inline int cpudl_maximum(struct cpudl *cp) * @p: the task * @later_mask: a mask to fill in with the selected CPUs (not NULL) * - * Returns: int - best CPU (heap maximum if suitable) + * Returns: int + * CPUDL_FIND_NONE: no available cpus; + * CPUDL_FIND_CPUMASK: available cpus in later_mask + * >=0: the only one available 0-based cpu */ int cpudl_find(struct cpudl *cp, struct task_struct *p, struct cpumask *later_mask) { - int best_cpu = -1; const struct sched_dl_entity *dl_se = &p->dl; cpumask_and(later_mask, cpu_active_mask, &p->cpus_allowed); if (cpumask_and(later_mask, later_mask, cp->free_cpus)) { - best_cpu = cpumask_any(later_mask); - goto out; + return CPUDL_FIND_CPUMASK; } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) && dl_time_before(dl_se->deadline, cp->elements[0].dl)) { - best_cpu = cpudl_maximum(cp); - cpumask_set_cpu(best_cpu, later_mask); + return cpudl_maximum(cp); } -out: - WARN_ON(best_cpu != -1 && !cpu_present(best_cpu)); - return best_cpu; + return CPUDL_FIND_NONE; } /* diff --git a/kernel/sched/cpudeadline.h b/kernel/sched/cpudeadline.h index 4a10a65..235f2b9 100755 --- a/kernel/sched/cpudeadline.h +++ b/kernel/sched/cpudeadline.h @@ -3,6 +3,9 @@ #include +#define CPUDL_FIND_NONE -2 /* no available cpus */ +#define CPUDL_FIND_CPUMASK -1 /* available cpus in later_mask */ + #define IDX_INVALID -1 struct cpudl_item { diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 03bb3f0..bb37506 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -980,7 +980,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p) * let's hope p can move out. */ if (rq->curr->nr_cpus_allowed == 1 || - cpudl_find(&rq->rd->cpudl, rq->curr, later_mask) == -1) + cpudl_find(&rq->rd->cpudl, rq->curr, later_mask) == CPUDL_FIND_NONE) return; /* @@ -988,7 +988,7 @@ static void check_preempt_equal_dl(struct rq *rq, struct task_struct *p) * see if it is pushed or pulled somewhere else. */ if (p->nr_cpus_allowed != 1 && - cpudl_find(&rq->rd->cpudl, p, later_mask) != -1) + cpudl_find(&rq->rd->cpudl, p, later_mask) != CPUDL_FIND_NONE) return; resched_curr(rq); @@ -1195,8 +1195,10 @@ static int find_later_rq(struct task_struct *task) */ best_cpu = cpudl_find(&task_rq(task)->rd->cpudl, task, later_mask); - if (best_cpu == -1) + if (best_cpu == CPUDL_FIND_NONE) return -1; + if (best_cpu != CPUDL_FIND_CPUMASK) + return best_cpu; /* * If we are here, some target has been found, @@ -1234,12 +1236,9 @@ static int find_later_rq(struct task_struct *task) return this_cpu; } - /* - * Last chance: if best_cpu is valid and is - * in the mask, that becomes our choice. - */ - if (best_cpu < nr_cpu_ids && - cpumask_test_cpu(best_cpu, sched_domain_span(sd))) { + best_cpu = cpumask_first_and(later_mask, + sched_domain_span(sd)); + if (best_cpu < nr_cpu_ids) { rcu_read_unlock(); return best_cpu; }