Function pmu_x86::init

source ·
pub fn init() -> Result<(), &'static str>
Expand description

Initialization function that enables the PMU if one is available. We initialize the 3 fixed PMCs and general purpose PMCs. Calling this initialization function again on a core that has already been initialized will do nothing.

Currently we support a maximum core ID of 255, and up to 8 general purpose counters per core. A core ID greater than 255 is not supported in Theseus in general since the ID has to fit within a u8.

If the core ID limit is changed and we need to update the PMU data structures to support more cores then:

  • Increase WORDS_IN_BITMAP and CORES_SUPPORTED_BY_PMU as required. For example, the cores supported is 256 so there are 4 64-bit words in the bitmap, one bit per core.
  • Add additional AtomicU64 variables to the initialization of the CORES_SAMPLING and RESULTS_READY bitmaps.

If the general purpose PMC limit is reached then:

  • Update PMCS_SUPPORTED_BY_PMU to the new PMC limit.
  • Change the element type in the PMCS_AVAILABLE vector to be larger than AtomicU8 so that there is one bit per counter.
  • Update INIT_PMCS_AVAILABLE to the new maximum value for the per core bitmap.

Warning

This function should only be called after all the cores have been booted up.