zebra: reduce atomic ops in fpm_process_queue()

Maintain the count of contexts which have been processed in a local
variable, and perform a single atomic update after we have consumed
all queued contexts.

Generally this results in at least one less atomic operation per
context.

Signed-off-by: Duncan Eastoe <duncan.eastoe@att.com>
This commit is contained in:
Duncan Eastoe 2020-12-18 14:35:21 +00:00
parent 3f2b998f61
commit 438dd3e7df

View File

@ -1223,6 +1223,7 @@ static int fpm_process_queue(struct thread *t)
struct fpm_nl_ctx *fnc = THREAD_ARG(t);
struct zebra_dplane_ctx *ctx;
bool no_bufs = false;
uint64_t processed_contexts = 0;
while (true) {
/* No space available yet. */
@ -1241,8 +1242,7 @@ static int fpm_process_queue(struct thread *t)
fpm_nl_enqueue(fnc, ctx);
/* Account the processed entries. */
atomic_fetch_add_explicit(&fnc->counters.dplane_contexts, 1,
memory_order_relaxed);
processed_contexts++;
atomic_fetch_sub_explicit(&fnc->counters.ctxqueue_len, 1,
memory_order_relaxed);
@ -1250,6 +1250,10 @@ static int fpm_process_queue(struct thread *t)
dplane_provider_enqueue_out_ctx(fnc->prov, ctx);
}
/* Update count of processed contexts */
atomic_fetch_add_explicit(&fnc->counters.dplane_contexts,
processed_contexts, memory_order_relaxed);
/* Re-schedule if we ran out of buffer space */
if (no_bufs)
thread_add_timer(fnc->fthread->master, fpm_process_queue,