Skip to contentSkip to conversation

hash: optimize the softrss computation

PATCH Applied Yangchao Zhou 4 participants 4 messages Aug 22, 2017 – Oct 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hash: optimize the softrss computation

Use rte_bsf32 and fast bit unset operation to optimize the softrss computation. The following measurements shows improvement over the default softrss computation function.

tuple lens old(cycles) new(cycles)

    3        1225         337
    9        3743         992
---
 lib/librte_hash/rte_thash.h | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
lib/librte_hash/rte_thash.h +10 -12
index 2fffd61..4fa5e07 100644
@@ -207,15 +207,14 @@ 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;
+	uint32_t i, j, map, 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 |
+		for (map = input_tuple[j]; map;	map &= (map - 1)) {
+			i = rte_bsf32(map);
+			ret ^= rte_cpu_to_be_32(((const uint32_t *)rss_key)[j]) << (31 - i) |
 					(uint32_t)((uint64_t)(rte_cpu_to_be_32(((const uint32_t *)rss_key)[j + 1])) >>
-					(32 - i));
-			}
+					(i + 1));
 		}
 	}
 	return ret;
@@ -238,14 +237,13 @@ 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;
+	uint32_t i, j, map, 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));
-			}
+		for (map = input_tuple[j]; map;	map &= (map - 1)) {
+			i = rte_bsf32(map);
+			ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
+				(uint32_t)((uint64_t)(((const uint32_t *)rss_key)[j + 1]) >> (i + 1));
 		}
 	}
 	return ret;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw

Hi,

2017-08-22 15:02 GMT+03:00 Yangchao Zhou <[email protected]>:

Quoted 65 lines

Use rte_bsf32 and fast bit unset operation to optimize the softrss computation.
The following measurements shows improvement over the default softrss computation function.

tuple lens old(cycles) new(cycles)

    3        1225         337
    9        3743         992
---
 lib/librte_hash/rte_thash.h | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
lib/librte_hash/rte_thash.h +4 -4
index 2fffd61..4fa5e07 100644
@@ -207,15 +207,14 @@ 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;
+       uint32_t i, j, map, 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 |
+               for (map = input_tuple[j]; map; map &= (map - 1)) {
+                       i = rte_bsf32(map);
+                       ret ^= rte_cpu_to_be_32(((const uint32_t
 *)rss_key)[j]) << (31 - i) |
                                        (uint32_t)((uint64_t)(rte_cpu_to_be_32(((const

uint32_t *)rss_key)[j + 1])) >>

lib/librte_hash/rte_thash.h +2 -6
-                                       (32 - i));
-                       }
+                                       (i + 1));
                }
        }
        return ret;
@@ -238,14 +237,13 @@ 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;
+       uint32_t i, j, map, 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));

lib/librte_hash/rte_thash.h +4 -1
-                       }
+               for (map = input_tuple[j]; map; map &= (map - 1)) {
+                       i = rte_bsf32(map);
+                       ret ^= ((const uint32_t *)rss_key)[j] << (31 - i) |
+                               (uint32_t)((uint64_t)(((const uint32_t
*)rss_key)[j + 1]) >> (i + 1));
                }
        }
        return ret;
Quoted 4 lines

--
2.7.4

Looks good for me. Thanks!

Signature · 2 lines
Regards,
Vladimir
#2 lore raw

Hi,

Quoted 8 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Vladimir Medvedkin
Sent: Tuesday, August 22, 2017 4:57 PM
To: Yangchao Zhou <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH] hash: optimize the softrss computation

Quoted 14 lines

Hi,

2017-08-22 15:02 GMT+03:00 Yangchao Zhou <[email protected]>:

Quoted 10 lines

Use rte_bsf32 and fast bit unset operation to optimize the softrss computation.
The following measurements shows improvement over the default softrss computation function.

tuple lens old(cycles) new(cycles)

    3        1225         337
    9        3743         992

Commit message is a bit long. Could you wrap it to have less than 75 characters per line? Although, the patch itself has lines with more than 90 characters, which should be avoided:

http://dpdk.org/ml/archives/test-report/2017-August/027283.html

Last thing, the "Reviewed-by" has an extra space, before the name.

Thanks,
Pablo

Quoted 8 lines
Quoted 1 line

Looks good for me. Thanks!

--
Regards,
Vladimir

#3 lore raw

22/09/2017 17:33, De Lara Guarch, Pablo:

Quoted 12 lines

From: Vladimir Medvedkin

Quoted 11 lines

2017-08-22 15:02 GMT+03:00 Yangchao Zhou <[email protected]>:

Quoted 9 lines

Use rte_bsf32 and fast bit unset operation to optimize the softrss computation.
The following measurements shows improvement over the default softrss computation function.

tuple lens old(cycles) new(cycles)

    3        1225         337
    9        3743         992
Quoted 8 lines
Quoted 1 line
Quoted 1 line

Commit message is a bit long. Could you wrap it to have less than 75 characters per line? Although, the patch itself has lines with more than 90 characters, which should be avoided:

http://dpdk.org/ml/archives/test-report/2017-August/027283.html

Last thing, the "Reviewed-by" has an extra space, before the name.

Applied, thanks