From patchwork Fri Feb 8 11:11:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 14696 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C8F1F23F99 for ; Fri, 8 Feb 2013 11:12:05 +0000 (UTC) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by fiordland.canonical.com (Postfix) with ESMTP id 646FAA1825F for ; Fri, 8 Feb 2013 11:12:05 +0000 (UTC) Received: by mail-vc0-f172.google.com with SMTP id l6so2253258vcl.31 for ; Fri, 08 Feb 2013 03:12:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=fBZF5lXPsFv1oXZZQl8DOsYBvJ4H+4xSL5XYkhoqcyQ=; b=Li75HqwdjDH8ozyqPgUq4oIbpAyq4+VfCDLTPwzKobdBgxM3FuNJcFuvRlk1nlwpQb p3S9x3zHqt72945EOG+ABHp3JBT3OtwV1YehK3Tf2rGV/hSs+klCsPvUx79jXoCklLcC NGo3umiYiGB2b2A93j6YRe/l8Ur4klO9tgktn71FhGqFHvqUOuYEHkjOYUgX/0MDfwWv n53mOBo5JSa2vjLYrIdZQcxmLmFJ3RN38Qo2zvrzMnOdKeNq+M9deD16i/1WYNqww1rM 8H8aaCNhCHixxlKTVb+BUzJfsQtjxBI0JYxaJiJLZOrOjkAAtqPOkE4dP0DoFlQZOQEf /PWg== X-Received: by 10.220.149.200 with SMTP id u8mr5976885vcv.7.1360321924855; Fri, 08 Feb 2013 03:12:04 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp140035vec; Fri, 8 Feb 2013 03:12:04 -0800 (PST) X-Received: by 10.180.106.231 with SMTP id gx7mr1726925wib.4.1360321923680; Fri, 08 Feb 2013 03:12:03 -0800 (PST) Received: from mail-we0-x22c.google.com ([2a00:1450:400c:c03::22c]) by mx.google.com with ESMTPS id fh7si3122915wib.71.2013.02.08.03.12.03 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Feb 2013 03:12:03 -0800 (PST) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22c is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=2a00:1450:400c:c03::22c; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c03::22c is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) smtp.mail=vincent.guittot@linaro.org Received: by mail-we0-f172.google.com with SMTP id x10so2892074wey.31 for ; Fri, 08 Feb 2013 03:12:03 -0800 (PST) X-Received: by 10.180.80.35 with SMTP id o3mr1735545wix.9.1360321923029; Fri, 08 Feb 2013 03:12:03 -0800 (PST) Received: from localhost.localdomain (LPuteaux-156-14-44-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPS id q13sm14113817wie.0.2013.02.08.03.12.01 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Feb 2013 03:12:02 -0800 (PST) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, peterz@infradead.org, mingo@kernel.org, pjt@google.com, rostedt@goodmis.org, fweisbec@gmail.com Cc: Vincent Guittot Subject: [PATCH] sched: fix wrong rq's runnable_avg update with rt task Date: Fri, 8 Feb 2013 12:11:27 +0100 Message-Id: <1360321887-18251-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQn3rwHzPrZG0n1BqNOPvboDm2HlcmF3DAh7VGTEg20CHghzwcUX6KHHULgfP2QPONBrjI4P When a RT task is scheduled on an idle CPU, the update of the rq's load is not done because CFS's functions are not called. Then, the idle_balance, which is called just before entering the idle function, updates the rq's load and makes the assumption that the elapsed time since the last update, was only running time. The rq's load of a CPU that only runs a periodic RT task, is close to LOAD_AVG_MAX whatever the running duration of the RT task is. A new idle_exit function is called when the prev task is the idle function so the elapsed time will be accounted as idle time in the rq's load. Signed-off-by: Vincent Guittot --- kernel/sched/core.c | 3 +++ kernel/sched/fair.c | 10 ++++++++++ kernel/sched/sched.h | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 26058d0..592e06c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2927,6 +2927,9 @@ need_resched: pre_schedule(rq, prev); + if (unlikely(prev == rq->idle)) + idle_exit(cpu, rq); + if (unlikely(!rq->nr_running)) idle_balance(cpu, rq); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5eea870..520fe55 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1562,6 +1562,16 @@ static inline void dequeue_entity_load_avg(struct cfs_rq *cfs_rq, se->avg.decay_count = atomic64_read(&cfs_rq->decay_counter); } /* migrations, e.g. sleep=0 leave decay_count == 0 */ } + +/* + * Update the rq's load with the elapsed idle time before a task is + * scheduled. if the newly scheduled task is not a CFS task, idle_exit will + * be the only way to update the runnable statistic. + */ +void idle_exit(int this_cpu, struct rq *this_rq) +{ + update_rq_runnable_avg(this_rq, 0); +} #else static inline void update_entity_load_avg(struct sched_entity *se, int update_cfs_rq) {} diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index fc88644..9707092 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -877,6 +877,7 @@ extern const struct sched_class idle_sched_class; extern void trigger_load_balance(struct rq *rq, int cpu); extern void idle_balance(int this_cpu, struct rq *this_rq); +extern void idle_exit(int this_cpu, struct rq *this_rq); #else /* CONFIG_SMP */ @@ -884,6 +885,10 @@ static inline void idle_balance(int cpu, struct rq *rq) { } +static inline void idle_exit(int this_cpu, struct rq *this_rq) +{ +} + #endif extern void sysrq_sched_debug_show(void);