Linux-RISC-V Archive on lore.kernel.org
 help / Atom feed
* [PATCH v2 0/2] Provide sched_clock for riscv_timer
@ 2018-12-04 10:29 Anup Patel
  2018-12-04 10:29 ` [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers Anup Patel
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Anup Patel @ 2018-12-04 10:29 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Palmer Dabbelt, Albert Ou
  Cc: Christoph Hellwig, Atish Patra, linux-riscv, linux-kernel, Anup Patel

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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers
  2018-12-04 10:29 [PATCH v2 0/2] Provide sched_clock for riscv_timer Anup Patel
@ 2018-12-04 10:29 ` Anup Patel
  2018-12-07 17:58   ` Palmer Dabbelt
  2018-12-04 10:29 ` [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock Anup Patel
  2018-12-07 17:59 ` [PATCH v2 0/2] Provide sched_clock for riscv_timer Palmer Dabbelt
  2 siblings, 1 reply; 8+ messages in thread
From: Anup Patel @ 2018-12-04 10:29 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Palmer Dabbelt, Albert Ou
  Cc: Christoph Hellwig, Atish Patra, linux-riscv, linux-kernel, Anup Patel

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 <anup@brainfault.org>
---
 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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock
  2018-12-04 10:29 [PATCH v2 0/2] Provide sched_clock for riscv_timer Anup Patel
  2018-12-04 10:29 ` [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers Anup Patel
@ 2018-12-04 10:29 ` Anup Patel
  2018-12-07 17:58   ` Palmer Dabbelt
  2018-12-07 17:59 ` [PATCH v2 0/2] Provide sched_clock for riscv_timer Palmer Dabbelt
  2 siblings, 1 reply; 8+ messages in thread
From: Anup Patel @ 2018-12-04 10:29 UTC (permalink / raw)
  To: Daniel Lezcano, Thomas Gleixner, Palmer Dabbelt, Albert Ou
  Cc: Christoph Hellwig, Atish Patra, 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/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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers
  2018-12-04 10:29 ` [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers Anup Patel
@ 2018-12-07 17:58   ` Palmer Dabbelt
  0 siblings, 0 replies; 8+ messages in thread
From: Palmer Dabbelt @ 2018-12-07 17:58 UTC (permalink / raw)
  To: anup
  Cc: aou, anup, daniel.lezcano, linux-kernel, Christoph Hellwig,
	atish.patra, tglx, linux-riscv

On Tue, 04 Dec 2018 02:29:51 PST (-0800), anup@brainfault.org 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 <anup@brainfault.org>
> ---
>  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 <palmer@sifive.com>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock
  2018-12-04 10:29 ` [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock Anup Patel
@ 2018-12-07 17:58   ` Palmer Dabbelt
  0 siblings, 0 replies; 8+ messages in thread
From: Palmer Dabbelt @ 2018-12-07 17:58 UTC (permalink / raw)
  To: anup
  Cc: aou, anup, daniel.lezcano, linux-kernel, Christoph Hellwig,
	atish.patra, tglx, linux-riscv

On Tue, 04 Dec 2018 02:29:52 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/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 <palmer@sifive.com>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer
  2018-12-04 10:29 [PATCH v2 0/2] Provide sched_clock for riscv_timer Anup Patel
  2018-12-04 10:29 ` [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers Anup Patel
  2018-12-04 10:29 ` [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock Anup Patel
@ 2018-12-07 17:59 ` Palmer Dabbelt
  2018-12-09 16:30   ` Daniel Lezcano
  2 siblings, 1 reply; 8+ messages in thread
From: Palmer Dabbelt @ 2018-12-07 17:59 UTC (permalink / raw)
  To: anup
  Cc: aou, anup, daniel.lezcano, linux-kernel, Christoph Hellwig,
	atish.patra, tglx, linux-riscv

On Tue, 04 Dec 2018 02:29:50 PST (-0800), anup@brainfault.org 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.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer
  2018-12-07 17:59 ` [PATCH v2 0/2] Provide sched_clock for riscv_timer Palmer Dabbelt
@ 2018-12-09 16:30   ` Daniel Lezcano
  2018-12-10 17:31     ` Palmer Dabbelt
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Lezcano @ 2018-12-09 16:30 UTC (permalink / raw)
  To: Palmer Dabbelt, anup
  Cc: aou, linux-kernel, Christoph Hellwig, atish.patra, tglx, linux-riscv

On 07/12/2018 18:59, Palmer Dabbelt wrote:
> On Tue, 04 Dec 2018 02:29:50 PST (-0800), anup@brainfault.org 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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] Provide sched_clock for riscv_timer
  2018-12-09 16:30   ` Daniel Lezcano
@ 2018-12-10 17:31     ` Palmer Dabbelt
  0 siblings, 0 replies; 8+ messages in thread
From: Palmer Dabbelt @ 2018-12-10 17:31 UTC (permalink / raw)
  To: daniel.lezcano
  Cc: aou, anup, linux-kernel, Christoph Hellwig, atish.patra, tglx,
	linux-riscv

On Sun, 09 Dec 2018 08:30:34 PST (-0800), daniel.lezcano@linaro.org wrote:
> On 07/12/2018 18:59, Palmer Dabbelt wrote:
>> On Tue, 04 Dec 2018 02:29:50 PST (-0800), anup@brainfault.org 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.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-04 10:29 [PATCH v2 0/2] Provide sched_clock for riscv_timer Anup Patel
2018-12-04 10:29 ` [PATCH v2 1/2] RISC-V: Select GENERIC_SCHED_CLOCK for clocksource drivers Anup Patel
2018-12-07 17:58   ` Palmer Dabbelt
2018-12-04 10:29 ` [PATCH v2 2/2] clocksource: riscv_timer: Provide sched_clock Anup Patel
2018-12-07 17:58   ` Palmer Dabbelt
2018-12-07 17:59 ` [PATCH v2 0/2] Provide sched_clock for riscv_timer Palmer Dabbelt
2018-12-09 16:30   ` Daniel Lezcano
2018-12-10 17:31     ` Palmer Dabbelt

Linux-RISC-V Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linux-riscv/0 linux-riscv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-riscv linux-riscv/ https://lore.kernel.org/linux-riscv \
		linux-riscv@lists.infradead.org infradead-linux-riscv@archiver.kernel.org
	public-inbox-index linux-riscv


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-riscv


AGPL code for this site: git clone https://public-inbox.org/ public-inbox