numaperf_core/mode.rs
1//! Hard mode configuration.
2
3/// Controls whether numaperf enforces strict NUMA policies or falls back gracefully.
4///
5/// # Soft Mode (default)
6///
7/// In soft mode, numaperf does its best to honor NUMA policies but will
8/// degrade gracefully when kernel features or privileges are unavailable.
9/// Operations succeed with reduced guarantees, and the actual enforcement
10/// level is reported to the caller.
11///
12/// # Strict Mode
13///
14/// In strict mode, numaperf requires that all requested policies can be
15/// fully enforced. If a policy cannot be guaranteed (due to missing
16/// privileges, kernel features, or hardware), the operation fails with
17/// a structured error.
18///
19/// Strict mode is useful for:
20/// - Production systems where NUMA locality is critical
21/// - Benchmarking with guaranteed placement
22/// - Detecting configuration issues early
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
24pub enum HardMode {
25 /// Best-effort enforcement with graceful degradation.
26 #[default]
27 Soft,
28
29 /// Strict enforcement; fail if policy cannot be guaranteed.
30 Strict,
31}
32
33impl HardMode {
34 /// Check if this is soft mode.
35 #[inline]
36 pub fn is_soft(self) -> bool {
37 matches!(self, Self::Soft)
38 }
39
40 /// Check if this is strict mode.
41 #[inline]
42 pub fn is_strict(self) -> bool {
43 matches!(self, Self::Strict)
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_hard_mode_default() {
53 assert_eq!(HardMode::default(), HardMode::Soft);
54 }
55
56 #[test]
57 fn test_hard_mode_checks() {
58 assert!(HardMode::Soft.is_soft());
59 assert!(!HardMode::Soft.is_strict());
60 assert!(!HardMode::Strict.is_soft());
61 assert!(HardMode::Strict.is_strict());
62 }
63}