1use thiserror::Error as ThisError;
18
19use crate::LogicalCoreId;
20use crate::PhysicalCoreId;
21
22#[derive(Debug, ThisError)]
23pub enum CPUTopologyError {
24 #[error(transparent)]
25 RawHwlocError(#[from] hwlocality::errors::RawHwlocError),
26
27 #[error(transparent)]
28 TypeToDepthError(#[from] hwlocality::object::depth::TypeToDepthError),
29
30 #[error(transparent)]
31 CPUBindingError(#[from] hwlocality::cpu::binding::CpuBindingError),
32
33 #[error("topology allocation failed, probably not enough free memory")]
34 TopologyAllocationFailed,
35
36 #[error("physical core id {core_id} is too big to be represented as a signed int")]
37 LogicalCoreIdTooBig { core_id: LogicalCoreId },
38
39 #[error("physical cores not found")]
40 PhysicalCoresNotFound,
41
42 #[error("physical core with {core_id} id not found")]
43 PhysicalCoreNotFound { core_id: PhysicalCoreId },
44
45 #[error("logical cores for physical core with {core_id} id not found")]
46 LogicalCoresNotFound { core_id: PhysicalCoreId },
47
48 #[error("cpuset for a physical core with {core_id} not found")]
49 CPUSetNotFound { core_id: PhysicalCoreId },
50}
51
52impl CPUTopologyError {
53 pub fn physical_core_not_found(core_id: PhysicalCoreId) -> Self {
54 Self::PhysicalCoreNotFound { core_id }
55 }
56
57 pub fn logical_cores_not_found(core_id: PhysicalCoreId) -> Self {
58 Self::PhysicalCoreNotFound { core_id }
59 }
60
61 pub fn cpuset_not_found(core_id: PhysicalCoreId) -> Self {
62 Self::CPUSetNotFound { core_id }
63 }
64
65 pub fn logical_core_too_big(core_id: LogicalCoreId) -> Self {
66 Self::LogicalCoreIdTooBig { core_id }
67 }
68}