Skip to contentSkip to conversation

Provide sched_clock for riscv_timer

PATCH In review Anup Patel 3 participants 8 messages Dec 4, 2018 – Dec 10, 2018

Subsystems (2)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

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
author
#1 lore raw

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
index 55da93f4e818..09a0f2582cad 100644
@@ -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
Reviewed-by on v2 1/2
#2 lore raw

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_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 +0 -0
index 55da93f4e818..09a0f2582cad 100644

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
author
#3 lore raw

PATCH v2 2/2 clocksource: riscv_timer: Provide sched_clock

In reply to Anup Patel

Currently, 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
index 55c77e44bb2d..19649abd7c75 100644
@@ -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
index 084e97dc10ed..431892200a08 100644
@@ -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
Reviewed-by on v2 2/2
#4 lore raw

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_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
index 55c77e44bb2d..19649abd7c75 100644
@@ -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 +6 -0
index 084e97dc10ed..431892200a08 100644
@@ -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);
#5 lore raw
In reply to Anup Patel
Quoted 11 lines · On Tue, 04 Dec 2018 02:29:50 PST (-0800), [email protected] wrote:

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

Quoted 8 lines

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(-)

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.

#6 lore raw
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_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

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
#7 lore raw
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_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(-)
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.