Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2103420imu; Tue, 6 Nov 2018 09:07:57 -0800 (PST) X-Google-Smtp-Source: AJdET5f9ZFUeKKKmqUFfxqKzj+v1YnEhB4HvjDn18fNH+wVnJrxzWgkbG90vx06yXhyOSZaJ1LY7 X-Received: by 2002:a62:d084:: with SMTP id p126-v6mr28182610pfg.147.1541524077059; Tue, 06 Nov 2018 09:07:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541524077; cv=none; d=google.com; s=arc-20160816; b=z25cmGpBeKWzM8wmoSLasv7kcTVXLZIgwy8PZVj9sxDVv+M/M/1uR7t6MiWer3/ko8 xliOWUu0ie2FbR5TTQjqQzgiz+/R6uanMn3MCHOvr1vP8xIdxAcCELpYy3+mBDDjKLp0 vRgK+Adrr+5y3sH8X6E++/Em1G6xNP3/60EQOC4cVGkvsDuXG+d3IkRrNshnbQBk3mSO qdkYtahq8lpIy0hASCL+veD073Pbr25ZfJaLWpOcjto3qE5waJ2g6hmoPhgOcDqKXz78 wr3dv+rYjBGLxaXek8sr+9r99sz6qQyc3sX51ZCQW2xgSS63NpHEH1F2egOCyKg54TmE OSsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=J+AQHXDaRXe5s5Tal8bIIneMc3X482IV7r7MRuAHypk=; b=bD1+rV0FNdqD2b4RJK+Nkd99PaGa7kLJCrttSNO6jVI95l5wRwlsG62bmGOcyLCCFj q4D1qZiEN5sTSZ7CQNidi62NeRIqBn9wDrv8R+meNwczjn6GbNay9DH/P9RCENXiNkG2 rA+u4j76lgGSVD1WRICLh38sQyyQbZUv4htJZ7L+y1gHtEWRqKAD8WO/pnTYKWXqx79t fM5dmdyYAhcDTRhIbFs1bSIKTyo9umzW5xlv+e+/7XaQ0GkFY33M8sI4hNkMUd9L7+Oh Go8O6BOIqA245hTtu4pb28/p4cyFKslk1CNR2jazZCdR8N45ezVaWW+YubunbM0roYSF XVHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VwviLJCr; 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 j5-v6si52734617pfb.211.2018.11.06.09.07.23; Tue, 06 Nov 2018 09:07:57 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VwviLJCr; 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 S2389585AbeKGCbA (ORCPT + 99 others); Tue, 6 Nov 2018 21:31:00 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:58172 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389389AbeKGCbA (ORCPT ); Tue, 6 Nov 2018 21:31:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=J+AQHXDaRXe5s5Tal8bIIneMc3X482IV7r7MRuAHypk=; b=VwviLJCrqrKrK9wWgeTnIndCi 6Knc9NQXCxj7sCKNBpbXLHpSM27iHUT/hmL25k4PSy/TRV7EJtQ/iWLJa5SC4m13HAngo+e8V2qRZ 9/6DL6WLoVF8+bQyhyvGWXXvNNYnF97PgbVTUIsyhAS5pQ2/EyCWjraU6CMneI4WF/Zd4gTjflmEM kZtXLu0Kf/6QKJLCB0vPqLbSpNGA+XCOmsyJobibKyBdKVgNvakplsyKpRI+ISxVAXK35FeipkdDs AW119Nd5yax78WgNuRbcHALXhIX/T1cnxBlx4F340+oPYhBJzxhgd7U7eb5WLcmoKXnC67BfM3XXE QfFGnYfyQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK4mT-00020L-KN; Tue, 06 Nov 2018 17:04:45 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E4FA320284C62; Tue, 6 Nov 2018 18:04:42 +0100 (CET) Date: Tue, 6 Nov 2018 18:04:42 +0100 From: Peter Zijlstra To: "Rafael J. Wysocki" Cc: Linux PM , Giovanni Gherdovich , Doug Smythies , Srinivas Pandruvada , LKML , Frederic Weisbecker , Mel Gorman , Daniel Lezcano Subject: Re: [RFC/RFT][PATCH v3] cpuidle: New timer events oriented governor for tickless systems Message-ID: <20181106170442.GC9781@hirez.programming.kicks-ass.net> References: <1556808.yKVbhZSazi@aspire.rjw.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1556808.yKVbhZSazi@aspire.rjw.lan> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 04, 2018 at 05:31:20PM +0100, Rafael J. Wysocki wrote: > + * - If there is a pattern of 5 or more recent non-timer wakeups earlier than > + * the closest timer event, expect one more of them to occur and use the > + * average of the idle duration values corresponding to them to select an > + * idle state for the CPU. > +/** > + * teo_idle_duration - Estimate the duration of the upcoming CPU idle time. > + * @drv: cpuidle driver containing state data. > + * @cpu_data: Governor data for the target CPU. > + * @sleep_length_us: Time till the closest timer event in microseconds. > + */ > +unsigned int teo_idle_duration(struct cpuidle_driver *drv, > + struct teo_cpu *cpu_data, > + unsigned int sleep_length_us) > +{ > + u64 range, max_spread, max, sum; > + unsigned int count; > + > + /* > + * If the sleep length is below the target residency of idle state 1, > + * the only viable choice is to select the first available (enabled) > + * idle state, so return immediately in that case. > + */ > + if (sleep_length_us < drv->states[1].target_residency) > + return sleep_length_us; > + > + /* > + * The purpose of this function is to check if there is a pattern of > + * wakeups indicating that it would be better to select a state > + * shallower than the deepest one matching the sleep length or the > + * deepest one at all if the sleep lenght is long. Larger idle duration > + * values are beyond the interesting range. > + * > + * Narrowing the range of interesting values down upfront also helps to > + * avoid overflows during the computation below. > + */ > + range = drv->states[drv->state_count-1].target_residency; > + range = min_t(u64, sleep_length_us, range + (range >> 2)); > + > + /* > + * This is the value to compare with the distance between the average > + * and the greatest sample to decide whether or not it is small enough. > + * Take 10 us as the total cap of it. > + */ > + max_spread = max_t(u64, range >> MAX_SPREAD_SHIFT, 10); > + > + max = range; > + > + do { > + u64 cap = max; > + int i; > + > + /* > + * Compute the sum of the saved intervals below the cap and the > + * sum of of their squares. Count them and find the maximum > + * interval below the cap. > + */ > + count = 0; > + sum = 0; > + max = 0; > + > + for (i = 0; i < INTERVALS; i++) { > + u64 val = cpu_data->intervals[i]; > + > + if (val >= cap) > + continue; > + > + count++; > + sum += val; > + if (max < val) > + max = val; > + } > + > + /* > + * Give up if the total number of interesting samples is too > + * small. > + */ > + if (cap == range && count <= INTERVALS / 2) > + return sleep_length_us; > + > + /* > + * If the distance between the max and the average is too large, > + * discard the max an repeat. > + */ > + } while (count > 3 && max > max_spread && (max - max_spread) * count > sum); > + > + return div64_u64(sum, count); > +} Instead of this detector; why haven't you used the code from kernel/irq/timings.c ?