#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum EventSupport {
Supported,
Unsupported,
ImplementationDefined,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct PmuInfo {
pub version: u8,
pub num_counters: usize,
pub has_instruction_counter: bool,
pub counter_width: u8,
pub cycle_counter_width: u8,
pub pmceid0: u64,
pub pmceid1: u64,
}
impl PmuInfo {
pub const fn has_long_counters(self) -> bool {
self.version >= 6
}
pub const fn event_support(self, event: u16) -> EventSupport {
let (bitmap, bit) = match event {
0x0000..=0x001f => (self.pmceid0, event),
0x0020..=0x003f => (self.pmceid1, event - 0x20),
0x4000..=0x401f => (self.pmceid0, event - 0x4000 + 32),
0x4020..=0x403f => (self.pmceid1, event - 0x4020 + 32),
_ => return EventSupport::ImplementationDefined,
};
if bitmap & (1u64 << bit) != 0 {
EventSupport::Supported
} else {
EventSupport::Unsupported
}
}
}