From: Willy Tarreau Date: Wed, 6 Oct 2021 15:14:49 +0000 (+0200) Subject: REORG: connection: move the hash-related stuff to connection.c X-Git-Tag: v2.5-dev9~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5983ffb3adbf71a8f286094b1c1afce6061d1f3;p=thirdparty%2Fhaproxy.git REORG: connection: move the hash-related stuff to connection.c We do not really need to have them inlined, and having xxhash.h included by connection.h results in this 4700-lines file being processed 101 times over the whole project, which accounts for 13.5% of the total size! Additionally, half of the functions are only needed from connection.c. Let's move the functions there and get rid of the painful include. The build time is now down to 6.2s just due to this. --- diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index a50b0bb4f7..c4d9e06e80 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -37,7 +37,6 @@ #include #include #include -#include extern struct pool_head *pool_head_connection; @@ -79,6 +78,17 @@ int conn_recv_socks4_proxy_response(struct connection *conn); /* If we delayed the mux creation because we were waiting for the handshake, do it now */ int conn_create_mux(struct connection *conn); +/* connection hash stuff */ +uint64_t conn_calculate_hash(const struct conn_hash_params *params); +uint64_t conn_hash_prehash(char *buf, size_t size); +void conn_hash_update(char *buf, size_t *idx, + const void *data, size_t size, + enum conn_hash_params_t *flags, + enum conn_hash_params_t type); +uint64_t conn_hash_digest(char *buf, size_t bufsize, + enum conn_hash_params_t flags); + + extern struct idle_conns idle_conns[MAX_THREADS]; /* returns true if the transport layer is ready */ @@ -1195,39 +1205,6 @@ static inline int conn_upgrade_mux_fe(struct connection *conn, void *ctx, struct return 0; } -/* Generate the hash of a connection with params as input - * Each non-null field of params is taken into account for the hash calcul. - */ -uint64_t conn_calculate_hash(const struct conn_hash_params *params); - -static inline uint64_t conn_hash_prehash(char *buf, size_t size) -{ - return XXH64(buf, size, 0); -} - -/* Append into at offset in preparation for connection hash - * calcul. is incremented beyond data . In the same time, - * are updated with for the hash header. - */ -static inline void conn_hash_update(char *buf, size_t *idx, - const void *data, size_t size, - enum conn_hash_params_t *flags, - enum conn_hash_params_t type) -{ - memcpy(&buf[*idx], data, size); - *idx += size; - *flags |= type; -} - -static inline uint64_t conn_hash_digest(char *buf, size_t bufsize, - enum conn_hash_params_t flags) -{ - const uint64_t flags_u64 = (uint64_t)flags; - const uint64_t hash = XXH64(buf, bufsize, 0); - - return (flags_u64 << CONN_HASH_PAYLOAD_LEN) | CONN_HASH_GET_PAYLOAD(hash); -} - /* boolean, returns true if connection is over SSL */ static inline int conn_is_ssl(struct connection *conn) diff --git a/src/connection.c b/src/connection.c index 2e734f7246..1dcba8a945 100644 --- a/src/connection.c +++ b/src/connection.c @@ -26,6 +26,7 @@ #include #include #include +#include DECLARE_POOL(pool_head_connection, "connection", sizeof(struct connection)); @@ -1627,6 +1628,37 @@ static void conn_calculate_hash_sockaddr(const struct sockaddr_storage *ss, } } +/* Generate the hash of a connection with params as input + * Each non-null field of params is taken into account for the hash calcul. + */ +uint64_t conn_hash_prehash(char *buf, size_t size) +{ + return XXH64(buf, size, 0); +} + +/* Append into at offset in preparation for connection hash + * calcul. is incremented beyond data . In the same time, + * are updated with for the hash header. + */ +void conn_hash_update(char *buf, size_t *idx, + const void *data, size_t size, + enum conn_hash_params_t *flags, + enum conn_hash_params_t type) +{ + memcpy(&buf[*idx], data, size); + *idx += size; + *flags |= type; +} + +uint64_t conn_hash_digest(char *buf, size_t bufsize, + enum conn_hash_params_t flags) +{ + const uint64_t flags_u64 = (uint64_t)flags; + const uint64_t hash = XXH64(buf, bufsize, 0); + + return (flags_u64 << CONN_HASH_PAYLOAD_LEN) | CONN_HASH_GET_PAYLOAD(hash); +} + uint64_t conn_calculate_hash(const struct conn_hash_params *params) { char *buf;