Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3096223imu; Wed, 7 Nov 2018 05:06:14 -0800 (PST) X-Google-Smtp-Source: AJdET5e35lZgzKzaEKiiDG8ZXJexVkgqH0TFWAw4IfC3TJz3fSzBXecOq8JR1a6Cbt3mbFL5JrDy X-Received: by 2002:a63:2ad4:: with SMTP id q203-v6mr115661pgq.356.1541595974094; Wed, 07 Nov 2018 05:06:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541595974; cv=none; d=google.com; s=arc-20160816; b=BrKhMNCkQyqLIEcJnLqmaMRYdxhiK3+ymMrqM7vGarFyYtVzNHT2oWUK8VkplnYiYM igbLsjxFyoqWsgNC4i9B/DeRthY3kWXx58g5bHlVysAwvU7LsuR/aWIL7n4m81z6YdaP 2ZBE2hJmQc1D08CVYSJzc8hdNxC1MjPElCWhEEyLpLBRkKCnO8wH9Hd9+hV8gp+v5Vdl 6p2HxWdU1mjwKPxW9tGjSKEfRipP0zMaMadKVNqz1eqW4C/3swo7oehLMMLOHF805NOb ivFN3PQ5P+7eP6Co+B+fTOP6+KtTGF6/2zf5GAGNOKVFOJOBfcmy2uQLFBAxnszcgsJu 96uw== 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=LX38V2snMzi7Z0f79R9pskMuYEeIMOrNQmAvtTr/MuI=; b=pjrzaBq03djYhwjYHgQPXaRfrpEHypGLmBfLcGKtWYl4IQwANs55frF/LLNyxZwLwJ c6Iv43Gu1li35UAqxiJqwJ0UYQoqCVncTpmtvN+8M6jWkNYzfYlQ+XqthOVbirhbVl49 DLvJt4Ef0DPA6OxK/Pzw7ZfE7LAx+FGsSlV1Enkvvhft1TQmSbA605kiGWmrVZnXF98U EfrSzGHn2MDgfW9l7wcjkHpmpONsC7wX2YqvJ5WuihpD9ISbluoN5DtACX3fWVXTw+Zn t9/5vd7EoiJ2BmcKhLT13TZ5lG6qWXE3fndT2/de5EOwkLWXHNgvGLSKIjSXmKvbrFxX raXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=NeZ+RNpE; 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 o184si460410pgo.591.2018.11.07.05.05.58; Wed, 07 Nov 2018 05:06:14 -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=NeZ+RNpE; 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 S1726886AbeKGWfo (ORCPT + 99 others); Wed, 7 Nov 2018 17:35:44 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:35732 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbeKGWfo (ORCPT ); Wed, 7 Nov 2018 17:35:44 -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=LX38V2snMzi7Z0f79R9pskMuYEeIMOrNQmAvtTr/MuI=; b=NeZ+RNpE2+HGv4SM4KaPVpwN9 +zXcfoatTP9yoIzKvlDn6Ew7jeW4lisfwYYWaW7c+r98+DAdIHtNKnubENg8Xhzi8oiLW031uXEgi iA6/9L/lW/7S2LtwG4T1Ndu/8FGnbamq2J3NCC4lunMrg4pe4zsba44ZZMn7dIMgHNKGwrBIKNzS4 NrqDiKI+EK0nu6X2uNo4EKKqsQBTYfSRpt4uY/Y1/fJUwX66o/S/Xorry4U1AwQLSkqxfA1mf0mbq nawLsn/hNg77OuaGkZTBcoWHzZR4oCKVmI13rY+K7Ojw5q4SFJBGzGzHpXM/BZ3s42VR9jPgZpsWV 7A9lTOsvQ==; 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 1gKNW9-0006X6-GR; Wed, 07 Nov 2018 13:05:10 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CE85A20284F98; Wed, 7 Nov 2018 14:05:07 +0100 (CET) Date: Wed, 7 Nov 2018 14:05:07 +0100 From: Peter Zijlstra To: Daniel Lezcano 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 Subject: Re: [PATCH] irq/timings: Fix model validity Message-ID: <20181107130507.GD9761@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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'. > > @@ -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.