]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: vars: only takes the variables lock on shared entries
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:20:45 +0000 (15:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:44:45 +0000 (15:44 +0200)
There's no point taking the variables locks for sess/txn/req/res
contexts since these ones always run inside the same thread anyway.
This patch conditions the lock on the variable's scope to avoid
flushing cache lines when not needed.

This showed an improvement of ~5% on a 16-thread machine with 12
variables.

include/haproxy/vars.h

index 30e6fe0c8841772bdd10609093078d315ad1e470..ebd1f15790372ab1fafd78377f9d7c46ede577d4 100644 (file)
@@ -41,28 +41,32 @@ int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp)
 int vars_get_by_desc(const struct var_desc *var_desc, struct sample *smp, const struct buffer *def);
 int vars_check_arg(struct arg *arg, char **err);
 
-/* locks the <vars> for writes */
+/* locks the <vars> for writes if it's in a shared scope */
 static inline void vars_wrlock(struct vars *vars)
 {
-       HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
+       if (vars->scope == SCOPE_PROC)
+               HA_RWLOCK_WRLOCK(VARS_LOCK, &vars->rwlock);
 }
 
-/* unlocks the <vars> for writes */
+/* unlocks the <vars> for writes if it's in a shared scope */
 static inline void vars_wrunlock(struct vars *vars)
 {
-       HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
+       if (vars->scope == SCOPE_PROC)
+               HA_RWLOCK_WRUNLOCK(VARS_LOCK, &vars->rwlock);
 }
 
-/* locks the <vars> for reads */
+/* locks the <vars> for reads if it's in a shared scope */
 static inline void vars_rdlock(struct vars *vars)
 {
-       HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
+       if (vars->scope == SCOPE_PROC)
+               HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
 }
 
-/* unlocks the <vars> for reads */
+/* unlocks the <vars> for reads if it's in a shared scope */
 static inline void vars_rdunlock(struct vars *vars)
 {
-       HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
+       if (vars->scope == SCOPE_PROC)
+               HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
 }
 
 #endif