From patchwork Mon Apr 22 15:38:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 16324 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D5A2A23919 for ; Mon, 22 Apr 2013 15:39:40 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id b41sf11545557yha.1 for ; Mon, 22 Apr 2013 08:38:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=Ib0+QXK1iYqOGdSPm0w+kh47EY0SVZW6h5bvzMID6OQ=; b=blFUqsx4Pqqmgu+YUv09aLbYknEfb7bKptZKi5nl+XXXwY9WjF1IjYkoh2MqFu6DKW dRHAwDbSnqwbZqakdeMEqzEgOZ50QU9o9mb9Uy7p2H1uWYtD9Erpwcez4kTruOw1XQ+y 2BBXextYjv+5DJj66jWm6e7XaA32GxAAx5USA55mN6ynVhV3VQeOhHspxERo2d/yk+jB msy/5PPOKIm5h5L7wn8kVHMbe/LzdapUupCKXiNStGTMmfhAqNjobqsAwWgEQVW2JmpD r3zPpw3HhRwpbesIESw79it4k7Pl6MDLrwUbaajPfe9CDqOi5yXEopucXqF8a8POgx9l 5ztQ== X-Received: by 10.224.185.17 with SMTP id cm17mr6243061qab.6.1366645133969; Mon, 22 Apr 2013 08:38:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.87.103 with SMTP id w7ls3182832qez.83.gmail; Mon, 22 Apr 2013 08:38:53 -0700 (PDT) X-Received: by 10.221.3.2 with SMTP id nw2mr16041446vcb.55.1366645133789; Mon, 22 Apr 2013 08:38:53 -0700 (PDT) Received: from mail-vb0-x22a.google.com (mail-vb0-x22a.google.com [2607:f8b0:400c:c02::22a]) by mx.google.com with ESMTPS id q13si16174255vcw.82.2013.04.22.08.38.53 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 08:38:53 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c02::22a is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c02::22a; Received: by mail-vb0-f42.google.com with SMTP id p12so6022256vbe.15 for ; Mon, 22 Apr 2013 08:38:53 -0700 (PDT) X-Received: by 10.52.228.71 with SMTP id sg7mr16072842vdc.51.1366645133403; Mon, 22 Apr 2013 08:38:53 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp83039veb; Mon, 22 Apr 2013 08:38:51 -0700 (PDT) X-Received: by 10.194.133.198 with SMTP id pe6mr53728349wjb.9.1366645129724; Mon, 22 Apr 2013 08:38:49 -0700 (PDT) Received: from mail-wg0-x230.google.com (mail-wg0-x230.google.com [2a00:1450:400c:c00::230]) by mx.google.com with ESMTPS id by4si958772wjc.146.2013.04.22.08.38.48 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 08:38:49 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c00::230 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=2a00:1450:400c:c00::230; Received: by mail-wg0-f48.google.com with SMTP id f11so1010286wgh.3 for ; Mon, 22 Apr 2013 08:38:48 -0700 (PDT) X-Received: by 10.180.185.179 with SMTP id fd19mr7851137wic.1.1366645128762; Mon, 22 Apr 2013 08:38:48 -0700 (PDT) Received: from localhost.localdomain (LPuteaux-156-14-44-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPSA id nf9sm3103433wic.3.2013.04.22.08.38.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 08:38:47 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, peterz@infradead.org, mingo@kernel.org, fweisbec@gmail.com, pjt@google.com, rostedt@goodmis.org, efault@gmx.de Cc: Vincent Guittot Subject: [PATCH v7] sched: fix init NOHZ_IDLE flag Date: Mon, 22 Apr 2013 17:38:06 +0200 Message-Id: <1366645086-20345-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnRSqpQkenDig+ulJAVLcw5shvtUOmta+udo/xwCbo2ntVFzgiGjsTQLzTNAO+1UMyngyUX X-Original-Sender: vincent.guittot@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c02::22a is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 is: 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. More generally, the NOHZ_IDLE flag must be initialized when new sched_domains are created in order to ensure that NOHZ_IDLE and nr_busy_cpus are aligned. This condition can be ensured by adding a synchronize_rcu between the destruction of old sched_domains and the creation of new ones so the NOHZ_IDLE flag will not be updated with old sched_domain once it has been initialized. But this solution introduces a additionnal latency in the rebuild sequence that is called during cpu hotplug. As suggested by Frederic Weisbecker, another solution is to have the same rcu lifecycle for both NOHZ_IDLE and sched_domain struct. A new nohz_flags has been added to sched_domain so both flags and sched_domain will share the same RCU lifecycle and will be always synchronized. This solution is prefered to the creation of a new struct with an extra pointer indirection. The synchronization is done at the cost of : - An additional indirection and a rcu_dereference for accessing the NOHZ_IDLE flag. - We use only the nohz_flags field of the top sched_domain. Change since v6: - Add the flags in struct sched_domain instead of creating a sched_domain_rq. Change since v5: - minor variable and function name change. - remove a useless null check before kfree - fix a compilation error when NO_HZ is not set. Change since v4: - link both sched_domain and NOHZ_IDLE flag in one RCU object so their states are always synchronized. 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 --- include/linux/sched.h | 1 + kernel/sched/fair.c | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index d35d2b6..cde4f7f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -899,6 +899,7 @@ struct sched_domain { unsigned int wake_idx; unsigned int forkexec_idx; unsigned int smt_gain; + unsigned long nohz_flags; /* NOHZ_IDLE flag status */ int flags; /* See SD_* */ int level; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7a33e59..09e440f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5394,14 +5394,21 @@ static inline void set_cpu_sd_state_busy(void) { struct sched_domain *sd; int cpu = smp_processor_id(); - - if (!test_bit(NOHZ_IDLE, nohz_flags(cpu))) - return; - clear_bit(NOHZ_IDLE, nohz_flags(cpu)); + int first_nohz_idle = 1; rcu_read_lock(); - for_each_domain(cpu, sd) + for_each_domain(cpu, sd) { + if (first_nohz_idle) { + if (!test_bit(NOHZ_IDLE, &sd->nohz_flags)) + goto unlock; + + clear_bit(NOHZ_IDLE, &sd->nohz_flags); + first_nohz_idle = 0; + } + atomic_inc(&sd->groups->sgp->nr_busy_cpus); + } +unlock: rcu_read_unlock(); } @@ -5409,14 +5416,21 @@ void set_cpu_sd_state_idle(void) { struct sched_domain *sd; int cpu = smp_processor_id(); - - if (test_bit(NOHZ_IDLE, nohz_flags(cpu))) - return; - set_bit(NOHZ_IDLE, nohz_flags(cpu)); + int first_nohz_idle = 1; rcu_read_lock(); - for_each_domain(cpu, sd) + for_each_domain(cpu, sd) { + if (first_nohz_idle) { + if (test_bit(NOHZ_IDLE, &sd->nohz_flags)) + goto unlock; + + set_bit(NOHZ_IDLE, &sd->nohz_flags); + first_nohz_idle = 0; + } + atomic_dec(&sd->groups->sgp->nr_busy_cpus); + } +unlock: rcu_read_unlock(); }