From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by dpdk.org (Postfix) with ESMTP id 8CDC23F9 for ; Thu, 5 Jun 2014 17:15:48 +0200 (CEST) Received: by mail-pb0-f54.google.com with SMTP id jt11so1251320pbb.13 for ; Thu, 05 Jun 2014 08:16:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=xCmfPPjtWiYF7P89lEqSP+RYkGVIhFzM6JvmGvluJG4=; b=IAFOqwkKifxYpUaH7h9yl/UcF8zgRhZvdCQvujwoOjiCO7xs/A6HqwZWrLmYJG1ieX rcATufwTL6mamR2K3QK044HEZUKh2Ufvqf5zk0Ac/U2WEWNdAxUg+OP13WGZqMP1wsNo amUzU51Vd7Vuu1+DxHvo8dzjLZFlDcX9ubD54xW6fDPjIndbMnMMyQAlZbD58lJitFkX NJhY+OAYfEz0Qd0N2hOLVp9b9fSECpDFzKoZAPlgXywy8a18tDWeTT4EvIjkKcyNYcaz OV2YW/H3Jk4Q/UMoH5Mwnp3dGA3fp0A28KTfTPAwdDlKvUH6xFIqrNvB3WRHxNs21b2+ wXyg== X-Gm-Message-State: ALoCoQl3beLEoZ+8SDvLeCcEMmEO636qlVEgGWtn5BsG+9zpmzUeV0t38KWGL6tQ0HXSH9iQPP4J X-Received: by 10.69.17.230 with SMTP id gh6mr11542912pbd.0.1401981360919; Thu, 05 Jun 2014 08:16:00 -0700 (PDT) Received: from nehalam.linuxnetplumber.net (static-50-53-83-51.bvtn.or.frontiernet.net. [50.53.83.51]) by mx.google.com with ESMTPSA id ky8sm23990159pbc.64.2014.06.05.08.16.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 05 Jun 2014 08:16:00 -0700 (PDT) Date: Thu, 5 Jun 2014 08:15:57 -0700 From: Stephen Hemminger To: declan.doherty@intel.com Message-ID: <20140605081557.42a797e8@nehalam.linuxnetplumber.net> In-Reply-To: References: X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH v2 1/4] Link Bonding Library X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jun 2014 15:15:49 -0000 On Wed, 4 Jun 2014 16:18:02 +0100 declan.doherty@intel.com wrote: > From: Declan Doherty > > - Broadcast TX burst broadcast bug fix > - Add/remove slave behavior fix > - Checkpatch fixes > > Signed-off-by: Declan Doherty There are some pretty weak hash functions in there. What about using: --- a/lib/librte_eal/common/include/rte_common.h 2014-02-27 09:02:23.424698279 -0800 +++ b/lib/librte_eal/common/include/rte_common.h 2014-06-05 08:03:51.615839548 -0700 @@ -365,6 +365,31 @@ rte_str_to_size(const char *str) } /** + * Multiplicative hash functions useful to distrbute + * a uniform set of consective keys + * + * @param val + * The input uniform key + * @param bits + * Number of bits desired + */ +#define GOLDEN_RATIO_32 2654404609U +static inline uint32_t +rte_fib_hash32(uint32_t val, unsigned int bits) +{ + val *= GOLDEN_RATIO_32; + return val >> (32 - bits); +} + +#define GOLDEN_RATIO_64 0x9e37fffffffc0001UL +static inline uint64_t +rte_fib_hash64(uint64_t val, unsigned bits) +{ + val *= GOLDEN_RATIO_64; + return val >> (64 - bits); +} + +/** * Function to terminate the application immediately, printing an error * message and returning the exit_code back to the shell. * --- a/lib/librte_ether/rte_ether.h 2014-02-27 09:02:23.438697987 -0800 +++ b/lib/librte_ether/rte_ether.h 2014-06-05 08:14:15.438080058 -0700 @@ -48,6 +48,8 @@ extern "C" { #include #include +#include +#include #define ETHER_ADDR_LEN 6 /**< Length of Ethernet address. */ #define ETHER_TYPE_LEN 2 /**< Length of Ethernet type field. */ @@ -250,6 +252,80 @@ struct ether_hdr { uint16_t ether_type; /**< Frame type. */ } __attribute__((__packed__)); + +/* + * These functions work by aliasing the 6 byte Ethernet address + * into a 64 bit value. The macro shift16, removes the extra + * bytes with the correct shift depending on byte order + */ +#ifdef __BYTE_ORDER + #if __BYTE_ORDER == __BIG_ENDIAN + #define shift16(s) (s >>= 16) + #else + #define shift16(s) (s <<= 16) + #endif +#endif + +/** + * Fast compare of Ethernet address. + * + * @param e1 + * A pointer to a ether_addr structure one address + * @param e2 + * A pointer to a ether_addr structure holding other address + * @return + * True (1) if addresses are the same + * false (0) otherwise. + */ +static inline int +ether_addr_equal(const struct ether_addr *e1, const struct ether_addr *e2) +{ + uint64_t e1_addr = *(const uint64_t *) e1; + shift16(e1_addr); + uint64_t e2_addr = *(const uint64_t *) e2; + shift16(e2_addr); + + return (e1_addr == e2_addr); +} + +/** + * Fast hash of ethernet address + * + * @param ea + * A pointer to a ether_addr structure + * @param bits + * Number of bits desired + * @return + * Calculated hash value. + */ +static inline uint32_t +ether_addr_hash(const struct ether_addr *ea, unsigned bits) +{ + uint64_t val = *(const uint64_t *) ea; + + shift16(val); + return rte_fib_hash64(val, bits); +} +#undef shift16 + +/** + * Hash of ethernet source and destination + * + * @param ea + * A pointer to a ether_hdr structure + * @param initval + * Initialising value of hash. + * @return + * Calculated hash value. + */ +static inline uint32_t +ether_header_hash(const struct ether_hdr *hdr, unsigned seed) +{ + const uint32_t *key = (const uint32_t *)hdr; + + return rte_jhash(key, 2*ETHER_ADDR_LEN, seed); +} + /** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type