ccp_msr/linux_x86_64/
errors.rs1use nix::errno::Errno;
18use thiserror::Error as ThisError;
19
20use ccp_shared::types::LogicalCoreId;
21
22#[derive(ThisError, Debug)]
23pub enum MSRError {
24 #[error("opening MSR file '/dev/cpu/{core_id:}/msr' for read there is an error: {io_error:?}")]
25 OpenForRead {
26 core_id: LogicalCoreId,
27 io_error: std::io::Error,
28 },
29
30 #[error(
31 "opening MSR file '/dev/cpu/{core_id:}/msr' for write there is an error: {io_error:?}"
32 )]
33 OpenForWrite {
34 core_id: LogicalCoreId,
35 io_error: std::io::Error,
36 },
37
38 #[error(
39 "reading from register_id {register_id:} and MSR file '/dev/cpu/{core_id:}/msr' there is an error: {errno:?}"
40 )]
41 ReadWNoErr {
42 register_id: u32,
43 core_id: LogicalCoreId,
44 errno: Errno,
45 },
46
47 #[error(
48 "writing value {value:} for register_id {register_id:} into MSR file '/dev/cpu/{core_id:}/msr' there is an error: {errno:?}"j
49 )]
50 WriteWNoErr {
51 value: u64,
52 register_id: u32,
53 core_id: LogicalCoreId,
54 errno: Errno,
55 },
56}
57
58impl MSRError {
59 pub(crate) fn open_for_read(core_id: LogicalCoreId, io_error: std::io::Error) -> Self {
60 Self::OpenForRead { core_id, io_error }
61 }
62
63 pub(crate) fn open_for_write(core_id: LogicalCoreId, io_error: std::io::Error) -> Self {
64 Self::OpenForWrite { core_id, io_error }
65 }
66
67 pub(crate) fn read_w_no_err(register_id: u32, core_id: LogicalCoreId, errno: Errno) -> Self {
68 Self::ReadWNoErr {
69 register_id,
70 core_id,
71 errno,
72 }
73 }
74
75 pub(crate) fn write_w_no_err(
76 value: u64,
77 register_id: u32,
78 core_id: LogicalCoreId,
79 errno: Errno,
80 ) -> Self {
81 Self::WriteWNoErr {
82 value,
83 register_id,
84 core_id,
85 errno,
86 }
87 }
88}