From: Willy Tarreau Date: Mon, 14 Nov 2022 16:54:07 +0000 (+0100) Subject: OPTIM: stick-table: avoid atomic ops in stktable_requeue_exp() when possible X-Git-Tag: v2.7-dev9~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3238f79d12871937c55ff05f2853679a0d511420;p=thirdparty%2Fhaproxy.git 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 61e63b8ae6..1820da3d9d 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -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); }