From: Frederic Lecaille Date: Mon, 24 Aug 2026 14:07:42 +0000 (+0200) Subject: CLEANUP: haload: factor out two more duplicated -ee blocks X-Git-Tag: v3.5-dev6~80 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=6292861aa2dd6698d4506952ef0780a1f8f8a5f9;p=haproxy.git CLEANUP: haload: factor out two more duplicated -ee blocks hld_usr_schedule() and hld_rate_task() had the same four lines to reset a thread's rate history on a new -ee ramp generation. Move this into hld_thr_sync_ramp_gen(). hld_usr_schedule() and the budget check added to hld_usr_task() had the same throttle max computation. Move this into hld_thr_rate_max(), built on top of hld_thr_rate_share(). --- diff --git a/src/haload.c b/src/haload.c index a30a260dd..1423cc1ab 100644 --- a/src/haload.c +++ b/src/haload.c @@ -1402,19 +1402,25 @@ static inline uint32_t hld_thr_rate_share(int rate) return (rate + tid) / arg_thrd; } -/* Schedule user, depending on conn/req rate value */ -static inline void hld_usr_schedule(struct hld_usr *usr, int rate) +/* If a new -ee ramp just started, reset this thread's own rate + * history: it must not carry over data from before the ramp. + */ +static inline void hld_thr_sync_ramp_gen(struct hld_thr_info *ti) { - uint32_t max, wait; - struct hld_thr_info *ti = &thrs_info[tid]; - uint32_t maxusrs = ti->maxusrs; - if (HA_ATOMIC_LOAD(&err_ramp_active) && ti->err_ramp_gen != HA_ATOMIC_LOAD(&err_ramp_gen)) { - /* reset this thread's own rate history for the new -ee ramp */ memset(&ti->req_rate, 0, sizeof(ti->req_rate)); memset(&ti->conn_rate, 0, sizeof(ti->conn_rate)); ti->err_ramp_gen = HA_ATOMIC_LOAD(&err_ramp_gen); } +} + +/* This thread's send budget for right now: 0 while is + * still ramping up its user count under -s, otherwise its exact + * share of (see hld_thr_rate_share()). + */ +static inline uint32_t hld_thr_rate_max(struct hld_thr_info *ti, int rate) +{ + uint32_t maxusrs = ti->maxusrs; if (throttle) { maxusrs = mul32hi(maxusrs, throttle); @@ -1422,9 +1428,18 @@ static inline void hld_usr_schedule(struct hld_usr *usr, int rate) } if (ti->curusrs < maxusrs && throttle) - max = 0; - else - max = hld_thr_rate_share(rate); + return 0; + return hld_thr_rate_share(rate); +} + +/* Schedule user, depending on conn/req rate value */ +static inline void hld_usr_schedule(struct hld_usr *usr, int rate) +{ + uint32_t max, wait; + struct hld_thr_info *ti = &thrs_info[tid]; + + hld_thr_sync_ramp_gen(ti); + max = hld_thr_rate_max(ti, rate); if (!max) { /* this thread has no budget right now (its exact share of @@ -2214,12 +2229,7 @@ static struct task *hld_rate_task(struct task *t, void *context, unsigned int st uint32_t b1, b2; int nb_usr = thrs_info[tid].maxusrs; - if (HA_ATOMIC_LOAD(&err_ramp_active) && thrs_info[tid].err_ramp_gen != HA_ATOMIC_LOAD(&err_ramp_gen)) { - /* reset this thread's own rate history for the new -ee ramp */ - memset(&thrs_info[tid].req_rate, 0, sizeof(thrs_info[tid].req_rate)); - memset(&thrs_info[tid].conn_rate, 0, sizeof(thrs_info[tid].conn_rate)); - thrs_info[tid].err_ramp_gen = HA_ATOMIC_LOAD(&err_ramp_gen); - } + hld_thr_sync_ramp_gen(&thrs_info[tid]); if (throttle) { nb_usr = mul32hi(thrs_info[tid].maxusrs, throttle);