From patchwork Wed Feb 13 08:54:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 14773 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 88D0B23EAD for ; Wed, 13 Feb 2013 08:54:54 +0000 (UTC) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by fiordland.canonical.com (Postfix) with ESMTP id 2B727A183EC for ; Wed, 13 Feb 2013 08:54:54 +0000 (UTC) Received: by mail-vb0-f48.google.com with SMTP id fc21so612036vbb.7 for ; Wed, 13 Feb 2013 00:54:53 -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=1mBvwTohD+7iy6UQFjYdgFkM5kB7OFsSHX6lLA4rp8M=; b=ob+Rxj/WgZJn0eDQnXc21l5qDAezd0ZNtvPKIfbluk3D1wXHOYWda82xeANljT+KoQ BJG/1YlnPhltfqmw4/A4rK7F+yq3rWeB9NtqirHlflOHHv7Zm2LjppDjOucwV1HUK78L 2UQ66RDfnybaTEk71N0mkJkP6JOK9XBLs/ILNKKXlc3JEgNzLniPiRK2eczZ8bE6mBEY oVWmBvzxbKcoOJBM79/y/rx/XHPb8pS1QNmtRPGPY4Ha6rs0KY5cmEeS3iIObXbmT+vw m763FRx4l4qk8a/a3T6BWyEZX+8rIVM83sjYIluDAa6qmP30d92h+NXm2yrJq+EHEEOo lyUA== X-Received: by 10.52.175.66 with SMTP id by2mr24794063vdc.53.1360745693606; Wed, 13 Feb 2013 00:54:53 -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.221.4.5 with SMTP id oa5csp182381vcb; Wed, 13 Feb 2013 00:54:52 -0800 (PST) X-Received: by 10.180.79.201 with SMTP id l9mr8215795wix.20.1360745692344; Wed, 13 Feb 2013 00:54:52 -0800 (PST) Received: from mail-we0-x22b.google.com ([2a00:1450:400c:c03::22b]) by mx.google.com with ESMTPS id e4si3323937wjw.57.2013.02.13.00.54.51 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Feb 2013 00:54:52 -0800 (PST) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::22b is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=2a00:1450:400c:c03::22b; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c03::22b 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-f171.google.com with SMTP id u54so806729wey.30 for ; Wed, 13 Feb 2013 00:54:51 -0800 (PST) X-Received: by 10.194.236.166 with SMTP id uv6mr36190908wjc.34.1360745691633; Wed, 13 Feb 2013 00:54:51 -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 m6sm44646616wic.2.2013.02.13.00.54.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Feb 2013 00:54:50 -0800 (PST) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org, peterz@infradead.org, mingo@kernel.org, fweisbec@gmail.com, rostedt@goodmis.org, efault@gmx.de Cc: Vincent Guittot Subject: [PATCH v3] sched: fix wrong rq's runnable_avg update with rt task Date: Wed, 13 Feb 2013 09:54:29 +0100 Message-Id: <1360745669-7996-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnAdcbOAAKQIaMPC9ZXO1vl1xqdV9mHFfxxsaNRt2njXfDvJeCGasDxi7rUDSR5sRmDEAk+ 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. Changes since V2: - remove useless definition for UP platform - rebased on top of Steven Rostedt's patches : https://lkml.org/lkml/2013/2/12/558 Changes since V1: - move code out of schedule function and create a pre_schedule callback for idle class instead. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 10 ++++++++++ kernel/sched/idle_task.c | 7 +++++++ kernel/sched/sched.h | 1 + 3 files changed, 18 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0fcdbff..6af5db3 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/idle_task.c b/kernel/sched/idle_task.c index 66b5220..6e7e63c 100644 --- a/kernel/sched/idle_task.c +++ b/kernel/sched/idle_task.c @@ -14,6 +14,12 @@ select_task_rq_idle(struct task_struct *p, int sd_flag, int flags) return task_cpu(p); /* IDLE tasks as never migrated */ } +static void pre_schedule_idle(struct rq *rq, struct task_struct *prev) +{ + /* Update rq's load with elapsed idle time */ + idle_exit(smp_processor_id(), rq); +} + static void post_schedule_idle(struct rq *rq) { idle_balance(smp_processor_id(), rq); @@ -95,6 +101,7 @@ const struct sched_class idle_sched_class = { #ifdef CONFIG_SMP .select_task_rq = select_task_rq_idle, + .pre_schedule = pre_schedule_idle, .post_schedule = post_schedule_idle, #endif diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index fc88644..5f26c93f 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 */