pmu.rs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //! Chapter 11. Performance Monitoring Unit Extension (EID #0x504D55 "PMU").
  2. /// Extension ID for Performance Monitoring Unit extension.
  3. #[doc(alias = "SBI_EXT_PMU")]
  4. pub const EID_PMU: usize = crate::eid_from_str("PMU") as _;
  5. pub use fid::*;
  6. /// Declared in §11.11.
  7. mod fid {
  8. /// Function ID to get the number of counters, both hardware and firmware.
  9. ///
  10. /// Declared in §11.6.
  11. #[doc(alias = "SBI_EXT_PMU_NUM_COUNTERS")]
  12. pub const NUM_COUNTERS: usize = 0;
  13. /// Function ID to get details about the specified counter.
  14. ///
  15. /// Declared in §11.7.
  16. #[doc(alias = "SBI_EXT_PMU_COUNTER_GET_INFO")]
  17. pub const COUNTER_GET_INFO: usize = 1;
  18. /// Function ID to find and configure a counter from a set of counters.
  19. ///
  20. /// Declared in §11.8.
  21. #[doc(alias = "SBI_EXT_PMU_COUNTER_CFG_MATCH")]
  22. pub const COUNTER_CONFIG_MATCHING: usize = 2;
  23. /// Function ID to start or enable a set of counters on the calling hart with the specified initial value.
  24. ///
  25. /// Declared in §11.9.
  26. #[doc(alias = "SBI_EXT_PMU_COUNTER_START")]
  27. pub const COUNTER_START: usize = 3;
  28. /// Function ID to stop or disable a set of counters on the calling hart.
  29. ///
  30. /// Declared in §11.10.
  31. #[doc(alias = "SBI_EXT_PMU_COUNTER_STOP")]
  32. pub const COUNTER_STOP: usize = 4;
  33. /// Function ID to provide the current value of a firmware counter.
  34. ///
  35. /// Declared in §11.11.
  36. #[doc(alias = "SBI_EXT_PMU_COUNTER_FW_READ")]
  37. pub const COUNTER_FW_READ: usize = 5;
  38. /// Function ID to provide the upper 32 bits from the value of the current firmware counter.
  39. ///
  40. /// Declared in §11.12.
  41. #[doc(alias = "SBI_EXT_PMU_COUNTER_FW_READ_HI")]
  42. pub const COUNTER_FW_READ_HI: usize = 6;
  43. /// Function ID to set and enable the PMU snapshot shared memory.
  44. ///
  45. /// Declared in §11.13.
  46. #[doc(alias = "SBI_EXT_PMU_SNAPSHOT_SET_SHMEM")]
  47. pub const SNAPSHOT_SET_SHMEM: usize = 7;
  48. /// Function ID to get details about any PMU event via shared memory.
  49. ///
  50. /// Declared in §11.14.
  51. #[doc(alias = "SBI_EXT_PMU_EVENT_GET_INFO")]
  52. pub const EVENT_GET_INFO: usize = 8;
  53. }
  54. /// PMU Event Types.
  55. ///
  56. /// Declared in §11.
  57. pub mod event_type {
  58. /// Type for all hardware general events.
  59. ///
  60. /// Declared in §11.1.
  61. pub const HARDWARE_GENERAL: usize = 0;
  62. /// Type for all hardware cache events.
  63. ///
  64. /// Declared in §11.2.
  65. pub const HARDWARE_CACHE: usize = 1;
  66. /// Type for all hardware raw events.
  67. ///
  68. /// Declared in §11.3.
  69. pub const HARDWARE_RAW: usize = 2;
  70. /// Type for all hardware raw events v2.
  71. ///
  72. /// Declared in §11.4.
  73. pub const HARDWARE_RAW_V2: usize = 3;
  74. /// Type for all firmware events.
  75. ///
  76. /// Declared in §11.5.
  77. pub const FIRMWARE: usize = 15;
  78. }
  79. /// Hardware General Event Codes.
  80. ///
  81. /// Declared in §11.1.
  82. pub mod hardware_event {
  83. /// Unused event because event_idx cannot be zero.
  84. pub const NO_EVENT: usize = 0;
  85. /// Event for each CPU cycle.
  86. pub const CPU_CYCLES: usize = 1;
  87. /// Event for each completed instruction.
  88. pub const INSTRUCTIONS: usize = 2;
  89. /// Event for cache hit.
  90. pub const CACHE_REFERENCES: usize = 3;
  91. /// Event for cache miss.
  92. pub const CACHE_MISSES: usize = 4;
  93. /// Event for a branch instruction.
  94. pub const BRANCH_INSTRUCTIONS: usize = 5;
  95. /// Event for a branch misprediction.
  96. pub const BRANCH_MISSES: usize = 6;
  97. /// Event for each BUS cycle.
  98. pub const BUS_CYCLES: usize = 7;
  99. /// Event for a stalled cycle in micro-architecture frontend.
  100. pub const STALLED_CYCLES_FRONTEND: usize = 8;
  101. /// Event for a stalled cycle in micro-architecture backend.
  102. pub const STALLED_CYCLES_BACKEND: usize = 9;
  103. /// Event for each reference CPU cycle.
  104. pub const REF_CPU_CYCLES: usize = 10;
  105. }
  106. /// Hardware Cache Event ID.
  107. ///
  108. /// Declared in §11.2.
  109. pub mod cache_event {
  110. /// Level 1 data cache event.
  111. pub const L1D: usize = 0;
  112. /// Level 1 instruction cache event.
  113. pub const L1I: usize = 1;
  114. /// Last level cache event.
  115. pub const LL: usize = 2;
  116. /// Data TLB event.
  117. pub const DTLB: usize = 3;
  118. /// Instruction TLB event.
  119. pub const ITLB: usize = 4;
  120. /// Branch predictor unit event.
  121. pub const BPU: usize = 5;
  122. /// NUMA node cache event.
  123. pub const NODE: usize = 6;
  124. }
  125. /// Hardware Cache Operation ID.
  126. ///
  127. /// Declared in §11.2.
  128. pub mod cache_operation {
  129. /// Read cache line.
  130. pub const READ: usize = 0;
  131. /// Write cache line.
  132. pub const WRITE: usize = 1;
  133. /// Prefetch cache line.
  134. pub const PREFETCH: usize = 2;
  135. }
  136. /// Hardware Cache Operation Result ID.
  137. ///
  138. /// Declared in §11.2.
  139. pub mod cache_result {
  140. /// Cache access.
  141. pub const ACCESS: usize = 0;
  142. /// Cache miss.
  143. pub const MISS: usize = 1;
  144. }
  145. /// Firmware Event Codes.
  146. ///
  147. /// Declared in §11.5.
  148. pub mod firmware_event {
  149. /// Misaligned load trap event.
  150. pub const MISALIGNED_LOAD: usize = 0;
  151. /// Misaligned store trap event.
  152. pub const MISALIGNED_STORE: usize = 1;
  153. /// Load access trap event.
  154. pub const ACCESS_LOAD: usize = 2;
  155. /// Store access trap event.
  156. pub const ACCESS_STORE: usize = 3;
  157. /// Illegal instruction trap event.
  158. pub const ILLEGAL_INSN: usize = 4;
  159. /// Set timer event.
  160. pub const SET_TIMER: usize = 5;
  161. /// Sent IPI to other HART event.
  162. pub const IPI_SENT: usize = 6;
  163. /// Received IPI from other HART event.
  164. pub const IPI_RECEIVED: usize = 7;
  165. /// Sent FENCE.I request to other HART event.
  166. pub const FENCE_I_SENT: usize = 8;
  167. /// Received FENCE.I request from other HART event.
  168. pub const FENCE_I_RECEIVED: usize = 9;
  169. /// Sent SFENCE.VMA request to other HART event.
  170. pub const SFENCE_VMA_SENT: usize = 10;
  171. /// Received SFENCE.VMA request from other HART event.
  172. pub const SFENCE_VMA_RECEIVED: usize = 11;
  173. /// Sent SFENCE.VMA with ASID request to other HART event.
  174. pub const SFENCE_VMA_ASID_SENT: usize = 12;
  175. /// Received SFENCE.VMA with ASID request from other HART event.
  176. pub const SFENCE_VMA_ASID_RECEIVED: usize = 13;
  177. /// Sent HFENCE.GVMA request to other HART event.
  178. pub const HFENCE_GVMA_SENT: usize = 14;
  179. /// Received HFENCE.GVMA request from other HART event.
  180. pub const HFENCE_GVMA_RECEIVED: usize = 15;
  181. /// Sent HFENCE.GVMA with VMID request to other HART event.
  182. pub const HFENCE_GVMA_VMID_SENT: usize = 16;
  183. /// Received HFENCE.GVMA with VMID request from other HART event.
  184. pub const HFENCE_GVMA_VMID_RECEIVED: usize = 17;
  185. /// Sent HFENCE.VVMA request to other HART event.
  186. pub const HFENCE_VVMA_SENT: usize = 18;
  187. /// Received HFENCE.VVMA request from other HART event.
  188. pub const HFENCE_VVMA_RECEIVED: usize = 19;
  189. /// Sent HFENCE.VVMA with ASID request to other HART event.
  190. pub const HFENCE_VVMA_ASID_SENT: usize = 20;
  191. /// Received HFENCE.VVMA with ASID request from other HART event.
  192. pub const HFENCE_VVMA_ASID_RECEIVED: usize = 21;
  193. /// RISC-V platform specific firmware events.
  194. ///
  195. /// The `event_data` configuration (or parameter) contains the event encoding.
  196. pub const PLATFORM: usize = 65535;
  197. }
  198. /// Size of shared memory on PMU extension set by supervisor software for current hart.
  199. pub mod shmem_size {
  200. /// Size of PMU snapshot shared memory.
  201. ///
  202. /// PMU snapshot memory size must be 4096 size on all architecture XLEN configurations.
  203. pub const SIZE: usize = 4096;
  204. }
  205. /// Find and configure a matching counter.
  206. /// Start a set of counters.
  207. /// Stop a set of counters.
  208. ///
  209. /// Declared in §11.8, §11.9 and §11.10.
  210. pub mod flags {
  211. use bitflags::bitflags;
  212. bitflags! {
  213. #[derive(Clone, Copy, PartialEq, Eq)]
  214. /// Declared in Table 37.
  215. pub struct CounterCfgFlags: usize {
  216. /// Skip the counter matching.
  217. const SKIP_MATCH = 1 << 0;
  218. /// Clear (or zero) the counter value in counter configuration.
  219. const CLEAR_VALUE = 1 << 1;
  220. /// Start the counter after configuring a matching counter.
  221. const AUTO_START = 1 << 2;
  222. /// Event counting inhibited in VU-mode.
  223. const SET_VUINH = 1 << 3;
  224. /// Event counting inhibited in VS-mode.
  225. const SET_VSINH = 1 << 4;
  226. /// Event counting inhibited in U-mode.
  227. const SET_UINH = 1 << 5;
  228. /// Event counting inhibited in S-mode.
  229. const SET_SINH = 1 << 6;
  230. /// Event counting inhibited in M-mode.
  231. const SET_MINH = 1 << 7;
  232. }
  233. }
  234. bitflags! {
  235. #[derive(Clone, Copy, PartialEq, Eq)]
  236. /// Declared in Table 39.
  237. pub struct CounterStartFlags: usize {
  238. /// Set the value of counters based on the initial_value parameter.
  239. const INIT_VALUE = 1 << 0;
  240. /// Initialize the given counters from shared memory if available.
  241. const INIT_SNAPSHOT = 1 << 1;
  242. }
  243. }
  244. bitflags! {
  245. #[derive(Clone, Copy, PartialEq, Eq)]
  246. /// Declared in Table 41.
  247. pub struct CounterStopFlags: usize {
  248. /// Reset the counter to event mapping.
  249. const RESET = 1 << 0;
  250. /// Save a snapshot of the given counter’s values in the shared memory if available.
  251. const TAKE_SNAPSHOT = 1 << 1;
  252. }
  253. }
  254. }