Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7596422imu; Mon, 3 Dec 2018 15:49:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/UpbLrIJJx8Ch4nWlrmBP9Lqo+BkiZaXe5g+hqlIqk6iKG9DX20zd8tkB8FgwHl4wIkxG56 X-Received: by 2002:a17:902:4d46:: with SMTP id o6mr17035559plh.302.1543880988894; Mon, 03 Dec 2018 15:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543880988; cv=none; d=google.com; s=arc-20160816; b=zrMNnOYfcKHbiSbyGJssl6jbYnYRRCwDASXhdQC5P9eijrgOCVNk++bhYH2l/JG6ZJ QLJJ5yi2SEkM5iWdif1j97iQ3zgUFuNRGsSYJnsZShIfKqZzYbHK4DTRm8rEWHXtGF47 I8A1Hn4Nq3CibvfxLEBltRu8pYJbRV2E/HOLpub3EcARXh2s5Lw1I+mFuua6lmjb/K6O Yfu/1PnJN6pqf6ufMbrKZxCUVszL0PEtl4ta8riVVPO5rB8mZdSqQRS1pz7/pK7ilp2o 9ZJjp7wWCe7+C33QZUL/hDAozZ8jCx0sO3bC/96ztFZt/XTkTWrY9PZlSz9GRwtUJxnG rszg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ETeeadHZ99IdY5Jk0KzP16Lyq+vyYBLDq3fNCf7ACK8=; b=ZJIrnMXd1MhFKYCQArWVLc8M1qXRX50gYyHgxaNQzVsF3lw/DaTUlkDz73AAkZyxeU Al8jfX2tVUac+vzJRR9TuaZp1Ad6P4Hv2koXgFvZbWuWTRV7Entaef5VCw6m4PDo8qSn +QANPzDWnbLL681SGWIR0PuPdDYNVKauKSs9Ql9otGluiGuB1cl7YtZEk0R9Ep6pL2dA PjOB6dM2XDKUDeR5uOlyHKSJlWi3P6QVfCJ60X/GOpVQYqKi2dsMT5lakBmebc48GdX2 1CD0771JLhZuDkvbKByWC/NklV7061agOjm9lRu5U1ExplVYLxtpcvUlIyUWnJS5LA0S o8NA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8si15174004plk.9.2018.12.03.15.49.34; Mon, 03 Dec 2018 15:49:48 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725962AbeLCXry (ORCPT + 99 others); Mon, 3 Dec 2018 18:47:54 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:64228 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbeLCXrx (ORCPT ); Mon, 3 Dec 2018 18:47:53 -0500 Received: from 79.184.252.87.ipv4.supernova.orange.pl (79.184.252.87) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.157) id b5e424915e71a5cf; Tue, 4 Dec 2018 00:47:41 +0100 From: "Rafael J. Wysocki" To: Doug Smythies Cc: Giovanni Gherdovich , Srinivas Pandruvada , Peter Zijlstra , Linux Kernel Mailing List , Frederic Weisbecker , Mel Gorman , Daniel Lezcano , Linux PM Subject: Re: [RFC/RFT][PATCH v6] cpuidle: New timer events oriented governor for tickless systems Date: Tue, 04 Dec 2018 00:47:31 +0100 Message-ID: <2107394.tME3olEdyg@aspire.rjw.lan> In-Reply-To: References: <001901d48881$29ea59d0$7dbf0d70$@net> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, November 30, 2018 9:51:19 AM CET Rafael J. Wysocki wrote: > Hi Doug, > > On Fri, Nov 30, 2018 at 8:49 AM Doug Smythies wrote: > > > > Hi Rafael, > > > > On 2018.11.23 02:36 Rafael J. Wysocki wrote: > > > > ... [snip]... > > > > > +/** > > > + * teo_find_shallower_state - Find shallower idle state matching given duration. > > > + * @drv: cpuidle driver containing state data. > > > + * @dev: Target CPU. > > > + * @state_idx: Index of the capping idle state. > > > + * @duration_us: Idle duration value to match. > > > + */ > > > +static int teo_find_shallower_state(struct cpuidle_driver *drv, > > > + struct cpuidle_device *dev, int state_idx, > > > + unsigned int duration_us) > > > +{ > > > + int i; > > > + > > > + for (i = state_idx - 1; i > 0; i--) { > > > + if (drv->states[i].disabled || dev->states_usage[i].disable) > > > + continue; > > > + > > > + if (drv->states[i].target_residency <= duration_us) > > > + break; > > > + } > > > + return i; > > > +} > > > > I think this subroutine has a problem when idle state 0 > > is disabled. > > You are right, thanks! > > > Perhaps something like this might help: > > > > diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c > > index bc1c9a2..5b97639 100644 > > --- a/drivers/cpuidle/governors/teo.c > > +++ b/drivers/cpuidle/governors/teo.c > > @@ -196,7 +196,8 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) > > } > > > > /** > > - * teo_find_shallower_state - Find shallower idle state matching given duration. > > + * teo_find_shallower_state - Find shallower idle state matching given > > + * duration, if possible. > > * @drv: cpuidle driver containing state data. > > * @dev: Target CPU. > > * @state_idx: Index of the capping idle state. > > @@ -208,13 +209,15 @@ static int teo_find_shallower_state(struct cpuidle_driver *drv, > > { > > int i; > > > > - for (i = state_idx - 1; i > 0; i--) { > > + for (i = state_idx - 1; i >= 0; i--) { > > if (drv->states[i].disabled || dev->states_usage[i].disable) > > continue; > > > > if (drv->states[i].target_residency <= duration_us) > > break; > > } > > + if (i < 0) > > + i = state_idx; > > return i; > > } > > I'll do something slightly similar, but equivalent. I actually ended up fixing it differently, as the above will cause state_idx to be returned even if some states shallower than state_idx are enabled, but their target residencies are higher than duration_us. In that case, though, it still is more correct to return the shallowest enabled state rather than state_idx. > > > > @@ -264,7 +267,6 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > > if (max_early_idx >= 0 && > > count < cpu_data->states[i].early_hits) > > count = cpu_data->states[i].early_hits; > > - > > continue; > > } > > > > There is an additional issue where if idle state 0 is disabled (with the above suggested code patch), > > idle state usage seems to fall to deeper states than idle state 1. > > This is not the expected behaviour. > > No, it isn't. > > > Kernel 4.20-rc3 works as expected. > > I have not figured this issue out yet, in the code. > > > > Example (1 minute per sample. Number of entries/exits per state): > > State 0 State 1 State 2 State 3 State 4 Watts > > 28235143, 83, 26, 17, 837, 64.900 > > 5583238, 657079, 5884941, 8498552, 30986831, 62.433 << Transition sample, after idle state 0 disabled > > 0, 793517, 7186099, 10559878, 38485721, 61.900 << ?? should have all gone into Idle state 1 > > 0, 795414, 7340703, 10553117, 38513456, 62.050 > > 0, 807028, 7288195, 10574113, 38523524, 62.167 > > 0, 814983, 7403534, 10575108, 38571228, 62.167 > > 0, 838302, 7747127, 10552289, 38556054, 62.183 > > 9664999, 544473, 4914512, 6942037, 25295361, 63.633 << Transition sample, after idle state 0 enabled > > 27893504, 96, 40, 9, 912, 66.500 > > 26556343, 83, 29, 7, 814, 66.683 > > 27929227, 64, 20, 10, 931, 66.683 > > I see. > > OK, I'll look into this too, thanks! This probably is the artifact of the fix for the teo_find_shallower_state() issue. Anyway, I'm not able to reproduce this with the teo_find_shallower_state() issue fixed differently. Thanks, Rafael