From patchwork Sat Jul 1 05:06:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 106782 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp3121055qge; Fri, 30 Jun 2017 22:07:02 -0700 (PDT) X-Received: by 10.99.165.82 with SMTP id r18mr24563783pgu.65.1498885622180; Fri, 30 Jun 2017 22:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498885622; cv=none; d=google.com; s=arc-20160816; b=tMy6HNPVtSWWFo6hwDP4eYnBbEnBAfgCMctUtZfeszRK6VHnaVaUNEWrf6ufusiq2j iJn5r/4Y69MKsTToWP++2Vyk2ttTYV5j2LoUmeRPxjneTuIH5SIww1X6ddTZ/VvhbxzM 4HDT33lJ/7JDDkSJVZ8LwbMeCBfuooAzC/vqTX4COkMubgeHTGrdaE1DsTRHO8jM8djo EHXopcNM2uLutb6+ODBM6KbfmRXYER75qJWkDqetwVmqCKj4OpVt6M02Tp6dzCMrYfu2 xfdr6ZJAPEq6oCuEVMPjy6ioyqfjlSTbr+Ji0nluWxxhVwXaK0J35CnTWJCPbiFJ0ROX fspQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=wp9tGT6R7e8YkdQmkNzVH6YoOla4Pqs3m3NiqxeWjFU=; b=GtHP1f85LqHMTunOFukAQtJIkxzcxsGHkH4v1vsZS2Rhv6P4ikbMyd7kbi35KxYi+z nUALWc2HytdcUq0txCNLGZa14BmV0v0GXhYdgj+DC0zE4FzYmfeckDT60fuOCA/8Jx7A W04lAwOXNXEH4uBo4WNwgu7VSPkMhJVtLzaitnHFD3ixoiB8ldfwEjFrrIn1T2gyLAhy reyHV2SoHg6yckT4NcjJNwGhcxx9o9KxUoFZ7ZhFbAeyxk9vdBB+XeaWEAdc/WGgQb3g oWpfd7fsoJ9KnJfePBcgtahP4YF0O5+AEJBJkeKptTSN4o41Jo3pmSlWY330yj3eiPmc Uwxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Jvc/RNUI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si7547003pgp.88.2017.06.30.22.07.01; Fri, 30 Jun 2017 22:07:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=Jvc/RNUI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751825AbdGAFGr (ORCPT + 25 others); Sat, 1 Jul 2017 01:06:47 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:35905 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751233AbdGAFGp (ORCPT ); Sat, 1 Jul 2017 01:06:45 -0400 Received: by mail-wr0-f179.google.com with SMTP id c11so212345907wrc.3 for ; Fri, 30 Jun 2017 22:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wp9tGT6R7e8YkdQmkNzVH6YoOla4Pqs3m3NiqxeWjFU=; b=Jvc/RNUIVGvpG4EP8+N0kC4MR19pwE3REPN8k5HQIZrWoZkTfaWfzePaSWZ9nJkdKC k4EJhF9yRC6lLWgjnCZc/MahE5JgacGuJYoWqnqEQTURrnN6Ndavl0m7XohTpzzhfXtg jPjqTV6ZOl9kC8vqDvcaRTBF0ZNW5A3tLfDgg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wp9tGT6R7e8YkdQmkNzVH6YoOla4Pqs3m3NiqxeWjFU=; b=hzj/tVnD37OoDVggCK46UCT+hnvupjyuxGHFVDIjfy5uLDjJkyv6aDtLZkDUMWWmCo N+YCHF4Rq3wzNJaLA63O7kBHxvuN9GxAzgWziinKlJtULCSh65GA1+93PnL33Pz0FgDj irPmw7Sa8sId0fFs2VdSnFaVMGoox+QErVgJmZyuzcMUVqwtE/m4z8joPXUOxbrcNVlZ zaXJWwKh8V6buamyq45pH5KRaId4Bk0tZFkZITI/YcFiY2Th4zCWcjhpqN9L3d9siET3 YBhuQUzisEWlfi+eZEBq199wwUfV9GPUaZ9K+uoybDlga4CDCFwtogjNCrQEp220Cc1m 8byg== X-Gm-Message-State: AKS2vOwXRgzpQywlzSU4tPab09lfWNfmp3cv22dEVbcxH0FgCIuGiIIW ekoa5gENz/W+ySFP X-Received: by 10.223.148.226 with SMTP id 89mr28731863wrr.169.1498885604371; Fri, 30 Jun 2017 22:06:44 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:6194:6ddb:7983:d460]) by smtp.gmail.com with ESMTPSA id 31sm5275711wrd.20.2017.06.30.22.06.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jun 2017 22:06:43 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: dietmar.eggemann@arm.com, Morten.Rasmussen@arm.com, Vincent Guittot Subject: [PATCH v2] sched/pelt: fix false running accounting Date: Sat, 1 Jul 2017 07:06:13 +0200 Message-Id: <1498885573-18984-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498831118-22672-1-git-send-email-vincent.guittot@linaro.org> References: <1498831118-22672-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The running state is a subset of runnable state which means that running can't be set if runnable (weight) is cleared. There are corner cases where the current sched_entity has been already dequeued but cfs_rq->curr has not been updated yet and still points to the dequeued sched_entity. If ___update_load_avg is called at that time, weight will be 0 and running will be set which is not possible. This case happens during pick_next_task_fair() when a cfs_rq becomes idles. The current sched_entity has been dequeued so se->on_rq is cleared and cfs_rq->weight is null. But cfs_rq->curr still points to se (it will be cleared when picking the idle thread). Because the cfs_rq becomes idle, idle_balance() is called and ends up to call update_blocked_averages() with these wrong running and runnable states. Add a test in ___update_load_avg to correct the running state in this case. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 008c514..bc36a75 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2968,6 +2968,18 @@ ___update_load_avg(u64 now, int cpu, struct sched_avg *sa, sa->last_update_time += delta << 10; /* + * running is a subset of runnable (weight) so running can't be set if + * runnable is clear. But there are some corner cases where the current + * se has been already dequeued but cfs_rq->curr still points to it. + * This means that weight will be 0 but not running for a sched_entity + * but also for a cfs_rq if the latter becomes idle. As an example, + * this happens during idle_balance() which calls + * update_blocked_averages() + */ + if (!weight) + running = 0; + + /* * Now we know we crossed measurement unit boundaries. The *_avg * accrues by two steps: *