From e5983ffb3adbf71a8f286094b1c1afce6061d1f3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 6 Oct 2021 17:14:49 +0200 Subject: [PATCH] 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. --- include/haproxy/connection.h | 45 +++++++++--------------------------- src/connection.c | 32 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index a50b0bb4f..c4d9e06e8 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 2e734f724..1dcba8a94 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;