From patchwork Thu Feb 21 08:29:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 15011 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 72E7B2429C for ; Thu, 21 Feb 2013 08:29:33 +0000 (UTC) Received: from mail-vb0-f51.google.com (mail-vb0-f51.google.com [209.85.212.51]) by fiordland.canonical.com (Postfix) with ESMTP id 10F34A19BD7 for ; Thu, 21 Feb 2013 08:29:32 +0000 (UTC) Received: by mail-vb0-f51.google.com with SMTP id fq11so5467558vbb.38 for ; Thu, 21 Feb 2013 00:29:32 -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=Wb4GUy+FIaD2u2Wdwu15PYtOeVgIMqm2sHj7eVPgUcY=; b=o9TYmNHQHKoLA/02y80k7fYLYJj6097Yh1rQVG3AmMOskNtd1Vb/hKPV5/bNY+n+AL PvQvJA5JKkEQUGS9XUpMnmmEftEJRJP4JUekZWWxWnoDI0HUhBaQtCJn101nJ6jEfMs7 vKPxr/DZ5XACxlOXO+CiG/9+KOVApaf1e4pSQHg2OJdrfzNCVOZ3C/ZMkNQX8157YbGB ESrNbwHTojIJgnvPH0l9Tc25DEc6Pj3514Qja+vcX8tBf1bOmdLhjOM2meUpYP+8WLKo x8/IjBiDqRSDPHsl7+qGVmEIzo37dFu5eO77iOlhTgySpvLYMK8QrMGHcuPPy7ocGVhO uWLA== X-Received: by 10.52.18.148 with SMTP id w20mr26039529vdd.8.1361435372307; Thu, 21 Feb 2013 00:29:32 -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.145.101 with SMTP id st5csp4920veb; Thu, 21 Feb 2013 00:29:31 -0800 (PST) X-Received: by 10.180.98.98 with SMTP id eh2mr39679751wib.7.1361435370731; Thu, 21 Feb 2013 00:29:30 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by mx.google.com with ESMTPS id n9si7852495wia.81.2013.02.21.00.29.30 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Feb 2013 00:29:30 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.45 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=74.125.82.45; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.45 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-wg0-f45.google.com with SMTP id dq12so7387867wgb.24 for ; Thu, 21 Feb 2013 00:29:30 -0800 (PST) X-Received: by 10.194.242.69 with SMTP id wo5mr39318045wjc.10.1361435370146; Thu, 21 Feb 2013 00:29:30 -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 bj9sm35460185wib.4.2013.02.21.00.29.28 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Feb 2013 00:29:29 -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 v4] sched: fix init NOHZ_IDLE flag Date: Thu, 21 Feb 2013 09:29:16 +0100 Message-Id: <1361435356-28466-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQknojLpgrqhfa387Oy5LWjRn17W9zoc5np5o7FVUQZkq2VMtF5DYVJS5mdGRix+Hw9qNPVT On my smp platform which is made of 5 cores in 2 clusters, I have the nr_busy_cpu field of sched_group_power struct that is not null when the platform is fully idle. The root cause seems to be: During the boot sequence, some CPUs reach the idle loop and set their NOHZ_IDLE flag while waiting for others CPUs to boot. But the nr_busy_cpus field is initialized later with the assumption that all CPUs are in the busy state whereas some CPUs have already set their NOHZ_IDLE flag. During the initialization of the sched_domain, we set the NOHZ_IDLE flag when nr_busy_cpus is initialized to 0 in order to have a coherent configuration. If a CPU enters idle and call set_cpu_sd_state_idle during the build of the new sched_domain it will not corrupt the initial state set_cpu_sd_state_busy is modified and clears the NOHZ_IDLE only if a non NULL sched_domain is attached to the CPU (which is the case during the rebuild) Change since V3; - NOHZ flag is not cleared if a NULL domain is attached to the CPU - Remove patch 2/2 which becomes useless with latest modifications Change since V2: - change the initialization to idle state instead of busy state so a CPU that enters idle during the build of the sched_domain will not corrupt the initialization state Change since V1: - remove the patch for SCHED softirq on an idle core use case as it was a side effect of the other use cases. Signed-off-by: Vincent Guittot --- kernel/sched/core.c | 4 +++- kernel/sched/fair.c | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 26058d0..c730a4e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5884,7 +5884,9 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) return; update_group_power(sd, cpu); - atomic_set(&sg->sgp->nr_busy_cpus, sg->group_weight); + atomic_set(&sg->sgp->nr_busy_cpus, 0); + set_bit(NOHZ_IDLE, nohz_flags(cpu)); + } int __weak arch_sd_sibling_asym_packing(void) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 81fa536..2701a92 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5403,15 +5403,20 @@ static inline void set_cpu_sd_state_busy(void) { struct sched_domain *sd; int cpu = smp_processor_id(); + int clear = 0; if (!test_bit(NOHZ_IDLE, nohz_flags(cpu))) return; - clear_bit(NOHZ_IDLE, nohz_flags(cpu)); rcu_read_lock(); - for_each_domain(cpu, sd) + for_each_domain(cpu, sd) { atomic_inc(&sd->groups->sgp->nr_busy_cpus); + clear = 1; + } rcu_read_unlock(); + + if (likely(clear)) + clear_bit(NOHZ_IDLE, nohz_flags(cpu)); } void set_cpu_sd_state_idle(void)