From: Paul Durrant <Paul.Durrant@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Ian Jackson <Ian.Jackson@citrix.com>,
"Tim (Xen.org)" <tim@xen.org>, "Keir (Xen.org)" <keir@xen.org>,
Ian Campbell <Ian.Campbell@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] public/io/netif.h: make control ring hash protocol more general
Date: Mon, 15 Feb 2016 11:17:59 +0000 [thread overview]
Message-ID: <2820a08181dc4c7fa5081d3843115633@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <56C1C0BF02000078000D2045@prv-mh.provo.novell.com>
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 15 February 2016 11:13
> To: Paul Durrant
> Cc: Ian Campbell; Ian Jackson; xen-devel@lists.xenproject.org; Keir
> (Xen.org); Tim (Xen.org)
> Subject: Re: [PATCH] public/io/netif.h: make control ring hash protocol more
> general
>
> >>> On 15.02.16 at 11:17, <paul.durrant@citrix.com> wrote:
> > +#define NETIF_CTRL_HASH_ALGORITHM_TOEPLITZ 1
> > +
> > +/*
> > + * This algorithm uses a 'key' as well as the data buffer itself.
> > + * (Buffer[] and Key[] are treated as shift-registers where the MSB of
> > + * Buffer/Key[0] is considered 'left-most' and the LSB of Buffer/Key[N-1]
> > + * is the 'right-most').
> > + *
> > + * Value = 0
> > + * For number of bits in Buffer[]
> > + * If (left-most bit of Buffer[] is 1)
> > + * Value ^= left-most 32 bits of Key[]
> > + * Key[] << 1
> > + * Buffer[] << 1
> > + *
> > + * The code below is provided for convenience where an operating
> system
> > + * does not already provide an implementation.
> > + */
> > +
> > +static inline uint32_t netif_toeplitz_hash(const uint8_t *key,
> > + unsigned int keylen,
> > + const uint8_t *buf,
> > + unsigned int buflen)
> > +{
> > + unsigned int keyi, bufi;
> > + uint64_t prefix = 0;
> > + uint64_t hash = 0;
> > +
> > + /* Pre-load prefix with the first 8 bytes of the key */
> > + for (keyi = 0; keyi < 8; keyi++) {
> > + prefix <<= 8;
> > + prefix |= (keyi < keylen) ? key[keyi] : 0;
> > + }
> > +
> > + for (bufi = 0; bufi < buflen; bufi++) {
> > + uint8_t byte = buf[bufi];
> > + unsigned int bit;
> > +
> > + for (bit = 0; bit < 8; bit++) {
> > + if (byte & 0x80)
> > + hash ^= prefix;
> > + prefix <<= 1;
> > + byte <<=1;
> > + }
> > +
> > + /*
> > + * 'prefix' has now been left-shifted by 8, so
> > + * OR in the next byte.
> > + */
> > + prefix |= (keyi < keylen) ? key[keyi] : 0;
> > + keyi++;
> > + }
> > +
> > + /* The valid part of the hash is in the upper 32 bits. */
> > + return hash >> 32;
> > +}
>
> "inline" is not a C89 keyword and hence can't be used without
> suitable guarding in a public header. I'd suggest making this
> reference implementation an opt-in thing, controllable by the
> consumer needing to #define some tbd identifier.
>
Ok. That's a good idea. I'll wrap it with something.
Paul
> Jan
prev parent reply other threads:[~2016-02-15 11:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-15 10:17 [PATCH] public/io/netif.h: make control ring hash protocol more general Paul Durrant
2016-02-15 11:12 ` Jan Beulich
2016-02-15 11:17 ` Paul Durrant [this message]
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=2820a08181dc4c7fa5081d3843115633@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=tim@xen.org \
--cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).