Skip to content

Commit

Permalink
Fix broken build on platforms without threads
Browse files Browse the repository at this point in the history
Closes #2178
  • Loading branch information
riptl authored and ripatel-fd committed Jun 26, 2024
1 parent 9757139 commit a113749
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/app/fdctl/Local.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ifdef FD_HAS_HOSTED
ifdef FD_HAS_THREADS
ifdef FD_HAS_ALLOCA
ifdef FD_HAS_DOUBLE
ifdef FD_HAS_INT128
Expand Down Expand Up @@ -156,3 +157,4 @@ endif
endif
endif
endif
endif
12 changes: 12 additions & 0 deletions src/disco/bank/fd_rwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ typedef struct fd_rwlock fd_rwlock_t;

static inline void
fd_rwlock_write( fd_rwlock_t * lock ) {
# if FD_HAS_THREADS
for(;;) {
ushort value = lock->value;
if( FD_LIKELY( !value ) ) {
if( FD_LIKELY( !FD_ATOMIC_CAS( &lock->value, 0, 0xFFFF ) ) ) return;
}
FD_SPIN_PAUSE();
}
# else
lock->value = 0xFFFF;
# endif
FD_COMPILER_MFENCE();
}

Expand All @@ -36,6 +40,7 @@ fd_rwlock_unwrite( fd_rwlock_t * lock ) {

static inline void
fd_rwlock_read( fd_rwlock_t * lock ) {
# if FD_HAS_THREADS
for(;;) {
ushort value = lock->value;
if( FD_UNLIKELY( value!=0xFFFE ) ) {
Expand All @@ -45,13 +50,20 @@ fd_rwlock_read( fd_rwlock_t * lock ) {
}
FD_SPIN_PAUSE();
}
# else
lock->value++;
# endif
FD_COMPILER_MFENCE();
}

static inline void
fd_rwlock_unread( fd_rwlock_t * lock ) {
FD_COMPILER_MFENCE();
# if FD_HAS_THREADS
FD_ATOMIC_FETCH_AND_SUB( &lock->value, 1 );
# else
lock->value--;
# endif
}

#endif /* HEADER_fd_src_disco_bank_rwlock_h */
2 changes: 2 additions & 0 deletions src/disco/topo/Local.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ifdef FD_HAS_HOSTED
ifdef FD_HAS_THREADS
ifdef FD_HAS_LINUX
$(call add-hdrs,fd_topo.h fd_pod_format.h)
$(call add-objs,fd_topo fd_topob fd_topo_run,fd_disco)
endif
endif
endif
10 changes: 7 additions & 3 deletions src/disco/tvu/fd_pending_slots.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fd_pending_slots_new( void * mem, ulong lo_wmark ) {

laddr += sizeof( fd_pending_slots_t );
pending_slots->pending = (void *)laddr;

laddr += sizeof(long) * FD_PENDING_MAX;

FD_TEST( laddr == (ulong)mem + footprint );
Expand Down Expand Up @@ -78,10 +78,14 @@ fd_pending_slots_delete( void * pending_slots ) {

static void
fd_pending_slots_lock( fd_pending_slots_t * pending_slots ) {
# if FD_HAS_THREADS
for(;;) {
if( FD_LIKELY( !FD_ATOMIC_CAS( &pending_slots->lock, 0UL, 1UL) ) ) break;
FD_SPIN_PAUSE();
}
# else
pending_slots->lock = 1UL;
# endif
FD_COMPILER_MFENCE();
}

Expand Down Expand Up @@ -134,14 +138,14 @@ fd_pending_slots_add( fd_pending_slots_t * pending_slots,
ulong slot,
long when ) {
fd_pending_slots_lock( pending_slots );

long * pending = pending_slots->pending;
if( pending_slots->start == pending_slots->end ) {
/* Queue is empty */
pending_slots->start = slot;
pending_slots->end = slot+1U;
pending[slot & FD_PENDING_MASK] = when;

} else if ( slot < pending_slots->start ) {
/* Grow down */
if( (long)(pending_slots->end - slot) > (long)FD_PENDING_MAX )
Expand Down
4 changes: 4 additions & 0 deletions src/disco/tvu/fd_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ fd_replay_delete( void * replay ) {

static void
fd_replay_pending_lock( fd_replay_t * replay ) {
# if FD_HAS_THREADS
for( ;; ) {
if( FD_LIKELY( !FD_ATOMIC_CAS( &replay->pending_lock, 0UL, 1UL ) ) ) break;
FD_SPIN_PAUSE();
}
# else
replay->pending_lock = 1;
# endif
FD_COMPILER_MFENCE();
}

Expand Down
6 changes: 5 additions & 1 deletion src/flamenco/gossip/fd_gossip.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,14 @@ fd_gossip_delete ( void * shmap ) {

static void
fd_gossip_lock( fd_gossip_t * gossip ) {
# if FD_HAS_THREADS
for(;;) {
if( FD_LIKELY( !FD_ATOMIC_CAS( &gossip->lock, 0UL, 1UL) ) ) break;
FD_SPIN_PAUSE();
}
# else
gossip->lock = 1;
# endif
FD_COMPILER_MFENCE();
}

Expand Down Expand Up @@ -511,7 +515,7 @@ fd_gossip_update_tvu_addr( fd_gossip_t * glob, const fd_gossip_peer_addr_t * tvu
}

int
fd_gossip_update_tpu_addr( fd_gossip_t * glob,
fd_gossip_update_tpu_addr( fd_gossip_t * glob,
fd_gossip_peer_addr_t const * tpu,
fd_gossip_peer_addr_t const * tpu_fwd ) {
char tmp[100];
Expand Down
8 changes: 6 additions & 2 deletions src/flamenco/repair/fd_repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,14 @@ fd_repair_delete ( void * shmap ) {

static void
fd_repair_lock( fd_repair_t * repair ) {
# if FD_HAS_THREADS
for(;;) {
if( FD_LIKELY( !FD_ATOMIC_CAS( &repair->lock, 0UL, 1UL) ) ) break;
FD_SPIN_PAUSE();
}
# else
repair->lock = 1;
# endif
FD_COMPILER_MFENCE();
}

Expand Down Expand Up @@ -695,7 +699,7 @@ fd_actives_shuffle( fd_repair_t * repair ) {
leftovers = fd_scratch_alloc(
alignof( fd_active_elem_t * ),
sizeof( fd_active_elem_t * ) * fd_active_table_key_cnt( repair->actives ) );

for( fd_active_table_iter_t iter = fd_active_table_iter_init( repair->actives );
!fd_active_table_iter_done( repair->actives, iter );
iter = fd_active_table_iter_next( repair->actives, iter ) ) {
Expand Down Expand Up @@ -726,7 +730,7 @@ fd_actives_shuffle( fd_repair_t * repair ) {

long latencies[ FD_REPAIR_STICKY_MAX ];
ulong latencies_cnt = 0UL;

long first_quartile_latency = LONG_MAX;

/* fetch all latencies */
Expand Down
4 changes: 4 additions & 0 deletions src/flamenco/runtime/fd_bank_hash_cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ fd_bank_hash_cmp_delete( void * bank_hash_cmp ) {
void
fd_bank_hash_cmp_lock( fd_bank_hash_cmp_t * bank_hash_cmp ) {
volatile int * lock = &bank_hash_cmp->lock;
# if FD_HAS_THREADS
for( ;; ) {
if( FD_LIKELY( !FD_ATOMIC_CAS( lock, 0UL, 1UL ) ) ) break;
FD_SPIN_PAUSE();
}
# else
*lock = 1;
# endif
FD_COMPILER_MFENCE();
}

Expand Down
16 changes: 16 additions & 0 deletions src/flamenco/runtime/fd_readwrite_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fd_readwrite_delete( void * shreadwrite ) {

static inline void
fd_readwrite_start_read( fd_readwrite_lock_t * lock ) {
# if FD_HAS_THREADS
for(;;) {
register int l = lock->lock;
if( FD_UNLIKELY( l < 0 || FD_ATOMIC_CAS( &lock->lock, l, l+1 ) != l ) ) {
Expand All @@ -53,10 +54,14 @@ fd_readwrite_start_read( fd_readwrite_lock_t * lock ) {
break;
}
FD_COMPILER_MFENCE();
# else
lock->lock++;
# endif
}

static inline void
fd_readwrite_end_read( fd_readwrite_lock_t * lock ) {
# if FD_HAS_THREADS
FD_COMPILER_MFENCE();
for(;;) {
register int l = lock->lock;
Expand All @@ -69,10 +74,14 @@ fd_readwrite_end_read( fd_readwrite_lock_t * lock ) {
}
break;
}
# else
lock->lock--;
# endif
}

static inline void
fd_readwrite_start_write( fd_readwrite_lock_t * lock ) {
# if FD_HAS_THREADS
for(;;) {
register int l = lock->lock;
if( FD_UNLIKELY( l != 0 || FD_ATOMIC_CAS( &lock->lock, l, -1 ) != l ) ) {
Expand All @@ -81,6 +90,9 @@ fd_readwrite_start_write( fd_readwrite_lock_t * lock ) {
}
break;
}
# else
lock->lock = -1;
# endif
FD_COMPILER_MFENCE();
lock->seqnum++;
FD_COMPILER_MFENCE();
Expand All @@ -91,6 +103,7 @@ fd_readwrite_end_write( fd_readwrite_lock_t * lock ) {
FD_COMPILER_MFENCE();
lock->seqnum++;
FD_COMPILER_MFENCE();
# if FD_HAS_THREADS
for(;;) {
register int l = lock->lock;
if( FD_UNLIKELY( l >= 0 ) ) {
Expand All @@ -102,6 +115,9 @@ fd_readwrite_end_write( fd_readwrite_lock_t * lock ) {
}
break;
}
# else
lock->lock = 0;
# endif
}

/* The pattern for concurrent reads is:
Expand Down
2 changes: 2 additions & 0 deletions src/flamenco/snapshot/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ $(call add-hdrs,fd_snapshot_http.h)
$(call add-objs,fd_snapshot_http,fd_flamenco)
$(call make-unit-test,test_snapshot_http,test_snapshot_http,fd_flamenco fd_disco fd_funk fd_ballet fd_util)
$(call run-unit-test,test_snapshot_http)
ifdef FD_HAS_THREADS
$(call make-fuzz-test,fuzz_snapshot_http,fuzz_snapshot_http,fd_flamenco fd_disco fd_funk fd_ballet fd_util)
endif
endif

$(call add-hdrs,fd_snapshot_istream.h)
$(call add-objs,fd_snapshot_istream,fd_flamenco)
Expand Down

0 comments on commit a113749

Please sign in to comment.