]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: stick-table: avoid atomic ops in stktable_requeue_exp() when possible
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Nov 2022 16:54:07 +0000 (17:54 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Nov 2022 17:20:38 +0000 (18:20 +0100)
Since the task's time resolution is the millisecond we know there
will not be more than 1000 useful updates per second, so there's no
point in doing a CAS and a task_queue() for each call, better first
check if we're going to change the date. Now we're certain not to
perform such operations more than 1000 times a second for a given
table.

The loop was modified because this improvement will also be used to fix a
bug later.

src/stick_table.c

index 61e63b8ae68a5405f0a14f79b3267cf97be930f3..1820da3d9dfd87008c50d376d703f723d90ec16c 100644 (file)
@@ -550,11 +550,17 @@ void stktable_requeue_exp(struct stktable *t, const struct stksess *ts)
 
        /* set the task's expire to the newest expiration date. */
        old_exp = HA_ATOMIC_LOAD(&t->exp_task->expire);
-       do {
+       new_exp = tick_first(expire, old_exp);
+
+       /* let's not go further if we're already up to date */
+       if (new_exp == old_exp)
+               return;
+
+       while (new_exp != old_exp &&
+              !HA_ATOMIC_CAS(&t->exp_task->expire, &old_exp, new_exp)) {
+               __ha_cpu_relax();
                new_exp = tick_first(expire, old_exp);
-       } while (new_exp != old_exp &&
-                !HA_ATOMIC_CAS(&t->exp_task->expire, &old_exp, new_exp) &&
-                __ha_cpu_relax());
+       }
 
        task_queue(t->exp_task);
 }