mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-09 07:00:23 +02:00
Add helper for yielding in a spinlock
This commit is contained in:
parent
52166fe286
commit
e4342f6c45
2 changed files with 21 additions and 11 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "inline.h"
|
#include "inline.h"
|
||||||
|
#include "spin.h"
|
||||||
|
|
||||||
// The Chase-Lev work-stealing deque, as initially described in "Dynamic
|
// The Chase-Lev work-stealing deque, as initially described in "Dynamic
|
||||||
// Circular Work-Stealing Deque" (Chase and Lev, SPAA'05)
|
// Circular Work-Stealing Deque" (Chase and Lev, SPAA'05)
|
||||||
|
@ -530,8 +531,7 @@ trace_worker_check_termination(struct trace_worker *worker,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t spin_count = 0;
|
for (size_t spin_count = 0;; spin_count++) {
|
||||||
while (1) {
|
|
||||||
if (trace_worker_can_steal_from_any(worker, tracer)) {
|
if (trace_worker_can_steal_from_any(worker, tracer)) {
|
||||||
atomic_fetch_add_explicit(&tracer->active_tracers, 1,
|
atomic_fetch_add_explicit(&tracer->active_tracers, 1,
|
||||||
memory_order_relaxed);
|
memory_order_relaxed);
|
||||||
|
@ -544,15 +544,7 @@ trace_worker_check_termination(struct trace_worker *worker,
|
||||||
}
|
}
|
||||||
// spin
|
// spin
|
||||||
DEBUG("tracer #%zu: spinning #%zu\n", worker->id, spin_count);
|
DEBUG("tracer #%zu: spinning #%zu\n", worker->id, spin_count);
|
||||||
if (spin_count < 10)
|
yield_for_spin(spin_count);
|
||||||
__builtin_ia32_pause();
|
|
||||||
else if (spin_count < 20)
|
|
||||||
sched_yield();
|
|
||||||
else if (spin_count < 40)
|
|
||||||
usleep(0);
|
|
||||||
else
|
|
||||||
usleep(1);
|
|
||||||
spin_count++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
spin.h
Normal file
18
spin.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef SPIN_H
|
||||||
|
#define SPIN_H
|
||||||
|
|
||||||
|
#include <sched.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static inline void yield_for_spin(size_t spin_count) {
|
||||||
|
if (spin_count < 10)
|
||||||
|
__builtin_ia32_pause();
|
||||||
|
else if (spin_count < 20)
|
||||||
|
sched_yield();
|
||||||
|
else if (spin_count < 40)
|
||||||
|
usleep(0);
|
||||||
|
else
|
||||||
|
usleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SPIN_H
|
Loading…
Add table
Add a link
Reference in a new issue