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.
This commit is contained in:
Willy Tarreau 2023-09-20 20:30:27 +02:00
parent 49ddc0138c
commit e00470378b
2 changed files with 12 additions and 9 deletions

View File

@ -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 <smp_rgs> 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 {

View File

@ -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)