From: Eric Dumazet <eric.dumazet@gmail.com>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: David Miller <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [RFC] sched: CHOKe packet scheduler
Date: Wed, 05 Jan 2011 18:25:32 +0100 [thread overview]
Message-ID: <1294248332.10633.25.camel@edumazet-laptop> (raw)
In-Reply-To: <20110105091718.02f8a00f@nehalam>
Le mercredi 05 janvier 2011 à 09:17 -0800, Stephen Hemminger a écrit :
> On Wed, 05 Jan 2011 07:19:35 +0100
> Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> > Le mardi 04 janvier 2011 à 16:29 -0800, Stephen Hemminger a écrit :
> > > +static struct sk_buff *skb_peek_random(struct sk_buff_head *list)
> > > +{
> > > + struct sk_buff *skb = list->next;
> > > + unsigned int idx = net_random() % list->qlen;
> > > +
> > > + while (skb && idx-- > 0)
> > > + skb = skb->next;
> > > +
> > > + return skb;
> > > +}
> >
> > You could avoid the divide op :
> >
> > unsigned int idx = reciprocal_divide(random32(), list->qlen);
>
> How would this work, it is a mod not a divide??
>
It works, because random32() provides a 32bit 'random' number.
between 0 and 0xFFFFFFFF
We multiply it by X, get a 64bit number between 0 and 0xFFFFFFFF * X
then we right shift it by 32, get a number between 0 and X - 1
We dont need to get the modulus, just a random number between 0 and X -
1
Dont worry, we should add a helper function to do that, since it might
be used in many places.
/* deliver a random number between 0 and N - 1 */
u32 random_N(unsigned int N)
{
reciprocal_divide(random32(), N);
}
next prev parent reply other threads:[~2011-01-05 17:25 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-05 0:29 [RFC] sched: CHOKe packet scheduler Stephen Hemminger
2011-01-05 6:02 ` Eric Dumazet
2011-01-05 6:19 ` Eric Dumazet
2011-01-05 17:17 ` Stephen Hemminger
2011-01-05 17:25 ` Eric Dumazet [this message]
2011-01-05 19:21 ` [RFC] sched: CHOKe packet scheduler (v0.2) Stephen Hemminger
2011-01-05 20:06 ` Eric Dumazet
2011-01-05 20:15 ` Stephen Hemminger
2011-01-06 4:07 ` Eric Dumazet
2011-01-06 6:53 ` Stephen Hemminger
2011-01-07 4:55 ` Stephen Hemminger
2011-01-07 5:39 ` Changli Gao
2011-01-07 7:10 ` Stephen Hemminger
2011-01-07 8:37 ` Eric Dumazet
2011-01-10 13:46 ` Eric Dumazet
2011-01-10 17:31 ` Stephen Hemminger
2011-01-10 17:45 ` Eric Dumazet
2011-01-10 23:44 ` [RFC] sched: CHOKe packet scheduler (v0.4) Stephen Hemminger
2011-01-11 0:00 ` Eric Dumazet
2011-01-11 1:10 ` Stephen Hemminger
2011-01-11 6:18 ` Eric Dumazet
2011-01-11 6:34 ` Eric Dumazet
2011-01-11 23:48 ` Stephen Hemminger
2011-01-12 0:04 ` Eric Dumazet
2011-01-12 7:13 ` [RFC] sched: CHOKe packet scheduler (v0.6) Eric Dumazet
2011-01-12 17:27 ` Stephen Hemminger
2011-01-12 17:33 ` Eric Dumazet
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=1294248332.10633.25.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox