Craig, Dave wrote:
Please consider the attached patch for incorporation into the next Linux 2.6 release. I found that using the __builtin_memcmp GCC intrinsic for doing IPv6 address comparison a lot more slow than integer comparison. In significant SCTP workloads I found address comparison taking roughly 10% of the CPU time. After changing the address comparison to an integer-based approach the comparison consumed 5% of the CPU time.
This is what IN6_ARE_ADDR_EQUAL() does in netinet/in.h in user-space.
I also microbenchmarked the comparison on my architecture, a Pentium 4, and found the integer comparison was over 3x faster than the string comparison. The microbenchmark consisted of a series of address comparisons where 20% matched and 80% that didn't match. I looked at addresses that differed in the first, last, and random byte.
struct in6_addr
{
union
{
__u8 u6_addr8[16];
__u16 u6_addr16[8];
__u32 u6_addr32[4];
+ __u64 u6_addr64[2];
} in6_u;
#define s6_addr in6_u.u6_addr8
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
+#defind s6_addr64 in6_u.u6_addr64
};-Brian