Add toeplitz hash algorithm
PATCH 1/1 Add toeplitz hash algorithm
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 179 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -50,6 +50,7 @@ SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h # this lib needs eal DEPDIRS-$(CONFIG_RTE_LIBRTE_HASH) += lib/librte_eal lib/librte_malloc
lib/librte_hash/rte_thash.h new file +179 -0
179 lines not on this page · raw message
Signature · 1 line
1.8.3.2
A message that is not in the archive (sent off-list or not yet received): 1428519973-10550-1-git-send-email-medvedkinv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 12 lines · On Wed, 8 Apr 2015 15:06:13 -0400 Vladimir Medvedkin…
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
Signed-off-by Vladimir Medvedkin <[email protected]>lib/librte_hash/rte_thash.h new file +5
-0+enum rte_thash_flag { +RTE_THASH_L3 =0 ,//calculate hash tacking into account only l3 header +RTE_THASH_L4 //calculate hash tacking into account l4 + l4 headers +}; +
lib/librte_hash/rte_thash.h line 71
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +*/ + +static inline void +rte_convert_rss_key (uint32_t *orig,uint32_t *targ)
orig should be const
lib/librte_hash/rte_thash.h line 100
Quoted 9 lines
lib/librte_hash/rte_thash.h new file +8
-0+{ +int i; +for (i =0 ; i <10 ; i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} +static inline uint32_t +rte_softrss (uint32_t sip,uint32_t dip,uint16_t sp,uint16_t dp,enum rte_thash_flag flag,uint32_t *rss_key)
rss_key should be const
lib/librte_hash/rte_thash.h line 104
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0+{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) {
blank line after declaration please
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (sip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) << i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
Long expression > 80 characters.
Repeated multiple times (should be inline) Extra parens ()
Extension to 64 bits is only to avoid compiler warning?
Quoted 34 lines
lib/librte_hash/rte_thash.h new file +34
-0+ } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32 (*rss_key) << i)|(uint32_t )((uint64_t )(rte_cpu_to_be_32 (*(rss_key +1 ))) >> (32 - i)); + } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32 (*rss_key) << i)|(uint32_t )((uint64_t )(rte_cpu_to_be_32 (*(rss_key +1 ))) >> (32 - i)); + } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* All ip's and ports have to be CPU byte order. +* @param sip +* Source ip address. +* @param dip +* Destination ip address. +* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip
lib/librte_hash/rte_thash.h line 150
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp +* @param *rss_key +* Pointer to 40-byte RSS hash key. +* @return +* Calculated hash value. +*/ + +static inline uint32_t +rte_softrss_be (uint32_t sip,uint32_t dip,uint16_t sp,uint16_t dp,enum rte_thash_flag flag,uint32_t *rss_key) +{
Same problems as previous code.
Also lots of copy paste (see Do Not Repeat Yourself principle).
Hi Stephen,
2015-04-09 1:24 GMT+03:00 Stephen Hemminger <[email protected]>:
Quoted 48 lines
Review
Quoted 9 lines · On Wed, 8 Apr 2015 15:06:13 -0400 Vladimir Medvedkin…
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
Signed-off-by Vladimir Medvedkin <[email protected]>(quoted diff) +2
-0+enum rte_thash_flag { + RTE_THASH_L3 = 0, //calculate hash tacking into account onlyl3 header
Quoted 1 line
+
RTE_THASH_L4//calculate hash tacking into account l4 +l4 headers
lib/librte_hash/rte_thash.h line 71
Quoted 12 lines
lib/librte_hash/rte_thash.h new file +12
-0+}; + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +*/ + +static inline void +rte_convert_rss_key (uint32_t *orig,uint32_t *targ)orig should be const
lib/librte_hash/rte_thash.h
Quoted 9 lines
lib/librte_hash/rte_thash.h new file +8
-0+{ +int i; +for (i =0 ; i <10 ; i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} +static inline uint32_t +rte_softrss(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum
rte_thash_flagflag,uint32_t*rss_key)
rss_keyshould be constlib/librte_hash/rte_thash.h line 104
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0+{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) {blank line after declaration please
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (sip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
Long expression > 80 characters.
Repeated multiple times (should be inline)
Extra parens ()
Thanks for remarks, I'll fix it.
Quoted 2 lines
Extension to 64 bits is only to avoid compiler warning?
No, in case when i = 0 we shift uint32_t left by 32 bits, which leads to undefined behaviour. In fact, shift counter just masked to 5 bits, so count range is limited to 0 to 31.
Quoted 55 lines
lib/librte_hash/rte_thash.h
Quoted 8 lines
lib/librte_hash/rte_thash.h new file +6
-0+ } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
Quoted 11 lines
lib/librte_hash/rte_thash.h new file +11
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* All ip's and ports have to be CPU byte order. lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* @param sip +* Source ip address. +* @param dip +* Destination ip address. +* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip
Quoted 1 line
+ *
RTE_THASH_L4: calculate hash tacking into account sip, dip, spand dp
lib/librte_hash/rte_thash.h
Quoted 8 lines
+ * @param
*rss_key
+ * Pointer to 40-byte RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +3
-0+ +static inline uint32_t +rte_softrss_be(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp,enum
rte_thash_flagflag,uint32_t*rss_key)Quoted 1 line
+{
Same problems as previous code.
Also lots of copy paste (see Do Not Repeat Yourself principle).
Quoted 105 lines · Vladimir Medvedkin
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
Signed-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 179 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile +1
-0@@ -50,6 +50,7 @@ SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h # this lib needs eal DEPDIRS-$(CONFIG_RTE_LIBRTE_HASH) += lib/librte_eal lib/librte_malloclib/librte_hash/rte_thash.h new file +75
-0@@ -0,0 +1,179 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> + +enum rte_thash_flag { + RTE_THASH_L3 = 0, //calculate hash tacking into account only l3 header + RTE_THASH_L4 //calculate hash tacking into account l4 + l4 headers +}; + +/** + * Prepare special converted key to use with rte_softrss_be() + * @param orig + * pointer to original RSS key + * @param targ + * pointer to target RSS key + */ + +static inline void +rte_convert_rss_key(uint32_t *orig, uint32_t *targ) +{ + int i; + for (i = 0; i < 10; i++) { + targ[i] = rte_be_to_cpu_32(orig[i]);
lib/librte_hash/rte_thash.h line 85
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ } +} + +/** +* Generic implementation. Can be used with original rss_key +* All ip's and ports have to be CPU byte order. +* @param sip +* Source ip address. +* @param dip +* Destination ip address.
ipv4, what about ipv6? Why not define rss function that works on byte buffer and let caller build it according to whatever fields it want to hash?
lib/librte_hash/rte_thash.h line 94
Quoted 9 lines
lib/librte_hash/rte_thash.h new file +9
-0+* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip +* RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp +* @param *rss_key +* Pointer to 40-byte RSS hash key.
i40e has 52 byte RSS hash key.
Quoted 88 lines
lib/librte_hash/rte_thash.h new file +85
-0+* @return +* Calculated hash value. +*/ + +static inline uint32_t +rte_softrss (uint32_t sip,uint32_t dip,uint16_t sp,uint16_t dp,enum rte_thash_flag flag,uint32_t *rss_key) +{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) { +if (sip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32 (*rss_key) << i)|(uint32_t )((uint64_t )(rte_cpu_to_be_32 (*(rss_key +1 ))) >> (32 - i)); + } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32 (*rss_key) << i)|(uint32_t )((uint64_t )(rte_cpu_to_be_32 (*(rss_key +1 ))) >> (32 - i)); + } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32 (*rss_key) << i)|(uint32_t )((uint64_t )(rte_cpu_to_be_32 (*(rss_key +1 ))) >> (32 - i)); + } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* All ip's and ports have to be CPU byte order. +* @param sip +* Source ip address. +* @param dip +* Destination ip address. +* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip +* RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp +* @param *rss_key +* Pointer to 40-byte RSS hash key. +* @return +* Calculated hash value. +*/ + +static inline uint32_t +rte_softrss_be (uint32_t sip,uint32_t dip,uint16_t sp,uint16_t dp,enum rte_thash_flag flag,uint32_t *rss_key) +{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) { +if (sip & (1 << (31 - i))) { + ret ^= (*rss_key << i)|(uint32_t )((uint64_t )*(rss_key +1 ) >> (32 - i)); + } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (*rss_key << i)|(uint32_t )((uint64_t )*(rss_key +1 ) >> (32 - i)); + } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (*rss_key << i)|(uint32_t )((uint64_t )*(rss_key +1 ) >> (32 - i)); + } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ Signature · 1 line
1.8.3.2
--
Gleb.
A message that is not in the archive (sent off-list or not yet received): 20150409063742.GA16818-RmZWMc9puTNJc61us3aD9laTQe2KTcn/@public.gmane.org
Hi Gleb,
2015-04-09 9:37 GMT+03:00 Gleb Natapov <gleb-RmZWMc9puTNJc61us3aD9laTQe2KTcn/@public.gmane.org>:
Quoted 122 lines · Vladimir Medvedkin
Quoted 9 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
Signed-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 179++++++++++++++++++++++++++++++++++++++++++++
Quoted 24 lines
2 files changed, 180 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile +1
-0@@ -50,6 +50,7 @@ SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h # this lib needs eal DEPDIRS-$(CONFIG_RTE_LIBRTE_HASH) += lib/librte_eal lib/librte_malloclib/librte_hash/rte_thash.h new file +3
-0@@ -0,0 +1,179 @@ +/*- +* BSD LICENSE +* lib/librte_hash/rte_thash.h line 13
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright
lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
lib/librte_hash/rte_thash.h line 24
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
lib/librte_hash/rte_thash.h line 25
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lib/librte_hash/rte_thash.h line 27
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
lib/librte_hash/rte_thash.h line 28
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
lib/librte_hash/rte_thash.h line 30
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
lib/librte_hash/rte_thash.h line 31
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Quoted 17 lines
lib/librte_hash/rte_thash.h new file +17
-0+*/ + +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS.lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* Can be used either for packet distribution on single queue NIC +* or for simulating of RSS computation on specific NIC (for example +* after GRE header decapsulating) +*/ + +#include <stdint.h> +#include <rte_byteorder.h> + +enum rte_thash_flag { +RTE_THASH_L3 =0 ,//calculate hash tacking into account only l3 header
lib/librte_hash/rte_thash.h line 59
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+RTE_THASH_L4 //calculate hash tacking into account l4 + l4 headers
Quoted 21 lines
lib/librte_hash/rte_thash.h new file +21
-0+}; + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +*/ + +static inline void +rte_convert_rss_key (uint32_t *orig,uint32_t *targ) +{ +int i; +for (i =0 ; i <10 ; i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Generic implementation. Can be used with original rss_key
Quoted 9 lines
lib/librte_hash/rte_thash.h line 85
Quoted 5 lines
lib/librte_hash/rte_thash.h new file +5
-0+* All ip's and ports have to be CPU byte order. +* @param sip +* Source ip address. +* @param dip +* Destination ip address. ipv4, what about ipv6? Why not define rss function that works on byte buffer and let caller build it according to whatever fields it want to hash?
Good idea, I will think about it.
Quoted 117 lines
lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +6
-0+* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip
lib/librte_hash/rte_thash.h line 92
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp
lib/librte_hash/rte_thash.h line 94
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+* @param *rss_key +* Pointer to 40-byte RSS hash key. i40e has 52 byte RSS hash key.
lib/librte_hash/rte_thash.h
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+* @return +* Calculated hash value. +*/ + +static inline uint32_t +rte_softrss(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum
rte_thash_flagflag,uint32_t*rss_key)lib/librte_hash/rte_thash.h
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) { +if (sip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
lib/librte_hash/rte_thash.h
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+ } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (rte_cpu_to_be_32(*rss_key) <<i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i));
Quoted 11 lines
lib/librte_hash/rte_thash.h new file +11
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* All ip's and ports have to be CPU byte order. lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* @param sip +* Source ip address. +* @param dip +* Destination ip address. +* @param sp +* Source TCP|UDP port. +* @param dp +* Destination TCP|UDP port. +* @param flag +* RTE_THASH_L3: calculate hash tacking into account only sip and dip
lib/librte_hash/rte_thash.h line 141
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp
lib/librte_hash/rte_thash.h
Quoted 8 lines
lib/librte_hash/rte_thash.h new file +8
-0+* @param *rss_key +* Pointer to 40-byte RSS hash key. +* @return +* Calculated hash value. +*/ + +static inline uint32_t +rte_softrss_be(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp,enum
rte_thash_flagflag,uint32_t*rss_key)lib/librte_hash/rte_thash.h
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+{ +uint32_t ret =0 ; +int i; +for (i =0 ; i <32 ; i++) { +if (sip & (1 << (31 - i))) { + ret ^= (*rss_key <<i)|(uint32_t)((uint64_t)*(rss_key + 1) >> (32 - i));
lib/librte_hash/rte_thash.h
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+ } + } + rss_key++; +for (i =0 ; i <32 ; i++) { +if (dip & (1 << (31 - i))) { + ret ^= (*rss_key <<i)|(uint32_t)((uint64_t)*(rss_key + 1) >> (32 - i));
lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ } + } +if (flag ==RTE_THASH_L4 ) { + rss_key++; +for (i =0 ; i <32 ; i++) { +if (((sp<<16 )|dp) & (1 << (31 - i))) { + ret ^= (*rss_key <<i)|(uint32_t)((uint64_t)*(rss_key + 1) >> (32 - i));
Quoted 12 lines
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --Quoted 2 lines
1.8.3.2
--
Gleb.
PATCH v2 1/1 Add toeplitz hash algorithm used by RSS
In reply to a message not in the archiveSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v2 changes
- Add ipv6 support
- Various style fixes
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eal
lib/librte_hash/rte_thash.h new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
1.8.3.2
A message that is not in the archive (sent off-list or not yet received): 1430832011-17764-1-git-send-email-medvedkinv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Vladimir,
Why limit Toeplitz hash calculation to predefined tuples and length? Should it be more general, something likerte_softrss_be(void *input, uint32_t input_len, const uint8_t *rss_key) to enable hash calculation for an input of any size? It would be useful for distributing packets using some non-standard tuples, like hashing on QinQ or adding IP protocol to hash calculation to separate UDP and TCP flows or even some other fields from a packet, for example, tunnel ID from VXLAN headers. By the way, i40e already supports RSS for SCTP in addition to TCP and UDP and includes Verification Tag as well as SCTP source and destination ports for RSS hash.
Regards,
Andrey
Quoted 277 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Tuesday, May 5, 2015 2:20 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.hlib/librte_hash/Makefile +1
-0+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h new file renamed from lib/librte_hash/rte_thash.h +0
-0mode 100644 index 0000000..42c7bf6
lib/librte_hash/rte_thash.h new file +21
-0@@ -0,0 +1,209 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +31
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203, +0x0C0D0E0F08090A0B}; #endif + +enum rte_thash_len { + RTE_THASH_V4_L3 = 2, /*calculate hash of ipv4 headeronly*/
lib/librte_hash/rte_thash.h new file +1
-0+ RTE_THASH_V4_L4 = 3, /*calculate hash of ipv4 + transportheaders*/
lib/librte_hash/rte_thash.h new file +1
-0+ RTE_THASH_V6_L3 = 8, /*calculate hash of ipv6 header only*/
lib/librte_hash/rte_thash.h new file +1
-0+ RTE_THASH_V6_L4 = 9, /*calculate hash of ipv6 + transportheaders */
lib/librte_hash/rte_thash.h new file +75
-0+}; + +/** +* IPv4 tuple +* addreses and ports have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +uint16_t dport; +uint16_t sport; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (16 ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void +rte_thash_load_v6_addr (const uint8_t *orig,uint8_t *targ) {#ifdef +__SSE3__ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask);#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + } +#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address and IPv4 dst
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @paramrss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h new file +8
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (((uint32_t *)input_tuple)[j] & (1 << (31 - i))) { + ret ^= rte_cpu_to_be_32(((const uint32_t*)rss_key)[j]) << i |
+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t*)rss_key)[j + 1])) >> (32 - i));
lib/librte_hash/rte_thash.h new file +15
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address and IPv4 dst
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @param*rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss_be(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h new file +9
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (((uint32_t *)input_tuple)[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i | + (uint32_t)((uint64_t)(((const uint32_t*)rss_key)[j + 1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
A message that is not in the archive (sent off-list or not yet received): AAC06825A3B29643AF5372F5E0DDF053350C754D-kPTMFJFq+rFT4JjzTwqWc7fspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Andrey,
The main goal of this new functions is to calculate the hash which is equal to the hash of the NIC.
According to XL710 datasheet table 7-5 for sctp input set consists of IP4-S, IP4-D, SCTP-Verification-Tag. I don't see any NIC that uses QinQ or single vlan tag, ip proto number, tunnel id, vxlan, etc for calculating RSS hash. If it appear we can always update union rte_thash_tuple. I think it should be like:
struct rte_ports {
uint16_t dport;
uint16_t sport;
};union rte_thash_l4 {
struct rte_ports ports;
uint32_t sctp_tag;
};
struct rte_ipv4_tuple {
uint32_t src_addr;
uint32_t dst_addr;
union rte_thash_l4 l4;
};If it is necessary to distribute packets according to non standart tuples I think it's more appropriate to use crc32 or jhash because of speed. rte_softrss_be consumes 400-500 clocks for each 4-byte input at E3 [email protected]. This means for ipv4+tcp it consumes ~1500 clocks. If you or someone still think you need general toeplitz hash I'll add it.
Regards,
Vladimir
2015-05-05 19:03 GMT+03:00 Chilikin, Andrey <[email protected]>:
Quoted 306 lines
Hi Vladimir,
Why limit Toeplitz hash calculation to predefined tuples and length? Should it be more general, something like
rte_softrss_be(void *input, uint32_t input_len, const uint8_t *rss_key)to enable hash calculation for an input of any size? It would be useful for distributing packets using some non-standard tuples, like hashing on QinQ or adding IP protocol to hash calculation to separate UDP and TCP flows or even some other fields from a packet, for example, tunnel ID from VXLAN headers. By the way, i40e already supports RSS for SCTP in addition to TCP and UDP and includes Verification Tag as well as SCTP source and destination ports for RSS hash.Regards,
AndreyQuoted 10 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Tuesday, May 5, 2015 2:20 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE
header
lib/librte_hash/rte_thash.h
Quoted 27 lines
decapsulating).
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.hlib/librte_hash/Makefile +1
-0+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h +0
-0new file
Quoted 7 lines
mode 100644 index 0000000..42c7bf6
lib/librte_hash/rte_thash.h new file +3
-0@@ -0,0 +1,209 @@ +/*- +* BSD LICENSE +* lib/librte_hash/rte_thash.h line 13
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright
Quoted 133 lines
lib/librte_hash/rte_thash.h new file +8
-0+* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +31
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203, +0x0C0D0E0F08090A0B}; #endif + +enum rte_thash_len { + RTE_THASH_V4_L3 = 2, /*calculate hash of ipv4 headeronly*/
+RTE_THASH_V4_L4= 3, /*calculate hash of ipv4 + transport
headers*/
+RTE_THASH_V6_L3= 8, /*calculate hash of ipv6 header only
*/
+RTE_THASH_V6_L4= 9, /*calculate hash of ipv6 + transport
headers */lib/librte_hash/rte_thash.h new file +65
-0+}; + +/** +* IPv4 tuple +* addreses and ports have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +uint16_t dport; +uint16_t sport; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (16 ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void +rte_thash_load_v6_addr (const uint8_t *orig,uint8_t *targ) {#ifdef +__SSE3__ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask);#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + }lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst
Quoted 4 lines
address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address andIPv4 dst
Quoted 11 lines
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @paramrss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { + if (((uint32_t *)input_tuple)[j] & (1 << (31 -i))) {
Quoted 10 lines
+ ret ^= rte_cpu_to_be_32(((const
uint32_t
*)rss_key)[j]) << i |
+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t*)rss_key)[j + 1])) >> (32 - i));
lib/librte_hash/rte_thash.h new file +5
-0+ } + } + } +return ret; +}lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst
Quoted 4 lines
address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address andIPv4 dst
Quoted 11 lines
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @param*rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss_be(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { + if (((uint32_t *)input_tuple)[j] & (1 << (31 -i))) {
Quoted 1 line
+ ret ^= ((const
uint32_t*)rss_key)[j] << i|
Quoted 1 line
+ (uint32_t)((uint64_t)(((const
uint32_tQuoted 14 lines
*)rss_key)[j + 1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
A message that is not in the archive (sent off-list or not yet received): CANDrEH=uUjgE8aVsFJ6qSWnh3bZfXjKyyx3xfQFfjiHV0DWw6A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Vladimir,
Yes, at the moment NICs support limited input sets for hash calculation, but why limit SW for the same sets if it can be done in more general way and be easily scalable for HW updates? Using limited input set for RSS is not a feature of Toeplitz hash, but limitation of HW. I believe that general Toeplitz function will be more appropriate – it will cover input sets currently supported by HW and also will be easily scalable for future HW. Also, talking about different NICs – Niantic and Fortville, for example, have hash keys of different length, so rte_softrss() function should take into account hash key’s length as well. Regards,
Andrey
From: Vladimir Medvedkin [mailto:[email protected]]
Sent: Thursday, May 7, 2015 11:28 AM
To: Chilikin, Andrey
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Andrey,
The main goal of this new functions is to calculate the hash which is equal to the hash of the NIC.
According to XL710 datasheet table 7-5 for sctp input set consists of IP4-S, IP4-D, SCTP-Verification-Tag. I don't see any NIC that uses QinQ or single vlan tag, ip proto number, tunnel id, vxlan, etc for calculating RSS hash. If it appear we can always update union rte_thash_tuple. I think it should be like:
struct rte_ports {
uint16_t dport;
uint16_t sport;
};union rte_thash_l4 {
struct rte_ports ports;
uint32_t sctp_tag;
};
struct rte_ipv4_tuple {
uint32_t src_addr;
uint32_t dst_addr;
union rte_thash_l4 l4;
};If it is necessary to distribute packets according to non standart tuples I think it's more appropriate to use crc32 or jhash because of speed. rte_softrss_be consumes 400-500 clocks for each 4-byte input at E3 [email protected]<mailto:[email protected]>. This means for ipv4+tcp it consumes ~1500 clocks. If you or someone still think you need general toeplitz hash I'll add it.
Regards,
Vladimir
2015-05-05 19:03 GMT+03:00 Chilikin, Andrey <[email protected]<mailto:[email protected]>>:
Hi Vladimir,
Why limit Toeplitz hash calculation to predefined tuples and length? Should it be more general, something likerte_softrss_be(void *input, uint32_t input_len, const uint8_t *rss_key) to enable hash calculation for an input of any size? It would be useful for distributing packets using some non-standard tuples, like hashing on QinQ or adding IP protocol to hash calculation to separate UDP and TCP flows or even some other fields from a packet, for example, tunnel ID from VXLAN headers. By the way, i40e already supports RSS for SCTP in addition to TCP and UDP and includes Verification Tag as well as SCTP source and destination ports for RSS hash.
Regards,
Andrey
Quoted 277 lines
-----Original Message-----
From: dev [mailto:[email protected]<mailto:[email protected]>] On Behalf Of Vladimir Medvedkin
Sent: Tuesday, May 5, 2015 2:20 PM
To: [email protected]<mailto:[email protected]>
Subject: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v2 changes
- Add ipv6 support
- Various style fixes--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.hlib/librte_hash/Makefile +1
-0+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h new file renamed from lib/librte_hash/rte_thash.h +0
-0mode 100644 index 0000000..42c7bf6
lib/librte_hash/rte_thash.h new file +21
-0@@ -0,0 +1,209 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +31
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203, +0x0C0D0E0F08090A0B}; #endif + +enum rte_thash_len { + RTE_THASH_V4_L3 = 2, /*calculate hash of ipv4 headeronly*/
+RTE_THASH_V4_L4= 3, /*calculate hash of ipv4 + transport
headers*/
+RTE_THASH_V6_L3= 8, /*calculate hash of ipv6 header only
*/
+RTE_THASH_V6_L4= 9, /*calculate hash of ipv6 + transport
headers */lib/librte_hash/rte_thash.h new file +75
-0+}; + +/** +* IPv4 tuple +* addreses and ports have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +uint16_t dport; +uint16_t sport; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (16 ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void +rte_thash_load_v6_addr (const uint8_t *orig,uint8_t *targ) {#ifdef +__SSE3__ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask);#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + } +#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address and IPv4 dst
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @paramrss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h new file +8
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (((uint32_t *)input_tuple)[j] & (1 << (31 - i))) { + ret ^= rte_cpu_to_be_32(((const uint32_t*)rss_key)[j]) << i |
+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t*)rss_key)[j + 1])) >> (32 - i));
lib/librte_hash/rte_thash.h new file +15
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address and IPv4 dst
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @param*rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss_be(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h new file +9
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (((uint32_t *)input_tuple)[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i | + (uint32_t)((uint64_t)(((const uint32_t*)rss_key)[j + 1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
A message that is not in the archive (sent off-list or not yet received): AAC06825A3B29643AF5372F5E0DDF053350C7DF4-kPTMFJFq+rFT4JjzTwqWc7fspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Andrey,
OK, so be it. Thus in case you want to distribute (or just calculate hash based on non standart tuple) - use your own tuple and own hash key (length of tuple and key - responsible of the programmer). In case you want to emulate NIC RSS - use union rte_thash_tuple (still needs to be updated with new NICs input tuples) and NIC RSS hash key.P.S Thanks for reviews.
Regards,
Vladimir
2015-05-07 14:38 GMT+03:00 Chilikin, Andrey <[email protected]>:
Quoted 385 lines
Hi Vladimir,
Yes, at the moment NICs support limited input sets for hash calculation, but why limit SW for the same sets if it can be done in more general way and be easily scalable for HW updates? Using limited input set for RSS is not a feature of Toeplitz hash, but limitation of HW. I believe that general Toeplitz function will be more appropriate – it will cover input sets currently supported by HW and also will be easily scalable for future HW. Also, talking about different NICs – Niantic and Fortville, for example, have hash keys of different length, so
rte_softrss()function should take into account hash key’s length as well.Regards,
Andrey
*From:* Vladimir Medvedkin [mailto:[email protected]] *Sent:* Thursday, May 7, 2015 11:28 AM
*To:* Chilikin, Andrey
*Cc:* [email protected]
*Subject:* Re: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSSHi Andrey,
The main goal of this new functions is to calculate the hash which is equal to the hash of the NIC.
According to XL710 datasheet table 7-5 for sctp input set consists of IP4-S, IP4-D, SCTP-Verification-Tag. I don't see any NIC that uses QinQ or single vlan tag, ip proto number, tunnel id, vxlan, etc for calculating RSS hash. If it appear we can always update unionrte_thash_tuple. I think it should be like:struct rte_ports { uint16_t dport; uint16_t sport; };union rte_thash_l4 { struct rte_ports ports; uint32_t sctp_tag; }; struct rte_ipv4_tuple { uint32_t src_addr; uint32_t dst_addr; union rte_thash_l4 l4; };If it is necessary to distribute packets according to non standart tuples I think it's more appropriate to use crc32 or jhash because of speed.
rte_softrss_beconsumes 400-500 clocks for each 4-byte input at E3 [email protected]. This means for ipv4+tcp it consumes ~1500 clocks.If you or someone still think you need general toeplitz hash I'll add it.
Regards,
Vladimir
2015-05-05 19:03 GMT+03:00 Chilikin, Andrey <[email protected]>:
Hi Vladimir,
Why limit Toeplitz hash calculation to predefined tuples and length? Should it be more general, something like
rte_softrss_be(void *input, uint32_t input_len, const uint8_t *rss_key)to enable hash calculation for an input of any size? It would be useful for distributing packets using some non-standard tuples, like hashing on QinQ or adding IP protocol to hash calculation to separate UDP and TCP flows or even some other fields from a packet, for example, tunnel ID from VXLAN headers. By the way, i40e already supports RSS for SCTP in addition to TCP and UDP and includes Verification Tag as well as SCTP source and destination ports for RSS hash.Regards,
AndreyQuoted 10 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Tuesday, May 5, 2015 2:20 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v2] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE
header
lib/librte_hash/rte_thash.h
Quoted 27 lines
decapsulating).
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 209 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK- $(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.hlib/librte_hash/Makefile +1
-0+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h +0
-0new file
Quoted 7 lines
mode 100644 index 0000000..42c7bf6
lib/librte_hash/rte_thash.h new file +3
-0@@ -0,0 +1,209 @@ +/*- +* BSD LICENSE +* lib/librte_hash/rte_thash.h line 13
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright
Quoted 137 lines
lib/librte_hash/rte_thash.h new file +8
-0+* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +31
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203, +0x0C0D0E0F08090A0B}; #endif + +enum rte_thash_len { + RTE_THASH_V4_L3 = 2, /*calculate hash of ipv4 headeronly*/
+RTE_THASH_V4_L4= 3, /*calculate hash of ipv4 + transport
headers*/
+RTE_THASH_V6_L3= 8, /*calculate hash of ipv6 header only
*/
+RTE_THASH_V6_L4= 9, /*calculate hash of ipv6 + transport
headers */lib/librte_hash/rte_thash.h new file +65
-0+}; + +/** +* IPv4 tuple +* addreses and ports have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +uint16_t dport; +uint16_t sport; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (16 ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void +rte_thash_load_v6_addr (const uint8_t *orig,uint8_t *targ) {#ifdef +__SSE3__ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask);#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + }lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst
Quoted 4 lines
address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address andIPv4 dst
Quoted 11 lines
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @paramrss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { + if (((uint32_t *)input_tuple)[j] & (1 << (31 -i))) {
Quoted 10 lines
+ ret ^= rte_cpu_to_be_32(((const
uint32_t
*)rss_key)[j]) << i |
+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t*)rss_key)[j + 1])) >> (32 - i));
lib/librte_hash/rte_thash.h new file +5
-0+ } + } + } +return ret; +}lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. +* @param input_tuple +* Pointer to rte_thash_tuple union +* @param input_len +* Length of input_tuple in 4-bytes chunks +* RTE_THASH_V4_L3: calculate hash of IPv4 src address and IPv4 dst
Quoted 4 lines
address
+ *RTE_THASH_V4_L4calculate hash of IPv4 adresses and TCP|UDP
ports
+ *RTE_THASH_V6_L3: calculate hash of IPv6 src address andIPv4 dst
Quoted 11 lines
address
+ *RTE_THASH_V6_L4calculate hash of IPv6 adresses and TCP|UDP
ports
+ * @param*rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */lib/librte_hash/rte_thash.h new file +2
-0+static inline uint32_t +rte_softrss_be(union rte_thash_tuple *input_tuple, enum rte_thash_len
input_len,lib/librte_hash/rte_thash.h
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+ const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { + if (((uint32_t *)input_tuple)[j] & (1 << (31 -i))) {
Quoted 1 line
+ ret ^= ((const
uint32_t*)rss_key)[j] << i|
Quoted 1 line
+ (uint32_t)((uint64_t)(((const
uint32_tQuoted 14 lines
*)rss_key)[j + 1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
PATCH v2 1/1 Add toeplitz hash algorithm used by RSS
In reply to a message not in the archiveSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Add sctp_tag into tuple
v2 changes
- Add ipv6 support
- Various style fixes
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eal
lib/librte_hash/rte_thash.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
2015-05-08 10:58, Vladimir Medvedkin:
Quoted 9 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuple
Quoted 8 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++
Without any comment, it seems this v3 is approved.
Maybe that this patch would be even better by implementing some unit tests. I wonder if the hash chapter of the prog guide could list the different algorithms and why/when use them?
Thanks
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
2015-06-03 16:07, Thomas Monjalon:
Quoted 19 lines
2015-05-08 10:58, Vladimir Medvedkin:
Quoted 9 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Addsctp_taginto tupleQuoted 8 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++
Quoted 4 lines
Without any comment, it seems this v3 is approved.
Maybe that this patch would be even better by implementing some unit tests. I wonder if the hash chapter of the prog guide could list the different algorithms and why/when use them?
Bruce, any opinion?
Don't you think that unit tests are required?
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Quoted 20 lines · Thomas Monjalon
2015-06-03 16:07, Thomas Monjalon:
Quoted 19 lines
2015-05-08 10:58, Vladimir Medvedkin:
Quoted 17 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
Quoted 4 lines
Without any comment, it seems this v3 is approved.
Maybe that this patch would be even better by implementing some unit tests. I wonder if the hash chapter of the prog guide could list the different algorithms and why/when use them?Bruce, any opinion?
Don't you think that unit tests are required?
Sorry, I missed this patch set. I'll take a look at it today.
/Bruce
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
In reply to Vladimir MedvedkinQuoted 9 lines · Vladimir Medvedkin
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuple
Quoted 5 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>
Hi Vladimir,
first off, thanks for this patch, it looks like something we want into DPDK. However, as Thomas has already pointed out, I think we could really do with some unit tests for this code. As it stands right now, we don't even know if this header compiles, as the header file is not used by any C file in DPDK.
Some other comments are inline below.
Regards,
/Bruce
Quoted 24 lines
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile +1
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h new file +0
-0
lib/librte_hash/rte_thash.h line 4
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0@@ -0,0 +1,207 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
Date and copyright owner look to need update here.
Quoted 46 lines
lib/librte_hash/rte_thash.h new file +46
-0+* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example
lib/librte_hash/rte_thash.h line 60
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* after GRE header decapsulating) +*/ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203 ,0x0C0D0E0F08090A0B }; +#endif
I think a more descriptive name for this might help. Yes, it's a mask for byteswapping, but I think the name could do with being more descriptive. I see below it's used for IPv6 IP extraction, so maybe that could be put in the name somehow. A comment should also be added on what it is used for. Finally, since this is a public symbol in the including C file, it should have an rte_ prefix - or perhaps just an underscore prefix "_".
lib/librte_hash/rte_thash.h line 66
Quoted 6 lines
lib/librte_hash/rte_thash.h new file +6
-0+ +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/ +#define RTE_THASH_V4_L4 3/*calculate hash of ipv4 + transport headers*/ +#define RTE_THASH_V6_L3 8/*calculate hash of ipv6 header only */ +#define RTE_THASH_V6_L4 9/*calculate hash of ipv6 + transport headers */ +
Are these #defines used anywhere? If not, they should be removed.
lib/librte_hash/rte_thash.h line 76
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+struct rte_ports { +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_l4 { +struct rte_ports ports; +uint32_t sctp_tag; +}; +
Any reason for the rte_ports struct being separated out from the rte_thash_l4 structure?
Quoted 16 lines
lib/librte_hash/rte_thash.h new file +16
-0+/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union rte_thash_l4 l4; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv6_tuple {
lib/librte_hash/rte_thash.h line 102
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union rte_thash_l4 l4; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (16 ))); +
I can see the reason for these structure, but they are not actually used anywhere in the code below. Should some of the functions, e.g. load_v6_addr fn not use these as type parameters?
Quoted 18 lines
lib/librte_hash/rte_thash.h new file +18
-0+/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) +{ +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +}
lib/librte_hash/rte_thash.h line 130
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void +rte_thash_load_v6_addr (const uint8_t *orig,uint8_t *targ)
Why not take a struct ipv6_hdr (from ip.h) and struct rte_ipv6_tuple parameters directly, rather than uint8_t parameters to somewhere in the middle of the structures? Specifying that way allows the compile to check the user is doing things correctly.
lib/librte_hash/rte_thash.h line 132
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+{ +#ifdef __SSE3__
I actually think the minimum supported SSE instruction set level for DPDK is SSE3, so perhaps these #idefs could be removed.
Quoted 24 lines
lib/librte_hash/rte_thash.h new file +24
-0+__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask); +#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + } +#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ +static inline uint32_t
lib/librte_hash/rte_thash.h line 166
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+rte_softrss(uint32_t *input_tuple, uint32_t input_len, + const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^=rte_cpu_to_be_32 (((const uint32_t *)rss_key)[j]) << i | + (uint32_t )((uint64_t )(rte_cpu_to_be_32 (((const uint32_t *)rss_key)[j +1 ])) >> (32 - i));
Line is rather long and not terribly readable. Can it be split up into a number of easier to read statements (without affecting performance)?
lib/librte_hash/rte_thash.h line 176
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key.
Put in reference to function used for the conversion.
Can you also document when you might want to use this version over the previous one?
Quoted 34 lines
lib/librte_hash/rte_thash.h new file +31
-0+* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param *rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ +static inline uint32_t +rte_softrss_be (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i | + (uint32_t )((uint64_t )(((const uint32_t *)rss_key)[j +1 ]) >> (32 - i)); + } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ Signature · 1 line
1.8.3.2
Re: [PATCH v2] Add toeplitz hash algorithm used by RSS
Hi Bruce,
2015-06-16 15:29 GMT+03:00 Bruce Richardson <[email protected]>:
Quoted 16 lines · Vladimir Medvedkin
Quoted 9 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v3 changes
- Rework API to be more generic
- Addsctp_taginto tupleQuoted 5 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>
Quoted 9 lines
Hi Vladimir,
first off, thanks for this patch, it looks like something we want into DPDK.
However, as Thomas has already pointed out, I think we could really do with some unit tests for this code. As it stands right now, we don't even know if this
header compiles, as the header file is not used by any C file in DPDK.
I'll try to make a unit test this week
Quoted 119 lines
Some other comments are inline below.
Regards,
/BruceQuoted 3 lines
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207++++++++++++++++++++++++++++++++++++++++++++
Quoted 21 lines
2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.hlib/librte_hash/Makefile +1
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eallib/librte_hash/rte_thash.h new file +0
-0lib/librte_hash/rte_thash.h line 4
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0@@ -0,0 +1,207 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. Date and copyright owner look to need update here.
lib/librte_hash/rte_thash.h
Quoted 9 lines
lib/librte_hash/rte_thash.h new file +9
-0+* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright
lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
lib/librte_hash/rte_thash.h line 24
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
lib/librte_hash/rte_thash.h line 25
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lib/librte_hash/rte_thash.h line 27
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
lib/librte_hash/rte_thash.h line 28
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
lib/librte_hash/rte_thash.h line 30
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
lib/librte_hash/rte_thash.h line 31
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Quoted 18 lines
lib/librte_hash/rte_thash.h new file +18
-0+*/ + +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIClib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* or for simulating of RSS computation on specific NIC (for example +* after GRE header decapsulating) +*/ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> + +#ifdef __SSE3__ +static const __m128i bswap_mask = {0x0405060700010203,
0x0C0D0E0F08090A0B};lib/librte_hash/rte_thash.h line 60
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+#endif I think a more descriptive name for this might help. Yes, it's a mask for byteswapping, but I think the name could do with being more descriptive. I see
below it's used for IPv6 IP extraction, so maybe that could be put in the name
somehow. A comment should also be added on what it is used for. Finally, since this is a public symbol in the including C file, it should have
anrte_prefix - or perhaps just an underscore prefix "_".I think
rte_thash_ipv6_bswap_maskwillbe more appropriatelib/librte_hash/rte_thash.h line 62
Quoted 2 lines
lib/librte_hash/rte_thash.h new file +2
-0+ +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/
lib/librte_hash/rte_thash.h line 63
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+#define RTE_THASH_V4_L4 3/*calculate hash of ipv4 +
Quoted 9 lines
transport headers*/
lib/librte_hash/rte_thash.h line 64
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+#define RTE_THASH_V6_L3 8/*calculate hash of ipv6 header only */
lib/librte_hash/rte_thash.h line 65
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+#define RTE_THASH_V6_L4 9/*calculate hash of ipv6 + transport headers */
lib/librte_hash/rte_thash.h line 66
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+Are these #defines used anywhere? If not, they should be removed.
It can be used in code that uses this library.
Quoted 16 lines
lib/librte_hash/rte_thash.h line 76
Quoted 11 lines
lib/librte_hash/rte_thash.h new file +10
-0+struct rte_ports { +uint16_t dport; +uint16_t sport; +}; + +union rte_thash_l4 { +struct rte_ports ports; +uint32_t sctp_tag; +}; +Any reason for the
rte_portsstruct being separated out from therte_thash_l4
structure?
You're right, no reason, I'll make unnamed struct field.
Quoted 24 lines
Quoted 24 lines
lib/librte_hash/rte_thash.h new file +23
-0+/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union rte_thash_l4 l4; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union rte_thash_l4 l4; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4;
Quoted 9 lines
lib/librte_hash/rte_thash.h line 102
Quoted 3 lines
lib/librte_hash/rte_thash.h new file +3
-0+struct rte_ipv6_tuple v6; +} __attribute__((aligned(16))); +I can see the reason for these structure, but they are not actually used anywhere in the code below. Should some of the functions, e.g.
load_v6_addrfn
not use these as type parameters?
Agree
Quoted 28 lines
Quoted 28 lines
lib/librte_hash/rte_thash.h new file +27
-0+/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) +{ +int i; + +for (i =0 ; i < (len >>2 ); i++) { + targ[i] =rte_be_to_cpu_32 (orig[i]); + } +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 address inside ipv6_hdr +* @param targ +* Pointer to ipv6 address inside rte_ipv6_tuple +*/ +static inline void
Quoted 9 lines
lib/librte_hash/rte_thash.h line 130
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+rte_thash_load_v6_addr(const uint8_t *orig, uint8_t *targ)Why not take a struct
ipv6_hdr(fromip.h) and structrte_ipv6_tupleparameters
directly, rather thanuint8_tparameters to somewhere in the middle of the structures? Specifying that way allows the compile to check the user is doing
things correctly.
Agree too. I think it shoul be like rte_thash_load_v6_addr(const struct ipv6_hdr *orig, union rte_thash_tuple *targ)
Quoted 42 lines
lib/librte_hash/rte_thash.h line 132
Quoted 3 lines
lib/librte_hash/rte_thash.h new file +2
-0+{ +#ifdef __SSE3__I actually think the minimum supported SSE instruction set level for DPDK is
SSE3, so perhaps these #idefs could be removed.Quoted 23 lines
lib/librte_hash/rte_thash.h new file +23
-0+__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig); + *(__m128i *)targ =_mm_shuffle_epi8 (ipv6, bswap_mask); +#else +int i; + +for (i =0 ; i <4 ; i++) { + *((uint32_t *)targ + i) = +rte_be_to_cpu_32 (*((const uint32_t *)orig + i)); + } +#endif +} + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline uint32_t +rte_softrss (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= rte_cpu_to_be_32(((const uint32_t*)rss_key)[j]) << i |
Quoted 8 lines
lib/librte_hash/rte_thash.h line 166
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const
uint32_t*)rss_key)[j +
1])) >> (32 - i));Line is rather long and not terribly readable. Can it be split up into a number
of easier to read statements (without affecting performance)?
I don't see how it can be done
Quoted 53 lines
lib/librte_hash/rte_thash.h line 176
Quoted 11 lines
lib/librte_hash/rte_thash.h new file +10
-0+ } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key. Put in reference to function used for the conversion.
Can you also document when you might want to use this version over the previous one?Quoted 9 lines
lib/librte_hash/rte_thash.h new file +9
-0+* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param *rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline uint32_t +rte_softrss_be (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i|
lib/librte_hash/rte_thash.h line 196
Quoted 1 line
lib/librte_hash/rte_thash.h new file +1
-0+ (uint32_t)((uint64_t)(((const
uint32_t*)rss_key)[j + 1]) >> (32 - i));Quoted 14 lines
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
PATCH v4 1/1 Add toeplitz hash algorithm used by RSS
In reply to Vladimir Medvedkinv4 changes
- Fix copyright
- rename bswap_mask constant, add rte_ prefix
- change rte_ipv[46]_tuple struct
- change rte_thash_load_v6_addr prototype
v3 changes
- Rework API to be more generic
- Add sctp_tag into tuple
v2 changes
- Add ipv6 support
- Various style fixes
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 202 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eal
lib/librte_hash/rte_thash.h new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v4] Add toeplitz hash algorithm used by RSS
Quoted 14 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Friday, June 19, 2015 3:56 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4] Add toeplitz hash algorithm used by RSSv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototype
Quoted 8 lines
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixes
Missing signoff line.
Quoted 7 lines
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 202 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
<...snip...>
Quoted 8 lines
(quoted diff) +2
-0+ +/* Byte swap mask used for converting IPv6 address 4-byte chunks to CPUbyte order */
+static const__m128irte_thash_ipv6_bswap_mask= {0x0405060700010203,0x0C0D0E0F08090A0B};lib/librte_hash/rte_thash.h new file +3
-0+ +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/ +#define RTE_THASH_V4_L4 3/*calculate hash of ipv4 + transport
Quoted 5 lines
headers*/
+#defineRTE_THASH_V6_L38 /*calculate hash of ipv6 header only
*/
+#defineRTE_THASH_V6_L49 /*calculate hash of ipv6 + transport
headers */
I'm still not seeing why these values need to be defined here, rather than in a specific app. Also, the choice of values for these defines seems strange to me? How were they chosen?
/Bruce
Re: [PATCH v4] Add toeplitz hash algorithm used by RSS
Hi Bruce,
2015-06-19 18:59 GMT+03:00 Richardson, Bruce <[email protected]>:
Quoted 48 lines
Quoted 14 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Friday, June 19, 2015 3:56 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4] Add toeplitz hash algorithm used by RSSv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypeQuoted 8 lines
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesMissing signoff line.
Quoted 7 lines
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 202 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h<...snip...>
Review
Quoted 7 lines
(quoted diff) +2
-0+ +/* Byte swap mask used for converting IPv6 address 4-byte chunks to CPUbyte order */
+static const__m128irte_thash_ipv6_bswap_mask= {0x0405060700010203,0x0C0D0E0F08090A0B};(quoted diff) +2
-0+ +#define RTE_THASH_V4_L3 2 /*calculate hash of ipv4 headeronly*/
Quoted 1 line
+#define
RTE_THASH_V4_L43 /*calculate hash of ipv4 +transport
Quoted 2 lines
headers*/
+#defineRTE_THASH_V6_L38 /*calculate hash of ipv6 headeronly
Quoted 2 lines
*/
+#defineRTE_THASH_V6_L49 /*calculate hash of ipv6 +
Quoted 8 lines
transport
Quoted 1 line
headers */
I'm still not seeing why these values need to be defined here, rather than in a specific app.
Also, the choice of values for these defines seems strange to me? How were they chosen?
This is a predefined values. They mean the length (in 4-bytes) of the input data
in hashing. I think it's like defines in rte_ip.h, for example.
Quoted 4 lines
/Bruce
Re: [PATCH v4] Add toeplitz hash algorithm used by RSS
Quoted 55 lines · Vladimir Medvedkin
Hi Bruce,
2015-06-19 18:59 GMT+03:00 Richardson, Bruce <[email protected]>:
Quoted 51 lines
Quoted 14 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Friday, June 19, 2015 3:56 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH v4] Add toeplitz hash algorithm used by RSSv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypeQuoted 8 lines
v3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesMissing signoff line.
Quoted 7 lines
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 202 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h<...snip...>
Review
Quoted 7 lines
(quoted diff) +2
-0+ +/* Byte swap mask used for converting IPv6 address 4-byte chunks to CPUbyte order */
+static const__m128irte_thash_ipv6_bswap_mask= {0x0405060700010203,0x0C0D0E0F08090A0B};(quoted diff) +2
-0+ +#define RTE_THASH_V4_L3 2 /*calculate hash of ipv4 headeronly*/
Quoted 1 line
+#define
RTE_THASH_V4_L43 /*calculate hash of ipv4 +transport
Quoted 2 lines
headers*/
+#defineRTE_THASH_V6_L38 /*calculate hash of ipv6 headeronly
Quoted 2 lines
*/
+#defineRTE_THASH_V6_L49 /*calculate hash of ipv6 +transport
Quoted 1 line
headers */
Quoted 9 lines
Quoted 5 lines
I'm still not seeing why these values need to be defined here, rather than in a specific app.
Also, the choice of values for these defines seems strange to me? How were they chosen?This is a predefined values. They mean the length (in 4-bytes) of the input data
in hashing. I think it's like defines inrte_ip.h, for example.
I'm still not convined of the need for them in this file. If they are to be kept though, they should instead have "LEN" in the name to indicate that they are the lengths of the different keys. You could also make this clearer by changing the L4 values to be computed using "sizeof()" given that the appropriate tuple structures are present later in the header file to allow the sizes to be correctly calculated.
/Bruce
Re: [PATCH v4] Add toeplitz hash algorithm used by RSS
In reply to Richardson, BruceQuoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Richardson, Bruce
Sent: Friday, June 19, 2015 5:00 PM
To: Vladimir Medvedkin; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4] Add toeplitz hash algorithm used by RSSMissing signoff line.
Hi,
It would also be worth running Linux checkpatch against the patch, which would have caught the missing signoff. It also shows a lot of warnings in the patch which indicates conflicts with the coding guidelines.
John
PATCH v5 1/1 Add toeplitz hash algorithm used by RSS
In reply to Vladimir MedvedkinSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v5 changes
- Fix errors reported by checkpatch.pl
v4 changes
- Fix copyright
- rename bswap_mask constant, add rte_ prefix
- change rte_ipv[46]_tuple struct
- change rte_thash_load_v6_addr prototype
v3 changes
- Rework API to be more generic
- Add sctp_tag into tuple
v2 changes
- Add ipv6 support
- Various style fixes
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eal
lib/librte_hash/rte_thash.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v5] Add toeplitz hash algorithm used by RSS
Quoted 29 lines · Vladimir Medvedkin
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
<snip>
lib/librte_hash/rte_thash.h line 69
Quoted 8 lines
lib/librte_hash/rte_thash.h new file +8
-0+static const __m128i rte_thash_ipv6_bswap_mask = { +0x0405060700010203 ,0x0C0D0E0F08090A0B }; + +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/ +#define RTE_THASH_V4_L4 3/*calculate hash of ipv4 + transport headers*/ +#define RTE_THASH_V6_L3 8/*calculate hash of ipv6 header only */ +#define RTE_THASH_V6_L4 9/*calculate hash of ipv6 + transport headers */ +
Comment as on V4 patch - add LEN to name to make it clear they are lengths in quadwords.
Quoted 28 lines
lib/librte_hash/rte_thash.h new file +28
-0+/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv6_tuple { + uint8_t src_addr[16]; + uint8_t dst_addr[16]; + union { + struct { + uint16_t dport; + uint16_t sport;
lib/librte_hash/rte_thash.h line 107
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ }; +uint32_t sctp_tag; + }; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +}__aligned(size) ; +
This throws an error on compilation [with unit test patch also applied].
In file included from /home/bruce/dpdk.org/app/test/test_thash.c:40:0:/home/bruce/dpdk.org/x86_64-native-linuxapp-gcc/include/rte_thash.h:106:1: error: parameter names (without types) in function declaration [-Werror]
} __aligned(size);
^
Quoted 25 lines
lib/librte_hash/rte_thash.h new file +25
-0+/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) +{ +int i; + +for (i =0 ; i < (len >>2 ); i++) + targ[i] =rte_be_to_cpu_32 (orig[i]); +} + +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 header of the original packet +* @param targ +* Pointer to rte_ipv6_tuple structure +*/
lib/librte_hash/rte_thash.h line 142
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline void +rte_thash_load_v6_addr (const struct ipv6_hdr *orig,union rte_thash_tuple *targ) +{ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); + ipv6 =_mm_loadu_si128 ((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); +}
I think the function name needs to be pluralized, and the comment updated to make it clear that it is not just one IPv6 address that is loaded, but rather both source and destination.
Regards,
/Bruce
Re: [PATCH v5] Add toeplitz hash algorithm used by RSS
Hi Bruce,
2015-06-29 15:40 GMT+03:00 Bruce Richardson <[email protected]>:
Quoted 39 lines · Vladimir Medvedkin
Quoted 18 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tupleQuoted 8 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines
2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h<snip>
lib/librte_hash/rte_thash.h
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0+static const __m128i rte_thash_ipv6_bswap_mask = { +0x0405060700010203 ,0x0C0D0E0F08090A0B }; + +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/
Quoted 1 line
+#define
RTE_THASH_V4_L43 /*calculate hash of ipv4 +transport headers*/
Quoted 9 lines
Quoted 1 line
+#define
RTE_THASH_V6_L38 /*calculate hash of ipv6 headeronly */
Quoted 1 line
+#define
RTE_THASH_V6_L49 /*calculate hash of ipv6 +transport headers */
Quoted 1 line
+
Comment as on V4 patch - add LEN to name to make it clear they are lengths in quadwords.
Agree, but length dwords
Quoted 32 lines
Quoted 32 lines
lib/librte_hash/rte_thash.h new file +31
-0+/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + };
Quoted 9 lines
lib/librte_hash/rte_thash.h line 107
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +}__aligned(size) ; +This throws an error on compilation [with unit test patch also applied].
I will never copy paste
I will never copy paste
I will never... =)
Quoted 35 lines
In file included from
/home/bruce/dpdk.org/app/test/test_thash.c:40:0:/home/bruce/dpdk.org/x86_64-native-linuxapp-gcc/include/rte_thash.h:106:1:
error: parameter names (without types) in function declaration [-Werror]
}__aligned(size);
^+/**
Quoted 16 lines
+ * Prepare special converted key to use with
rte_softrss_be()
+ * @param orig
+ * pointer to original RSS key
+ * @param targ
+ * pointer to target RSS key
+ * @param len
+ * RSS key length
+ */lib/librte_hash/rte_thash.h new file +8
-0+static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) +{ +int i; + +for (i =0 ; i < (len >>2 ); i++) + targ[i] =rte_be_to_cpu_32 (orig[i]); +}lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 header of the original packet +* @param targ +* Pointer to rte_ipv6_tuple structure +*/ +static inline void +rte_thash_load_v6_addr(const struct ipv6_hdr *orig, union
rte_thash_tuple*targ)
Quoted 15 lines
lib/librte_hash/rte_thash.h line 142
Quoted 8 lines
lib/librte_hash/rte_thash.h new file +8
-0+{ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); + ipv6 =_mm_loadu_si128 ((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); +}I think the function name needs to be pluralized, and the comment updated to make
it clear that it is not just one IPv6 address that is loaded, but rather both
source and destination.
I think no need to make too long function name like rte_thash_load_v6_addresses(), instead I'll make comment more clear. Is it enough?
Quoted 4 lines
Regards,
/Bruce
Re: [PATCH v5] Add toeplitz hash algorithm used by RSS
Quoted 45 lines · Vladimir Medvedkin
Hi Bruce,
2015-06-29 15:40 GMT+03:00 Bruce Richardson <[email protected]>:
Quoted 41 lines · Vladimir Medvedkin
Quoted 18 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tupleQuoted 8 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 207++++++++++++++++++++++++++++++++++++++++++++
Quoted 3 lines
2 files changed, 208 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h<snip>
lib/librte_hash/rte_thash.h
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0+static const __m128i rte_thash_ipv6_bswap_mask = { +0x0405060700010203 ,0x0C0D0E0F08090A0B }; + +#define RTE_THASH_V4_L3 2/*calculate hash of ipv4 header only*/
Quoted 1 line
+#define
RTE_THASH_V4_L43 /*calculate hash of ipv4 +transport headers*/
Quoted 1 line
+#define
RTE_THASH_V6_L38 /*calculate hash of ipv6 headeronly */
Quoted 9 lines
Quoted 7 lines
Quoted 1 line
+#define
RTE_THASH_V6_L49 /*calculate hash of ipv6 +transport headers */
Quoted 1 line
+
Comment as on V4 patch - add LEN to name to make it clear they are lengths in quadwords.
Agree, but length dwords
Yes, my mistake.
Quoted 95 lines
Quoted 32 lines
Quoted 32 lines
lib/librte_hash/rte_thash.h new file +31
-0+/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order +*/ +struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + };Quoted 9 lines
lib/librte_hash/rte_thash.h line 107
Quoted 7 lines
lib/librte_hash/rte_thash.h new file +7
-0+}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +}__aligned(size) ; +This throws an error on compilation [with unit test patch also applied].
I will never copy paste
I will never copy paste
I will never... =)Quoted 35 lines
In file included from
/home/bruce/dpdk.org/app/test/test_thash.c:40:0:/home/bruce/dpdk.org/x86_64-native-linuxapp-gcc/include/rte_thash.h:106:1:
error: parameter names (without types) in function declaration [-Werror]
}__aligned(size);
^+/**
Quoted 16 lines
+ * Prepare special converted key to use with
rte_softrss_be()
+ * @param orig
+ * pointer to original RSS key
+ * @param targ
+ * pointer to target RSS key
+ * @param len
+ * RSS key length
+ */lib/librte_hash/rte_thash.h new file +8
-0+static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) +{ +int i; + +for (i =0 ; i < (len >>2 ); i++) + targ[i] =rte_be_to_cpu_32 (orig[i]); +}lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+ +/** +* Prepare and load IPv6 address +* @param orig +* Pointer to ipv6 header of the original packet +* @param targ +* Pointer to rte_ipv6_tuple structure +*/ +static inline void +rte_thash_load_v6_addr(const struct ipv6_hdr *orig, union
rte_thash_tuple*targ)Quoted 15 lines
lib/librte_hash/rte_thash.h line 142
Quoted 8 lines
lib/librte_hash/rte_thash.h new file +8
-0+{ +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); + ipv6 =_mm_loadu_si128 ((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); +}I think the function name needs to be pluralized, and the comment updated to make
it clear that it is not just one IPv6 address that is loaded, but rather both
source and destination.
Quoted 3 lines
I think no need to make too long function name like
rte_thash_load_v6_addresses(), instead I'll make comment more clear. Is it enough?
I was actually thinking "addrs" rather than full "addresses" in the name. The extra "s" should be enough to make it appear as plural. Please make the comment clear anyway.
/Bruce
PATCH v6 1/1 Add toeplitz hash algorithm used by RSS
In reply to Vladimir MedvedkinSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and function
v5 changes
- Fix errors reported by checkpatch.pl
v4 changes
- Fix copyright
- rename bswap_mask constant, add rte_ prefix
- change rte_ipv[46]_tuple struct
- change rte_thash_load_v6_addr prototype
v3 changes
- Rework API to be more generic
- Add sctp_tag into tuple
v2 changes
- Add ipv6 support
- Various style fixes
--- lib/librte_hash/Makefile | 1 + lib/librte_hash/rte_thash.h | 231 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile +1 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h # this lib needs eal
lib/librte_hash/rte_thash.h new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v6] Add toeplitz hash algorithm used by RSS
Quoted 22 lines · Vladimir Medvedkin
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and functionv5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuple
Quoted 5 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>
Thomas Monjalon
AppliedRe: [PATCH v6] Add toeplitz hash algorithm used by RSS
2015-07-01 16:29, Bruce Richardson:
Quoted 23 lines · Vladimir Medvedkin
Quoted 22 lines
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for simulating of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and functionv5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuple
Quoted 7 lines
Quoted 5 lines
v2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>Acked-by Bruce Richardson <[email protected]>
Applied, thanks
Re: [PATCH v6] Add toeplitz hash algorithm used by RSS
In reply to Vladimir MedvedkinHi, Vladimir
When compiling thash for no-X86 arches, it fails with the following errors. I wonder if
it is possible to make the thash library arch-independent?
== Build app/test
CC test_thash.o
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:56:22:
error: rte_vect.h: No such file or directory
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:62:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rte_thash_ipv6_bswap_mask' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:129:
error: requested alignment is not a constant /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h: In function 'rte_thash_load_v6_addrs':
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: '__m128i' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: (Each undeclared identifier is reported only once /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: for each function it appears in.) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: expected ';' before 'ipv6' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:161:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: 'ipv6' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: implicit declaration of function '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: nested extern declaration of '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: expected ')' before '__m128i' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: type defaults to 'int' in declaration of 'type name' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: cast from pointer to integer of different size /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:164:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:158:
warning: unused parameter 'targ'
make[3]: *** [test_thash.o] Error 1
make[2]: *** [test] Error 2
make[1]: *** [app] Error 2
make: *** [all] Error 2
Thanks
-Zhigang Lu
Quoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Wednesday, July 01, 2015 7:40 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v6] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for
simulating
lib/librte_hash/rte_thash.h new
Quoted 45 lines
of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and functionv5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>---
lib/librte_hash/Makefile| 1 +lib/librte_hash/rte_thash.h| 231
++++++++++++++++++++++++++++++++++++++++++++2 files changed, 232 insertions(+)create mode 100644
lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.h+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_thash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_fbk_hash.h# this lib needs eallib/librte_hash/rte_thash.h new renamed from lib/librte_hash/rte_thash.h +0
-0
file
Quoted 188 lines
mode 100644 index 0000000..1808f47
lib/librte_hash/rte_thash.h new file +21
-0@@ -0,0 +1,231 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2015 Vladimir Medvedkin <[email protected]> +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +141
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> +#include <rte_ip.h> + +/* Byte swap mask used for converting IPv6 address + * 4-byte chunks to CPU byte order + */ +static const __m128i rte_thash_ipv6_bswap_mask = { + 0x0405060700010203, 0x0C0D0E0F08090A0B}; + +/** + * length in dwords of input tuple to + * calculate hash of ipv4 header only + */ +#define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \ + sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) / 4) + +/** + * length in dwords of input tuple to + * calculate hash of ipv4 header + + * transport header + */ +#define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4) + +/** + * length in dwords of input tuple to + * calculate hash of ipv6 header only + */ +#define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \ + sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) / 4) + +/** + * length in dwords of input tuple to + * calculate hash of ipv6 header + + * transport header + */ +#define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4) + +/** + * IPv4 tuple + * addreses and ports/sctp_tag have to be CPU byte order */ struct +rte_ipv4_tuple { + uint32_t src_addr; + uint32_t dst_addr; + union { + struct { + uint16_t dport; + uint16_t sport; + }; + uint32_t sctp_tag; + }; +}; + +/** + * IPv6 tuple + * Addresses have to be filled by rte_thash_load_v6_addr() + * ports/sctp_tag have to be CPU byte order */ struct rte_ipv6_tuple { + uint8_t src_addr[16]; + uint8_t dst_addr[16]; + union { + struct { + uint16_t dport; + uint16_t sport; + }; + uint32_t sctp_tag; + }; +}; + +union rte_thash_tuple { + struct rte_ipv4_tuple v4; + struct rte_ipv6_tuple v6; +} __attribute__((aligned(XMM_SIZE))); + +/** + * Prepare special converted key to use with rte_softrss_be() + * @param orig + * pointer to original RSS key + * @param targ + * pointer to target RSS key + * @param len + * RSS key length + */ +static inline void +rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len) { + int i; + + for (i = 0; i < (len >> 2); i++) + targ[i] = rte_be_to_cpu_32(orig[i]); +} + +/** + * Prepare and load IPv6 addresses (src and dst) + * into target tuple + * @param orig + * Pointer to ipv6 header of the original packet + * @param targ + * Pointer to rte_ipv6_tuple structure + */ +static inline void +rte_thash_load_v6_addrs(const struct ipv6_hdr *orig, union +rte_thash_tuple *targ) { + __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = + _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask); + ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = + _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask); } + +/** + * Generic implementation. Can be used with original rss_key + * @param input_tuple + * Pointer to input tuple + * @param input_len + * Length of input_tuple in 4-bytes chunks + * @param rss_key + * Pointer to RSS hash key. + * @return + * Calculated hash value. + */
lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline uint32_t +rte_softrss (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= rte_cpu_to_be_32(((const uint32_t
*)rss_key)[j]) << i
Quoted 2 lines
|
+
(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const
Quoted 22 lines
uint32_t*)rss_key)[j + 1])) >>lib/librte_hash/rte_thash.h new file +21
-0+ (32 - i)); + } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key with rte_convert_rss_key() fn. +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param *rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ +static inline uint32_t
lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+rte_softrss_be(uint32_t *input_tuple, uint32_t input_len, + const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i | + (uint32_t)((uint64_t)(((const
uint32_t *)rss_key)[j +
Quoted 14 lines
1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
Re: [PATCH v6] Add toeplitz hash algorithm used by RSS
Hi Tony,
Sorry for the late reply, I was on vacation.
I'll prepare patch soon.
Regards,
Vladimir
2015-07-22 10:55 GMT+03:00 Tony Lu <[email protected]>:
Quoted 365 lines
Hi, Vladimir
When compiling thash for no-X86 arches, it fails with the following errors. I wonder if
it is possible to make the thash library arch-independent?== Build app/test
CC test_thash.o
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:56:22 :
error:rte_vect.h: No such file or directory
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:62:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rte_thash_ipv6_bswap_mask' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:129:
error: requested alignment is not a constant /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h: In function 'rte_thash_load_v6_addrs':
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: '__m128i' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: (Each undeclared identifier is reported only once /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: for each function it appears in.) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: expected ';' before 'ipv6' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:161:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: 'ipv6' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: implicit declaration of function '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: nested extern declaration of '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: expected ')' before '__m128i' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: type defaults to 'int' in declaration of 'type name' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: cast from pointer to integer of different size /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:164:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:158:
warning: unused parameter 'targ'
make[3]: *** [test_thash.o] Error 1
make[2]: *** [test] Error 2
make[1]: *** [app] Error 2
make: *** [all] Error 2Thanks
-Zhigang LuQuoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Wednesday, July 01, 2015 7:40 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v6] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for
simulating
lib/librte_hash/rte_thash.h new
Quoted 45 lines
of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and functionv5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixesSigned-off-by Vladimir Medvedkin <[email protected]>---
lib/librte_hash/Makefile| 1 +lib/librte_hash/rte_thash.h| 231
++++++++++++++++++++++++++++++++++++++++++++2 files changed, 232 insertions(+)create mode 100644
lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.h+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_thash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_fbk_hash.h# this lib needs eallib/librte_hash/rte_thash.h new renamed from lib/librte_hash/rte_thash.h +0
-0file
Quoted 7 lines
mode 100644 index 0000000..1808f47
lib/librte_hash/rte_thash.h new file +3
-0@@ -0,0 +1,231 @@ +/*- +* BSD LICENSE +* lib/librte_hash/rte_thash.h line 13
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* Copyright(c) 2015 Vladimir Medvedkin <[email protected]> +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright
Quoted 58 lines
lib/librte_hash/rte_thash.h new file +8
-0+* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +28
-0+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** + * @file + * + * toeplitz hash functions. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Software implementation of the Toeplitz hash function used by RSS. + * Can be used either for packet distribution on single queue NIC + * or for simulating of RSS computation on specific NIC (for example + * after GRE header decapsulating) + */ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> +#include <rte_ip.h> + +/* Byte swap mask used for converting IPv6 address + * 4-byte chunks to CPU byte orderlib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+*/ +static const __m128i rte_thash_ipv6_bswap_mask = { +0x0405060700010203 ,0x0C0D0E0F08090A0B }; + +/** +* length in dwords of input tuple to +* calculate hash of ipv4 header only +*/ +#define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \ + sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) /4)
Quoted 4 lines
lib/librte_hash/rte_thash.h new file +4
-0+ +/** +* length in dwords of input tuple to +* calculate hash of ipv4 header + lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+* transport header +*/ +#define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4) + +/** +* length in dwords of input tuple to +* calculate hash of ipv6 header only +*/ +#define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \ + sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) /4)
Quoted 67 lines
lib/librte_hash/rte_thash.h new file +67
-0+ +/** +* length in dwords of input tuple to +* calculate hash of ipv6 header + +* transport header +*/ +#define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4) + +/** +* IPv4 tuple +* addreses and ports/sctp_tag have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order */ struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (XMM_SIZE ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) + targ[i] =rte_be_to_cpu_32 (orig[i]); +} + +/** +* Prepare and load IPv6 addresses (src and dst) +* into target tuple +* @param orig +* Pointer to ipv6 header of the original packet +* @param targ +* Pointer to rte_ipv6_tuple structure lib/librte_hash/rte_thash.h line 165
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+*/ +static inline void +rte_thash_load_v6_addrs (const struct ipv6_hdr *orig,union +rte_thash_tuple *targ) { +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); + ipv6 =_mm_loadu_si128 ((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask);}
Quoted 12 lines
lib/librte_hash/rte_thash.h new file +12
-0+ +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline uint32_t +rte_softrss (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= rte_cpu_to_be_32(((const uint32_t*)rss_key)[j]) << i
Quoted 2 lines
|
+(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const
Quoted 21 lines
uint32_t*)rss_key)[j + 1])) >>lib/librte_hash/rte_thash.h new file +20
-0+ (32 - i)); + } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key with rte_convert_rss_key() fn. +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param *rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ lib/librte_hash/rte_thash.h
Quoted 10 lines
lib/librte_hash/rte_thash.h new file +10
-0+static inline uint32_t +rte_softrss_be (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i|
Quoted 1 line
+ (uint32_t)((uint64_t)(((const
uint32_t*)rss_key)[j +Quoted 14 lines
1]) >> (32 - i));
lib/librte_hash/rte_thash.h new file +11
-1+ } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
Re: [PATCH v6] Add toeplitz hash algorithm used by RSS
Hi, Vladimir
You need also to fix this issue in i686 platform:
RHEL65_32,2.6.32,4.4.7,14.0.0
SUSE11SP3_32,3.0.76-0,4.3.4,14.0.0
i686-native-linuxapp-gcc/include/rte_thash.h:63: error: integer constant is too large for 'long' type i686-native-linuxapp-gcc/include/rte_thash.h:63: error: integer constant is too large for 'long' type
Thanks,
Michael
On 2015/7/27 4:58, Vladimir Medvedkin wrote:
Hi Tony,
Sorry for the late reply, I was on vacation.
I'll prepare patch soon.
Regards,
Vladimir
2015-07-22 10:55 GMT+03:00 Tony Lu <[email protected]><mailto:[email protected]>:
Hi, Vladimir
When compiling thash for no-X86 arches, it fails with the following errors. I wonder if
it is possible to make the thash library arch-independent?
== Build app/test
CC test_thash.o
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:56:22 :
error: rte_vect.h: No such file or directory
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:62:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rte_thash_ipv6_bswap_mask' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:129:
error: requested alignment is not a constant /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h: In function 'rte_thash_load_v6_addrs':
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: '__m128i' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: (Each undeclared identifier is reported only once /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: for each function it appears in.) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: expected ';' before 'ipv6' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:161:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: 'ipv6' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: implicit declaration of function '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: nested extern declaration of '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: expected ')' before '__m128i' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: type defaults to 'int' in declaration of 'type name' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: cast from pointer to integer of different size /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:164:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:158:
warning: unused parameter 'targ'
make[3]: *** [test_thash.o] Error 1
make[2]: *** [test] Error 2
make[1]: *** [app] Error 2
make: *** [all] Error 2
Thanks
-Zhigang Lu
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Wednesday, July 01, 2015 7:40 AM
To: [email protected]<mailto:[email protected]>
Subject: [dpdk-dev] [PATCH v6] Add toeplitz hash algorithm used by RSS
Software implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for
simulating
of RSS computation on specific NIC (for example after GRE header decapsulating).
v6 changes
- Fix compilation error
- Rename some defines and function
v5 changes
- Fix errors reported by checkpatch.pl
v4 changes
- Fix copyright
- rename bswap_mask constant, add rte_ prefix
- change rte_ipv[46]_tuple struct
- change rte_thash_load_v6_addr prototype
v3 changes
- Rework API to be more generic
- Add sctp_tag into tuple
v2 changes
- Add ipv6 support
- Various style fixes
---lib/librte_hash/Makefile | 1 +lib/librte_hash/rte_thash.h | 231
++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 232 insertions(+)
create mode 100644 lib/librte_hash/rte_thash.h
lib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0 -0
3696cb1..981230b 100644
lib/librte_hash/Makefile +0 -0
@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.c
SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include := rte_hash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_hash_crc.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_jhash.h +SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_thash.h SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include += rte_fbk_hash.h
# this lib needs eal
lib/librte_hash/rte_thash.h new renamed from lib/librte_hash/rte_thash.h +0 -0
file
mode 100644 index 0000000..1808f47
lib/librte_hash/rte_thash.h new file +13 -0
@@ -0,0 +1,231 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2015 Vladimir Medvedkin <[email protected]><mailto:[email protected]> +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above
copyright
+ * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */
+
+#ifndef _RTE_THASH_H
+#define _RTE_THASH_H
+
+/**
+ * @file
+ *
+ * toeplitz hash functions.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Software implementation of the Toeplitz hash function used by RSS.
+ * Can be used either for packet distribution on single queue NIC
+ * or for simulating of RSS computation on specific NIC (for example
+ * after GRE header decapsulating)
+ */
+
+#include <stdint.h>
+#include <rte_byteorder.h>
+#include <rte_vect.h>
+#include <rte_ip.h>
+
+/* Byte swap mask used for converting IPv6 address
+ * 4-byte chunks to CPU byte order
+ */
+static const __m128i rte_thash_ipv6_bswap_mask = {
+ 0x0405060700010203, 0x0C0D0E0F08090A0B};
+
+/**
+ * length in dwords of input tuple to
+ * calculate hash of ipv4 header only
+ */
+#define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \
+ sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) /
4)
+
+/**
+ * length in dwords of input tuple to
+ * calculate hash of ipv4 header +
+ * transport header
+ */
+#define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4)
+
+/**
+ * length in dwords of input tuple to
+ * calculate hash of ipv6 header only
+ */
+#define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \
+ sizeof(((struct rte_ipv6_tuple *)0)->sctp_tag)) /
4)
+
+/**
+ * length in dwords of input tuple to
+ * calculate hash of ipv6 header +
+ * transport header
+ */
+#define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4)
+
+/**
+ * IPv4 tuple
+ * addreses and ports/sctp_tag have to be CPU byte order */ struct +rte_ipv4_tuple {
+ uint32_t src_addr;
+ uint32_t dst_addr;
+ union {+ struct {
+ uint16_t dport;
+ uint16_t sport;
+ };
+ uint32_t sctp_tag;
+ };
+};
+
+/**
+ * IPv6 tuple
+ * Addresses have to be filled by rte_thash_load_v6_addr()
+ * ports/sctp_tag have to be CPU byte order */ struct rte_ipv6_tuple {
+ uint8_t src_addr[16];
+ uint8_t dst_addr[16];
+ union {+ struct {
+ uint16_t dport;
+ uint16_t sport;
+ };
+ uint32_t sctp_tag;
+ };
+};
+
+union rte_thash_tuple {
+ struct rte_ipv4_tuple v4; + struct rte_ipv6_tuple v6;
+} __attribute__((aligned(XMM_SIZE)));
+
+/**
+ * Prepare special converted key to use with rte_softrss_be()
+ * @param orig
+ * pointer to original RSS key
+ * @param targ
+ * pointer to target RSS key
+ * @param len
+ * RSS key length
+ */
+static inline void
+rte_convert_rss_key(const uint32_t *orig, uint32_t *targ, int len) {
+ int i;
+
+ for (i = 0; i < (len >> 2); i++)
+ targ[i] = rte_be_to_cpu_32(orig[i]);
+}
+
+/**
+ * Prepare and load IPv6 addresses (src and dst)
+ * into target tuple
+ * @param orig
+ * Pointer to ipv6 header of the original packet
+ * @param targ
+ * Pointer to rte_ipv6_tuple structure
+ */
+static inline void
+rte_thash_load_v6_addrs(const struct ipv6_hdr *orig, union +rte_thash_tuple *targ) {
+ __m128i ipv6 = _mm_loadu_si128((const __m128i *)orig->src_addr);
+ *(__m128i *)targ->v6.src_addr =
+ _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
+ ipv6 = _mm_loadu_si128((const __m128i *)orig->dst_addr);
+ *(__m128i *)targ->v6.dst_addr =
+ _mm_shuffle_epi8(ipv6, rte_thash_ipv6_bswap_mask);
}
+
+/**
+ * Generic implementation. Can be used with original rss_key
+ * @param input_tuple
+ * Pointer to input tuple
+ * @param input_len
+ * Length of input_tuple in 4-bytes chunks
+ * @param rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */
+static inline uint32_t
+rte_softrss(uint32_t *input_tuple, uint32_t input_len,
+ const uint8_t *rss_key)
+{
+ uint32_t i, j, ret = 0;
+
+ for (j = 0; j < input_len; j++) {
+ for (i = 0; i < 32; i++) {
+ if (input_tuple[j] & (1 << (31 - i))) {
+ ret ^= rte_cpu_to_be_32(((const uint32_t
*)rss_key)[j]) << i
|
+
(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const
uint32_t *)rss_key)[j + 1])) >>
+ (32 - i));
+ }
+ }
+ }
+ return ret;
+}
+
+/**
+ * Optimized implementation.
+ * If you want the calculated hash value matches NIC RSS value
+ * you have to use special converted key with rte_convert_rss_key() fn.
+ * @param input_tuple
+ * Pointer to input tuple
+ * @param input_len
+ * Length of input_tuple in 4-bytes chunks
+ * @param *rss_key
+ * Pointer to RSS hash key.
+ * @return
+ * Calculated hash value.
+ */
+static inline uint32_t
+rte_softrss_be(uint32_t *input_tuple, uint32_t input_len,
+ const uint8_t *rss_key)
+{
+ uint32_t i, j, ret = 0;
+
+ for (j = 0; j < input_len; j++) {
+ for (i = 0; i < 32; i++) {
+ if (input_tuple[j] & (1 << (31 - i))) {
+ ret ^= ((const uint32_t *)rss_key)[j] << i
|
+ (uint32_t)((uint64_t)(((const
uint32_t *)rss_key)[j +
1]) >> (32 - i));
+ }
+ }
+ }
+ return ret;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_THASH_H */
--
1.8.3.2
Re: [PATCH v6] Add toeplitz hash algorithm used by RSS
Hi Michael,
Thanks for comment, it will be fixed in next patch.
Regards,
Vladimir
2015-07-29 8:01 GMT+03:00 Qiu, Michael <[email protected]>:
Quoted 417 lines
Hi, Vladimir
You need also to fix this issue in i686 platform:
RHEL65_32,2.6.32,4.4.7,14.0.0
SUSE11SP3_32,3.0.76-0,4.3.4,14.0.0
i686-native-linuxapp-gcc/include/rte_thash.h:63: error: integer constant is too large for 'long' typei686-native-linuxapp-gcc/include/rte_thash.h:63: error: integer constant is too large for 'long' typeThanks,
MichaelOn 2015/7/27 4:58, Vladimir Medvedkin wrote:
Hi Tony,
Sorry for the late reply, I was on vacation.
I'll prepare patch soon.Regards,
Vladimir2015-07-22 10:55 GMT+03:00 Tony Lu <[email protected]> <[email protected]>:
Hi, Vladimir
When compiling thash for no-X86 arches, it fails with the following errors. I wonder if
it is possible to make the thash library arch-independent?== Build app/test
CC test_thash.o
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:56:22 :
error:rte_vect.h: No such file or directory
In file included from /u/zlu.bjg/git/dpdk.org/app/test/test_thash.c:40:
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:62:
error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rte_thash_ipv6_bswap_mask' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:129:
error: requested alignment is not a constant /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h: In function 'rte_thash_load_v6_addrs':
/u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: '__m128i' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: (Each undeclared identifier is reported only once /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: for each function it appears in.) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:160:
error: expected ';' before 'ipv6' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:161:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: 'ipv6' undeclared (first use in this function) /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: implicit declaration of function '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: nested extern declaration of '_mm_loadu_si128' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
error: expected ')' before '__m128i' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: type defaults to 'int' in declaration of 'type name' /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:163:
warning: cast from pointer to integer of different size /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:164:
error: expected expression before ')' token /u/zlu.bjg/git/dpdk.org/tile-tilegx-linuxapp-gcc/include/rte_thash.h:158:
warning: unused parameter 'targ'
make[3]: *** [test_thash.o] Error 1
make[2]: *** [test] Error 2
make[1]: *** [app] Error 2
make: *** [all] Error 2Thanks
-Zhigang Lu-----Original Message-----
From: dev [mailto:[email protected] <[email protected]>] On Behalf Of Vladimir Medvedkin
Sent: Wednesday, July 01, 2015 7:40 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v6] Add toeplitz hash algorithm used by RSSSoftware implementation of the Toeplitz hash function used by RSS. Can be used either for packet distribution on single queue NIC or for
simulating
of RSS computation on specific NIC (for example after GRE header
decapsulating).v6 changes
- Fix compilation error
- Rename some defines and functionv5 changes
- Fix errors reported by checkpatch.plv4 changes
- Fix copyright
- renamebswap_maskconstant, addrte_prefix
- change rte_ipv[46]_tuple struct
- changerte_thash_load_v6_addrprototypev3 changes
- Rework API to be more generic
- Addsctp_taginto tuplev2 changes
- Add ipv6 support
- Various style fixes---
lib/librte_hash/Makefile| 1 +lib/librte_hash/rte_thash.h| 231
++++++++++++++++++++++++++++++++++++++++++++2 files changed, 232 insertions(+)create mode 100644
lib/librte_hash/rte_thash.hlib/librte_hash/Makefile index renamed from lib/librte_hash/Makefile +0
-03696cb1..981230b 100644
lib/librte_hash/Makefile +0
-0@@ -49,6 +49,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += rte_fbk_hash.cSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include :=
rte_hash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_hash_crc.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_jhash.h+SYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_thash.hSYMLINK-$(CONFIG_RTE_LIBRTE_HASH)-include +=rte_fbk_hash.h# this lib needs eallib/librte_hash/rte_thash.h new renamed from lib/librte_hash/rte_thash.h +0
-0file mode 100644 index 0000000..1808f47lib/librte_hash/rte_thash.h new file +20
-0@@ -0,0 +1,231 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2015 Vladimir Medvedkin <[email protected]> <[email protected]> +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */lib/librte_hash/rte_thash.h new file +190
-1+ +#ifndef _RTE_THASH_H +#define _RTE_THASH_H + +/** +* @file +* +* toeplitz hash functions. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Software implementation of the Toeplitz hash function used by RSS. +* Can be used either for packet distribution on single queue NIC +* or for simulating of RSS computation on specific NIC (for example +* after GRE header decapsulating) +*/ + +#include <stdint.h> +#include <rte_byteorder.h> +#include <rte_vect.h> +#include <rte_ip.h> + +/* Byte swap mask used for converting IPv6 address +* 4-byte chunks to CPU byte order +*/ +static const __m128i rte_thash_ipv6_bswap_mask = { +0x0405060700010203 ,0x0C0D0E0F08090A0B }; + +/** +* length in dwords of input tuple to +* calculate hash of ipv4 header only +*/ +#define RTE_THASH_V4_L3_LEN ((sizeof(struct rte_ipv4_tuple) - \ + sizeof(((struct rte_ipv4_tuple *)0)->sctp_tag)) / 4) + +/** +* length in dwords of input tuple to +* calculate hash of ipv4 header + +* transport header +*/ +#define RTE_THASH_V4_L4_LEN ((sizeof(struct rte_ipv4_tuple)) / 4) + +/** + * length in dwords of input tuple to + * calculate hash of ipv6 header only + */ +#define RTE_THASH_V6_L3_LEN ((sizeof(struct rte_ipv6_tuple) - \ +sizeof (((struct rte_ipv6_tuple *)0 )->sctp_tag)) /4 ) + +/** +* length in dwords of input tuple to +* calculate hash of ipv6 header + +* transport header +*/ +#define RTE_THASH_V6_L4_LEN ((sizeof(struct rte_ipv6_tuple)) / 4) + +/** +* IPv4 tuple + * addreses and ports/sctp_tag have to be CPU byte order */ struct +rte_ipv4_tuple { +uint32_t src_addr; +uint32_t dst_addr; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +/** +* IPv6 tuple +* Addresses have to be filled by rte_thash_load_v6_addr() +* ports/sctp_tag have to be CPU byte order */ struct rte_ipv6_tuple { +uint8_t src_addr[16 ]; +uint8_t dst_addr[16 ]; +union { +struct { +uint16_t dport; +uint16_t sport; + }; +uint32_t sctp_tag; + }; +}; + +union rte_thash_tuple { +struct rte_ipv4_tuple v4; +struct rte_ipv6_tuple v6; +} __attribute__((aligned (XMM_SIZE ))); + +/** +* Prepare special converted key to use with rte_softrss_be() +* @param orig +* pointer to original RSS key +* @param targ +* pointer to target RSS key +* @param len +* RSS key length +*/ +static inline void +rte_convert_rss_key (const uint32_t *orig,uint32_t *targ,int len) { +int i; + +for (i =0 ; i < (len >>2 ); i++) + targ[i] =rte_be_to_cpu_32 (orig[i]); +} + +/** +* Prepare and load IPv6 addresses (src and dst) +* into target tuple +* @param orig +* Pointer to ipv6 header of the original packet +* @param targ +* Pointer to rte_ipv6_tuple structure +*/ +static inline void +rte_thash_load_v6_addrs (const struct ipv6_hdr *orig,union +rte_thash_tuple *targ) { +__m128i ipv6 =_mm_loadu_si128 ((const __m128i *)orig->src_addr); + *(__m128i *)targ->v6.src_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); + ipv6 =_mm_loadu_si128 ((const __m128i *)orig->dst_addr); + *(__m128i *)targ->v6.dst_addr = +_mm_shuffle_epi8 (ipv6, rte_thash_ipv6_bswap_mask); } + +/** +* Generic implementation. Can be used with original rss_key +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ +static inline uint32_t +rte_softrss (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^=rte_cpu_to_be_32 (((const uint32_t *)rss_key)[j]) << i | + (uint32_t )((uint64_t )(rte_cpu_to_be_32 (((const uint32_t *)rss_key)[j +1 ])) >> + (32 - i)); + } + } + } +return ret; +} + +/** +* Optimized implementation. +* If you want the calculated hash value matches NIC RSS value +* you have to use special converted key with rte_convert_rss_key() fn. +* @param input_tuple +* Pointer to input tuple +* @param input_len +* Length of input_tuple in 4-bytes chunks +* @param *rss_key +* Pointer to RSS hash key. +* @return +* Calculated hash value. +*/ +static inline uint32_t +rte_softrss_be (uint32_t *input_tuple,uint32_t input_len, +const uint8_t *rss_key) +{ +uint32_t i, j, ret =0 ; + +for (j =0 ; j < input_len; j++) { +for (i =0 ; i <32 ; i++) { +if (input_tuple[j] & (1 << (31 - i))) { + ret ^= ((const uint32_t *)rss_key)[j] << i | + (uint32_t )((uint64_t )(((const uint32_t *)rss_key)[j +1 ]) >> (32 - i)); + } + } + } +return ret; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_THASH_H */ --1.8.3.2
PATCH v3 1/1 Add unit test for thash library
In reply to Vladimir MedvedkinAdd unit test for thash library
v3 changes
- Fix checkpatch errors
v2 changes
- fix typo
- remove unnecessary comments
--- app/test/Makefile | 2 + app/test/autotest_data.py | 13 ++++ app/test/test_thash.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 app/test/test_thash.c
app/test/Makefile +2 -0
@@ -86,6 +86,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_functions.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_scaling.c +SRCS-y += test_thash.c + SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm.c SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6.c
app/test/autotest_data.py +13 -0
@@ -475,6 +475,19 @@ non_parallel_test_group_list = [ }, ] }, +{ + "Prefix" : "thash", + "Memory" : "32", + "Tests" : + [ + { + "Name" : "Thash autotest", + "Command" : "thash_autotest", + "Func" : default_autotest, + "Report" : None, + }, + ] +}, # # Please always make sure that ring_perf is the last test!
app/test/test_thash.c new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v3] Add unit test for thash library
Quoted 10 lines · Vladimir Medvedkin
Add unit test for thash library
v3 changes
- Fix checkpatch errorsv2 changes
- fix typo
- remove unnecessary commentsSigned-off-by Vladimir Medvedkin <[email protected]>
Patch obviously depends on the thash patch which is sent out separately. However, this patch is itself fine.
Quoted 229 lines
--- app/test/Makefile | 2 + app/test/autotest_data.py | 13 ++++ app/test/test_thash.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 app/test/test_thash.capp/test/Makefile +2
-0@@ -86,6 +86,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_functions.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_scaling.c +SRCS-y += test_thash.c + SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm.c SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6.capp/test/autotest_data.py +13
-0@@ -475,6 +475,19 @@ non_parallel_test_group_list = [ }, ] }, +{ + "Prefix" : "thash", + "Memory" : "32", + "Tests" : + [ + { + "Name" : "Thash autotest", + "Command" : "thash_autotest", + "Func" : default_autotest, + "Report" : None, + }, + ] +}, # # Please always make sure that ring_perf is the last test!app/test/test_thash.c new file +176
-0@@ -0,0 +1,176 @@ +/*- +* BSD LICENSE +* +* Copyright(c) 2015 Vladimir Medvedkin <[email protected]> +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* * Neither the name of Intel Corporation nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <rte_common.h> +#include <rte_eal.h> +#include <rte_ip.h> + +#include "test.h" + +#include <rte_thash.h> + +struct test_thash_v4 { +uint32_t dst_ip; +uint32_t src_ip; +uint16_t dst_port; +uint16_t src_port; +uint32_t hash_l3; +uint32_t hash_l3l4; +}; + +struct test_thash_v6 { +uint8_t dst_ip[16 ]; +uint8_t src_ip[16 ]; +uint16_t dst_port; +uint16_t src_port; +uint32_t hash_l3; +uint32_t hash_l3l4; +}; + +/*From 82599 Datasheet 7.1.2.8.3 RSS Verification Suite*/ +struct test_thash_v4 v4_tbl[] = { +{IPv4 (161 ,142 ,100 ,80 ),IPv4 (66 ,9 ,149 ,187 ), +1766 ,2794 ,0x323e8fc2 ,0x51ccc178 }, +{IPv4 (65 ,69 ,140 ,83 ),IPv4 (199 ,92 ,111 ,2 ), +4739 ,14230 ,0xd718262a ,0xc626b0ea }, +{IPv4 (12 ,22 ,207 ,184 ),IPv4 (24 ,19 ,198 ,95 ), +38024 ,12898 ,0xd2d0a5de ,0x5c2b394a }, +{IPv4 (209 ,142 ,163 ,6 ),IPv4 (38 ,27 ,205 ,30 ), +2217 ,48228 ,0x82989176 ,0xafc7327f }, +{IPv4 (202 ,188 ,127 ,2 ),IPv4 (153 ,39 ,163 ,191 ), +1303 ,44251 ,0x5d1809c5 ,0x10e828a2 }, +}; + +struct test_thash_v6 v6_tbl[] = { +/*3ffe:2501:200:3::1*/ +{{0x3f ,0xfe ,0x25 ,0x01 ,0x02 ,0x00 ,0x00 ,0x03 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,}, +/*3ffe:2501:200:1fff::7*/ +{0x3f ,0xfe ,0x25 ,0x01 ,0x02 ,0x00 ,0x1f ,0xff , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x07 ,}, +1766 ,2794 ,0x2cc18cd5 ,0x40207d3d }, +/*ff02::1*/ +{{0xff ,0x02 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,}, +/*3ffe:501:8::260:97ff:fe40:efab*/ +{0x3f ,0xfe ,0x05 ,0x01 ,0x00 ,0x08 ,0x00 ,0x00 , +0x02 ,0x60 ,0x97 ,0xff ,0xfe ,0x40 ,0xef ,0xab ,}, +4739 ,14230 ,0x0f0c461c ,0xdde51bbf }, +/*fe80::200:f8ff:fe21:67cf*/ +{{0xfe ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x02 ,0x00 ,0xf8 ,0xff ,0xfe ,0x21 ,0x67 ,0xcf ,}, +/*3ffe:1900:4545:3:200:f8ff:fe21:67cf*/ +{0x3f ,0xfe ,0x19 ,0x00 ,0x45 ,0x45 ,0x00 ,0x03 , +0x02 ,0x00 ,0xf8 ,0xff ,0xfe ,0x21 ,0x67 ,0xcf ,}, +38024 ,44251 ,0x4b61e985 ,0x02d1feef }, +}; + +uint8_t default_rss_key[] = { +0x6d ,0x5a ,0x56 ,0xda ,0x25 ,0x5b ,0x0e ,0xc2 , +0x41 ,0x67 ,0x25 ,0x3d ,0x43 ,0xa3 ,0x8f ,0xb0 , +0xd0 ,0xca ,0x2b ,0xcb ,0xae ,0x7b ,0x30 ,0xb4 , +0x77 ,0xcb ,0x2d ,0xa3 ,0x80 ,0x30 ,0xf2 ,0x0c , +0x6a ,0x42 ,0xb7 ,0x3b ,0xbe ,0xac ,0x01 ,0xfa , +}; + +static int +test_thash (void ) +{ +uint32_t i, j; +union rte_thash_tuple tuple; +uint32_t rss_l3, rss_l3l4; +uint8_t rss_key_be[RTE_DIM (default_rss_key)]; +struct ipv6_hdr ipv6_hdr; + +/* Convert RSS key*/ +rte_convert_rss_key ((uint32_t *)&default_rss_key, + (uint32_t *)rss_key_be,RTE_DIM (default_rss_key)); + + +for (i =0 ; i <RTE_DIM (v4_tbl); i++) { + tuple.v4.src_addr = v4_tbl[i].src_ip; + tuple.v4.dst_addr = v4_tbl[i].dst_ip; + tuple.v4.sport = v4_tbl[i].src_port; + tuple.v4.dport = v4_tbl[i].dst_port; +/*Calculate hash with original key*/ + rss_l3 =rte_softrss ((uint32_t *)&tuple, +RTE_THASH_V4_L3 , default_rss_key); + rss_l3l4 =rte_softrss ((uint32_t *)&tuple, +RTE_THASH_V4_L4 , default_rss_key); +if ((rss_l3 != v4_tbl[i].hash_l3) || + (rss_l3l4 != v4_tbl[i].hash_l3l4)) +return -1 ; +/*Calculate hash with converted key*/ + rss_l3 =rte_softrss_be ((uint32_t *)&tuple, +RTE_THASH_V4_L3 , rss_key_be); + rss_l3l4 =rte_softrss_be ((uint32_t *)&tuple, +RTE_THASH_V4_L4 , rss_key_be); +if ((rss_l3 != v4_tbl[i].hash_l3) || + (rss_l3l4 != v4_tbl[i].hash_l3l4)) +return -1 ; + } +for (i =0 ; i <RTE_DIM (v6_tbl); i++) { +/*Fill ipv6 hdr*/ +for (j =0 ; j <RTE_DIM (ipv6_hdr.src_addr); j++) + ipv6_hdr.src_addr[j] = v6_tbl[i].src_ip[j]; +for (j =0 ; j <RTE_DIM (ipv6_hdr.dst_addr); j++) + ipv6_hdr.dst_addr[j] = v6_tbl[i].dst_ip[j]; +/*Load and convert ipv6 address into tuple*/ +rte_thash_load_v6_addr (&ipv6_hdr, &tuple); + tuple.v6.sport = v6_tbl[i].src_port; + tuple.v6.dport = v6_tbl[i].dst_port; +/*Calculate hash with original key*/ + rss_l3 =rte_softrss ((uint32_t *)&tuple, +RTE_THASH_V6_L3 , default_rss_key); + rss_l3l4 =rte_softrss ((uint32_t *)&tuple, +RTE_THASH_V6_L4 , default_rss_key); +if ((rss_l3 != v6_tbl[i].hash_l3) || + (rss_l3l4 != v6_tbl[i].hash_l3l4)) +return -1 ; +/*Calculate hash with converted key*/ + rss_l3 =rte_softrss_be ((uint32_t *)&tuple, +RTE_THASH_V6_L3 , rss_key_be); + rss_l3l4 =rte_softrss_be ((uint32_t *)&tuple, +RTE_THASH_V6_L4 , rss_key_be); +if ((rss_l3 != v6_tbl[i].hash_l3) || + (rss_l3l4 != v6_tbl[i].hash_l3l4)) +return -1 ; + } +return 0 ; +} + +static struct test_command thash_cmd = { + .command ="thash_autotest" , + .callback = test_thash, +}; +REGISTER_TEST_COMMAND (thash_cmd);Signature · 1 line
1.8.3.2
PATCH v4 1/1 Add unit test for thash library
In reply to Vladimir MedvedkinAdd unit test for thash library
v4 changes
- Reflect rte_thash.h changes
v3 changes
- Fix checkpatch errors
v2 changes
- fix typo
- remove unnecessary comments
--- app/test/Makefile | 1 + app/test/test_thash.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 app/test/test_thash.c
app/test/Makefile +1 -0
@@ -82,6 +82,7 @@ SRCS-y += test_memcpy.c SRCS-y += test_memcpy_perf.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash.c +SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_thash.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_functions.c SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_scaling.c
app/test/test_thash.c new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v4] Add unit test for thash library
Quoted 5 lines · Vladimir Medvedkin
Add unit test for thash library
v4 changes
- Reflectrte_thash.hchanges
Quoted 8 lines
v3 changes
- Fix checkpatch errorsv2 changes
- fix typo
- remove unnecessary commentsSigned-off-by Vladimir Medvedkin <[email protected]>
Thomas Monjalon
AppliedRe: [PATCH v4] Add unit test for thash library
2015-07-01 16:30, Bruce Richardson:
Quoted 9 lines · Vladimir Medvedkin
Quoted 8 lines
Add unit test for thash library
v4 changes
- Reflectrte_thash.hchangesv3 changes
- Fix checkpatch errors
Quoted 7 lines
Quoted 5 lines
v2 changes
- fix typo
- remove unnecessary commentsSigned-off-by Vladimir Medvedkin <[email protected]>Acked-by Bruce Richardson <[email protected]>
Applied, thanks