~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/bit_spinlock.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/bit_spinlock.h (Version linux-6.12-rc7) and /include/linux/bit_spinlock.h (Version linux-6.8.12)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __LINUX_BIT_SPINLOCK_H                      2 #ifndef __LINUX_BIT_SPINLOCK_H
  3 #define __LINUX_BIT_SPINLOCK_H                      3 #define __LINUX_BIT_SPINLOCK_H
  4                                                     4 
  5 #include <linux/kernel.h>                           5 #include <linux/kernel.h>
  6 #include <linux/preempt.h>                          6 #include <linux/preempt.h>
  7 #include <linux/atomic.h>                           7 #include <linux/atomic.h>
  8 #include <linux/bug.h>                              8 #include <linux/bug.h>
  9                                                     9 
 10 /*                                                 10 /*
 11  *  bit-based spin_lock()                          11  *  bit-based spin_lock()
 12  *                                                 12  *
 13  * Don't use this unless you really need to: s     13  * Don't use this unless you really need to: spin_lock() and spin_unlock()
 14  * are significantly faster.                       14  * are significantly faster.
 15  */                                                15  */
 16 static inline void bit_spin_lock(int bitnum, u     16 static inline void bit_spin_lock(int bitnum, unsigned long *addr)
 17 {                                                  17 {
 18         /*                                         18         /*
 19          * Assuming the lock is uncontended, t     19          * Assuming the lock is uncontended, this never enters
 20          * the body of the outer loop. If it i     20          * the body of the outer loop. If it is contended, then
 21          * within the inner loop a non-atomic      21          * within the inner loop a non-atomic test is used to
 22          * busywait with less bus contention f     22          * busywait with less bus contention for a good time to
 23          * attempt to acquire the lock bit.        23          * attempt to acquire the lock bit.
 24          */                                        24          */
 25         preempt_disable();                         25         preempt_disable();
 26 #if defined(CONFIG_SMP) || defined(CONFIG_DEBU     26 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 27         while (unlikely(test_and_set_bit_lock(     27         while (unlikely(test_and_set_bit_lock(bitnum, addr))) {
 28                 preempt_enable();                  28                 preempt_enable();
 29                 do {                               29                 do {
 30                         cpu_relax();               30                         cpu_relax();
 31                 } while (test_bit(bitnum, addr     31                 } while (test_bit(bitnum, addr));
 32                 preempt_disable();                 32                 preempt_disable();
 33         }                                          33         }
 34 #endif                                             34 #endif
 35         __acquire(bitlock);                        35         __acquire(bitlock);
 36 }                                                  36 }
 37                                                    37 
 38 /*                                                 38 /*
 39  * Return true if it was acquired                  39  * Return true if it was acquired
 40  */                                                40  */
 41 static inline int bit_spin_trylock(int bitnum,     41 static inline int bit_spin_trylock(int bitnum, unsigned long *addr)
 42 {                                                  42 {
 43         preempt_disable();                         43         preempt_disable();
 44 #if defined(CONFIG_SMP) || defined(CONFIG_DEBU     44 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 45         if (unlikely(test_and_set_bit_lock(bit     45         if (unlikely(test_and_set_bit_lock(bitnum, addr))) {
 46                 preempt_enable();                  46                 preempt_enable();
 47                 return 0;                          47                 return 0;
 48         }                                          48         }
 49 #endif                                             49 #endif
 50         __acquire(bitlock);                        50         __acquire(bitlock);
 51         return 1;                                  51         return 1;
 52 }                                                  52 }
 53                                                    53 
 54 /*                                                 54 /*
 55  *  bit-based spin_unlock()                        55  *  bit-based spin_unlock()
 56  */                                                56  */
 57 static inline void bit_spin_unlock(int bitnum,     57 static inline void bit_spin_unlock(int bitnum, unsigned long *addr)
 58 {                                                  58 {
 59 #ifdef CONFIG_DEBUG_SPINLOCK                       59 #ifdef CONFIG_DEBUG_SPINLOCK
 60         BUG_ON(!test_bit(bitnum, addr));           60         BUG_ON(!test_bit(bitnum, addr));
 61 #endif                                             61 #endif
 62 #if defined(CONFIG_SMP) || defined(CONFIG_DEBU     62 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 63         clear_bit_unlock(bitnum, addr);            63         clear_bit_unlock(bitnum, addr);
 64 #endif                                             64 #endif
 65         preempt_enable();                          65         preempt_enable();
 66         __release(bitlock);                        66         __release(bitlock);
 67 }                                                  67 }
 68                                                    68 
 69 /*                                                 69 /*
 70  *  bit-based spin_unlock()                        70  *  bit-based spin_unlock()
 71  *  non-atomic version, which can be used eg.      71  *  non-atomic version, which can be used eg. if the bit lock itself is
 72  *  protecting the rest of the flags in the wo     72  *  protecting the rest of the flags in the word.
 73  */                                                73  */
 74 static inline void __bit_spin_unlock(int bitnu     74 static inline void __bit_spin_unlock(int bitnum, unsigned long *addr)
 75 {                                                  75 {
 76 #ifdef CONFIG_DEBUG_SPINLOCK                       76 #ifdef CONFIG_DEBUG_SPINLOCK
 77         BUG_ON(!test_bit(bitnum, addr));           77         BUG_ON(!test_bit(bitnum, addr));
 78 #endif                                             78 #endif
 79 #if defined(CONFIG_SMP) || defined(CONFIG_DEBU     79 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 80         __clear_bit_unlock(bitnum, addr);          80         __clear_bit_unlock(bitnum, addr);
 81 #endif                                             81 #endif
 82         preempt_enable();                          82         preempt_enable();
 83         __release(bitlock);                        83         __release(bitlock);
 84 }                                                  84 }
 85                                                    85 
 86 /*                                                 86 /*
 87  * Return true if the lock is held.                87  * Return true if the lock is held.
 88  */                                                88  */
 89 static inline int bit_spin_is_locked(int bitnu     89 static inline int bit_spin_is_locked(int bitnum, unsigned long *addr)
 90 {                                                  90 {
 91 #if defined(CONFIG_SMP) || defined(CONFIG_DEBU     91 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 92         return test_bit(bitnum, addr);             92         return test_bit(bitnum, addr);
 93 #elif defined CONFIG_PREEMPT_COUNT                 93 #elif defined CONFIG_PREEMPT_COUNT
 94         return preempt_count();                    94         return preempt_count();
 95 #else                                              95 #else
 96         return 1;                                  96         return 1;
 97 #endif                                             97 #endif
 98 }                                                  98 }
 99                                                    99 
100 #endif /* __LINUX_BIT_SPINLOCK_H */               100 #endif /* __LINUX_BIT_SPINLOCK_H */
101                                                   101 
102                                                   102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php