1 #ifndef __MTCP_UTIL_H__ 2 #define __MTCP_UTIL_H__ 3 4 #include <stdint.h> 5 #include <netinet/in.h> 6 #include <arpa/inet.h> 7 #include <unistd.h> 8 9 10 /** Calculate the RSS hash result using given addresses and 11 * port number, and returns the CPU core to be mapped. 12 * @param [in] sip: source IP address 13 * @param [in] dip: destination IP address 14 * @param [in] sp: source port number 15 * @param [in] dp: destination port number 16 * @param [in] num_queues: number of receive-side queues 17 * @return core number which will be mapped to the given addr 18 */ 19 int 20 GetRSSCPUCore(in_addr_t sip, in_addr_t dip, 21 in_port_t sp, in_port_t dp, int num_queues); 22 23 /** Fill argc and argv by parsing str. Original str might be modified. 24 * @param [in] str: source string 25 * @param [in] argc: number of parsed arguments 26 * @param [in] argv: argument string list 27 * @param [in] max_argc: maximum value of argc 28 * @return 0 for success, -1 for error 29 */ 30 int 31 StrToArgs(char *str, int *argc, char **argv, int max_argc); 32 33 34 35 /* 36 xxHash - Extremely Fast Hash algorithm 37 Header File 38 Copyright (C) 2012-2015, Yann Collet. 39 40 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) 41 42 Redistribution and use in source and binary forms, with or without 43 modification, are permitted provided that the following conditions are 44 met: 45 46 * Redistributions of source code must retain the above copyright 47 notice, this list of conditions and the following disclaimer. 48 * Redistributions in binary form must reproduce the above 49 copyright notice, this list of conditions and the following disclaimer 50 in the documentation and/or other materials provided with the 51 distribution. 52 53 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 54 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 55 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 56 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 57 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 58 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 59 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 63 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 65 You can contact the author at : 66 - xxHash source repository : https://github.com/Cyan4973/xxHash 67 */ 68 69 /* Notice extracted from xxHash homepage : 70 71 xxHash is an extremely fast Hash algorithm, running at RAM speed limits. 72 It also successfully passes all tests from the SMHasher suite. 73 74 Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) 75 76 Name Speed Q.Score Author 77 xxHash 5.4 GB/s 10 78 CrapWow 3.2 GB/s 2 Andrew 79 MumurHash 3a 2.7 GB/s 10 Austin Appleby 80 SpookyHash 2.0 GB/s 10 Bob Jenkins 81 SBox 1.4 GB/s 9 Bret Mulvey 82 Lookup3 1.2 GB/s 9 Bob Jenkins 83 SuperFastHash 1.2 GB/s 1 Paul Hsieh 84 CityHash64 1.05 GB/s 10 Pike & Alakuijala 85 FNV 0.55 GB/s 5 Fowler, Noll, Vo 86 CRC32 0.43 GB/s 9 87 MD5-32 0.33 GB/s 10 Ronald L. Rivest 88 SHA1-32 0.28 GB/s 10 89 90 Q.Score is a measure of quality of the hash function. 91 It depends on successfully passing SMHasher test set. 92 10 is a perfect score. 93 94 A 64-bits version, named XXH64, is available since r35. 95 It offers much better speed, but for 64-bits applications only. 96 Name Speed on 64 bits Speed on 32 bits 97 XXH64 13.8 GB/s 1.9 GB/s 98 XXH32 6.8 GB/s 6.0 GB/s 99 */ 100 101 #if defined (__cplusplus) 102 extern "C" { 103 #endif 104 105 106 /***************************** 107 * Simple Hash Functions 108 *****************************/ 109 110 unsigned int XXH32 (const void* input, size_t length, unsigned seed); 111 unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed); 112 113 /* 114 XXH32() : 115 Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". 116 The memory between input & input+length must be valid (allocated and read-accessible). 117 "seed" can be used to alter the result predictably. 118 This function successfully passes all SMHasher tests. 119 Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s 120 XXH64() : 121 Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". 122 Faster on 64-bits systems. Slower on 32-bits systems. 123 */ 124 125 126 #if defined (__cplusplus) 127 } 128 #endif 129 130 #endif /* !__MTCP_UTIL_H__ */ 131