From: Bruno Randolf <br1@einfach.org>
To: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: randy.dunlap@oracle.com, akpm@linux-foundation.org,
kevin.granade@gmail.com, Lars_Ericsson@telia.com,
blp@cs.stanford.edu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] Add generic exponentially weighted moving average (EWMA) function
Date: Fri, 22 Oct 2010 10:25:30 +0900 [thread overview]
Message-ID: <201010221025.30164.br1@einfach.org> (raw)
In-Reply-To: <20101022100316.53A3.A69D9226@jp.fujitsu.com>
On Fri October 22 2010 10:11:38 KOSAKI Motohiro wrote:
> few additional reviewing comments is here.
>
> > +struct ewma {
> > + unsigned int internal;
> > + unsigned int factor;
> > + unsigned int weight;
> > +};
>
> I think unsigned long is better because long is natual register size
> on both 32bit and 64bit arch.
> and, example, almost linux resource limit is using long or ulong. then
> uint may have overflow risk if we are using this one on 64bit arch.
> Does uint has any benefit? (note: scheduler loadavg has already used ulong)
You know more about this than me. I have no specific reason to use unsigned
int. I'll change it to unsigned long, if that's better.
> > +struct ewma*
> > +ewma_add(struct ewma *avg, const unsigned int val)
> > +{
> > + avg->internal = avg->internal ?
> > + (((avg->internal * (avg->weight - 1)) +
> > + (val * avg->factor)) / avg->weight) :
> > + (val * avg->factor);
> > + return avg;
>
> Hm, if ewma_add has this function prototype, we almost always need to
> typing "new = ewma_get(ewma_add(&ewma, val))". Is this intentional?
> if so, why?
>
> Why can't we simple do following?
>
> unsigned long ewma_add(struct ewma *avg, const unsigned int val)
> {
> (snip)
> return ewma_get(avg);
> }
Hmm, I guess that depends on the way you want to use it. In my case, most of
the times when I add a value to the average, I don't need to get the value.
I'd call ewma_add() many more times than ewma_get(). Having the functions
defined like this gives us the flexibility to choose and IMHO
ewma_get(ewma_add(&ewma, val)) isn't so bad?
bruno
next prev parent reply other threads:[~2010-10-22 1:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-20 8:23 [PATCH v3] Add generic exponentially weighted moving average (EWMA) function Bruno Randolf
2010-10-20 15:03 ` Peter Zijlstra
2010-10-21 5:40 ` Bruno Randolf
2010-10-21 10:04 ` Peter Zijlstra
2010-10-21 10:31 ` KOSAKI Motohiro
2010-10-22 0:53 ` Bruno Randolf
2010-10-22 1:11 ` KOSAKI Motohiro
2010-10-22 1:25 ` Bruno Randolf [this message]
2010-10-22 1:28 ` KOSAKI Motohiro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201010221025.30164.br1@einfach.org \
--to=br1@einfach.org \
--cc=Lars_Ericsson@telia.com \
--cc=akpm@linux-foundation.org \
--cc=blp@cs.stanford.edu \
--cc=kevin.granade@gmail.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.