pub fn pmu_counter_config_matching<T>(
    counter_idx_base: usize,
    counter_idx_mask: usize,
    config_flags: T,
    event_idx: usize,
    event_data: u64
) -> SbiRet
where T: ConfigFlags,
Expand description

Find and configure a counter from a set of counters.

The counters to be found and configured should not be started (or enabled) and should be able to monitor the specified event.

§Parameters

The counter_idx_base and counter_idx_mask parameters represent the set of counters, whereas the event_idx represent the event to be monitored and event_data represents any additional event configuration.

The config_flags parameter represents additional configuration and filter flags of the counter. The bit definitions of the config_flags parameter are shown in the table below:

Flag NameBitsDescription
SBI_PMU_CFG_FLAG_SKIP_MATCH0:0Skip the counter matching
SBI_PMU_CFG_FLAG_CLEAR_VALUE1:1Clear (or zero) the counter value in counter configuration
SBI_PMU_CFG_FLAG_AUTO_START2:2Start the counter after configuring a matching counter
SBI_PMU_CFG_FLAG_SET_VUINH3:3Event counting inhibited in VU-mode
SBI_PMU_CFG_FLAG_SET_VSINH4:4Event counting inhibited in VS-mode
SBI_PMU_CFG_FLAG_SET_UINH5:5Event counting inhibited in U-mode
SBI_PMU_CFG_FLAG_SET_SINH6:6Event counting inhibited in S-mode
SBI_PMU_CFG_FLAG_SET_MINH7:7Event counting inhibited in M-mode
RESERVED8:(XLEN-1)All non-zero values are reserved for future use.

NOTE: When SBI_PMU_CFG_FLAG_SKIP_MATCH is set in config_flags, the SBI implementation will unconditionally select the first counter from the set of counters specified by the counter_idx_base and counter_idx_mask.

NOTE: The SBI_PMU_CFG_FLAG_AUTO_START flag in config_flags has no impact on the value of the counter.

NOTE: The config_flags[3:7] bits are event filtering hints so these can be ignored or overridden by the SBI implementation for security concerns or due to lack of event filtering support in the underlying RISC-V platform.

§Return value

Returns the counter_idx in sbiret.value upon success.

In case of failure, the possible error codes returned in sbiret.error are shown in the table below:

Return codeDescription
SbiRet::success()counter found and configured successfully.
SbiRet::invalid_param()set of counters has an invalid counter.
SbiRet::not_supported()none of the counters can monitor specified event.

This function is defined in RISC-V SBI Specification chapter 11.7.