RISC-V cycle timer fixes
Subsystems (2)
cover RISC-V cycle timer fixes
Antony Pavlov (3):
clocksource: timer-riscv: adapt riscv_timer_get_count_rdcycle() for
RV32
RISC-V: erizo.dtsi: set timebase-frequency = <24000000>
RISC-V: drop old timer handling code
arch/riscv/dts/erizo.dtsi | 2 + arch/riscv/lib/Makefile | 2 +- arch/riscv/lib/riscv_timer.c | 63 ------------------------------- drivers/clocksource/timer-riscv.c | 13 +++++-- 4 files changed, 13 insertions(+), 67 deletions(-) delete mode 100644 arch/riscv/lib/riscv_timer.c
Signature · 7 lines
2.30.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/3 clocksource: timer-riscv: adapt riscv_timer_get_count_rdcycle() for RV32
On RV64 rdcycle instruction reads 64-bit counter which holds a count of the number of clock cycles executed by the processor core.
On RV32 rdcycle instruction reads only bits 31-0 of the same counter; RDCYCLEH should be used to read bits 63–32.
The code of this patch is based on Figure 2.5: 'Sample code for reading the 64-bit cycle counter in RV32' [1]:
again:
rdcycleh x3
rdcycle x2
rdcycleh x4
bne x3, x4, again
[1] The RISC-V Instruction Set Manual. Volume I:
User-Level ISA, Document Version 2.2
--- drivers/clocksource/timer-riscv.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/clocksource/timer-riscv.c +10 -3
@@ -30,10 +30,17 @@ static u64 notrace riscv_timer_get_count_sbi(void) static u64 notrace riscv_timer_get_count_rdcycle(void) { -u64 ticks; - asmvolatile ("rdcycle %0" :"=r" (ticks)); +__maybe_unused u32 hi, lo; -return ticks; +if (IS_ENABLED (CONFIG_64BIT )) +return csr_read (CSR_CYCLE ); + +do { + hi =csr_read (CSR_CYCLEH ); + lo =csr_read (CSR_CYCLE ); + }while (hi !=csr_read (CSR_CYCLEH )); + +return ((u64 )hi <<32 ) | lo; } static u64 notrace riscv_timer_get_count(void)
Signature · 7 lines
2.30.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/3 RISC-V: erizo.dtsi: set timebase-frequency = <24000000>
In reply to Antony PavlovThis patch makes it possible to use drivers/clocksource/timer-riscv.c with erizo. Without timebase-frequency initialized we have this warning at startup:
RISC-V system with no 'timebase-frequency' in DTS
--- arch/riscv/dts/erizo.dtsi | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/dts/erizo.dtsi +2 -0
@@ -20,6 +20,8 @@ #address-cells = <1>; #size-cells = <0>; + timebase-frequency = <24000000>; + cpu@0 { device_type = "cpu"; compatible = "cliffordwolf,picorv32", "riscv";
Signature · 7 lines
2.30.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/3 RISC-V: drop old timer handling code
In reply to Antony PavlovUse drivers/clocksource/timer-riscv.c driver introduced in '2ee369dcf7a5 ("clocksource: add driver for RISC-V and CLINT timers")' instead.
--- arch/riscv/lib/Makefile | 2 +- arch/riscv/lib/riscv_timer.c | 63 ------------------------------------ 2 files changed, 1 insertion(+), 64 deletions(-)
arch/riscv/lib/Makefile +1 -1
@@ -2,7 +2,7 @@ extra-y += barebox.lds -obj-y += riscv_timer.o dtb.o +obj-y += dtb.o obj-pbl-y += sections.o setupc.o reloc.o sections.o runtime-offset.o obj-$(CONFIG_HAS_ARCH_SJLJ) += setjmp.o longjmp.o obj-$(CONFIG_RISCV_OPTIMZED_STRING_FUNCTIONS) += memcpy.o memset.o memmove.o
arch/riscv/lib/riscv_timer.c deleted +0 -63
63 lines not on this page · raw message
Signature · 7 lines
2.30.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 6 lines · Antony Pavlov
Antony Pavlov (3):
clocksource: timer-riscv: adaptriscv_timer_get_count_rdcycle()forRV32RISC-V:
erizo.dtsi: set timebase-frequency = <24000000>
RISC-V: drop old timer handling code
Applied, thanks
Sascha
Quoted 11 lines
arch/riscv/dts/erizo.dtsi | 2 + arch/riscv/lib/Makefile | 2 +- arch/riscv/lib/riscv_timer.c | 63 ------------------------------- drivers/clocksource/timer-riscv.c | 13 +++++-- 4 files changed, 13 insertions(+), 67 deletions(-) delete mode 100644 arch/riscv/lib/riscv_timer.cSignature · 1 line
2.30.1
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox