* [PATCH] clocksource: riscv_timer: Provide sched_clock
@ 2018-12-03 12:35 Anup Patel
2018-12-03 12:59 ` Daniel Lezcano
2018-12-06 20:32 ` Palmer Dabbelt
0 siblings, 2 replies; 6+ messages in thread
From: Anup Patel @ 2018-12-03 12:35 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner, Palmer Dabbelt, Albert Ou
Cc: Atish Patra, Christoph Hellwig, linux-riscv, linux-kernel, 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).
Signed-off-by: Anup Patel <anup@brainfault.org>
---
drivers/clocksource/riscv_timer.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c
index 084e97dc10ed..431892200a08 100644
--- a/drivers/clocksource/riscv_timer.c
+++ b/drivers/clocksource/riscv_timer.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] clocksource: riscv_timer: Provide sched_clock
2018-12-03 12:35 [PATCH] clocksource: riscv_timer: Provide sched_clock Anup Patel
@ 2018-12-03 12:59 ` Daniel Lezcano
2018-12-03 14:50 ` Anup Patel
2018-12-06 20:32 ` Palmer Dabbelt
1 sibling, 1 reply; 6+ messages in thread
From: Daniel Lezcano @ 2018-12-03 12:59 UTC (permalink / raw)
To: Anup Patel, Thomas Gleixner, Palmer Dabbelt, Albert Ou
Cc: Atish Patra, Christoph Hellwig, linux-riscv, linux-kernel
On 03/12/2018 13:35, Anup Patel 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).
>
> Signed-off-by: Anup Patel <anup@brainfault.org>
Hi Anup,
the GENERIC_SCHED_CLOCK dependency in the Kconfig is missing.
Thanks
> ---
> drivers/clocksource/riscv_timer.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c
> index 084e97dc10ed..431892200a08 100644
> --- a/drivers/clocksource/riscv_timer.c
> +++ b/drivers/clocksource/riscv_timer.c
> @@ -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);
>
--
<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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] clocksource: riscv_timer: Provide sched_clock
2018-12-03 12:59 ` Daniel Lezcano
@ 2018-12-03 14:50 ` Anup Patel
2018-12-03 14:53 ` Daniel Lezcano
0 siblings, 1 reply; 6+ messages in thread
From: Anup Patel @ 2018-12-03 14:50 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Thomas Gleixner, Palmer Dabbelt, Albert Ou, Atish Patra,
Christoph Hellwig, linux-riscv,
linux-kernel@vger.kernel.org List
On Mon, Dec 3, 2018 at 6:29 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 03/12/2018 13:35, Anup Patel 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).
> >
> > Signed-off-by: Anup Patel <anup@brainfault.org>
>
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] clocksource: riscv_timer: Provide sched_clock
2018-12-03 14:50 ` Anup Patel
@ 2018-12-03 14:53 ` Daniel Lezcano
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Lezcano @ 2018-12-03 14:53 UTC (permalink / raw)
To: Anup Patel
Cc: Thomas Gleixner, Palmer Dabbelt, Albert Ou, Atish Patra,
Christoph Hellwig, linux-riscv,
linux-kernel@vger.kernel.org List
On 03/12/2018 15:50, Anup Patel wrote:
> On Mon, Dec 3, 2018 at 6:29 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>>
>> On 03/12/2018 13:35, Anup Patel 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).
>>>
>>> Signed-off-by: Anup Patel <anup@brainfault.org>
>>
>> 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.
--
<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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] clocksource: riscv_timer: Provide sched_clock
2018-12-03 12:35 [PATCH] clocksource: riscv_timer: Provide sched_clock Anup Patel
2018-12-03 12:59 ` Daniel Lezcano
@ 2018-12-06 20:32 ` Palmer Dabbelt
2018-12-07 2:27 ` Anup Patel
1 sibling, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2018-12-06 20:32 UTC (permalink / raw)
To: anup
Cc: daniel.lezcano, tglx, aou, atish.patra, Christoph Hellwig,
linux-riscv, linux-kernel, anup
On Mon, 03 Dec 2018 04:35:24 PST (-0800), anup@brainfault.org 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).
>
> Signed-off-by: Anup Patel <anup@brainfault.org>
> ---
> drivers/clocksource/riscv_timer.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c
> index 084e97dc10ed..431892200a08 100644
> --- a/drivers/clocksource/riscv_timer.c
> +++ b/drivers/clocksource/riscv_timer.c
> @@ -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);
Shouldn't this just be 64, not BITS_PER_LONG? We have 64-bit counters on
RV32I.
> +
> error = cpuhp_setup_state(CPUHP_AP_RISCV_TIMER_STARTING,
> "clockevents/riscv/timer:starting",
> riscv_timer_starting_cpu, riscv_timer_dying_cpu);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] clocksource: riscv_timer: Provide sched_clock
2018-12-06 20:32 ` Palmer Dabbelt
@ 2018-12-07 2:27 ` Anup Patel
0 siblings, 0 replies; 6+ messages in thread
From: Anup Patel @ 2018-12-07 2:27 UTC (permalink / raw)
To: Palmer Dabbelt
Cc: Daniel Lezcano, Thomas Gleixner, Albert Ou, Atish Patra,
Christoph Hellwig, linux-riscv,
linux-kernel@vger.kernel.org List
On Fri, Dec 7, 2018 at 2:02 AM Palmer Dabbelt <palmer@sifive.com> wrote:
>
> On Mon, 03 Dec 2018 04:35:24 PST (-0800), anup@brainfault.org 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).
> >
> > Signed-off-by: Anup Patel <anup@brainfault.org>
> > ---
> > drivers/clocksource/riscv_timer.c | 9 +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/clocksource/riscv_timer.c b/drivers/clocksource/riscv_timer.c
> > index 084e97dc10ed..431892200a08 100644
> > --- a/drivers/clocksource/riscv_timer.c
> > +++ b/drivers/clocksource/riscv_timer.c
> > @@ -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);
>
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-12-07 2:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 12:35 [PATCH] clocksource: riscv_timer: Provide sched_clock Anup Patel
2018-12-03 12:59 ` Daniel Lezcano
2018-12-03 14:50 ` Anup Patel
2018-12-03 14:53 ` Daniel Lezcano
2018-12-06 20:32 ` Palmer Dabbelt
2018-12-07 2:27 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).