Implement rte_memcmp with AVX/SSE instructions.
PATCH 1/1 Implement rte_memcmp with AVX/SSE instructions.
Background:
After preliminary discussion with John (Zhihong) and Tim from Intel it was decided that it would be beneficial to use AVX/SSE instructions for memcmp similar to memcpy being implemeneted. In addition, we decided to use librte_hash as a test candidate to test both functionality and performance.
Currently memcmp in librte_hash is used for key comparisons whose length can vary and max key length is defined to 64 bytes. Similarly strncmp is used to compare names whose max lengh is 32 bytes. When memcmp and strncmp is replaced with rte_memcmp test results show minor improvements in "hash_perf" tests with a decrease of "1s" out of total "1m 3s" run time. Similarly when key_length is increased to 128 bytes, "hash_perf" shows decrease of "4s" out of total "1m 49s" run time with rte_memcmp.
Test was conducted on Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz, Ubuntu 14.04, x86_64, 16GB DDR3 system.
Plan is to engage the team and get feedback to further improvise performace.
Ravi Kerur (1):
Implement memcmp using AVX/SSE instructio
app/test/test_hash.c | 2 +- app/test/test_hash_perf.c | 302 +++++++------ .../common/include/arch/ppc_64/rte_memcmp.h | 62 +++ .../common/include/arch/x86/rte_memcmp.h | 479 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_memcmp.h | 119 +++++ lib/librte_hash/rte_fbk_hash.c | 7 +- lib/librte_hash/rte_hash.c | 15 +- lib/librte_hash/rte_hash.h | 2 +- 8 files changed, 857 insertions(+), 131 deletions(-) create mode 100644 lib/librte_eal/common/include/arch/ppc_64/rte_memcmp.h create mode 100644 lib/librte_eal/common/include/arch/x86/rte_memcmp.h create mode 100644 lib/librte_eal/common/include/generic/rte_memcmp.h
Signature · 1 line
1.9.1
PATCH 1/1 Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveThis patch replaces memcmp and strncmp in librte_hash with rte_memcmp which is implemented with AVX/SSE instructions.
Preliminary results on Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz, Ubuntu 14.04 x86_64 shows
1 second improvement when hash key length <= 64
4 seconds improvement when hash key length <= 128
This patch is RFC to engage the team and improvise performance further.
--- app/test/test_hash.c | 2 +- app/test/test_hash_perf.c | 302 +++++++------ .../common/include/arch/ppc_64/rte_memcmp.h | 62 +++ .../common/include/arch/x86/rte_memcmp.h | 479 +++++++++++++++++++++ lib/librte_eal/common/include/generic/rte_memcmp.h | 119 +++++ lib/librte_hash/rte_fbk_hash.c | 7 +- lib/librte_hash/rte_hash.c | 15 +- lib/librte_hash/rte_hash.h | 2 +- 8 files changed, 857 insertions(+), 131 deletions(-) create mode 100644 lib/librte_eal/common/include/arch/ppc_64/rte_memcmp.h create mode 100644 lib/librte_eal/common/include/arch/x86/rte_memcmp.h create mode 100644 lib/librte_eal/common/include/generic/rte_memcmp.h
app/test/test_hash.c +1 -1
@@ -65,7 +65,7 @@*/ static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc};static uint32_t hashtest_initvals[] = {0 }; -static uint32_t hashtest_key_lens[] = {0 ,2 ,4 ,5 ,6 ,7 ,8 ,10 ,11 ,15 ,16 ,21 ,31 ,32 ,33 ,63 ,64 }; +static uint32_t hashtest_key_lens[] = {0 ,2 ,4 ,5 ,6 ,7 ,8 ,10 ,11 ,15 ,16 ,21 ,31 ,32 ,33 ,40 ,42 ,48 ,54 ,60 ,63 ,64 ,128 };/******************************************************************************/ #define LOCAL_FBK_HASH_ENTRIES_MAX (1 << 15)
app/test/test_hash_perf.c +181 -121
356 lines not on this page · raw message
lib/librte_eal/common/include/arch/ppc_64/rte_memcmp.h new file +62 -0
62 lines not on this page · raw message
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +479 -0
479 lines not on this page · raw message
lib/librte_eal/common/include/generic/rte_memcmp.h new file +119 -0
119 lines not on this page · raw message
lib/librte_hash/rte_fbk_hash.c +5 -2
@@ -40,6 +40,7 @@#include <sys/queue.h> #include <rte_memory.h> #include <rte_memzone.h> +#include <rte_memcmp.h> #include <rte_eal.h> #include <rte_eal_memconfig.h> #include <rte_malloc.h>
@@ -83,7 +84,8 @@ rte_fbk_hash_find_existing(const char *name)rte_rwlock_read_lock (RTE_EAL_TAILQ_RWLOCK ); TAILQ_FOREACH(te, fbk_hash_list, next) { h = (struct rte_fbk_hash_table *) te->data; -if (strncmp (name, h->name,RTE_FBK_HASH_NAMESIZE ) ==0 ) +if (rte_memcmp (name, h->name, +RTE_MIN (strlen (name),strlen (h->name)) +1 ) ==0 )break ; }rte_rwlock_read_unlock (RTE_EAL_TAILQ_RWLOCK );
@@ -137,7 +139,8 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params)/* guarantee there's no existing */ TAILQ_FOREACH(te, fbk_hash_list, next) { ht = (struct rte_fbk_hash_table *) te->data; -if (strncmp (params->name, ht->name,RTE_FBK_HASH_NAMESIZE ) ==0 ) +if (rte_memcmp (params->name, ht->name, +RTE_MIN (strlen (params->name),strlen (ht->name)) +1 ) ==0 )break ; }if (te !=NULL )
lib/librte_hash/rte_hash.c +9 -6
@@ -42,6 +42,7 @@#include <rte_memory.h> /* for definition of RTE_CACHE_LINE_SIZE */ #include <rte_log.h> #include <rte_memcpy.h> +#include <rte_memcmp.h> #include <rte_prefetch.h> #include <rte_branch_prediction.h> #include <rte_memzone.h>
@@ -153,7 +154,8 @@ rte_hash_find_existing(const char *name)rte_rwlock_read_lock (RTE_EAL_TAILQ_RWLOCK ); TAILQ_FOREACH(te, hash_list, next) { h = (struct rte_hash *) te->data; -if (strncmp (name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +if (rte_memcmp (name, h->name, +RTE_MIN (strlen (name),strlen (h->name)) +1 ) ==0 )break ; }rte_rwlock_read_unlock (RTE_EAL_TAILQ_RWLOCK );
@@ -213,7 +215,8 @@ rte_hash_create(const struct rte_hash_parameters *params)/* guarantee there's no existing */ TAILQ_FOREACH(te, hash_list, next) { h = (struct rte_hash *) te->data; -if (strncmp (params->name, h->name,RTE_HASH_NAMESIZE ) ==0 ) +if (rte_memcmp (params->name, h->name, +RTE_MIN (strlen (params->name),strlen (h->name)) +1 ) ==0 )break ; }if (te !=NULL )
@@ -309,7 +312,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h,/* Check if key is already present in the hash */ for (i =0 ; i < h->bucket_entries; i++) {if ((sig == sig_bucket[i]) && -likely (memcmp (key,get_key_from_bucket (h, key_bucket, i), +likely (rte_memcmp (key,get_key_from_bucket (h, key_bucket, i), h->key_len) ==0 )) {return bucket_index * h->bucket_entries + i; }
@@ -359,7 +362,7 @@ __rte_hash_del_key_with_hash(const struct rte_hash *h,/* Check if key is already present in the hash */ for (i =0 ; i < h->bucket_entries; i++) {if ((sig == sig_bucket[i]) && -likely (memcmp (key,get_key_from_bucket (h, key_bucket, i), +likely (rte_memcmp (key,get_key_from_bucket (h, key_bucket, i), h->key_len) ==0 )) { sig_bucket[i] =NULL_SIGNATURE ;return bucket_index * h->bucket_entries + i;
@@ -401,7 +404,7 @@ __rte_hash_lookup_with_hash(const struct rte_hash *h,/* Check if key is already present in the hash */ for (i =0 ; i < h->bucket_entries; i++) {if ((sig == sig_bucket[i]) && -likely (memcmp (key,get_key_from_bucket (h, key_bucket, i), +likely (rte_memcmp (key,get_key_from_bucket (h, key_bucket, i), h->key_len) ==0 )) {return bucket_index * h->bucket_entries + i; }
@@ -457,7 +460,7 @@ rte_hash_lookup_bulk(const struct rte_hash *h, const void **keys,for (j =0 ; j < h->bucket_entries; j++) {if ((sigs[i] == sig_bucket[j]) && -likely (memcmp (keys[i], +likely (rte_memcmp (keys[i],get_key_from_bucket (h, key_bucket, j), h->key_len) ==0 )) { positions[i] = bucket_index *
lib/librte_hash/rte_hash.h +1 -1
@@ -54,7 +54,7 @@ extern "C" {#define RTE_HASH_BUCKET_ENTRIES_MAX 16/** Maximum length of key that can be used. */ -#define RTE_HASH_KEY_LENGTH_MAX 64 +#define RTE_HASH_KEY_LENGTH_MAX 128/** Max number of keys that can be searched for using rte_hash_lookup_multi. */ #define RTE_HASH_LOOKUP_BULK_MAX 16
Signature · 1 line
1.9.1
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 8 lines · Ravi Kerur
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +8
-0+/** +* Compare bytes between two locations. The locations must not overlap. +* +* @note This is implemented as a macro, so it's address should not be taken +* and care is needed as parameter expressions may be evaluated multiple times. +* +* @param src_1 +* Pointer to the first source of the data.
lib/librte_eal/common/include/arch/x86/rte_memcmp.h line 71
Quoted 10 lines
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +10
-0+* @param src_2 +* Pointer to the second source of the data. +* @param n +* Number of bytes to compare. +* @return +* true if equal otherwise false. +*/ +static inline bool +rte_memcmp (const void *src_1,const void *src, +size_t n) __attribute__((always_inline));
You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
int memcmp(const void *s1, const void *s2, size_t n);
The memcmp() function returns an integer less than, equal to, or greater than
zero if the first n bytes of s1 is found, respectively, to
be less than, to
match, or be greater than the first n bytes of s2.
Signature · 1 line
Pawel
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 22 lines · Pawel Wodkowski
Quoted 8 lines · Ravi Kerur
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +8
-0+/** +* Compare bytes between two locations. The locations must not overlap. +* +* @note This is implemented as a macro, so it's address should not be taken +* and care is needed as parameter expressions may be evaluated multiple times. +* +* @param src_1 +* Pointer to the first source of the data. lib/librte_eal/common/include/arch/x86/rte_memcmp.h line 71
Quoted 10 lines
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +10
-0+* @param src_2 +* Pointer to the second source of the data. +* @param n +* Number of bytes to compare. +* @return +* true if equal otherwise false. +*/ +static inline bool +rte_memcmp (const void *src_1,const void *src, +size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 8 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, or greater than
zero if the first n bytes of s1 is found, respectively, to be
less than, to
match, or be greater than the first n bytes of s2.
+1 to this point.
Also, if I read your quoted performance numbers in your earlier mail correctly, we are only looking at a 1-4% performance increase. Is the additional code to maintain worth the benefit?
/Bruce
Quoted 2 lines
Signature · 1 line
Pawel
Re: [PATCH] Implement memcmp using AVX/SSE instructio
Quoted 6 lines · Bruce Richardson
Also, if I read your quoted performance numbers in your earlier mail correctly,
we are only looking at a 1-4% performance increase. Is the additional code to
maintain worth the benefit?
... and if so, how would one decide whether it is better to to add this to DPDK vs contribute it to GNU libc?
Pawel noted that this is not compatible with memcmp(3). It is very similar to the legacy function bcmp(3) though so perhaps libc would accept it as such.
Cheers,
-Luke
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to Bruce RichardsonQuoted 41 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Thursday, April 23, 2015 9:12 AM
To: Wodkowski, PawelX
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] Implement memcmp using AVX/SSE instructioQuoted 22 lines · Pawel Wodkowski
Quoted 8 lines · Ravi Kerur
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +8
-0+/** +* Compare bytes between two locations. The locations must not overlap. +* +* @note This is implemented as a macro, so it's address should not be taken +* and care is needed as parameter expressions may be evaluated multiple times. +* +* @param src_1 +* Pointer to the first source of the data. lib/librte_eal/common/include/arch/x86/rte_memcmp.h line 71
Quoted 10 lines
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +10
-0+* @param src_2 +* Pointer to the second source of the data. +* @param n +* Number of bytes to compare. +* @return +* true if equal otherwise false. +*/ +static inline bool +rte_memcmp (const void *src_1,const void *src, +size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 8 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, or greater than
zero if the first n bytes of s1 is found, respectively, to be
less than, to
match, or be greater than the first n bytes of s2.
Quoted 5 lines
+1 to this point.
Also, if I read your quoted performance numbers in your earlier mail correctly, we are only looking at a 1-4% performance increase. Is the additional code to maintain worth the benefit?
Yep, same thought here, is it really worth it?
Konstantin
Quoted 5 lines
/Bruce
Quoted 2 lines
--
Pawel
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 26 lines · Pawel Wodkowski
Quoted 18 lines · Ravi Kerur
+/**
+ * Compare bytes between two locations. The locations must not overlap.
+ *
+ * @note This is implemented as a macro, so it's address should not be taken
+ * and care is needed as parameter expressions may be evaluated multiple times.
+ *
+ * @paramsrc_1
+ * Pointer to the first source of the data.
+ * @paramsrc_2
+ * Pointer to the second source of the data.
+ * @param n
+ * Number of bytes to compare.
+ * @return
+ * true if equal otherwise false.
+ */lib/librte_eal/common/include/arch/x86/rte_memcmp.h line 71
Quoted 3 lines
lib/librte_eal/common/include/arch/x86/rte_memcmp.h new file +3
-0+static inline bool +rte_memcmp (const void *src_1,const void *src, +size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 9 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, or greater than
zero if the first n bytes of s1 is found, respectively, to be
less than, to
match, or be greater than the first n bytes of s2.
This can/will be fixed in future version.
Thanks.
Quoted 3 lines
--
Pawel
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 48 lines · Konstantin
Quoted 13 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Thursday, April 23, 2015 9:12 AM
To: Wodkowski, PawelX
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] Implement memcmp using AVX/SSE instructioQuoted 3 lines · Pawel Wodkowski
Quoted 2 lines · Ravi Kerur
+/**
+ * Compare bytes between two locations. The locations must notoverlap.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ *
+ * @note This is implemented as a macro, so it's address should notbe taken
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * and care is needed as parameter expressions may be evaluated
multiple times.
Quoted 16 lines
Quoted 16 lines
Review
Quoted 13 lines
+ *
+ * @paramsrc_1
+ * Pointer to the first source of the data.
+ * @paramsrc_2
+ * Pointer to the second source of the data.
+ * @param n
+ * Number of bytes to compare.
+ * @return
+ * true if equal otherwise false.
+ */(quoted diff) +3
-0+static inline bool +rte_memcmp(const void *src_1, const void *src, + size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 3 lines
Quoted 3 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, orgreater
Quoted 2 lines
Quoted 2 lines
than
zero if the first n bytes of s1 is found, respectively,to be
Quoted 6 lines
Quoted 3 lines
less than, to
match, or be greater than the first n bytes of s2.+1 to this point.
Quoted 15 lines
Quoted 1 line
Also, if I read your quoted performance numbers in your earlier mail
correctly,
Quoted 1 line
we are only looking at a 1-4% performance increase. Is the additional
code to
Quoted 1 line
maintain worth the benefit?
Yep, same thought here, is it really worth it?
KonstantinQuoted 5 lines
/Bruce
Quoted 2 lines
--
Pawel
I think I haven't exploited every thing x86 has to offer to improve performance. I am looking for inputs. Until we have exhausted all avenues I don't want to drop it. One thing I have noticed is that bigger key size gets better performance numbers. I plan to re-run perf tests with 64 and 128 bytes key size and will report back. Any other avenues to try out please let me know I will give it a shot.
Thanks,
Ravi
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 74 lines · Ravi Kerur
Quoted 48 lines · Konstantin
Quoted 13 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Thursday, April 23, 2015 9:12 AM
To: Wodkowski, PawelX
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] Implement memcmp using AVX/SSE instructioQuoted 3 lines · Pawel Wodkowski
Quoted 2 lines · Ravi Kerur
+/**
+ * Compare bytes between two locations. The locations must notoverlap.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ *
+ * @note This is implemented as a macro, so it's address should notbe taken
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * and care is needed as parameter expressions may be evaluated
multiple times.
Quoted 16 lines
Quoted 16 lines
Review
Quoted 13 lines
+ *
+ * @paramsrc_1
+ * Pointer to the first source of the data.
+ * @paramsrc_2
+ * Pointer to the second source of the data.
+ * @param n
+ * Number of bytes to compare.
+ * @return
+ * true if equal otherwise false.
+ */(quoted diff) +3
-0+static inline bool +rte_memcmp(const void *src_1, const void *src, + size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 3 lines
Quoted 3 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, orgreater
Quoted 2 lines
Quoted 2 lines
than
zero if the first n bytes of s1 is found, respectively,to be
Quoted 6 lines
Quoted 3 lines
less than, to
match, or be greater than the first n bytes of s2.+1 to this point.
Quoted 15 lines
Quoted 1 line
Also, if I read your quoted performance numbers in your earlier mail
correctly,
Quoted 1 line
we are only looking at a 1-4% performance increase. Is the additional
code to
Quoted 1 line
maintain worth the benefit?
Yep, same thought here, is it really worth it?
KonstantinQuoted 5 lines
/Bruce
Quoted 2 lines
--
PawelI think I haven't exploited every thing x86 has to offer to improve performance. I am looking for inputs. Until we have exhausted all avenues I don't want to drop it. One thing I have noticed is that bigger key size gets better performance numbers. I plan to re-run perf tests with 64 and 128 bytes key size and will report back. Any other avenues to try out please let me know I will give it a shot.
Quoted 2 lines
Thanks,
Ravi
Hi Ravi,
are 128 byte comparisons realistic? An IPv6 5-tuple with double vlan tags is still only 41 bytes, or 48 with some padding added?
While for a memcpy function, you can see cases where you are going to copy a whole packet, meaning that sizes of 128B+ (up to multiple k) are realistic, it's harder to see that for a compare function.
In any case, we await the results of your further optimization work to see how that goes.
Regards,
/Bruce
Re: [PATCH] Implement memcmp using AVX/SSE instructio
Quoted 94 lines · Bruce Richardson
Quoted 7 lines · Ravi Kerur
Quoted 4 lines · Konstantin
Quoted 4 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of BruceRichardson
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Sent: Thursday, April 23, 2015 9:12 AM
To: Wodkowski, PawelX
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] Implement memcmp using AVX/SSEinstructio
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Pawel Wodkowski
Quoted 3 lines · Ravi Kerur
Quoted 2 lines
+/**
+ * Compare bytes between two locations. The locations must notoverlap.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ *
+ * @note This is implemented as a macro, so it's address shouldnot
Quoted 19 lines
Quoted 19 lines
be taken
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * and care is needed as parameter expressions may be evaluated
multiple times.
Quoted 16 lines
Quoted 16 lines
Review
Quoted 13 lines
+ *
+ * @paramsrc_1
+ * Pointer to the first source of the data.
+ * @paramsrc_2
+ * Pointer to the second source of the data.
+ * @param n
+ * Number of bytes to compare.
+ * @return
+ * true if equal otherwise false.
+ */(quoted diff) +3
-0+static inline bool +rte_memcmp(const void *src_1, const void *src, + size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, orgreater
Quoted 2 lines
Quoted 2 lines
than
zero if the first n bytes of s1 is found,respectively,
Quoted 17 lines
Quoted 17 lines
to be
Quoted 7 lines
Quoted 3 lines
less than, to
match, or be greater than the first n bytes of s2.+1 to this point.
Also, if I read your quoted performance numbers in your earlier mail
correctly,
Quoted 1 line
we are only looking at a 1-4% performance increase. Is the additional
code to
Quoted 1 line
maintain worth the benefit?
Yep, same thought here, is it really worth it?
KonstantinQuoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
/Bruce
Quoted 2 lines
--
PawelI think I haven't exploited every thing x86 has to offer to improve performance. I am looking for inputs. Until we have exhausted all
avenues I
Quoted 7 lines
don't want to drop it. One thing I have noticed is that bigger key size gets better performance numbers. I plan to re-run perf tests with 64 and 128 bytes key size and will report back. Any other avenues to try out please let me know I will give it a shot.
Thanks,
RaviHi Ravi,
are 128 byte comparisons realistic? An IPv6 5-tuple with double vlan tags is still
only 41 bytes, or 48 with some padding added?
While for a memcpy function, you can see cases where you are going to copy a whole
packet, meaning that sizes of 128B+ (up to multiple k) are realistic, it's harder
to see that for a compare function.
Quoted 5 lines
In any case, we await the results of your further optimization work to see how
that goes.
Hi Bruce,
Couple of things I am planning to try
1. Use _xor_ and _testz_ instructions for comparison instead of _cmpeq_ and _mask_.
2. I am using unaligned loads, not sure about the penalty, I plan to try with aligned loads if address is aligned and compare results.
Agreed that with just L3 or even if we go with L2 + L3 + L4 tuples it will not exceed 64 bytes, 128 bytes is just a stretch for some weird MPLSoGRE header formats.
My focus is currently on improving performance for < 64 bytes and < 128 bytes key lengths only.
Thanks,
Ravi
Regards,
Quoted 2 lines
/Bruce
Re: [PATCH] Implement memcmp using AVX/SSE instructio
In reply to a message not in the archiveQuoted 100 lines · Ravi Kerur
Quoted 95 lines · Bruce Richardson
Quoted 7 lines · Ravi Kerur
Quoted 4 lines · Konstantin
Quoted 4 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of BruceRichardson
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Sent: Thursday, April 23, 2015 9:12 AM
To: Wodkowski, PawelX
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] Implement memcmp using AVX/SSEinstructio
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Pawel Wodkowski
Quoted 3 lines · Ravi Kerur
Quoted 2 lines
+/**
+ * Compare bytes between two locations. The locations must notoverlap.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
+ *
+ * @note This is implemented as a macro, so it's address shouldnot
Quoted 19 lines
Quoted 19 lines
be taken
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ * and care is needed as parameter expressions may be evaluated
multiple times.
Quoted 16 lines
Quoted 16 lines
Review
Quoted 13 lines
+ *
+ * @paramsrc_1
+ * Pointer to the first source of the data.
+ * @paramsrc_2
+ * Pointer to the second source of the data.
+ * @param n
+ * Number of bytes to compare.
+ * @return
+ * true if equal otherwise false.
+ */(quoted diff) +3
-0+static inline bool +rte_memcmp(const void *src_1, const void *src, + size_t n) __attribute__((always_inline));You are exposing this as public API, so I think you should follow description bellow or not call this _memcmp_
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
int
memcmp(const void *s1, const void *s2, size_t n);The
memcmp()function returns an integer less than, equal to, orgreater
Quoted 2 lines
Quoted 2 lines
than
zero if the first n bytes of s1 is found,respectively,
Quoted 10 lines
Quoted 10 lines
to be
Quoted 7 lines
Quoted 3 lines
less than, to
match, or be greater than the first n bytes of s2.+1 to this point.
Also, if I read your quoted performance numbers in your earlier mail
correctly,
Quoted 1 line
we are only looking at a 1-4% performance increase. Is the
additional
Quoted 7 lines
Quoted 7 lines
code to
Quoted 1 line
maintain worth the benefit?
Yep, same thought here, is it really worth it?
KonstantinQuoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
/Bruce
Quoted 2 lines
--
PawelI think I haven't exploited every thing x86 has to offer to improve performance. I am looking for inputs. Until we have exhausted all
avenues I
Quoted 7 lines
don't want to drop it. One thing I have noticed is that bigger key size gets better performance numbers. I plan to re-run perf tests with 64 and 128 bytes key size and will report back. Any other avenues to try out please let me know I will give it a shot.
Thanks,
RaviHi Ravi,
are 128 byte comparisons realistic? An IPv6 5-tuple with double vlan tags is still
only 41 bytes, or 48 with some padding added?
While for a memcpy function, you can see cases where you are going to copy a whole
packet, meaning that sizes of 128B+ (up to multiple k) are realistic, it's harder
to see that for a compare function.
Quoted 6 lines
Quoted 5 lines
In any case, we await the results of your further optimization work to see how
that goes.
Actually I was looking at wrong numbers. Wrote couple of sample programs and found that memory comparison with AVX/SSE takes almost 1/3rd less cpu ticks when compared with regular memcmp.
For 16bytes,
regular memcmp
Time: 276 ticks (3623188 memcmp/tick)
Time: 276 ticks (3623188 memcmp/tick)
memcmp with AVX/SSE
Time: 86 ticks (11627906 memcmp/tick)
Time: 87 ticks (11494252 memcmp/tick)
For 32bytes,
regular memcmp
Time: 301 ticks (3322259 memcmp/tick)
Time: 302 ticks (3311258 memcmp/tick)
memcmp with AVX/SSE
Time: 87 ticks (11494252 memcmp/tick)
Time: 88 ticks (11363636 memcmp/tick)
For 64bytes,
regular memcmp
Time: 376 ticks (2855696 memcmp/tick) 0
Time: 377 ticks (2848121 memcmp/tick) 0
memcmp with AVX/SSE
Time: 110 ticks (9761289 memcmp/tick) 0
Time: 110 ticks (9761289 memcmp/tick) 0
With some modifications to original patch, and looking through test_hash_perf which has statistics for every test (Add on empty, Add update, Lookup) it performs, in almost all categories (16, 32, 48 and 64 bytes) AVX/SSE beats regular memcmp. Please note that the time measured in test_hash_perf is for hash functions (jhash and hash_crc) and memcmp is just a small part of the hash functionality.
I will send modified patch later on.
Thanks,
Ravi
Quoted 24 lines
Hi Bruce,
Couple of things I am planning to try
1. Use _xor_ and _testz_ instructions for comparison instead of _cmpeq_ and _mask_.
2. I am using unaligned loads, not sure about the penalty, I plan to try with aligned loads if address is aligned and compare results.Agreed that with just L3 or even if we go with L2 + L3 + L4 tuples it will not exceed 64 bytes, 128 bytes is just a stretch for some weird MPLSoGRE header formats.
My focus is currently on improving performance for < 64 bytes and < 128 bytes key lengths only.
Thanks,
RaviRegards,
Quoted 2 lines
/Bruce