e310x_hal/core/
counters.rs1use riscv::register::{mcycle, mhpmcounter3, mhpmcounter4, minstret};
4
5pub struct MCYCLE;
7
8impl MCYCLE {
9 #[inline]
11 pub fn value(&self) -> u64 {
12 mcycle::read64()
13 }
14}
15
16pub struct MINSTRET;
18
19impl MINSTRET {
20 #[inline]
22 pub fn value(&self) -> u64 {
23 minstret::read64()
24 }
25}
26
27pub struct MHPMCOUNTER3;
29
30impl MHPMCOUNTER3 {
31 #[inline]
33 pub fn value(&self) -> u64 {
34 mhpmcounter3::read64()
35 }
36}
37
38pub struct MHPMCOUNTER4;
40
41impl MHPMCOUNTER4 {
42 #[inline]
44 pub fn value(&self) -> u64 {
45 mhpmcounter4::read64()
46 }
47}
48
49pub struct PerformanceCounters {
51 pub mcycle: MCYCLE,
53 pub minstret: MINSTRET,
55 pub mhpmcounter3: MHPMCOUNTER3,
57 pub mhpmcounter4: MHPMCOUNTER4,
59 }
61
62impl PerformanceCounters {
63 pub(crate) fn new() -> Self {
64 Self {
65 mcycle: MCYCLE,
66 minstret: MINSTRET,
67 mhpmcounter3: MHPMCOUNTER3,
68 mhpmcounter4: MHPMCOUNTER4,
69 }
70 }
71}