![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* Misc low level processor primitives */ 0003 #ifndef _LINUX_PROCESSOR_H 0004 #define _LINUX_PROCESSOR_H 0005 0006 #include <asm/processor.h> 0007 0008 /* 0009 * spin_begin is used before beginning a busy-wait loop, and must be paired 0010 * with spin_end when the loop is exited. spin_cpu_relax must be called 0011 * within the loop. 0012 * 0013 * The loop body should be as small and fast as possible, on the order of 0014 * tens of instructions/cycles as a guide. It should and avoid calling 0015 * cpu_relax, or any "spin" or sleep type of primitive including nested uses 0016 * of these primitives. It should not lock or take any other resource. 0017 * Violations of these guidelies will not cause a bug, but may cause sub 0018 * optimal performance. 0019 * 0020 * These loops are optimized to be used where wait times are expected to be 0021 * less than the cost of a context switch (and associated overhead). 0022 * 0023 * Detection of resource owner and decision to spin or sleep or guest-yield 0024 * (e.g., spin lock holder vcpu preempted, or mutex owner not on CPU) can be 0025 * tested within the loop body. 0026 */ 0027 #ifndef spin_begin 0028 #define spin_begin() 0029 #endif 0030 0031 #ifndef spin_cpu_relax 0032 #define spin_cpu_relax() cpu_relax() 0033 #endif 0034 0035 #ifndef spin_end 0036 #define spin_end() 0037 #endif 0038 0039 /* 0040 * spin_until_cond can be used to wait for a condition to become true. It 0041 * may be expected that the first iteration will true in the common case 0042 * (no spinning), so that callers should not require a first "likely" test 0043 * for the uncontended case before using this primitive. 0044 * 0045 * Usage and implementation guidelines are the same as for the spin_begin 0046 * primitives, above. 0047 */ 0048 #ifndef spin_until_cond 0049 #define spin_until_cond(cond) \ 0050 do { \ 0051 if (unlikely(!(cond))) { \ 0052 spin_begin(); \ 0053 do { \ 0054 spin_cpu_relax(); \ 0055 } while (!(cond)); \ 0056 spin_end(); \ 0057 } \ 0058 } while (0) 0059 0060 #endif 0061 0062 #endif /* _LINUX_PROCESSOR_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |