riscv: add support for SBI Supervisor Software Events
Subsystems (3)
cover riscv: add support for SBI Supervisor Software Events
The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].
Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the kernel at any time.
First patch adds the SSE definitions. Second one adds support for SSE itself. Implementation is split between arch specific code and generic part (similarly to what is done for ARM SDEI). Finally, the last patch add support fro SSE event in the SBI PMU driver. If the SSE event is available from the SBI then, it will be used instead of the normal interrupt.
Amongst the specific points that needs to be handle is the interruption at any point of the kernel execution and more specifically during exception handling. Due to the fact that the exception entry implementation uses the SCRATCH CSR as both the current task struct and as the temporary register to switch the stack and save register, it is difficult to reliably get the current task struct if we get interrupted at this specific moment. A fixup-like mechanism allows to mark the location of the current task struct depending on the entry level (user/kernel) and the location. This is then used in the SSE assembly to determine where is located the current task_struct.
Contrary to pseudo NMI [2], SSE does not modifies the way interrupts are handled and does not adds any overhead to existing code. Moreover, it provides "true" NMI-like interrupts which can interrupt the kernel at any time (even in exception handling). This is particularly crucial for RAS errors which needs to be handled as fast as possible to avoid any fault propagation. Additionally, SSE event handling is faster that the standard IRQ handling path with almost half executed instruction (700 vs 1590). Some complementary tests/perf measurements will be done.
For testing purpose, one can use the provided SBI implementation at [3]. This series also needs patch [4] to fix a bug in the PMU driver.
---
Clément Léger (3):
riscv: add SBI SSE extension definitions
riscv: add support for SBI Supervisor Software Events extension
perf: RISC-V: add support for SSE event
arch/riscv/include/asm/asm-prototypes.h | 5 + arch/riscv/include/asm/sbi.h | 40 ++ arch/riscv/include/asm/sse.h | 94 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 17 + arch/riscv/kernel/entry.S | 156 ++++++++ arch/riscv/kernel/sbi.c | 4 + arch/riscv/kernel/sse.c | 97 +++++ arch/riscv/kernel/stacktrace.c | 13 + arch/riscv/kernel/vmlinux.lds.S | 6 + drivers/firmware/Kconfig | 10 + drivers/firmware/Makefile | 1 + drivers/firmware/riscv_sse.c | 496 ++++++++++++++++++++++++ drivers/perf/riscv_pmu_sbi.c | 51 ++- include/linux/riscv_sse.h | 56 +++ 15 files changed, 1038 insertions(+), 9 deletions(-) create mode 100644 arch/riscv/include/asm/sse.h create mode 100644 arch/riscv/kernel/sse.c create mode 100644 drivers/firmware/riscv_sse.c create mode 100644 include/linux/riscv_sse.h
Signature · 1 line
2.42.0
RFC PATCH 1/3 riscv: add SBI SSE extension definitions
Add needed definitions for SBI Supervisor Software Events extension [1]. This extension enables the SBI to inject events into supervisor software much like ARM SDEI.
[1] https://lists.riscv.org/g/tech-prs/message/515
--- arch/riscv/include/asm/sbi.h | 38 ++++++++++++++++++++++++++++++++++++ arch/riscv/kernel/sbi.c | 4 ++++ 2 files changed, 42 insertions(+)
arch/riscv/include/asm/sbi.h +38 -0
@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , +SBI_EXT_SSE =0x535345 ,/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -236,6 +237,40 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +enum sbi_ext_sse_fid { +SBI_SSE_EVENT_ATTR_GET =0 , +SBI_SSE_EVENT_ATTR_SET , +SBI_SSE_EVENT_REGISTER , +SBI_SSE_EVENT_UNREGISTER , +SBI_SSE_EVENT_ENABLE , +SBI_SSE_EVENT_DISABLE , +SBI_SSE_EVENT_COMPLETE , +SBI_SSE_EVENT_SIGNAL , +}; + +#define SBI_SSE_EVENT_LOCAL_RAS 0x00000000 +#define SBI_SSE_EVENT_GLOBAL_RAS 0x00008000 +#define SBI_SSE_EVENT_LOCAL_ASYNC_PF 0x00010000 +#define SBI_SSE_EVENT_LOCAL_PMU 0x00010001 +#define SBI_SSE_EVENT_LOCAL_DEBUG 0xffff3fff +#define SBI_SSE_EVENT_GLOBAL_DEBUG 0xffffbfff + +#define SBI_SSE_EVENT_GLOBAL (1 << 15) +#define SBI_SSE_EVENT_PLATFORM (1 << 14) + +enum sbi_sse_event_attr { +SBI_SSE_EVENT_ATTR_STATE =0 , +SBI_SSE_EVENT_ATTR_PRIORITY , +SBI_SSE_EVENT_ATTR_INJECTION , +SBI_SSE_EVENT_ATTR_HART_ID , +SBI_SSE_EVENT_ATTR_RAW_PENDING_STATUS , +}; + +enum sbi_sse_event_handler_sts { +SBI_SSE_HANDLER_SUCCESS =0 , +SBI_SSE_HANDLER_FAILED , +}; +#define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
@@ -251,6 +286,9 @@ enum sbi_pmu_ctr_type {#define SBI_ERR_ALREADY_AVAILABLE -6#define SBI_ERR_ALREADY_STARTED -7#define SBI_ERR_ALREADY_STOPPED -8 +#define SBI_ERR_INVALID_STATE -10 +#define SBI_ERR_BAD_RANGE -11 +#define SBI_ERR_BUSY -12extern unsigned long sbi_spec_version;struct sbiret {
arch/riscv/kernel/sbi.c +4 -0
@@ -56,9 +56,13 @@ int sbi_err_map_linux_errno(int err)case SBI_ERR_DENIED :return -EPERM ;case SBI_ERR_INVALID_PARAM : +case SBI_ERR_BAD_RANGE : +case SBI_ERR_INVALID_STATE :return -EINVAL ;case SBI_ERR_INVALID_ADDRESS :return -EFAULT ; +case SBI_ERR_BUSY : +return -EBUSY ;case SBI_ERR_NOT_SUPPORTED :case SBI_ERR_FAILURE :default :
Signature · 7 lines
2.42.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 2/3 riscv: add support for SBI Supervisor Software Events extension
In reply to Clément LégerThe SBI SSE extension allows the supervisor software to be notified by the SBI of specific events that are not maskable. The context switch is handled entirely by the firmware which will save all registers into a supervisor provided context and restore a set of registers from this same context. This context contains all the RV GP registers and thus will also switch the stack.
Since each events (and each CPU for local events) have their own context (and thus their own set of register), allocate a stack for each event (and for each cpu for local events). This can be modified if needed to use a single stack per cpu for SSE event but will require a bit more additional plumbing.
When completing the event, if we were coming from kernel with interrupts disabled, simply return there. If coming from userspace or kernel with interrupts enabled, simulate an interrupt exception to allow delivery of signal to user task. For instance this can happen, when a RAS event has been generated and a SIGBUS has been sent to a task.
--- arch/riscv/include/asm/asm-prototypes.h | 5 + arch/riscv/include/asm/sse.h | 94 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 17 + arch/riscv/kernel/entry.S | 156 ++++++++ arch/riscv/kernel/sse.c | 97 +++++ arch/riscv/kernel/stacktrace.c | 13 + arch/riscv/kernel/vmlinux.lds.S | 6 + drivers/firmware/Kconfig | 10 + drivers/firmware/Makefile | 1 + drivers/firmware/riscv_sse.c | 496 ++++++++++++++++++++++++ include/linux/riscv_sse.h | 56 +++ 12 files changed, 952 insertions(+) create mode 100644 arch/riscv/include/asm/sse.h create mode 100644 arch/riscv/kernel/sse.c create mode 100644 drivers/firmware/riscv_sse.c create mode 100644 include/linux/riscv_sse.h
arch/riscv/include/asm/asm-prototypes.h +5 -0
@@ -3,6 +3,8 @@#define _ASM_RISCV_PROTOTYPES_H#include <linux/ftrace.h> +#include <linux/riscv_sse.h> +#include <asm/sse.h> #include <asm-generic/asm-prototypes.h> long long __lshrti3 (long long a,int b);
@@ -29,5 +31,8 @@ asmlinkage unsigned long get_overflow_stack(void); asmlinkage void handle_bad_stack(struct pt_regs *regs); asmlinkage void do_page_fault(struct pt_regs *regs); asmlinkage void do_irq(struct pt_regs *regs); +asmlinkage unsigned long do_sse (unsigned long evt, +struct sse_interrupted_state *i_state, +sse_event_handler *handler,void *arg);#endif /* _ASM_RISCV_PROTOTYPES_H */
arch/riscv/include/asm/sse.h new file +94 -0
94 lines not on this page · raw message
arch/riscv/kernel/Makefile +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += mcount-dyn.o obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o obj-$(CONFIG_RISCV_SBI) += sbi.o +obj-$(CONFIG_RISCV_SSE) += sse.o ifeq ($(CONFIG_RISCV_SBI), y) obj-$(CONFIG_SMP) += sbi-ipi.o obj-$(CONFIG_SMP) += cpu_ops_sbi.o
arch/riscv/kernel/asm-offsets.c +17 -0
@@ -14,7 +14,10 @@#include <asm/thread_info.h> #include <asm/ptrace.h> #include <asm/cpu_ops_sbi.h> +#include <asm/sbi.h> +#include <asm/sse.h> #include <asm/suspend.h> +#include <asm/stacktrace.h> void asm_offsets (void );
@@ -479,4 +482,18 @@ void asm_offsets(void)OFFSET (KERNEL_MAP_VIRT_ADDR , kernel_mapping, virt_addr);OFFSET (SBI_HART_BOOT_TASK_PTR_OFFSET , sbi_hart_boot_data, task_ptr);OFFSET (SBI_HART_BOOT_STACK_PTR_OFFSET , sbi_hart_boot_data, stack_ptr); + +OFFSET (SSE_INTERRUPTED_EXEC_MODE , sse_interrupted_state, exec_mode); +OFFSET (SSE_INTERRUPTED_S0 , sse_interrupted_state, s0); +OFFSET (SSE_INTERRUPTED_TP , sse_interrupted_state, tp); +OFFSET (SSE_INTERRUPTED_PC , sse_interrupted_state, pc); + +DEFINE (STACKFRAME_SIZE_ON_STACK ,ALIGN (sizeof (struct stackframe ), +STACK_ALIGN )); +OFFSET (STACKFRAME_FP , stackframe, fp); +OFFSET (STACKFRAME_RA , stackframe, ra); +DEFINE (SBI_EXT_SSE ,SBI_EXT_SSE ); +DEFINE (SBI_SSE_EVENT_COMPLETE ,SBI_SSE_EVENT_COMPLETE ); + +DEFINE (ASM_PAGE_OFFSET ,CONFIG_PAGE_OFFSET ); }
arch/riscv/kernel/entry.S +156 -0
194 lines not on this page · raw message
arch/riscv/kernel/sse.c new file +97 -0
97 lines not on this page · raw message
arch/riscv/kernel/stacktrace.c +13 -0
@@ -17,6 +17,7 @@#ifdef CONFIG_FRAME_POINTER extern asmlinkage void ret_from_exception(void); +extern asmlinkage void ret_from_sse(void); void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,bool (*fn)(void *,unsigned long ),void *arg)
@@ -68,6 +69,18 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, pc = ((struct pt_regs *)sp)->epc; fp = ((struct pt_regs *)sp)->s0; + }else if (pc == (unsigned long )ret_from_sse) { +if (unlikely (!fn (arg, pc))) +break ; +/* We don't have pt_regs when handling SSE +* events but we build a custom stackframe, +* moreover, the stack changes across boundaries +* so update it to avoid failing the checks above +*/ + frame = (struct stackframe *)fp -1 ; + fp = frame->fp; + pc = frame->ra; + sp = fp -sizeof (struct stackframe ); } }
arch/riscv/kernel/vmlinux.lds.S +6 -0
@@ -120,6 +120,12 @@ SECTIONS /* Start of data section */ _sdata = .; RO_DATA(SECTION_ALIGN) + +#ifdef CONFIG_RISCV_SSE + __task_loc : { + BOUNDED_SECTION_BY(__task_loc, ___task_loc) + } +#endif .srodata : { *(.srodata*) }
drivers/firmware/Kconfig +10 -0
@@ -226,6 +226,16 @@ config QCOM_SCM_DOWNLOAD_MODE_DEFAULT Say Y here to enable "download mode" by default. +config RISCV_SSE + bool + depends on RISCV_SBI + default y + help + The Supervisor Software Events support allow the SBI to deliver + NMI-like notifications to the supervisor mode software. When enable, + this option provides support to register callbacks on specific SSE + events. + config SYSFB bool select BOOT_VESA_SUPPORT
drivers/firmware/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o +obj-$(CONFIG_RISCV_SSE) += riscv_sse.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
drivers/firmware/riscv_sse.c new file +496 -0
496 lines not on this page · raw message
include/linux/riscv_sse.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.42.0
RFC PATCH 3/3 perf: RISC-V: add support for SSE event
In reply to Clément LégerIn order to use SSE within PMU drivers, register a SSE handler for the local PMU event. There is not a lot of specific code needed to handle the SSE event, just reuse the existing overlflow IRQ handler and pass appropriate pt_regs.
--- arch/riscv/include/asm/sbi.h | 2 ++ drivers/perf/riscv_pmu_sbi.c | 51 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-)
arch/riscv/include/asm/sbi.h +2 -0
@@ -121,6 +121,8 @@ enum sbi_ext_pmu_fid {SBI_EXT_PMU_COUNTER_START ,SBI_EXT_PMU_COUNTER_STOP ,SBI_EXT_PMU_COUNTER_FW_READ , +SBI_EXT_PMU_COUNTER_FW_READ_HI , + SBI_EXT_PMU_COUNTER_IRQ_CLEAR, }; union sbi_pmu_ctr_info {
drivers/perf/riscv_pmu_sbi.c +42 -9
116 lines not on this page · raw message
Signature · 1 line
2.42.0
Re: [RFC PATCH 3/3] perf: RISC-V: add support for SSE event
Quoted 17 lines · Clément Léger
In order to use SSE within PMU drivers, register a SSE handler for the local PMU event. There is not a lot of specific code needed to handle the SSE event, just reuse the existing overlflow IRQ handler and pass appropriate
pt_regs.Signed-off-by Clément Léger <[email protected]>--- arch/riscv/include/asm/sbi.h | 2 ++ drivers/perf/riscv_pmu_sbi.c | 51 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 9 deletions(-)arch/riscv/include/asm/sbi.h +0
-0
arch/riscv/include/asm/sbi.h enum sbi_ext_pmu_fid { · line 125
Quoted 5 lines
arch/riscv/include/asm/sbi.h +2
-0@@ -121,6 +121,8 @@ enum sbi_ext_pmu_fid {SBI_EXT_PMU_COUNTER_START ,SBI_EXT_PMU_COUNTER_STOP ,SBI_EXT_PMU_COUNTER_FW_READ , +SBI_EXT_PMU_COUNTER_FW_READ_HI , + SBI_EXT_PMU_COUNTER_IRQ_CLEAR,
FWIW: This is not part of the SBI v2.0 or any proposed improvements. As the SSE spec is in the draft state,
we need to evaluate if this is required or if there are better way to request the M-mode to clear the interrupt pending bit.
With counter delegation extensions in place, this requires a bit more thought as it won't use the SBI PMU at all.
In addition to that, there may be other use cases where irq needs to be cleared first thing in the handler
There are few options which we are looking at :
1. Move the irq processing to the workqueue and call SSE complete which can clear the irq
2. Define a generic irq clear function in the SSE extension itself to achieve this if we have to rely on the SBI call.
Quoted 133 lines
arch/riscv/include/asm/sbi.h +0
-0};union sbi_pmu_ctr_info {drivers/perf/riscv_pmu_sbi.c +42
-10@@ -17,6 +17,7 @@#include <linux/irqdomain.h> #include <linux/of_irq.h> #include <linux/of.h> +#include <linux/riscv_sse.h> #include <linux/cpu_pm.h> #include <linux/sched/clock.h> @@ -625,6 +626,12 @@ static inline void pmu_sbi_stop_hw_ctrs(struct riscv_pmu *pmu) cpu_hw_evt->used_hw_ctrs[0], 0, 0, 0, 0); } +static void pmu_sbi_irq_clear (void ) +{ +/* No need to check the error here as we can't do anything about the error */ +sbi_ecall (SBI_EXT_PMU ,SBI_EXT_PMU_COUNTER_IRQ_CLEAR ,0 ,0 ,0 ,0 ,0 ,0 ); +} +/* * This function starts all the used counters in two step approach. * Any counter that did not overflow can be start in a single step @@ -670,10 +677,10 @@ static inline void pmu_sbi_start_overflow_mask(struct riscv_pmu *pmu, } } -static irqreturn_t pmu_sbi_ovf_handler (int irq,void *dev) +static irqreturn_t pmu_sbi_ovf_handler (struct cpu_hw_events *cpu_hw_evt, +struct pt_regs *regs,bool from_sse) {struct perf_sample_data data; -struct pt_regs *regs;struct hw_perf_event *hw_evt;union sbi_pmu_ctr_info *info;int lidx, hidx, fidx;@@ -681,7 +688,6 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)struct perf_event *event;unsigned long overflow;unsigned long overflowed_ctrs =0 ; -struct cpu_hw_events *cpu_hw_evt = dev;u64 start_clock =sched_clock ();if (WARN_ON_ONCE (!cpu_hw_evt))@@ -691,7 +697,10 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev) fidx =find_first_bit (cpu_hw_evt->used_hw_ctrs,RISCV_MAX_COUNTERS ); event = cpu_hw_evt->events[fidx];if (!event) { -csr_clear (CSR_SIP ,BIT (riscv_pmu_irq_num)); +if (from_sse) +pmu_sbi_irq_clear (); +else +csr_clear (CSR_SIP ,BIT (riscv_pmu_irq_num));return IRQ_NONE ; }@@ -703,16 +712,16 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)/* * Overflow interrupt pending bit should only be cleared after stopping -* all the counters to avoid any race condition. +* all the counters to avoid any race condition. When using SSE, +* interrupt is cleared when stopping counters. */ -csr_clear (CSR_SIP ,BIT (riscv_pmu_irq_num)); +if (!from_sse) +csr_clear (CSR_SIP ,BIT (riscv_pmu_irq_num));/* No overflow bit is set */ if (!overflow)return IRQ_NONE ; - regs =get_irq_regs (); -for_each_set_bit (lidx, cpu_hw_evt->used_hw_ctrs,RISCV_MAX_COUNTERS ) {struct perf_event *event = cpu_hw_evt->events[lidx];@@ -758,6 +767,22 @@ static irqreturn_t pmu_sbi_ovf_handler(int irq, void *dev)return IRQ_HANDLED ; } +static irqreturn_t pmu_sbi_ovf_irq_handler (int irq,void *dev) +{ +return pmu_sbi_ovf_handler (dev,get_irq_regs (), false); +} + +static int pmu_sbi_ovf_sse_handler (uint32_t evt,void *arg, +struct pt_regs *regs) +{ +struct cpu_hw_events __percpu *hw_events = arg; +struct cpu_hw_events *hw_event =raw_cpu_ptr (hw_events); + +pmu_sbi_ovf_handler (hw_event, regs, true); + +return 0 ; +} +static int pmu_sbi_starting_cpu (unsigned int cpu,struct hlist_node *node) { struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node);@@ -801,9 +826,17 @@ static int pmu_sbi_dying_cpu(unsigned int cpu, struct hlist_node *node)static int pmu_sbi_setup_irqs (struct riscv_pmu *pmu,struct platform_device *pdev) {int ret; +struct sse_event *evt;struct cpu_hw_events __percpu *hw_events = pmu->hw_events;struct irq_domain *domain =NULL ; + evt =sse_event_register (SBI_SSE_EVENT_LOCAL_PMU ,0 , + pmu_sbi_ovf_sse_handler, hw_events); +if (!IS_ERR (evt)) { +sse_event_enable (evt); +return 0 ; + } +if (riscv_isa_extension_available (NULL ,SSCOFPMF )) { riscv_pmu_irq_num =RV_IRQ_PMU ; riscv_pmu_use_irq = true;@@ -831,7 +864,7 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pdereturn -ENODEV ; } - ret =request_percpu_irq (riscv_pmu_irq, pmu_sbi_ovf_handler,"riscv-pmu" , hw_events); + ret =request_percpu_irq (riscv_pmu_irq, pmu_sbi_ovf_irq_handler,"riscv-pmu" , hw_events);if (ret) {pr_err ("registering percpu irq failed [%d]\n" , ret);return ret; --
Quoted 2 lines
2.42.0
--
Regards,
Atish
Pardon. It seems that the code in opensbi[1] is not complete for PMU NMI now. For example, the pmu ovf irq is still delegated to supervisor mode and thus can not really play a role as NMI. And neither the kernel nor opensbi will inject a pmu event.
To complete the work, we think maybe 'enable_cb' and 'disable_cb' functions can be supplied for sbi_sse_cb_ops.
When sbi_sse_enable is called to enable pmu event, the enable_cb will be called to revoke the delegation of pmu ovf irq and enable this irq in CSR_MIE.
When pmu ovf irq occurs, kernel traps into opensbi and opensbi injects the event via sbi_sse_inject_event and eret back to kernel.
Please point it out if we have any misunderstanding.
By the way, how is SSE going now? We will appreciate it very much if we can participate in some development work in kernel or opensbi and be of any help.
Regards!
Quoted 75 lines · Clément Léger
The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].
Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the kernel at any time.
First patch adds the SSE definitions. Second one adds support for SSE itself. Implementation is split between arch specific code and generic part (similarly to what is done for ARM SDEI). Finally, the last patch add support fro SSE event in the SBI PMU driver. If the SSE event is available from the SBI then, it will be used instead of the normal interrupt.
Amongst the specific points that needs to be handle is the interruption at any point of the kernel execution and more specifically during exception handling. Due to the fact that the exception entry implementation uses the SCRATCH CSR as both the current task struct and as the temporary register to switch the stack and save register, it is difficult to reliably get the current task struct if we get interrupted at this specific moment. A fixup-like mechanism allows to mark the location of the current task struct depending on the entry level (user/kernel) and the location. This is then used in the SSE assembly to determine where is located the current
task_struct.Contrary to pseudo NMI [2], SSE does not modifies the way interrupts are handled and does not adds any overhead to existing code. Moreover, it provides "true" NMI-like interrupts which can interrupt the kernel at any time (even in exception handling). This is particularly crucial for RAS errors which needs to be handled as fast as possible to avoid any fault propagation. Additionally, SSE event handling is faster that the standard IRQ handling path with almost half executed instruction (700 vs 1590). Some complementary tests/perf measurements will be done.
For testing purpose, one can use the provided SBI implementation at [3]. This series also needs patch [4] to fix a bug in the PMU driver.
---
Clément Léger (3):
riscv: add SBI SSE extension definitions
riscv: add support for SBI Supervisor Software Events extension
perf: RISC-V: add support for SSE eventarch/riscv/include/asm/asm-prototypes.h | 5 + arch/riscv/include/asm/sbi.h | 40 ++ arch/riscv/include/asm/sse.h | 94 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 17 + arch/riscv/kernel/entry.S | 156 ++++++++ arch/riscv/kernel/sbi.c | 4 + arch/riscv/kernel/sse.c | 97 +++++ arch/riscv/kernel/stacktrace.c | 13 + arch/riscv/kernel/vmlinux.lds.S | 6 + drivers/firmware/Kconfig | 10 + drivers/firmware/Makefile | 1 + drivers/firmware/riscv_sse.c | 496 ++++++++++++++++++++++++ drivers/perf/riscv_pmu_sbi.c | 51 ++- include/linux/riscv_sse.h | 56 +++ 15 files changed, 1038 insertions(+), 9 deletions(-) create mode 100644 arch/riscv/include/asm/sse.h create mode 100644 arch/riscv/kernel/sse.c create mode 100644 drivers/firmware/riscv_sse.c create mode 100644 include/linux/riscv_sse.h
Quoted 3 lines
--
2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 10 lines · Xu Lu
Pardon. It seems that the code in opensbi[1] is not complete for PMU NMI now. For example, the pmu ovf irq is still delegated to supervisor mode and thus can not really play a role as NMI. And neither the kernel nor opensbi will inject a pmu event.
To complete the work, we think maybe '
enable_cb' and 'disable_cb' functions can be supplied forsbi_sse_cb_ops.
Whensbi_sse_enableis called to enable pmu event, theenable_cbwill be called to revoke the delegation of pmu ovf irq and enable this irq inCSR_MIE.
Hi Xu,
Indeed, this part has been developed but was left out for the RFC. But your understanding is correct.
Quoted 8 lines
When pmu ovf irq occurs, kernel traps into opensbi and opensbi injects the event via
sbi_sse_inject_eventand eret back to kernel.Please point it out if we have any misunderstanding.
By the way, how is SSE going now? We will appreciate it very much if we can participate in some development work in kernel or opensbi and be of any help.
The development is almost complete, Anup/Himanchu will send a new revision of the spec addressing various comments and I'll resend the RFC following that spec update.
Regards,
Clément
Quoted 84 lines
Regards!
Quoted 78 lines · Clément Léger
The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1].
Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the kernel at any time.
First patch adds the SSE definitions. Second one adds support for SSE itself. Implementation is split between arch specific code and generic part (similarly to what is done for ARM SDEI). Finally, the last patch add support fro SSE event in the SBI PMU driver. If the SSE event is available from the SBI then, it will be used instead of the normal interrupt.
Amongst the specific points that needs to be handle is the interruption at any point of the kernel execution and more specifically during exception handling. Due to the fact that the exception entry implementation uses the SCRATCH CSR as both the current task struct and as the temporary register to switch the stack and save register, it is difficult to reliably get the current task struct if we get interrupted at this specific moment. A fixup-like mechanism allows to mark the location of the current task struct depending on the entry level (user/kernel) and the location. This is then used in the SSE assembly to determine where is located the current
task_struct.Contrary to pseudo NMI [2], SSE does not modifies the way interrupts are handled and does not adds any overhead to existing code. Moreover, it provides "true" NMI-like interrupts which can interrupt the kernel at any time (even in exception handling). This is particularly crucial for RAS errors which needs to be handled as fast as possible to avoid any fault propagation. Additionally, SSE event handling is faster that the standard IRQ handling path with almost half executed instruction (700 vs 1590). Some complementary tests/perf measurements will be done.
For testing purpose, one can use the provided SBI implementation at [3]. This series also needs patch [4] to fix a bug in the PMU driver.
---
Clément Léger (3):
riscv: add SBI SSE extension definitions
riscv: add support for SBI Supervisor Software Events extension
perf: RISC-V: add support for SSE eventarch/riscv/include/asm/asm-prototypes.h | 5 + arch/riscv/include/asm/sbi.h | 40 ++ arch/riscv/include/asm/sse.h | 94 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 17 + arch/riscv/kernel/entry.S | 156 ++++++++ arch/riscv/kernel/sbi.c | 4 + arch/riscv/kernel/sse.c | 97 +++++ arch/riscv/kernel/stacktrace.c | 13 + arch/riscv/kernel/vmlinux.lds.S | 6 + drivers/firmware/Kconfig | 10 + drivers/firmware/Makefile | 1 + drivers/firmware/riscv_sse.c | 496 ++++++++++++++++++++++++ drivers/perf/riscv_pmu_sbi.c | 51 ++- include/linux/riscv_sse.h | 56 +++ 15 files changed, 1038 insertions(+), 9 deletions(-) create mode 100644 arch/riscv/include/asm/sse.h create mode 100644 arch/riscv/kernel/sse.c create mode 100644 drivers/firmware/riscv_sse.c create mode 100644 include/linux/riscv_sse.h--
2.42.0
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv