From patchwork Wed Apr 15 10:00:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 47172 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DA9862121F for ; Wed, 15 Apr 2015 10:01:39 +0000 (UTC) Received: by widjs5 with SMTP id js5sf10151084wid.3 for ; Wed, 15 Apr 2015 03:01:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=aeIKZsn5axyQmQMV+NT0LsNtxQYEG3c+8UzXV1xQVEo=; b=XqvIYO4eIFv51cPU7h2UwpMnihR4+X4BqDe/M98AMvK2YwsNR9T48YyFwcxgzYQ282 im1U2MlzbTahK8JQxPp/RWp5Us82BZmNk8cbeNePsKZLrtBUBTnlIkVDxiZPQl+VD4pl PMJ4/jclpD82MMUmLPX5XAX3UPXPf2GhizRarVHB796DWyzHVpaxeyQdkXsSw9et0UN/ 9deXIgCQFbf08eEzAomhZKJkU5UhlremDo+GXrTELR7GNM6GrLgzgiwE0Z1S/xyd8tzs v2Yjp3KNYDeFRs/3rqH5psNVJCZJE2k/W7dmfbgxmIDwH463zVBDba/r4/83tQY24gru 2Pcg== X-Gm-Message-State: ALoCoQksquN6xN2lBaudXBrAgWcjQHuMol1+o1pn/8P5VjCW/eWw4q1JMXzoW0Yi9AOwSBgfZI+j X-Received: by 10.112.29.39 with SMTP id g7mr4842823lbh.1.1429092099038; Wed, 15 Apr 2015 03:01:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.178.195 with SMTP id da3ls172710lac.30.gmail; Wed, 15 Apr 2015 03:01:38 -0700 (PDT) X-Received: by 10.112.167.36 with SMTP id zl4mr22476219lbb.22.1429092098883; Wed, 15 Apr 2015 03:01:38 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id u1si3490822lau.12.2015.04.15.03.01.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 03:01:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by layy10 with SMTP id y10so28635314lay.0 for ; Wed, 15 Apr 2015 03:01:38 -0700 (PDT) X-Received: by 10.152.234.169 with SMTP id uf9mr23033706lac.88.1429092098613; Wed, 15 Apr 2015 03:01:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp2400734lbt; Wed, 15 Apr 2015 03:01:37 -0700 (PDT) X-Received: by 10.70.88.108 with SMTP id bf12mr985483pdb.159.1429092096723; Wed, 15 Apr 2015 03:01:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ko11si6229303pbd.257.2015.04.15.03.01.35; Wed, 15 Apr 2015 03:01:36 -0700 (PDT) Received-SPF: none (google.com: linux-pm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755789AbbDOKB3 (ORCPT + 11 others); Wed, 15 Apr 2015 06:01:29 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:36456 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754407AbbDOKAj (ORCPT ); Wed, 15 Apr 2015 06:00:39 -0400 Received: by wgsk9 with SMTP id k9so40807282wgs.3 for ; Wed, 15 Apr 2015 03:00:37 -0700 (PDT) X-Received: by 10.194.221.100 with SMTP id qd4mr46822377wjc.113.1429092037041; Wed, 15 Apr 2015 03:00:37 -0700 (PDT) Received: from mai.lan (135-224-190-109.dsl.ovh.fr. [109.190.224.135]) by mx.google.com with ESMTPSA id z13sm5233590wjr.44.2015.04.15.03.00.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Apr 2015 03:00:36 -0700 (PDT) From: Daniel Lezcano To: peterz@infradead.org, rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, nicolas.pitre@linaro.org, Ingo Molnar Subject: [PATCH 3/3] sched: fair: Fix wrong idle timestamp usage Date: Wed, 15 Apr 2015 12:00:24 +0200 Message-Id: <1429092024-20498-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429092024-20498-1-git-send-email-daniel.lezcano@linaro.org> References: <1429092024-20498-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The find_idlest_cpu is assuming the rq->idle_stamp information reflects when the cpu entered the idle state. This is wrong as the cpu may exit and enter the idle state several times without the rq->idle_stamp being updated. We have two informations here: * rq->idle_stamp gives when the idle task has been scheduled * idle->idle_stamp gives when the cpu entered the idle state The patch fixes that by using the latter information and fallbacks to the rq's timestamp when the idle state is not accessible Signed-off-by: Daniel Lezcano --- kernel/sched/fair.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 46855d0..b44f1ad 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4704,21 +4704,35 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) if (idle_cpu(i)) { struct rq *rq = cpu_rq(i); struct cpuidle_state *idle = idle_get_state(rq); - if (idle && idle->exit_latency < min_exit_latency) { - /* - * We give priority to a CPU whose idle state - * has the smallest exit latency irrespective - * of any idle timestamp. - */ - min_exit_latency = idle->exit_latency; - latest_idle_timestamp = rq->idle_stamp; - shallowest_idle_cpu = i; - } else if ((!idle || idle->exit_latency == min_exit_latency) && - rq->idle_stamp > latest_idle_timestamp) { + + if (idle) { + if (idle->exit_latency < min_exit_latency) { + /* + * We give priority to a CPU + * whose idle state has the + * smallest exit latency + * irrespective of any idle + * timestamp. + */ + min_exit_latency = idle->exit_latency; + latest_idle_timestamp = idle->idle_stamp; + shallowest_idle_cpu = i; + } else if (idle->exit_latency == min_exit_latency && + idle->idle_stamp > latest_idle_timestamp) { + /* + * If the CPU is in the same + * idle state, choose the more + * recent one as it might have + * a warmer cache + */ + latest_idle_timestamp = idle->idle_stamp; + shallowest_idle_cpu = i; + } + } else if (rq->idle_stamp > latest_idle_timestamp) { /* - * If equal or no active idle state, then - * the most recently idled CPU might have - * a warmer cache. + * If no active idle state, then the + * most recent idled CPU might have a + * warmer cache */ latest_idle_timestamp = rq->idle_stamp; shallowest_idle_cpu = i;