[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] public/io/netif.h: make control ring hash protocol more general



>>> On 15.02.16 at 11:17, <paul.durrant@xxxxxxxxxx> 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.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.