Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: Inline bch2_two_state_(trylock|unlock)

Standard inlining of fast paths - these locks are now used by our new
nocow mode.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+37 -31
+1 -1
fs/bcachefs/nocow_locking.c
··· 10 10 struct bch_fs *c = container_of(t, struct bch_fs, nocow_locks); 11 11 u64 start_time = local_clock(); 12 12 13 - bch2_two_state_lock(l, flags & BUCKET_NOCOW_LOCK_UPDATE); 13 + __bch2_two_state_lock(l, flags & BUCKET_NOCOW_LOCK_UPDATE); 14 14 bch2_time_stats_update(&c->times[BCH_TIME_nocow_lock_contended], start_time); 15 15 }
+2 -27
fs/bcachefs/two_state_shared_lock.c
··· 2 2 3 3 #include "two_state_shared_lock.h" 4 4 5 - void bch2_two_state_unlock(two_state_lock_t *lock, int s) 5 + void __bch2_two_state_lock(two_state_lock_t *lock, int s) 6 6 { 7 - long i = s ? 1 : -1; 8 - 9 - BUG_ON(atomic_long_read(&lock->v) == 0); 10 - 11 - if (atomic_long_sub_return_release(i, &lock->v) == 0) 12 - wake_up_all(&lock->wait); 13 - } 14 - 15 - bool bch2_two_state_trylock(two_state_lock_t *lock, int s) 16 - { 17 - long i = s ? 1 : -1; 18 - long v = atomic_long_read(&lock->v), old; 19 - 20 - do { 21 - old = v; 22 - 23 - if (i > 0 ? v < 0 : v > 0) 24 - return false; 25 - } while ((v = atomic_long_cmpxchg_acquire(&lock->v, 26 - old, old + i)) != old); 27 - return true; 28 - } 29 - 30 - void bch2_two_state_lock(two_state_lock_t *lock, int s) 31 - { 32 - wait_event(lock->wait, bch2_two_state_trylock(lock, s)); 7 + __wait_event(lock->wait, bch2_two_state_trylock(lock, s)); 33 8 }
+34 -3
fs/bcachefs/two_state_shared_lock.h
··· 6 6 #include <linux/sched.h> 7 7 #include <linux/wait.h> 8 8 9 + #include "util.h" 10 + 9 11 /* 10 12 * Two-state lock - can be taken for add or block - both states are shared, 11 13 * like read side of rwsem, but conflict with other state: ··· 23 21 init_waitqueue_head(&lock->wait); 24 22 } 25 23 26 - void bch2_two_state_unlock(two_state_lock_t *, int); 27 - bool bch2_two_state_trylock(two_state_lock_t *, int); 28 - void bch2_two_state_lock(two_state_lock_t *, int); 24 + static inline void bch2_two_state_unlock(two_state_lock_t *lock, int s) 25 + { 26 + long i = s ? 1 : -1; 27 + 28 + EBUG_ON(atomic_long_read(&lock->v) == 0); 29 + 30 + if (atomic_long_sub_return_release(i, &lock->v) == 0) 31 + wake_up_all(&lock->wait); 32 + } 33 + 34 + static inline bool bch2_two_state_trylock(two_state_lock_t *lock, int s) 35 + { 36 + long i = s ? 1 : -1; 37 + long v = atomic_long_read(&lock->v), old; 38 + 39 + do { 40 + old = v; 41 + 42 + if (i > 0 ? v < 0 : v > 0) 43 + return false; 44 + } while ((v = atomic_long_cmpxchg_acquire(&lock->v, 45 + old, old + i)) != old); 46 + return true; 47 + } 48 + 49 + void __bch2_two_state_lock(two_state_lock_t *, int); 50 + 51 + static inline void bch2_two_state_lock(two_state_lock_t *lock, int s) 52 + { 53 + if (!bch2_two_state_trylock(lock, s)) 54 + __bch2_two_state_lock(lock, s); 55 + } 29 56 30 57 #endif /* _BCACHEFS_TWO_STATE_LOCK_H */