From patchwork Mon Nov 3 10:30:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 40011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7A32E21894 for ; Mon, 3 Nov 2014 10:31:29 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf6041485wgg.9 for ; Mon, 03 Nov 2014 02:31:28 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=xKD6iGh/+M0cvk3WqdwRk1vIr7zoIX9MqGijtSpn37c=; b=ZujejsY6CsrR3plYFOKcvWtunJIDgAA1IxB+eAexWndeTe5dkGkYh9SZxB8QUgEgld k6kvP3NfxhKBt4mhTxJ3MrirD4FY/2gHLOZdffjKi0mYcr+FNSnEMXB0fIzXDF81rFcG 3QLAkcj8TnSrdt6WM/YAlbUd+z+JEiAiRTR32nthRY0WtTbIIIjFB54/KDz4f7hJs5Iz ch+J7X+nS0HY0JroQ3ADIFiSTXa25EqgUzEgqaaxLRKK5nnmseBqJm8IZmmKLNzLFaub sKiWuS0HOJIjnQhk/z0qZCMtMZ8GERVxAmudOh20UFnnW06ZhR+fHzzHIa69sXXosWj0 RoqA== X-Gm-Message-State: ALoCoQnWus//hiDk3QkrWfEiwjBXunmGg7hY3ic68rkIXdkxrhUlOdGkYDCZDkiocKpfQl6CDFHM X-Received: by 10.181.27.135 with SMTP id jg7mr2694993wid.5.1415010688707; Mon, 03 Nov 2014 02:31:28 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.5 with SMTP id ca5ls564903lad.68.gmail; Mon, 03 Nov 2014 02:31:28 -0800 (PST) X-Received: by 10.112.85.138 with SMTP id h10mr49665464lbz.33.1415010688365; Mon, 03 Nov 2014 02:31:28 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id xm7si31837412lbb.97.2014.11.03.02.31.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 02:31:28 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id s18so4697617lam.28 for ; Mon, 03 Nov 2014 02:31:28 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr49464755lbc.34.1415010688260; Mon, 03 Nov 2014 02:31:28 -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.84.229 with SMTP id c5csp214088lbz; Mon, 3 Nov 2014 02:31:26 -0800 (PST) X-Received: by 10.70.109.169 with SMTP id ht9mr132253pdb.152.1415010686148; Mon, 03 Nov 2014 02:31:26 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ym5si14990207pab.161.2014.11.03.02.31.25 for ; Mon, 03 Nov 2014 02:31:26 -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 S1751174AbaKCKbR (ORCPT + 25 others); Mon, 3 Nov 2014 05:31:17 -0500 Received: from mail-pd0-f170.google.com ([209.85.192.170]:44719 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750959AbaKCKbP (ORCPT ); Mon, 3 Nov 2014 05:31:15 -0500 Received: by mail-pd0-f170.google.com with SMTP id z10so11255950pdj.15 for ; Mon, 03 Nov 2014 02:31:15 -0800 (PST) X-Received: by 10.70.5.227 with SMTP id v3mr82343pdv.165.1415010675411; Mon, 03 Nov 2014 02:31:15 -0800 (PST) Received: from wangdeqiang.com ([210.21.223.3]) by mx.google.com with ESMTPSA id no8sm16803468pdb.63.2014.11.03.02.31.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 02:31:14 -0800 (PST) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , "pang.xunlei" Subject: [PATCH 1/3] sched/cpupri: Deal with cpupri.pri_to_cpu[CPUPRI_IDLE] for idle cases Date: Mon, 3 Nov 2014 18:30:18 +0800 Message-Id: <1415010620-6176-1-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.9.5 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.41 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: , When a runqueue runs out of RT tasks, it may have non-RT tasks or none tasks(idle). Currently, RT balance treats the two cases equally and manipulates cpupri.pri_to_cpu[CPUPRI_NORMAL] only which may cause problems. For instance, 4 cpus system, non-RT task1 is running on cpu0, RT task2 is running on cpu3, cpu1/cpu2 both are idle. Then RT task3 (usually CPU-intensive) is waken up or created on cpu3, it will be placed to cpu0 (see find_lowest_rq()) causing task1 starving until cfs load balance places task1 to another cpu, or even worse if task1 is bound on cpu0. So, it would be reasonable to put task3 to cpu1 or cpu2 which is idle(even though doing this may break the energy-saving idle state). This patch tackles the problem by operating pri_to_cpu[CPUPRI_IDLE] of cpupri according to the stages of idle task, so that when pushing or selecting RT tasks through find_lowest_rq(), it will try to find one idle cpu as the goal. Signed-off-by: pang.xunlei --- kernel/sched/idle_task.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c index 67ad4e7..3dc372e 100644 --- a/kernel/sched/idle_task.c +++ b/kernel/sched/idle_task.c @@ -26,6 +26,15 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl static struct task_struct * pick_next_task_idle(struct rq *rq, struct task_struct *prev) { +#ifdef CONFIG_SMP + struct cpupri *cp = &rq->rd->cpupri; + int currpri = cp->cpu_to_pri[rq->cpu]; + + BUG_ON(currpri != CPUPRI_NORMAL); + /* Set CPUPRI_IDLE bitmap for this cpu */ + cpupri_set(cp, rq->cpu, MAX_PRIO); +#endif + put_prev_task(rq, prev); schedstat_inc(rq, sched_goidle); @@ -47,6 +56,18 @@ dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags) static void put_prev_task_idle(struct rq *rq, struct task_struct *prev) { +#ifdef CONFIG_SMP + struct cpupri *cp = &rq->rd->cpupri; + int currpri = cp->cpu_to_pri[rq->cpu]; + + /* + * Set CPUPRI_NORMAL bitmap for this cpu when exiting from idle. + * RT tasks may be queued beforehand, so the judgement is needed. + */ + if (currpri == CPUPRI_IDLE) + cpupri_set(cp, rq->cpu, MAX_RT_PRIO); +#endif + idle_exit_fair(rq); rq_last_tick_reset(rq); }