Skip to contentSkip to conversation

clocksource: riscv_timer: Provide sched_clock

PATCH Superseded Anup Patel 3 participants 6 messages Dec 3, 2018 – Dec 7, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 clocksource: riscv_timer: Provide sched_clock

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/riscv_timer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
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
#1 lore raw
Quoted 8 lines · 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).

Hi Anup,

the GENERIC_SCHED_CLOCK dependency in the Kconfig is missing.

Thanks

Quoted 39 lines
---
 drivers/clocksource/riscv_timer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
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 · 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
author
#2 lore raw
Quoted 6 lines · Daniel Lezcano
Quoted 4 lines · 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.

Quoted 8 lines
Quoted 4 lines

To avoid this, we explicity provide sched_clock using RISC-V rdtime instruction (similar to riscv_timer clocksource).

Hi Anup,

the GENERIC_SCHED_CLOCK dependency in the Kconfig is missing.

Sure, will do.

I also have another patch to select GENERIC_SCHED_CLOCK for CONFIG_RISCV. Should I squash that patch with this patch??

Regards,
Anup

#3 lore raw
Quoted 12 lines · Anup Patel
Quoted 11 lines · Daniel Lezcano
Quoted 8 lines · 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).

Quoted 8 lines
Quoted 3 lines

Hi Anup,

the GENERIC_SCHED_CLOCK dependency in the Kconfig is missing.

Sure, will do.

I also have another patch to select GENERIC_SCHED_CLOCK for CONFIG_RISCV. Should I squash that patch with this patch??

I prefer the riscv config option to be merged via the riscv tree.

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
#4 lore raw
In reply to Anup Patel
Quoted 37 lines · On Mon, 03 Dec 2018 04:35:24 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/riscv_timer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
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 107

Quoted 5 lines
drivers/clocksource/riscv_timer.c +2 -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);

Shouldn't this just be 64, not BITS_PER_LONG? We have 64-bit counters on RV32I.

Quoted 4 lines
drivers/clocksource/riscv_timer.c +1 -0
+
 	error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
 			 "clockevents/riscv/timer:starting",
 			 riscv_timer_starting_cpu, riscv_timer_dying_cpu);
author
#5 lore raw
Quoted 42 lines · Palmer Dabbelt
Quoted 40 lines · On Mon, 03 Dec 2018 04:35:24 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/riscv_timer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
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,
@@ -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);
 
Quoted 5 lines

drivers/clocksource/riscv_timer.c static int __init riscv_timer_init_dt(struct device_node *n) · line 107

Quoted 2 lines
drivers/clocksource/riscv_timer.c +2 -0
+     sched_clock_register(riscv_sched_clock,
+                     BITS_PER_LONG, riscv_timebase);

Shouldn't this just be 64, not BITS_PER_LONG? We have 64-bit counters on RV32I.

Ahh, yes. I got mislead by "mask" field of clocksource.

I will change this to 64 and add another patch on fix "mask" of clocksource as well.

Regards,
Anup