1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2026 Photon Ring Contributors
// SPDX-License-Identifier: Apache-2.0
//! CPU core affinity helpers for deterministic cross-core latency.
//!
//! Pinning publisher and subscriber threads to specific CPU cores
//! eliminates OS scheduler jitter and ensures consistent cache-coherence
//! transfer times.
//!
//! ## NUMA considerations
//!
//! On multi-socket systems, pin publisher and subscriber threads to
//! cores on the **same** socket. Cross-socket communication (QPI/UPI)
//! adds ~100-200 ns of additional latency per cache-line transfer
//! compared to intra-socket L3 snoops (~40-55 ns on Intel Comet Lake).
//!
//! ## Example
//!
//! ```no_run
//! use photon_ring::affinity;
//!
//! let cores = affinity::available_cores();
//! assert!(cores.len() >= 2, "need at least 2 cores");
//!
//! // Pin to the first core
//! assert!(affinity::pin_to_core(cores[0]));
//! ```
use Vec;
pub use CoreId;
/// Pin the current thread to a specific CPU core.
///
/// Returns `true` on success, `false` if the OS rejected the request
/// (e.g., invalid core ID, insufficient permissions, or unsupported
/// platform).
///
/// # Example
///
/// ```no_run
/// use photon_ring::affinity;
///
/// let cores = affinity::available_cores();
/// assert!(affinity::pin_to_core(cores[0]), "failed to pin");
/// ```
/// Return the list of CPU cores available to this process.
///
/// The returned [`CoreId`]s can be passed directly to [`pin_to_core`].
/// The list order matches the OS core numbering (logical CPUs including
/// SMT siblings).
/// Pin the current thread to a core by its numeric index.
///
/// Convenience wrapper around [`pin_to_core`] that looks up the core by
/// index in [`available_cores`]. Returns `true` on success, `false` if
/// the index is out of range or the OS rejects the request.
///
/// # Example
///
/// ```no_run
/// use photon_ring::affinity;
///
/// assert!(affinity::pin_to_core_id(0), "failed to pin to core 0");
/// ```
/// Return the number of CPU cores available to this process.