|
9 | 9 | #include "../ds_core/ds_core.h" |
10 | 10 | #include "aal_concept.h" |
11 | 11 | #include "aal_consts.h" |
12 | | - |
13 | | -#if __has_include(<time.h>) |
14 | | -# include <time.h> |
15 | | -# ifdef CLOCK_MONOTONIC |
16 | | -# define SNMALLOC_TICK_USE_CLOCK_GETTIME |
17 | | -# endif |
18 | | -#endif |
19 | 12 | #include "snmalloc/stl/utility.h" |
20 | 13 |
|
21 | 14 | #include <stdint.h> |
22 | 15 |
|
23 | | -#ifndef SNMALLOC_TICK_USE_CLOCK_GETTIME |
24 | | -# include <chrono> |
25 | | -#endif |
26 | | - |
27 | 16 | #if ( \ |
28 | 17 | defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \ |
29 | 18 | defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ |
@@ -169,37 +158,17 @@ namespace snmalloc |
169 | 158 | /** |
170 | 159 | * Return an architecture-specific cycle counter. |
171 | 160 | * |
172 | | - * If the compiler provides a portable prefetch builtin, use it directly, |
173 | | - * otherwise delegate to the architecture-specific layer. This allows new |
174 | | - * architectures to avoid needing to implement a custom `tick` method |
175 | | - * if they are used only with a compiler that provides the builtin. |
| 161 | + * If the architecture reports that CPU cycle counters are unavailable, |
| 162 | + * use any architecture-specific implementation that exists, otherwise |
| 163 | + * fall back to zero. When counters are available, prefer a compiler |
| 164 | + * builtin and then the architecture-specific implementation. |
176 | 165 | */ |
177 | 166 | static inline uint64_t tick() noexcept |
178 | 167 | { |
179 | 168 | if constexpr ( |
180 | 169 | (Arch::aal_features & NoCpuCycleCounters) == NoCpuCycleCounters) |
181 | 170 | { |
182 | | -#ifdef SNMALLOC_TICK_USE_CLOCK_GETTIME |
183 | | - // the buf is populated by clock_gettime |
184 | | - SNMALLOC_UNINITIALISED timespec buf; |
185 | | - // we can skip the error checking here: |
186 | | - // * EFAULT: for out-of-bound pointers (buf is always valid stack |
187 | | - // memory) |
188 | | - // * EINVAL: for invalid clock_id (we only use CLOCK_MONOTONIC enforced |
189 | | - // by POSIX.1) |
190 | | - // Notice that clock_gettime is a usually a vDSO call, so the overhead |
191 | | - // is minimal. |
192 | | - ::clock_gettime(CLOCK_MONOTONIC, &buf); |
193 | | - return static_cast<uint64_t>(buf.tv_sec) * 1000'000'000 + |
194 | | - static_cast<uint64_t>(buf.tv_nsec); |
195 | | -# undef SNMALLOC_TICK_USE_CLOCK_GETTIME |
196 | | -#else |
197 | | - auto tick = std::chrono::high_resolution_clock::now(); |
198 | | - return static_cast<uint64_t>( |
199 | | - std::chrono::duration_cast<std::chrono::nanoseconds>( |
200 | | - tick.time_since_epoch()) |
201 | | - .count()); |
202 | | -#endif |
| 171 | + return 0; |
203 | 172 | } |
204 | 173 | else |
205 | 174 | { |
|
0 commit comments