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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /* Misc low level processor primitives */
  3 #ifndef _LINUX_PROCESSOR_H
  4 #define _LINUX_PROCESSOR_H
  5 
  6 #include <asm/processor.h>
  7 
  8 /*
  9  * spin_begin is used before beginning a busy-wait loop, and must be paired
 10  * with spin_end when the loop is exited. spin_cpu_relax must be called
 11  * within the loop.
 12  *
 13  * The loop body should be as small and fast as possible, on the order of
 14  * tens of instructions/cycles as a guide. It should and avoid calling
 15  * cpu_relax, or any "spin" or sleep type of primitive including nested uses
 16  * of these primitives. It should not lock or take any other resource.
 17  * Violations of these guidelies will not cause a bug, but may cause sub
 18  * optimal performance.
 19  *
 20  * These loops are optimized to be used where wait times are expected to be
 21  * less than the cost of a context switch (and associated overhead).
 22  *
 23  * Detection of resource owner and decision to spin or sleep or guest-yield
 24  * (e.g., spin lock holder vcpu preempted, or mutex owner not on CPU) can be
 25  * tested within the loop body.
 26  */
 27 #ifndef spin_begin
 28 #define spin_begin()
 29 #endif
 30 
 31 #ifndef spin_cpu_relax
 32 #define spin_cpu_relax() cpu_relax()
 33 #endif
 34 
 35 #ifndef spin_end
 36 #define spin_end()
 37 #endif
 38 
 39 /*
 40  * spin_until_cond can be used to wait for a condition to become true. It
 41  * may be expected that the first iteration will true in the common case
 42  * (no spinning), so that callers should not require a first "likely" test
 43  * for the uncontended case before using this primitive.
 44  *
 45  * Usage and implementation guidelines are the same as for the spin_begin
 46  * primitives, above.
 47  */
 48 #ifndef spin_until_cond
 49 #define spin_until_cond(cond)                                   \
 50 do {                                                            \
 51         if (unlikely(!(cond))) {                                \
 52                 spin_begin();                                   \
 53                 do {                                            \
 54                         spin_cpu_relax();                       \
 55                 } while (!(cond));                              \
 56                 spin_end();                                     \
 57         }                                                       \
 58 } while (0)
 59 
 60 #endif
 61 
 62 #endif /* _LINUX_PROCESSOR_H */
 63 

~ [ 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