libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
os_cpu.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * Use of this source code is governed by the ISC License.
4 *
5 * src/inc/os_cpu.h
6 * CPU + NUMA topology surface.
7 */
8
9#ifndef XTC_OS_CPU_H
10#define XTC_OS_CPU_H
11
12/*
13 * PUBLIC: int __os_ncpus __P((void));
14 * PUBLIC: int __os_ncpus_perf __P((void));
15 * PUBLIC: int __os_ncpus_effic __P((void));
16 * PUBLIC: int __os_numa_nnodes __P((void));
17 * PUBLIC: int __os_numa_node_of_cpu __P((int));
18 * PUBLIC: int __os_numa_current_node __P((void));
19 */
20int __os_ncpus(void);
21int __os_ncpus_perf(void);
22int __os_ncpus_effic(void);
23int __os_numa_nnodes(void);
24int __os_numa_node_of_cpu(int cpu);
25int __os_numa_current_node(void);
26
27/*
28 * Spin-loop relaxation hint: tells the CPU we are in a busy-wait so it
29 * can save power and yield pipeline/SMT resources to the lock holder
30 * (x86 PAUSE, ARM YIELD). A no-op where unavailable. Header-only and
31 * always inlined -- it must be zero-cost in a tight CAS retry loop.
32 */
33static inline void
34__os_cpu_relax(void)
35{
36#if defined(__GNUC__) || defined(__clang__)
37# if defined(__i386__) || defined(__x86_64__)
38 __asm__ __volatile__("pause" ::: "memory");
39# elif defined(__aarch64__) || defined(__arm__)
40 __asm__ __volatile__("yield" ::: "memory");
41# else
42 __asm__ __volatile__("" ::: "memory"); /* compiler barrier only */
43# endif
44#else
45 /* MSVC / unknown compiler: no portable hint without <intrin.h>. */
46#endif
47}
48
49#endif /* XTC_OS_CPU_H */