From patchwork Fri Jun 30 13:58:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 106709 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2369157qge; Fri, 30 Jun 2017 06:58:53 -0700 (PDT) X-Received: by 10.84.228.207 with SMTP id y15mr24668413pli.13.1498831133530; Fri, 30 Jun 2017 06:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498831133; cv=none; d=google.com; s=arc-20160816; b=VM4UnUAHU/Y9QhKLSyEDU3nQG3yDNd+VChTLlGLxzrUUquFT8o38AO7TfXpoT8X0HK 5+vFB+GVoSqbaOjX/a9BJZp9QyIKt4Wnm10uox1QJ3X6hJZRHHygRLldwupxuleN+Dl5 100o1ZhCvAQcUmD3sY8ffbhkiUzJYNhTuS++6EdV5eAOXgNozZId9p/ueE+dq+loq7jT hzDdWLxlgB9k2AaUrv77kECpf2sWgJuezNCFsiSdK1S6D0D0mR+dXrDgIlmq/vJePUQt EJLPkX2TyeMUbyqyj19K7saln8l4GFS9GKaFxn52IZ5w9SGIZ5aW/6ANRZKwI3hP3hd4 88SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=iQgQ942+Q1rbaGxzMcgDFRJhzNWe3Hc8JK73XgT27uE=; b=I9jBK6NBhv7gbxz/Ntt9QnIwevJGrUxLay954Z9UxMhMOwRhTEvd/4mB3mz+I7ovYk WqQ5NmnrsHM2ZpCL5mYEiSrmdXO0Lkkjd2ElYE7uX4+s7hHXartCEOXLB+stSD+IYSzZ fmd1/KgbbvNUOcqwdMvLGF0fdh8vqDN9xoknuqMhtlV4L3oii5Lkecr6cVzWMQIEOps4 atkh8Nvs55+U99UWWz87eJiG3R+4wAoe8VUxuNNvxn6U8K8NDVRd+sO02PDuGOeyBQg4 urAKaZKziSMU0hNVS9QiDMUsOfgbhNTqJM7i4SHuqtwJFpcYes0n6ueppZyr0UuNVQMg 3/6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=YNSLzP7K; 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 d3si5811001pfj.118.2017.06.30.06.58.53; Fri, 30 Jun 2017 06:58:53 -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=YNSLzP7K; 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 S1752137AbdF3N6q (ORCPT + 25 others); Fri, 30 Jun 2017 09:58:46 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38054 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751944AbdF3N6o (ORCPT ); Fri, 30 Jun 2017 09:58:44 -0400 Received: by mail-wm0-f47.google.com with SMTP id b184so46931775wme.1 for ; Fri, 30 Jun 2017 06:58:44 -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; bh=iQgQ942+Q1rbaGxzMcgDFRJhzNWe3Hc8JK73XgT27uE=; b=YNSLzP7KUg+66Q0lNa6HetKtkAUGJ7fndVhYkBaNB/j56ekifwsCo6zUh5y5V7vuXS T9pF5NRmPgfTiLOc0kFwjPHE0Ok4PrL7f1wPEfH3poG6xAfEzArpzHv4RufOk/JXdNm2 szWXoBuwZ8T9tnJC9X/4lO5UjTSyfhoYdoLbo= 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; bh=iQgQ942+Q1rbaGxzMcgDFRJhzNWe3Hc8JK73XgT27uE=; b=CTyOpxw5jW56chXDLWrFdKJ+mI2WwDoTpB/0YUMZx2aDFmhz6WT1bP1EPuL0ADZio6 DqbRpfwwLEGeENiz50kPM+jkhvsuiQZp4FPT6QX//OZuIUzsLENK6US0EHX43i/5cODK aT5uRhF/7eu4Jk5q5hieEIlQMAhcMSgrWcNaX9BpgQBJmUBf/IbtLqwBvNFimNFKf03h caLukOEL7n2p1vCGjHKBWoyKaIPqvtWTszQkPAMedimAXMYM4XqbeJbFW9S9OHvBt9WK 3qmJ7GA+qPgiwRbvdY5WThfardu8DGJpuc+wWD/SuwpH3/yPGZiwGpeiaDd0HGBWPxIE tyUw== X-Gm-Message-State: AKS2vOyhCiXjGWKuVKnl4qzeMF3zPHjJA+3uf0hd3CQkz0vUNmHmRHr5 9af160EVtEYRDjb9 X-Received: by 10.28.167.205 with SMTP id q196mr15667867wme.54.1498831123300; Fri, 30 Jun 2017 06:58:43 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:6194:6ddb:7983:d460]) by smtp.gmail.com with ESMTPSA id v96sm6585196wrc.53.2017.06.30.06.58.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jun 2017 06:58:42 -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] sched/pelt: fix false running accounting in PELT Date: Fri, 30 Jun 2017 15:58:38 +0200 Message-Id: <1498831118-22672-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 008c514..5fdcb42 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2968,6 +2968,24 @@ ___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 = 1; + + /* + * Scale time to reflect the amount a computation effectively done + * during the time slot at current capacity + */ + delta = scale_time(delta, cpu, sa, weight, running); + + /* * Now we know we crossed measurement unit boundaries. The *_avg * accrues by two steps: *