/* SPDX-License-Identifier: GPL-2.0 */ /* * MCS lock defines * * This file contains the main data structure and API definitions of MCS lock. * * The MCS lock (proposed by Mellor-Crummey and Scott) is a simple spin-lock * with the desirable properties of being fair, and with each cpu trying * to acquire the lock spinning on a local variable. * It avoids expensive cache bounces that common test-and-set spin-lock * implementations incur. */ #ifndef __LINUX_MCS_SPINLOCK_H #define __LINUX_MCS_SPINLOCK_H #include <asm/mcs_spinlock.h> struct mcs_spinlock { … }; #ifndef arch_mcs_spin_lock_contended /* * Using smp_cond_load_acquire() provides the acquire semantics * required so that subsequent operations happen after the * lock is acquired. Additionally, some architectures such as * ARM64 would like to do spin-waiting instead of purely * spinning, and smp_cond_load_acquire() provides that behavior. */ #define arch_mcs_spin_lock_contended(l) … #endif #ifndef arch_mcs_spin_unlock_contended /* * smp_store_release() provides a memory barrier to ensure all * operations in the critical section has been completed before * unlocking. */ #define arch_mcs_spin_unlock_contended(l) … #endif /* * Note: the smp_load_acquire/smp_store_release pair is not * sufficient to form a full memory barrier across * cpus for many architectures (except x86) for mcs_unlock and mcs_lock. * For applications that need a full barrier across multiple cpus * with mcs_unlock and mcs_lock pair, smp_mb__after_unlock_lock() should be * used after mcs_lock. */ /* * In order to acquire the lock, the caller should declare a local node and * pass a reference of the node to this function in addition to the lock. * If the lock has already been acquired, then this will proceed to spin * on this node->locked until the previous lock holder sets the node->locked * in mcs_spin_unlock(). */ static inline void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) { … } /* * Releases the lock. The caller should pass in the corresponding node that * was used to acquire the lock. */ static inline void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) { … } #endif /* __LINUX_MCS_SPINLOCK_H */