toeplitz_hash() loops over every bit of its input: about 385 ns for
the 36 bytes of IPv6 addresses and ports on an Atom C1110. The
Toeplitz hash is linear over GF(2), so the hash of an input is the XOR
of the hashes of its bytes, each at its own offset. rss_key does not
change at run time, so rss_init() can build a table of the hash of
every value at every byte offset, and rss_hash() then needs one table
lookup per byte.
Add toeplitz_cache_init() and toeplitz_cache_hash() for inputs of up
to 36 bytes and use them in rss_hash(). toeplitz_cache_init() hashes
the 8 single bits at each offset and fills in the other values by XOR,
in 74 us on the C1110. toeplitz_hash() stays for other keys and longer
inputs.
rss_hash() runs for every TCP connection opened, and for every one
accepted from a SYN that came without a hash. With options RSS it
also runs for every packet without a usable hash from the NIC, in
epair(4) and netisr for example. On the C1110 the 36-byte hash now
takes 26 ns. Forwarding IPv6 with netisr hashing every packet, the
hash path cost about 75 ns per packet instead of about 450, and one
flow went from 741 to 1026 kpps.
The table takes 36 KB, and rss_config.c is in every kernel. It stays
in cache under load: the lookups took 34 ns per packet forwarding one
flow, and 45 ns with 65,536 flows and pf holding 131,072 states.
Tables per nibble would take 4.5 KB, but 53 to 71 ns.
The tables match toeplitz_hash() on 25.6 million random inputs and on
the Microsoft RSS verification vectors, and the software hash equalled
the I226's hash for all 603,597 forwarded packets checked.
MFC after: 2 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")