OPTIM: ring: don't even try to update offset when failed to read

If there's nothing to read, it's pointless for a reader to try to update
the offset pointer, that's two atomic ops to replace a value by itself
twice. Let's just stop this.
This commit is contained in:
Willy Tarreau 2024-02-29 11:57:28 +01:00
parent 9e99cfbeb6
commit 1f8b14b7be

View File

@ -538,17 +538,19 @@ int ring_dispatch_messages(struct ring *ring, void *ctx, size_t *ofs_ptr, size_t
vp_data_to_ring(v1, v2, (char *)ring_area, ring_size, &head_ofs, &tail_ofs);
/* inc readers count on new place */
do {
readers = _HA_ATOMIC_LOAD(ring_area + head_ofs);
} while ((readers > RING_MAX_READERS ||
!_HA_ATOMIC_CAS(ring_area + head_ofs, &readers, readers + 1)) && __ha_cpu_relax());
if (head_ofs != prev_ofs) {
/* inc readers count on new place */
do {
readers = _HA_ATOMIC_LOAD(ring_area + head_ofs);
} while ((readers > RING_MAX_READERS ||
!_HA_ATOMIC_CAS(ring_area + head_ofs, &readers, readers + 1)) && __ha_cpu_relax());
/* dec readers count on old place */
do {
readers = _HA_ATOMIC_LOAD(ring_area + prev_ofs);
} while ((readers > RING_MAX_READERS ||
!_HA_ATOMIC_CAS(ring_area + prev_ofs, &readers, readers - 1)) && __ha_cpu_relax());
/* dec readers count on old place */
do {
readers = _HA_ATOMIC_LOAD(ring_area + prev_ofs);
} while ((readers > RING_MAX_READERS ||
!_HA_ATOMIC_CAS(ring_area + prev_ofs, &readers, readers - 1)) && __ha_cpu_relax());
}
if (last_ofs_ptr)
*last_ofs_ptr = tail_ofs;