All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: David Miller <davem@davemloft.net>
Cc: herbert@gondor.apana.org.au, netdev@vger.kernel.org
Subject: Re: [PATCH 10/13]: net: Implement simple sw TX hashing.
Date: Tue, 15 Jul 2008 08:49:32 +0200	[thread overview]
Message-ID: <487C487C.5030403@cosmosbay.com> (raw)
In-Reply-To: <20080714.045806.213105998.davem@davemloft.net>

David Miller a écrit :
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Date: Mon, 14 Jul 2008 19:33:02 +0800
> 
>> Eric Dumazet <dada1@cosmosbay.com> wrote:
>>>> +     return hash % dev->real_num_tx_queues;
>>> simple but expensive... but could be changed to use reciprocal_divide() if necessary...
>> For the common cases it should be a power of 2 too.
> 
> Unfortunately it is not enforcable for it to be a power of 2
> and I fear it will in fact not be very often for several
> chips that will use this stuff.
> 
> BTW, how can reciprocal_divide() be used to compute a modulus?  Are
> you going to do the reciprocal divide, re-multiply, then subtract?
> :-)
> 

reciprocal divide is the name of the following
tranformation of a divide to one multiply.

f1(X) = X / N;  
->g1(X) ((u64)X * R) >> 32;

So you are right I was wrong to name the following 
transformation a reciprocal divide.

f2(X) = X % N ;
->g2(X) = ((u64)X * N) >> 32;

But g2() is quite similar to g1() :)

f2() & g2() functions are different of course, but should give 
same hash spreading if X has an uniform distribution in 32bits space.

simple_tx_hash() in its current form may not have this property, thats hard
to say.

For example, hash_dst() in net/netfilter/xt_hashlimit.c is using the following code :

static u_int32_t
hash_dst(const struct xt_hashlimit_htable *ht, const struct dsthash_dst *dst)
{
        u_int32_t hash = jhash2((const u32 *)dst,
                                sizeof(*dst)/sizeof(u32),
                                ht->rnd);
        /*
         * Instead of returning hash % ht->cfg.size (implying a divide)
         * we return the high 32 bits of the (hash * ht->cfg.size) that will
         * give results between [0 and cfg.size-1] and same hash distribution,
         * but using a multiply, less expensive than a divide
         */
        return ((u64)hash * ht->cfg.size) >> 32;
}





  reply	other threads:[~2008-07-15  6:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10 10:57 [PATCH 10/13]: net: Implement simple sw TX hashing David Miller
2008-07-11 20:49 ` Eric Dumazet
2008-07-14 11:33   ` Herbert Xu
2008-07-14 11:58     ` David Miller
2008-07-15  6:49       ` Eric Dumazet [this message]
2008-07-15  6:58         ` David Miller
2008-07-15 10:45         ` David Miller
2008-07-17 16:16 ` Stephen Hemminger
2008-07-17 16:21   ` Patrick McHardy
2008-07-19  7:26     ` David Miller

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=487C487C.5030403@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    /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.