Skip to content

Commit f0c9363

Browse files
mdchitalepalmer-dabbelt
authored andcommitted
perf/riscv-sbi: Add platform specific firmware event handling
The SBI v2.0 specification pointed to by the link below reserves the event code 0xffff for platform specific firmware events. Update the driver to be able to parse and program such events. The platform specific firmware events must now be specified in the perf command as below: perf stat -e rCxxx ... where bits[63:62] = 0x3 of the event config indicate a platform specific firmware event and xxx indicate the actual event code which is passed as the event data. Signed-off-by: Mayuresh Chitale <[email protected]> Link: https://github.com/riscv-non-isa/riscv-sbi-doc/releases/download/v2.0/riscv-sbi.pdf Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 47b9533 commit f0c9363

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

arch/riscv/include/asm/sbi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct riscv_pmu_snapshot_data {
158158

159159
#define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0)
160160
#define RISCV_PMU_RAW_EVENT_IDX 0x20000
161+
#define RISCV_PLAT_FW_EVENT 0xFFFF
161162

162163
/** General pmu event codes specified in SBI PMU extension */
163164
enum sbi_pmu_hw_generic_events_t {

drivers/perf/riscv_pmu_sbi.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ asm volatile(ALTERNATIVE( \
6060
#define PERF_EVENT_FLAG_LEGACY BIT(SYSCTL_LEGACY)
6161

6262
PMU_FORMAT_ATTR(event, "config:0-47");
63-
PMU_FORMAT_ATTR(firmware, "config:63");
63+
PMU_FORMAT_ATTR(firmware, "config:62-63");
6464

6565
static bool sbi_v2_available;
6666
static DEFINE_STATIC_KEY_FALSE(sbi_pmu_snapshot_available);
@@ -507,7 +507,6 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
507507
{
508508
u32 type = event->attr.type;
509509
u64 config = event->attr.config;
510-
int bSoftware;
511510
u64 raw_config_val;
512511
int ret;
513512

@@ -528,18 +527,32 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
528527
break;
529528
case PERF_TYPE_RAW:
530529
/*
531-
* As per SBI specification, the upper 16 bits must be unused for
532-
* a raw event. Use the MSB (63b) to distinguish between hardware
533-
* raw event and firmware events.
530+
* As per SBI specification, the upper 16 bits must be unused
531+
* for a raw event.
532+
* Bits 63:62 are used to distinguish between raw events
533+
* 00 - Hardware raw event
534+
* 10 - SBI firmware events
535+
* 11 - Risc-V platform specific firmware event
534536
*/
535-
bSoftware = config >> 63;
536537
raw_config_val = config & RISCV_PMU_RAW_EVENT_MASK;
537-
if (bSoftware) {
538+
switch (config >> 62) {
539+
case 0:
540+
ret = RISCV_PMU_RAW_EVENT_IDX;
541+
*econfig = raw_config_val;
542+
break;
543+
case 2:
538544
ret = (raw_config_val & 0xFFFF) |
539545
(SBI_PMU_EVENT_TYPE_FW << 16);
540-
} else {
541-
ret = RISCV_PMU_RAW_EVENT_IDX;
546+
break;
547+
case 3:
548+
/*
549+
* For Risc-V platform specific firmware events
550+
* Event code - 0xFFFF
551+
* Event data - raw event encoding
552+
*/
553+
ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT;
542554
*econfig = raw_config_val;
555+
break;
543556
}
544557
break;
545558
default:

0 commit comments

Comments
 (0)