Provide sched_clock for riscv_timer
Subsystems (2)
v2 cover Provide sched_clock for riscv_timer
This patchset extends riscv_timer to provide sched_clock using generic sched_clock framework.
The patchset is tested on QEMU virt machine. It is based on Linux-4.20-rc5 and can be found at riscv_sched_clock_v2 branch of:
https://github.com/avpatel/linux.git
Changes since v1:
- Added patch to select GENERIC_SCHED_CLOCK for RISC-V
- Kconfig RISCV_TIMER depends on GENERIC_SCHED_CLOCK
Anup Patel (2):
RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers
clocksource: riscv_timer: Provide sched_clock
arch/riscv/Kconfig | 1 + drivers/clocksource/Kconfig | 2 +- drivers/clocksource/riscv_timer.c | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
PATCH v2 1/2 RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers
The riscv_timer driver can provide sched_clock using "rdtime" instruction but to achieve this we require generic sched_clock framework hence this patch selects GENERIC_SCHED_CLOCK for RISCV.
--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
@@ -24,6 +24,7 @@ config RISCV select GENERIC_CPU_DEVICES select GENERIC_IRQ_SHOW select GENERIC_PCI_IOMAP + select GENERIC_SCHED_CLOCK select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_SMP_IDLE_THREAD
Signature · 1 line
2.17.1
Re: [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers
Quoted 14 lines · On Tue, 04 Dec 2018 02:29:51 PST (-0800), [email protected] wrote:
The
riscv_timerdriver can providesched_clockusing "rdtime" instruction but to achieve this we require genericsched_clockframework hence this patch selectsGENERIC_SCHED_CLOCKfor RISCV.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)arch/riscv/Kconfig +0
-0
arch/riscv/Kconfig config RISCV · line 30
Quoted 7 lines
arch/riscv/Kconfig +1
-0@@ -24,6 +24,7 @@ config RISCV select GENERIC_CPU_DEVICES select GENERIC_IRQ_SHOW select GENERIC_PCI_IOMAP + select GENERIC_SCHED_CLOCK select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_SMP_IDLE_THREAD
PATCH v2 2/2 clocksource: riscv_timer: Provide sched_clock
In reply to Anup PatelCurrently, we don't have a sched_clock registered for RISC-V systems. This means Linux time keeping will use jiffies (running at HZ) as the default sched_clock.
To avoid this, we explicity provide sched_clock using RISC-V rdtime instruction (similar to riscv_timer clocksource).
--- drivers/clocksource/Kconfig | 2 +- drivers/clocksource/riscv_timer.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/clocksource/Kconfig +1 -1
@@ -611,7 +611,7 @@ config ATCPIT100_TIMER config RISCV_TIMER bool "Timer for the RISC-V platform" - depends on RISCV + depends on GENERIC_SCHED_CLOCK && RISCV default y select TIMER_PROBE select TIMER_OF
drivers/clocksource/riscv_timer.c +9 -0
@@ -8,6 +8,7 @@#include <linux/cpu.h> #include <linux/delay.h> #include <linux/irq.h> +#include <linux/sched_clock.h> #include <asm/smp.h> #include <asm/sbi.h>
@@ -49,6 +50,11 @@ static unsigned long long riscv_clocksource_rdtime(struct clocksource *cs)return get_cycles64 (); } +static u64 riscv_sched_clock (void ) +{ +return get_cycles64 (); +} + static DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = { .name ="riscv_clocksource" , .rating =300 ,
@@ -97,6 +103,9 @@ static int __init riscv_timer_init_dt(struct device_node *n) cs =per_cpu_ptr (&riscv_clocksource, cpuid);clocksource_register_hz (cs, riscv_timebase); +sched_clock_register (riscv_sched_clock, +BITS_PER_LONG , riscv_timebase); + error =cpuhp_setup_state (CPUHP_AP_RISCV_TIMER_STARTING ,"clockevents/riscv/timer:starting" , riscv_timer_starting_cpu, riscv_timer_dying_cpu);
Signature · 1 line
2.17.1
Re: [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock
Quoted 51 lines · On Tue, 04 Dec 2018 02:29:52 PST (-0800), [email protected] wrote:
Currently, we don't have a
sched_clockregistered for RISC-V systems. This means Linux time keeping will use jiffies (running at HZ) as the defaultsched_clock.To avoid this, we explicity provide
sched_clockusing RISC-V rdtime instruction (similar toriscv_timerclocksource).Signed-off-by Anup Patel <[email protected]>--- drivers/clocksource/Kconfig | 2 +- drivers/clocksource/riscv_timer.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)drivers/clocksource/Kconfig +1
-1@@ -611,7 +611,7 @@ config ATCPIT100_TIMER config RISCV_TIMER bool "Timer for the RISC-V platform" - depends on RISCV + depends on GENERIC_SCHED_CLOCK && RISCV default y select TIMER_PROBE select TIMER_OFdrivers/clocksource/riscv_timer.c +6
-0@@ -8,6 +8,7 @@#include <linux/cpu.h> #include <linux/delay.h> #include <linux/irq.h> +#include <linux/sched_clock.h> #include <asm/smp.h> #include <asm/sbi.h> @@ -49,6 +50,11 @@ static unsigned long long riscv_clocksource_rdtime(struct clocksource *cs)return get_cycles64 (); } +static u64 riscv_sched_clock (void ) +{ +return get_cycles64 (); +} + static DEFINE_PER_CPU(struct clocksource, riscv_clocksource) = { .name ="riscv_clocksource" , .rating =300 ,
drivers/clocksource/riscv_timer.c static int __init riscv_timer_init_dt(struct device_node *n) · line 111
Quoted 9 lines
drivers/clocksource/riscv_timer.c +3
-0@@ -97,6 +103,9 @@ static int __init riscv_timer_init_dt(struct device_node *n) cs =per_cpu_ptr (&riscv_clocksource, cpuid);clocksource_register_hz (cs, riscv_timebase); +sched_clock_register (riscv_sched_clock, +BITS_PER_LONG , riscv_timebase); + error =cpuhp_setup_state (CPUHP_AP_RISCV_TIMER_STARTING ,"clockevents/riscv/timer:starting" , riscv_timer_starting_cpu, riscv_timer_dying_cpu);
Quoted 11 lines · On Tue, 04 Dec 2018 02:29:50 PST (-0800), [email protected] wrote:
This patchset extends
riscv_timerto providesched_clockusing genericsched_clockframework.The patchset is tested on QEMU virt machine. It is based on Linux-4.20-rc5 and can be found at
riscv_sched_clock_v2branch of:
https://github.com/avpatel/linux.gitChanges since v1:
- Added patch to selectGENERIC_SCHED_CLOCKfor RISC-V
-KconfigRISCV_TIMERdepends onGENERIC_SCHED_CLOCK
Quoted 8 lines
Anup Patel (2):
RISC-V: SelectGENERIC_SCHED_CLOCKfor clocksource drivers
clocksource:riscv_timer: Providesched_clockarch/riscv/Kconfig | 1 + drivers/clocksource/Kconfig | 2 +- drivers/clocksource/riscv_timer.c | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-)
I'm going to add these to my for-next, but let me know if these should go through a clock maintainer's tree instead and I'll drop them.
Quoted 17 lines · Palmer Dabbelt
Quoted 16 lines · On Tue, 04 Dec 2018 02:29:50 PST (-0800), [email protected] wrote:
This patchset extends
riscv_timerto providesched_clockusing genericsched_clockframework.The patchset is tested on QEMU virt machine. It is based on Linux-4.20-rc5
and can be found atriscv_sched_clock_v2branch of:
https://github.com/avpatel/linux.gitChanges since v1:
- Added patch to selectGENERIC_SCHED_CLOCKfor RISC-V
-KconfigRISCV_TIMERdepends onGENERIC_SCHED_CLOCKAnup Patel (2):
RISC-V: SelectGENERIC_SCHED_CLOCKfor clocksource drivers
clocksource:riscv_timer: Providesched_clock
Quoted 7 lines
Quoted 4 lines
arch/riscv/Kconfig | 1 +
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/riscv_timer.c | 9 +++++++++3 files changed, 11 insertions(+), 1 deletion(-)I'm going to add these to my for-next, but let me know if these should go through a clock maintainer's tree instead and I'll drop them.
I'll take the second one through my tree.
-- Daniel
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 23 lines · On Sun, 09 Dec 2018 08:30:34 PST (-0800), [email protected] wrote:
Quoted 22 lines · Palmer Dabbelt
Quoted 20 lines · On Tue, 04 Dec 2018 02:29:50 PST (-0800), [email protected] wrote:
This patchset extends
riscv_timerto providesched_clockusing genericsched_clockframework.The patchset is tested on QEMU virt machine. It is based on Linux-4.20-rc5
and can be found atriscv_sched_clock_v2branch of:
https://github.com/avpatel/linux.gitChanges since v1:
- Added patch to selectGENERIC_SCHED_CLOCKfor RISC-V
-KconfigRISCV_TIMERdepends onGENERIC_SCHED_CLOCKAnup Patel (2):
RISC-V: SelectGENERIC_SCHED_CLOCKfor clocksource drivers
clocksource:riscv_timer: Providesched_clockarch/riscv/Kconfig | 1 +
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/riscv_timer.c | 9 +++++++++3 files changed, 11 insertions(+), 1 deletion(-)
Quoted 4 lines
Quoted 2 lines
I'm going to add these to my for-next, but let me know if these should go through a clock maintainer's tree instead and I'll drop them.
I'll take the second one through my tree.
OK, I dropped it.