facebook / facebook/folly

EventCount::notify() can be made faster for case of single notifier on x86

Abierto
#1,368 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C++
Estrellas
30.5k
Forks
5.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

On x86 and modern SPARC it should be possible to optimize the EventCount::doNotify() for the case of just single notifier. Instead of using fetch add atomic (faa) with acq_rel memory order, a x86 `xadd` instruction can be used with memory operand (without LOCK prefix!), this is RMW operation, but supported on x86 since forever. The reason it works is that, even if the thread is attempted to be preempted by kernel when xadd started, it will need to wait to be finished, so externally it will either happen or not. And as there are no other notifiers there is no need for atomicity or locks.

This should remove all memory barriers on the notifier side, and improve performance of notify(), about 2-3 times. Plus it will keep the CPU store buffer queue full, so if needed CPU can read it back via a read bypass, saving probably another cycle and/or power.

To make this work slow path on a reader side should probably be changed to use futex wait with timeout, and use exponential backoff, and respin. If it fails only after long time wait forever. But in practice non-atomic / serializing writes from the notifier will be visible in less than 10ms (interrupts like timer interrupts do flush store buffers on the notifier CPU).

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.