OPTIM: stick-table: avoid atomic ops in stktable_requeue_exp() when possible
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.
diff --git a/src/stick_table.c b/src/stick_table.c
index 61e63b8..1820da3 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -550,11 +550,17 @@
/* 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);
}