From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB1CFC43334 for ; Fri, 24 Jun 2022 09:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230487AbiFXJWp (ORCPT ); Fri, 24 Jun 2022 05:22:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbiFXJWn (ORCPT ); Fri, 24 Jun 2022 05:22:43 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E6E69FB7 for ; Fri, 24 Jun 2022 02:22:42 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o4fWT-0001bX-2p; Fri, 24 Jun 2022 11:22:41 +0200 Message-ID: <1a694037c631c298c6952cdf4bf54fcc6d2f08e9.camel@pengutronix.de> Subject: Re: [PATCH v2 1/4] drm/etnaviv: add simple moving average (SMA) From: Lucas Stach To: Christian Gmeiner , linux-kernel@vger.kernel.org Cc: David Airlie , "moderated list:DRM DRIVERS FOR VIVANTE GPU IP" , "open list:DRM DRIVERS FOR VIVANTE GPU IP" , Daniel Vetter , Russell King Date: Fri, 24 Jun 2022 11:22:39 +0200 In-Reply-To: <20220621072050.76229-2-christian.gmeiner@gmail.com> References: <20220621072050.76229-1-christian.gmeiner@gmail.com> <20220621072050.76229-2-christian.gmeiner@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christian, Am Dienstag, dem 21.06.2022 um 09:20 +0200 schrieb Christian Gmeiner: > This adds a SMA algorithm inspired by Exponentially weighted moving > average (EWMA) algorithm found in the kernel. > Still not sure about this one. I _feel_ that a simple moving average over a period of one second does not do a good job of reflecting the real GPU load for a bursty workload, where EWMA might be better suited. But then I also don't have a real informed opinion to offer on this. Regards, Lucas > Signed-off-by: Christian Gmeiner > --- > drivers/gpu/drm/etnaviv/etnaviv_sma.h | 53 +++++++++++++++++++++++++++ > 1 file changed, 53 insertions(+) > create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_sma.h > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sma.h b/drivers/gpu/drm/etnaviv/etnaviv_sma.h > new file mode 100644 > index 000000000000..81564d5cbdc3 > --- /dev/null > +++ b/drivers/gpu/drm/etnaviv/etnaviv_sma.h > @@ -0,0 +1,53 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2020 Etnaviv Project > + */ > + > +#ifndef __ETNAVIV_SMA_H__ > +#define __ETNAVIV_SMA_H__ > + > +#include > +#include > + > +/* > + * Simple moving average (SMA) > + * > + * This implements a fixed-size SMA algorithm. > + * > + * The first argument to the macro is the name that will be used > + * for the struct and helper functions. > + * > + * The second argument, the samples, expresses how many samples are > + * used for the SMA algorithm. > + */ > + > +#define DECLARE_SMA(name, _samples) \ > + struct sma_##name { \ > + unsigned long pos; \ > + unsigned long sum; \ > + unsigned long samples[_samples]; \ > + }; \ > + static inline void sma_##name##_init(struct sma_##name *s) \ > + { \ > + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ > + memset(s, 0, sizeof(struct sma_##name)); \ > + } \ > + static inline unsigned long sma_##name##_read(struct sma_##name *s) \ > + { \ > + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ > + return s->sum / _samples; \ > + } \ > + static inline void sma_##name##_add(struct sma_##name *s, unsigned long val) \ > + { \ > + unsigned long pos = READ_ONCE(s->pos); \ > + unsigned long sum = READ_ONCE(s->sum); \ > + unsigned long sample = READ_ONCE(s->samples[pos]); \ > + \ > + BUILD_BUG_ON(!__builtin_constant_p(_samples)); \ > + \ > + WRITE_ONCE(s->sum, sum - sample + val); \ > + WRITE_ONCE(s->samples[pos], val); \ > + WRITE_ONCE(s->pos, pos + 1 == _samples ? 0 : pos + 1); \ > + } > + > +#endif /* __ETNAVIV_SMA_H__ */