From: Willy Tarreau Date: Wed, 20 Sep 2023 18:30:27 +0000 (+0200) Subject: MINOR: logs: use a single index to store the current range and index X-Git-Tag: v2.9-dev6~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e00470378bcd55321d649f21cd5d4df3318e2774;p=thirdparty%2Fhaproxy.git MINOR: logs: use a single index to store the current range and index By using a single long long to store both the current range and the next index, we'll make it possible to perform atomic operations instead of locking. Let's only regroup them for now under a new "curr_rg_idx". The upper word is the range, the lower is the index. --- diff --git a/include/haproxy/log-t.h b/include/haproxy/log-t.h index 2445051844..a503ef9afd 100644 --- a/include/haproxy/log-t.h +++ b/include/haproxy/log-t.h @@ -215,10 +215,7 @@ struct smp_info { struct smp_log_range *smp_rgs; /* Array of ranges for log sampling. */ size_t smp_rgs_sz; /* The size of array. */ size_t smp_sz; /* The total number of logs to be sampled. */ - unsigned int curr_rg; /* The current range to be sampled. */ - unsigned int curr_idx; /* A counter to store the current index of the log - * already sampled. - */ + ullong curr_rg_idx; /* 63:32 = current range; 31:0 = current index */ }; struct logsrv { diff --git a/src/log.c b/src/log.c index 6cc8050c13..a03172bb73 100644 --- a/src/log.c +++ b/src/log.c @@ -1830,11 +1830,14 @@ void process_send_log(struct list *logsrvs, int level, int facility, if (logsrv->lb.smp_rgs) { struct smp_log_range *smp_rg; - unsigned int next_idx; + uint next_idx, curr_rg; + ullong curr_rg_idx; HA_SPIN_LOCK(LOGSRV_LOCK, &logsrv->lock); - next_idx = logsrv->lb.curr_idx + 1; - smp_rg = &logsrv->lb.smp_rgs[logsrv->lb.curr_rg]; + curr_rg_idx = logsrv->lb.curr_rg_idx; + next_idx = (curr_rg_idx & 0xFFFFFFFFU) + 1; + curr_rg = curr_rg_idx >> 32; + smp_rg = &logsrv->lb.smp_rgs[curr_rg]; /* check if the index we're going to take is within range */ in_range = smp_rg->low <= next_idx && next_idx <= smp_rg->high; @@ -1842,10 +1845,13 @@ void process_send_log(struct list *logsrvs, int level, int facility, /* Let's consume this range. */ if (next_idx == smp_rg->high) { /* If consumed, let's select the next range. */ - logsrv->lb.curr_rg = (logsrv->lb.curr_rg + 1) % logsrv->lb.smp_rgs_sz; + curr_rg = (curr_rg + 1) % logsrv->lb.smp_rgs_sz; } } - logsrv->lb.curr_idx = next_idx % logsrv->lb.smp_sz; + + next_idx = next_idx % logsrv->lb.smp_sz; + curr_rg_idx = ((ullong)curr_rg << 32) + next_idx; + logsrv->lb.curr_rg_idx = curr_rg_idx; HA_SPIN_UNLOCK(LOGSRV_LOCK, &logsrv->lock); } if (in_range)