From patchwork Sun Apr 26 17:10:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 47584 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F02D720553 for ; Sun, 26 Apr 2015 17:12:41 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf20336232lbb.0 for ; Sun, 26 Apr 2015 10:12:40 -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=v3W1buxhz1Lxsf021VW8pYTE+bLofYSlWTouBDBTgPM=; b=TWNrwa8CDPh2r2xCmZmRAeK/1Yw8eq3YEtGFJpZRP/Aqwm6uXXeRup047ZpQ4DH4rZ 1e6sCCsh1l2Qg4nRnPDExd6aRHXBT18UT0HYPn6JsyjiWMT/3o0byzpFp0EQv26sSWor jPwiOmwpvDFi08XGymjNQ6a3o9JNhNTxoWRTu/DdeK+Y0h2sHar11MYvpbcyVjYMYg+w M4O9RtJov6Fm4TdbrZwwQbsuQaXu1E5ebkHREwpOtaxe0PSUtuKS1ef7/AJ126LeUWsj dS1nk23eBbJDLckIgjhQahcLI2mxjPD8dyCCYSuvPKVT0LxwMn2FV5OACS7Tm8mKEZJA i11g== X-Gm-Message-State: ALoCoQnWK4ANvQw407Xbrowp7AwwgxmO7sYhvOnBdlTxrk06BRl7WWgpuDNDjxe3rx5aRJVOWa1D X-Received: by 10.180.106.136 with SMTP id gu8mr4804698wib.6.1430068360534; Sun, 26 Apr 2015 10:12:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.111 with SMTP id v15ls681138lal.5.gmail; Sun, 26 Apr 2015 10:12:40 -0700 (PDT) X-Received: by 10.112.147.73 with SMTP id ti9mr6868008lbb.108.1430068360338; Sun, 26 Apr 2015 10:12:40 -0700 (PDT) Received: from mail-la0-x22a.google.com (mail-la0-x22a.google.com. [2a00:1450:4010:c03::22a]) by mx.google.com with ESMTPS id qf3si12959945lbb.143.2015.04.26.10.12.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Apr 2015 10:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22a as permitted sender) client-ip=2a00:1450:4010:c03::22a; Received: by laat2 with SMTP id t2so65041786laa.1 for ; Sun, 26 Apr 2015 10:12:39 -0700 (PDT) X-Received: by 10.112.204.72 with SMTP id kw8mr6871023lbc.88.1430068359920; Sun, 26 Apr 2015 10:12:39 -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 l1csp868149lbt; Sun, 26 Apr 2015 10:12:39 -0700 (PDT) X-Received: by 10.66.243.69 with SMTP id ww5mr15262348pac.106.1430068358071; Sun, 26 Apr 2015 10:12:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ub8si7050624pbc.64.2015.04.26.10.12.36; Sun, 26 Apr 2015 10:12:38 -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 S1751262AbbDZRMZ (ORCPT + 27 others); Sun, 26 Apr 2015 13:12:25 -0400 Received: from m15-114.126.com ([220.181.15.114]:53267 "EHLO m15-114.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750887AbbDZRMW (ORCPT ); Sun, 26 Apr 2015 13:12:22 -0400 Received: from localhost.localdomain (unknown [220.166.221.63]) by smtp7 (Coremail) with SMTP id DsmowACX+G4iHD1V8BojAA--.830S3; Mon, 27 Apr 2015 01:11:07 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Ingo Molnar , Xunlei Pang Subject: [RFC PATCH 2/6] sched/rt: Check to push task away when its affinity is changed Date: Mon, 27 Apr 2015 01:10:54 +0800 Message-Id: <1430068258-1960-2-git-send-email-xlpang@126.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430068258-1960-1-git-send-email-xlpang@126.com> References: <1430068258-1960-1-git-send-email-xlpang@126.com> X-CM-TRANSID: DsmowACX+G4iHD1V8BojAA--.830S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFy3Jr13XFykWrWrXrWUJwb_yoW5ZFy5pa ykC345Cw4DJFy2gw1fXw4kur4Yg3s7Zw13JFs5tr1SkFs0gr4FqF4qqF43AF9Igr15CFW2 qrn0gr92gr1jyaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jKYL9UUUUU= X-Originating-IP: [220.166.221.63] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbiXAvnv1R0V4Y03QAAsX 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:c03::22a 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 We may suffer from extra rt overload rq due to the affinity, so when the affinity of any runnable rt task is changed, we should check to trigger balancing, otherwise it will cause some unnecessary delayed real-time response. Unfortunately, current RT global scheduler does nothing about this. For example: a 2-cpu system with two runnable FIFO tasks(same rt_priority) bound on CPU0, let's name them rt1(running) and rt2(runnable) respectively; CPU1 has no RTs. Then, someone sets the affinity of rt2 to 0x3(i.e. CPU0 and CPU1), but after this, rt2 still can't be scheduled until rt1 enters schedule(), this definitely causes some/big response latency for rt2. This patch introduces new sched_class::post_set_cpus_allowed() for rt called after set_cpus_allowed_rt(). In this new function, it triggers a push action when detecting such cases. Signed-off-by: Xunlei Pang --- kernel/sched/core.c | 3 +++ kernel/sched/rt.c | 24 ++++++++++++++++++++++++ kernel/sched/sched.h | 1 + 3 files changed, 28 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f9123a8..dc646a6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4769,6 +4769,9 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask) cpumask_copy(&p->cpus_allowed, new_mask); p->nr_cpus_allowed = cpumask_weight(new_mask); + + if (p->sched_class->post_set_cpus_allowed) + p->sched_class->post_set_cpus_allowed(p); } /* diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 6b40555..7b76747 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2136,6 +2136,29 @@ static void set_cpus_allowed_rt(struct task_struct *p, update_rt_migration(&rq->rt); } +static void post_set_cpus_allowed_rt(struct task_struct *p) +{ + struct rq *rq; + + if (!task_on_rq_queued(p)) + return; + + rq = task_rq(p); + if (p->nr_cpus_allowed > 1 && + rq->rt.rt_nr_running > 1 && + rt_task(rq->curr) && !test_tsk_need_resched(rq->curr)) { + if (!task_running(rq, p)) { + push_rt_task(rq); + } else if (cpumask_test_cpu(task_cpu(p), &p->cpus_allowed)) { + /* + * p(current) may get migratable due to the change + * of its affinity, let's try to push it away. + */ + check_preempt_equal_prio_common(rq); + } + } +} + /* Assumes rq->lock is held */ static void rq_online_rt(struct rq *rq) { @@ -2350,6 +2373,7 @@ const struct sched_class rt_sched_class = { .select_task_rq = select_task_rq_rt, .set_cpus_allowed = set_cpus_allowed_rt, + .post_set_cpus_allowed = post_set_cpus_allowed_rt, .rq_online = rq_online_rt, .rq_offline = rq_offline_rt, .post_schedule = post_schedule_rt, diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e0e1299..6f90645 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1191,6 +1191,7 @@ struct sched_class { void (*set_cpus_allowed)(struct task_struct *p, const struct cpumask *newmask); + void (*post_set_cpus_allowed)(struct task_struct *p); void (*rq_online)(struct rq *rq); void (*rq_offline)(struct rq *rq);