aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_pmu.c
AgeCommit message (Collapse)Author
2021-12-11lib: pmu: check SSCOF before maskingNikita Shubin
We should check if SSCOF extension is present, before applying inhibit mask and clearing overflow, otherwise undesirable value can be written in MHPMEVENT_N CSR. Signed-off-by: Nikita Shubin <n.shubin@yadro.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-12-03lib: pmu: support the event ID encoded by a bitmap.Vincent Chen
RISC-V privilege specification does not specify how to encode the event ID. Therefore, each platform is allowed to customize its own encoding rule. The common encoding methods are as follow, directly assigning a number to an event, or every bit in the mphmevent CSR controls one specified event or mixes the above two methods. To enable OpenSBI to support the above three encoding methods simultaneously, this patch repurpose the dt property "riscv,raw-event-to-mhpmcounters". The "riscv,raw-event-to-mhpmcounters" will describes the one or multiple raw events that could be counted by a set of counters. But, the column number of "riscv,raw-event-to-mhpmcounters" is extended from 2 to 3. The 1st column (64bit) is the ID of the raw events. The 2nd column (64bit) represents a select_mask now to represent the bits used for event ID encoding. If a platform directly encodes each raw PMU event as a unique ID, the value of select_mask will be 0xffffffff_ffffffff. Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Atish Patra<atishp@rivosinc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-11-30lib: sbi: Resolve the uninitialized complaint in sbi_pmuDong Du
A recent commit (b28f0700) turns to read from CSR_MCOUNTINHIBIT after checking the SBI_HART_HAS_MCOUNTINHIBIT HART feature, which leaves the mctr_inhbt uninitialized in pmu_ctr_find_hw(). As a result, compiler will complain: error: 'mctr_inhbt' may be used uninitialized in this function. This commit resolves the issue by assigning an initial value to mctr_inhbt. Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-11-11lib: sbi: Fix initial value mask while updating the countersAtish Patra
The first 32 bits of the initial value for the counter should be preserved while updating the mhpmcounter for 32bit. Fixes: 13d40f21d588e ("lib: sbi: Add PMU support") Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-11-11lib: sbi: Enable PMU extension for platforms without mcountinhibitAtish Patra
Some platforms such as hifive unmatched doesn't implement mcountinhibit csr. However, it has hardware events that can be monitored using 2 hpmcounter it has (i.e. mhpmcounter3 & mhpmcounter4). Currently, PMU extension disabled if mcountinhibit is absent. That's not really necessary as long as the supervisor OS keeps track of the delta value of the counters. Without mcountinhibit, the delta value won't be entirely accurate because the counters are freely running. However, that should be fine to produce an approximate counter value which can help performance analysis. Perf sampling won't work though as sscof extension is not present in hifive unmatched. Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-11-11lib: sbi: Counter info width should be zero indexedAtish Patra
The mhpm bits represent the number of bits available in mhpmcounter while counter width describes a zero indexed value. Fix the counter width calculation. Fixes: 13d40f21d588 ("lib: sbi: Add PMU support") Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-11-11lib: sbi: Reset the mhpmevent value upon counter resetAtish Patra
The hardware solely relies on the event selector value in mhpmevent to figure out what event to monitor using that counter. It should be reset when counter reset happens. Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-11-11lib: sbi: Allow programmable counters to monitor cycle/instret eventsAtish Patra
A platform may use programmable counters for cycle/instret events. The priv spec allows that provided that cycle/instret also report those events in addition to the programmable counters. We should allow that functionality in OpenSBI. Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-11-11lib: sbi: Always enable access for all countersAtish Patra
OpenSBI doesn't use any counters for its own usage. Thus, all the counters can be made accessible for lower privilege mode always. However, the mcountinhibit must be set so that the counter doesn't increment. As a result, we don't have to enable/disable mcounteren at every start/stop. Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-11-11lib: sbi: Support sscofpmf extension in OpenSBIAtish Patra
This patch adds sscofpmf extension in pmu module which includes following things. 1. Enable overflow irq when starting a counter. 2. Setting the correct event filters passed from supervisor. 3. Delegating the overflow interrupt to the supervisor. 4. Add RV32 support for sscofpmf. Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csrAnup Patel
The sbi_pmu_exit() crashes on systems not having MCOUNTINHIBIT csr so to fix this we check SBI_HART_HAS_MCOUNTINHIBIT feature in sbi_pmu_exit() and do nothing if it is not available. Fixes: 13d40f21d588 ("lib: sbi: Add PMU support") Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-07-11lib: sbi: Implement SBI PMU extensionAtish Patra
RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor mode to start/stop/configure pmu related events. This patch implements all of the functionality defined in the specification. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Add PMU supportAtish Patra
RISC-V SBI v0.3 specification defined a PMU extension to configure/start/stop the hardware/firmware pmu events. Implement PMU support in OpenSBI library. The implementation is agnostic of event to counter mapping & mhpmevent value configuration. That means, it expects platform hooks will be used to set up the mapping and provide the mhpmevent value at runtime. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>