Skip to content

Commit

Permalink
ioq: Don't unroll the spin loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed Jan 16, 2025
1 parent f045573 commit 95bc3ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/bfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ extern const char bfs_ldlibs[];
# define _target_clones(...)
#endif

/**
* Optimization hint to not unroll a loop.
*/
#if __clang__
# define _nounroll _Pragma("nounroll")
#elif __GNUC__
# define _nounroll _Pragma("GCC unroll 0")
#else
# define _nounroll
#endif

#endif // BFS_H
5 changes: 4 additions & 1 deletion src/ioq.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,13 @@ static struct ioq_monitor *ioq_slot_monitor(struct ioqq *ioqq, ioq_slot *slot) {
/** Atomically wait for a slot to change. */
_noinline
static uintptr_t ioq_slot_wait(struct ioqq *ioqq, ioq_slot *slot, uintptr_t value) {
// Try spinning a few times before blocking
uintptr_t ret;

// Try spinning a few times before blocking
_nounroll
for (int i = 0; i < 10; ++i) {
// Exponential backoff
_nounroll
for (int j = 0; j < (1 << i); ++j) {

Check warning on line 287 in src/ioq.c

View workflow job for this annotation

GitHub Actions / Linux

Compiler warning

ignoring loop annotation
spin_loop();
}
Expand Down

0 comments on commit 95bc3ed

Please sign in to comment.