eal: simplify meson build of common directory
[dpdk.git] / lib / librte_eal / common / include / generic / rte_pause.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  * Copyright(c) 2019 Arm Limited
4  */
5
6 #ifndef _RTE_PAUSE_H_
7 #define _RTE_PAUSE_H_
8
9 /**
10  * @file
11  *
12  * CPU pause operation.
13  *
14  */
15
16 #include <stdint.h>
17 #include <assert.h>
18 #include <rte_common.h>
19 #include <rte_atomic.h>
20 #include <rte_compat.h>
21
22 /**
23  * Pause CPU execution for a short while
24  *
25  * This call is intended for tight loops which poll a shared resource or wait
26  * for an event. A short pause within the loop may reduce the power consumption.
27  */
28 static inline void rte_pause(void);
29
30 /**
31  * @warning
32  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
33  *
34  * Wait for *addr to be updated with a 16-bit expected value, with a relaxed
35  * memory ordering model meaning the loads around this API can be reordered.
36  *
37  * @param addr
38  *  A pointer to the memory location.
39  * @param expected
40  *  A 16-bit expected value to be in the memory location.
41  * @param memorder
42  *  Two different memory orders that can be specified:
43  *  __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to
44  *  C++11 memory orders with the same names, see the C++11 standard or
45  *  the GCC wiki on atomic synchronization for detailed definition.
46  */
47 __rte_experimental
48 static __rte_always_inline void
49 rte_wait_until_equal_16(volatile uint16_t *addr, uint16_t expected,
50                 int memorder);
51
52 /**
53  * @warning
54  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
55  *
56  * Wait for *addr to be updated with a 32-bit expected value, with a relaxed
57  * memory ordering model meaning the loads around this API can be reordered.
58  *
59  * @param addr
60  *  A pointer to the memory location.
61  * @param expected
62  *  A 32-bit expected value to be in the memory location.
63  * @param memorder
64  *  Two different memory orders that can be specified:
65  *  __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to
66  *  C++11 memory orders with the same names, see the C++11 standard or
67  *  the GCC wiki on atomic synchronization for detailed definition.
68  */
69 __rte_experimental
70 static __rte_always_inline void
71 rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected,
72                 int memorder);
73
74 /**
75  * @warning
76  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
77  *
78  * Wait for *addr to be updated with a 64-bit expected value, with a relaxed
79  * memory ordering model meaning the loads around this API can be reordered.
80  *
81  * @param addr
82  *  A pointer to the memory location.
83  * @param expected
84  *  A 64-bit expected value to be in the memory location.
85  * @param memorder
86  *  Two different memory orders that can be specified:
87  *  __ATOMIC_ACQUIRE and __ATOMIC_RELAXED. These map to
88  *  C++11 memory orders with the same names, see the C++11 standard or
89  *  the GCC wiki on atomic synchronization for detailed definition.
90  */
91 __rte_experimental
92 static __rte_always_inline void
93 rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
94                 int memorder);
95
96 #ifndef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
97 static __rte_always_inline void
98 rte_wait_until_equal_16(volatile uint16_t *addr, uint16_t expected,
99                 int memorder)
100 {
101         assert(memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED);
102
103         while (__atomic_load_n(addr, memorder) != expected)
104                 rte_pause();
105 }
106
107 static __rte_always_inline void
108 rte_wait_until_equal_32(volatile uint32_t *addr, uint32_t expected,
109                 int memorder)
110 {
111         assert(memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED);
112
113         while (__atomic_load_n(addr, memorder) != expected)
114                 rte_pause();
115 }
116
117 static __rte_always_inline void
118 rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected,
119                 int memorder)
120 {
121         assert(memorder == __ATOMIC_ACQUIRE || memorder == __ATOMIC_RELAXED);
122
123         while (__atomic_load_n(addr, memorder) != expected)
124                 rte_pause();
125 }
126 #endif
127
128 #endif /* _RTE_PAUSE_H_ */