2018-12-04 10:46:31

by Anup Patel

[permalink] [raw]
Subject: [PATCH v2 0/2] 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(-)

--
2.17.1



2018-12-04 10:46:37

by Anup Patel

[permalink] [raw]
Subject: [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.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 55da93f4e818..09a0f2582cad 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -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
--
2.17.1


2018-12-04 10:47:08

by Anup Patel

[permalink] [raw]
Subject: [PATCH v2 2/2] 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).

Signed-off-by: Anup Patel <[email protected]>
---
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/riscv_timer.c | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 55c77e44bb2d..19649abd7c75 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -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
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


2018-12-07 18:01:23

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers

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.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/Kconfig | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 55da93f4e818..09a0f2582cad 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -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

Reviewed-by: Palmer Dabbelt <[email protected]>

2018-12-07 18:01:34

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock

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).
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> drivers/clocksource/Kconfig | 2 +-
> drivers/clocksource/riscv_timer.c | 9 +++++++++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index 55c77e44bb2d..19649abd7c75 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -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
> 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);

Reviewed-by: Palmer Dabbelt <[email protected]>

2018-12-07 18:02:09

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer

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

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.

2018-12-09 16:46:45

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer

On 07/12/2018 18:59, Palmer Dabbelt wrote:
> 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(-)
>
> 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

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


2018-12-10 17:34:07

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer

On Sun, 09 Dec 2018 08:30:34 PST (-0800), [email protected] wrote:
> On 07/12/2018 18:59, Palmer Dabbelt wrote:
>> 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(-)
>>
>> 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.