From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Durrant Subject: Re: [PATCH] public/io/netif.h: make control ring hash protocol more general Date: Mon, 15 Feb 2016 11:17:59 +0000 Message-ID: <2820a08181dc4c7fa5081d3843115633@AMSPEX02CL03.citrite.net> References: <1455531466-6439-1-git-send-email-paul.durrant@citrix.com> <56C1C0BF02000078000D2045@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVHAI-0005Hl-Fg for xen-devel@lists.xenproject.org; Mon, 15 Feb 2016 11:18:02 +0000 In-Reply-To: <56C1C0BF02000078000D2045@prv-mh.provo.novell.com> Content-Language: en-US List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Ian Jackson , "Tim (Xen.org)" , "Keir (Xen.org)" , Ian Campbell , "xen-devel@lists.xenproject.org" List-Id: xen-devel@lists.xenproject.org > -----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, 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