Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp207505imu; Thu, 8 Nov 2018 00:11:43 -0800 (PST) X-Google-Smtp-Source: AJdET5ec4W1cdA9vBdMLlyYm6xN4awHn5yfCR/K/4qn05AE2pudR4y2I1yNVuYhShPS4cptJ49cU X-Received: by 2002:a62:4b8c:: with SMTP id d12-v6mr3619823pfj.38.1541664703450; Thu, 08 Nov 2018 00:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541664703; cv=none; d=google.com; s=arc-20160816; b=BZCr+qau7UPYfmWZDItNmVf1efRWIjDa8oTNzL63Fn3V5XglDiI6b9IMjKAh32sIdd 0roNn37KuJWLHKbAeh2QsMothjy9TZ8wq4GHrsZcyMItr73LgnGNjBLENpTfanXV8OZw ffOnu2gqLd5TUuZlMGhAfiJvCfHazavroTkv1rQcxIi/MBsydgoJIzxtRLRn+lwgwRvc vCDip/VJVXG233WL+mVYo/7GzwxsnFVzoXQmUAVDqLLNSVCQQ273hNFoarZeQ7rU7+qh jtc529i8Cem4gIf/BH7LbOc6Q90tVDyBeZyl/4PFFBXZFbGZjP40CxFspvqwuZuhqAjE qZ7A== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=aczT1AI8ofSXeg8XIZJpSK1FfsNvEbjAoYiBYGwb8gY=; b=musJXV/krI8BfavZM6I+G9pPEqx2sodDxM+BRi4Z4jtkO5NfAHbM2TcRrEA8UFBI+P gSjgAnwN025V8YpP/xPZOrXgtwd120Nt2Eh51fzJOI9o17Vt5Xr0jH5gXm+33ZfKrvuu 9FVzjXszfXhuE2aOI7HFBe3qo+UIqc233WP9l8BDjzmJPrmjTGfb8vKRFGMsg+QxvHWL WwM0ykukPJq4GyM6cYcVBsftBaO0f2r4QgKBi92jl+aowVqIrPUV1y89qxVRtUWBcViI N0v5bBZ2F5CgHgA3PwJ5LBhM7mDf4KykeJo/+ihuKB7Z+FwZ6NhnmUwkrnPUSjjfLgm1 vgYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K4WzW+WP; 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 e133-v6si4102431pfh.289.2018.11.08.00.11.28; Thu, 08 Nov 2018 00:11:43 -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=pass header.i=@linaro.org header.s=google header.b=K4WzW+WP; 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 S1726649AbeKHRot (ORCPT + 99 others); Thu, 8 Nov 2018 12:44:49 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33822 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbeKHRot (ORCPT ); Thu, 8 Nov 2018 12:44:49 -0500 Received: by mail-wr1-f66.google.com with SMTP id j26-v6so20190430wre.1 for ; Thu, 08 Nov 2018 00:10:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=aczT1AI8ofSXeg8XIZJpSK1FfsNvEbjAoYiBYGwb8gY=; b=K4WzW+WP8kkw319lIXo8aLnc/x17nP7W60kRoQxBEUHvUdniOYZzFbcCv2UgnxO2sU ttYJ/kwoseu5eqyMzARYXRe/BU6WsEl8ubjPcFH+HL4H/OefU35BBxbkhCXT8FYViPpL k1M1RAU1uFYBLSoEgA0rNe1Ap43aQm0Xc2XQc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=aczT1AI8ofSXeg8XIZJpSK1FfsNvEbjAoYiBYGwb8gY=; b=IvecbO/HRTERCadMS83lsgElztVORcRbBLuIEhVCtFx6Uhsln0KB0U3rujfzUUIdju DaGNmt1q6Qa8WqJWCAvQJcv0t9N1D+zawOoExobwqs4PEKvE4vsoh8I+P5QRMfSSDYwm 0OfoTDGDiaIaAPeWgarjmJBHoRQTMhO4HigWmptuiKlta6c7qhw/ieX5py94hsS92GM6 mpitiJ5T9NwoXlEKTi8rvkyfpR1IGrbukt8D5K3LxzMvl5sNpVSs2IOTSbfk3iOsFdKf TKNZckN11pRQXyY2H1hUbzCsY9XLMwCkIbz2K3A1EThVe9UqK8EeYl9QQwec2/nEPGgr m2wA== X-Gm-Message-State: AGRZ1gKttc0eWQejsfwDDyknzudkISRVgdh55rqteu4Lku0/TpnxbWfq 8rWCC1duVY9BNEg8T2Fd2O4mHA== X-Received: by 2002:a5d:66d0:: with SMTP id k16-v6mr3399438wrw.154.1541664629295; Thu, 08 Nov 2018 00:10:29 -0800 (PST) Received: from [192.168.0.40] (48.243.136.77.rev.sfr.net. [77.136.243.48]) by smtp.googlemail.com with ESMTPSA id x6-v6sm3242763wrq.52.2018.11.08.00.10.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 00:10:28 -0800 (PST) Subject: Re: [PATCH] irq/timings: Fix model validity To: Peter Zijlstra Cc: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Linux PM , Giovanni Gherdovich , Doug Smythies , Srinivas Pandruvada , Linux Kernel Mailing List , Frederic Weisbecker , Mel Gorman , Nicolas Pitre References: <1556808.yKVbhZSazi@aspire.rjw.lan> <20181106170442.GC9781@hirez.programming.kicks-ass.net> <20181106195127.GD9781@hirez.programming.kicks-ass.net> <20181107085936.GI9781@hirez.programming.kicks-ass.net> <20181107094624.GB9828@hirez.programming.kicks-ass.net> <20181107130507.GD9761@hirez.programming.kicks-ass.net> From: Daniel Lezcano Message-ID: Date: Thu, 8 Nov 2018 09:10:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181107130507.GD9761@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/11/2018 14:05, Peter Zijlstra wrote: > On Wed, Nov 07, 2018 at 11:52:31AM +0100, Daniel Lezcano wrote: >>> @@ -146,11 +152,38 @@ static void irqs_update(struct irqt_stat *irqs, u64 ts) >>> */ >>> diff = interval - irqs->avg; >>> >>> + /* >>> + * Online average algorithm: >>> + * >>> + * new_average = average + ((value - average) / count) >>> + * >>> + * The variance computation depends on the new average >>> + * to be computed here first. >>> + * >>> + */ >>> + irqs->avg = irqs->avg + (diff >> IRQ_TIMINGS_SHIFT); >>> + >>> + /* >>> + * Online variance algorithm: >>> + * >>> + * new_variance = variance + (value - average) x (value - new_average) >>> + * >>> + * Warning: irqs->avg is updated with the line above, hence >>> + * 'interval - irqs->avg' is no longer equal to 'diff' >>> + */ >>> + irqs->variance = irqs->variance + (diff * (interval - irqs->avg)); >>> + >>> /* >>> * Increment the number of samples. >>> */ >>> irqs->nr_samples++; > > FWIW, I'm confused on this. The normal (Welford's) online algorithm > does: > > count++; > delta = value - mean; > mean += delta / count; > M2 += delta * (value - mean); > > But the above uses: > > mean += delta / 32; > > Which, for count >> 32, over-estimates the mean adjustment. But worse, > it significantly under-estimates the mean during training. > > How is the computed variance still correct with this? I can not find any > comments that clarifies this. I'm thinking that since the mean will > slowly wander towards it's actual location (assuming an actual standard > distribution input) the resulting variance will be far too large, since > the (value - mean) term will be much larger than 'expected'. You are right, initially it was divided by min(count, 32) but for optimization reason, we decided to change that by a power of two constant assuming the number of samples will reach quickly 32 and the compiler will replace that by a shift. https://lkml.org/lkml/2017/3/23/696 >>> @@ -158,16 +191,12 @@ static void irqs_update(struct irqt_stat *irqs, u64 ts) >>> * more than 32 and dividing by 32 instead of 31 is enough >>> * precise. >>> */ >>> + variance = irqs->variance >> IRQ_TIMINGS_SHIFT; > > Worse; variance is actually (as the comment states): > > s^2 = M2 / (count -1) > > But instead you compute: > > s^2 = M2 / 32; > > Which is again much larger than the actual result; assuming count >> 32. > > So you compute a variance that is inflated in two different ways. > > > I'm not seeing how this thing works reliably. I have to revisit this part of code soon, I will double check that. -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog