From patchwork Thu Apr 30 16:33:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 47858 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 12FC620553 for ; Thu, 30 Apr 2015 17:07:40 +0000 (UTC) Received: by wgtl5 with SMTP id l5sf17083149wgt.1 for ; Thu, 30 Apr 2015 10:07:39 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=2d12kcxA3d4vCw0TO8trlMPbAHamrOKRfM86ZeueafM=; b=L4aOiUUsUtzOp3bZhVoBCTLSD+Ryp3eoz3y3oyUadP7efss3FGhIqX8fwUS+sHVnGQ O0wYPc2l+9TwtNIAip5tSMDevY4Wz1xD2KWZh07VwYYzBfPGLmHYqaKIidn1gWGyFfo5 vHSV9rn2fcB4sWD8EQXxgiNswQVi5Dp9KfzCrr1cDwsrFUsT+eLq3wbj9lRnE3JkT0D/ KGLETx3pIAgqNEC29CrlOD4FRc5xAEeA+8meZX4DMaQXI9qgLjkVak8hGF73et3EebV5 YZ9oFWYxTxs+a+JMFoj+YNJwurIhb+m0QrNiBKWXn47eE/Af0AraFYtZ49eWVRH3QMBd p//w== X-Gm-Message-State: ALoCoQnsb3yiocZpxBbBtuL66v++Uv1VxRXwlLIiaJP4UYykf8bEsp5Dh3FfBLLS8PT+PEM9uHhi X-Received: by 10.112.118.162 with SMTP id kn2mr3148484lbb.22.1430413659360; Thu, 30 Apr 2015 10:07:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.35 with SMTP id cr3ls348473lad.47.gmail; Thu, 30 Apr 2015 10:07:39 -0700 (PDT) X-Received: by 10.152.121.42 with SMTP id lh10mr4910357lab.0.1430413659188; Thu, 30 Apr 2015 10:07:39 -0700 (PDT) Received: from mail-la0-x231.google.com (mail-la0-x231.google.com. [2a00:1450:4010:c03::231]) by mx.google.com with ESMTPS id x10si2171099lbo.118.2015.04.30.10.07.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Apr 2015 10:07:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::231 as permitted sender) client-ip=2a00:1450:4010:c03::231; Received: by laat2 with SMTP id t2so49280749laa.1 for ; Thu, 30 Apr 2015 10:07:38 -0700 (PDT) X-Received: by 10.112.161.226 with SMTP id xv2mr4795836lbb.106.1430413658872; Thu, 30 Apr 2015 10:07:38 -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 l1csp3237903lbt; Thu, 30 Apr 2015 10:07:38 -0700 (PDT) X-Received: by 10.68.161.99 with SMTP id xr3mr10011735pbb.47.1430413657121; Thu, 30 Apr 2015 10:07:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si4391138pdn.1.2015.04.30.10.07.35; Thu, 30 Apr 2015 10:07:37 -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 S1751476AbbD3RHc (ORCPT + 28 others); Thu, 30 Apr 2015 13:07:32 -0400 Received: from m50-112.126.com ([123.125.50.112]:50179 "EHLO m50-112.126.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750802AbbD3RHa (ORCPT ); Thu, 30 Apr 2015 13:07:30 -0400 Received: from vptest-PC.zte.com.cn (unknown [118.114.222.231]) by smtp6 (Coremail) with SMTP id j9KowAA3KO1PWUJVW+IHBQ--.69S3; Fri, 01 May 2015 00:33:30 +0800 (CST) From: Xunlei Pang To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Steven Rostedt , Juri Lelli , Ingo Molnar , Xunlei Pang Subject: [PATCH 1/2] sched/rt: Check to push task away when its affinity is changed Date: Fri, 1 May 2015 00:33:17 +0800 Message-Id: <1430411598-4904-1-git-send-email-xlpang@126.com> X-Mailer: git-send-email 2.0.4 X-CM-TRANSID: j9KowAA3KO1PWUJVW+IHBQ--.69S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFy3Jr48JFWruFW7uFyDZFb_yoW5Aw1fpF Wvy345Cw4DtFy0gw1fZw4kCr4Ygwn7Zw13Gan5Jr1SkFn0gr4Fqr4qqF43AFZIgr15CFW2 qrn0g3s7KF1jyaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jfvtAUUUUU= X-Originating-IP: [118.114.222.231] X-CM-SenderInfo: p0ost0bj6rjloofrz/1tbipB3rv1GogeKhOAABsv 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::231 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 enters schedule(), this definitely causes some/big response latency for rt2. This patch introduces a new sched_class::post_set_cpus_allowed() for RT called after set_cpus_allowed_rt(). In this new function, if the task is runnable but not running, it tries to push it away once it got migratable. Signed-off-by: Xunlei Pang --- kernel/sched/core.c | 3 +++ kernel/sched/rt.c | 17 +++++++++++++++++ kernel/sched/sched.h | 1 + 3 files changed, 21 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d13fc13..64a1603 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4773,6 +4773,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 cc49a7c..a9d33a3 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2281,6 +2281,22 @@ 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 (!task_running(rq, p) && + p->nr_cpus_allowed > 1 && + !test_tsk_need_resched(rq->curr) && + cpupri_find(&rq->rd->cpupri, p, NULL)) { + push_rt_tasks(rq); + } +} + /* Assumes rq->lock is held */ static void rq_online_rt(struct rq *rq) { @@ -2495,6 +2511,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);