tcb_clksrc: Use 32 bit tcb as sched_clock
PATCH 1/1 tcb_clksrc: Use 32 bit tcb as sched_clock
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for sched_clock which is much more accurate than the jiffies implementation.
Tested on a Atmel SAMA5D2 board.
--- drivers/clocksource/tcb_clksrc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/clocksource/tcb_clksrc.c +15 -1
@@ -10,6 +10,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/atmel_tc.h> +#include <linux/sched_clock.h> /*
@@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)return (upper <<16 ) | lower; } -static u64 tc_get_cycles32 (struct clocksource *cs) +static u32 tc_get_cv32 (void ) {return __raw_readl (tcaddr +ATMEL_TC_REG (0 ,CV )); } +static u64 tc_get_cycles32 (struct clocksource *cs) +{ +return tc_get_cv32 (); +} +static struct clocksource clksrc = { .name ="tcb_clksrc" , .rating =200 ,
@@ -69,6 +75,11 @@ static struct clocksource clksrc = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static u64 notrace tc_read_sched_clock(void) +{ +return tc_get_cv32 (); +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS struct tc_clkevt_device {
@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void) clksrc.read = tc_get_cycles32;/* setup ony channel 0 */ tcb_setup_single_chan (tc, best_divisor_idx); + +/* register sched_clock on chips with single 32 bit counter */ +sched_clock_register (tc_read_sched_clock,32 , divided_rate); }else {/* tclib will give us three clocks no matter what the * underlying platform supports.
Signature · 1 line
2.9.3
PATCH 1/1 tcb_clksrc: Use 32 bit tcb as sched_clock
Quoted 5 lines · David Engraf
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.Tested on a Atmel SAMA5D2 board.
Is this change backward compatible ?
Quoted 58 lines
Signed-off-by David Engraf <[email protected]>--- drivers/clocksource/tcb_clksrc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/clocksource/tcb_clksrc.c +15
-1@@ -10,6 +10,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/atmel_tc.h> +#include <linux/sched_clock.h> /* @@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)return (upper <<16 ) | lower; } -static u64 tc_get_cycles32 (struct clocksource *cs) +static u32 tc_get_cv32 (void ) {return __raw_readl (tcaddr +ATMEL_TC_REG (0 ,CV )); } +static u64 tc_get_cycles32 (struct clocksource *cs) +{ +return tc_get_cv32 (); +} +static struct clocksource clksrc = { .name ="tcb_clksrc" , .rating =200 ,@@ -69,6 +75,11 @@ static struct clocksource clksrc = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static u64 notrace tc_read_sched_clock(void) +{ +return tc_get_cv32 (); +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS struct tc_clkevt_device {@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void) clksrc.read = tc_get_cycles32;/* setup ony channel 0 */ tcb_setup_single_chan (tc, best_divisor_idx); + +/* register sched_clock on chips with single 32 bit counter */ +sched_clock_register (tc_read_sched_clock,32 , divided_rate); }else {/* tclib will give us three clocks no matter what the * underlying platform supports.
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
Am 17.01.2017 um 10:13 schrieb Daniel Lezcano:
Quoted 8 lines · David Engraf
Quoted 5 lines
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.Tested on a Atmel SAMA5D2 board.
Is this change backward compatible ?
The way how the driver reads the clock hasn't been changed. I've only introduced the call to sched_clock_register() which will use this clock for the scheduler as long as no better clock is already used. So I don't see a backward compatibility problem.
Best regards
- David
Quoted 61 lines
Quoted 59 lines
Signed-off-by David Engraf <[email protected]>--- drivers/clocksource/tcb_clksrc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/clocksource/tcb_clksrc.c +15
-1@@ -10,6 +10,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/atmel_tc.h> +#include <linux/sched_clock.h> /* @@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)return (upper <<16 ) | lower; } -static u64 tc_get_cycles32 (struct clocksource *cs) +static u32 tc_get_cv32 (void ) {return __raw_readl (tcaddr +ATMEL_TC_REG (0 ,CV )); } +static u64 tc_get_cycles32 (struct clocksource *cs) +{ +return tc_get_cv32 (); +} +static struct clocksource clksrc = { .name ="tcb_clksrc" , .rating =200 ,@@ -69,6 +75,11 @@ static struct clocksource clksrc = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static u64 notrace tc_read_sched_clock(void) +{ +return tc_get_cv32 (); +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS struct tc_clkevt_device {@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void) clksrc.read = tc_get_cycles32;/* setup ony channel 0 */ tcb_setup_single_chan (tc, best_divisor_idx); + +/* register sched_clock on chips with single 32 bit counter */ +sched_clock_register (tc_read_sched_clock,32 , divided_rate); }else {/* tclib will give us three clocks no matter what the * underlying platform supports.
Quoted 1 line · David Engraf
Subject: [PATCH]
tcb_clksrc: Use 32 bit tcb assched_clock
I was puzzled by the TCB acronym :-)
Trusted Computing Base
Task Control Block
Transfer Control Block
Test Control Board
In fact, it (probably) stands for Timer Counter Block, which makes sense for a clksrc patch.
Regards.
Quoted 7 lines · David Engraf
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.Tested on a Atmel SAMA5D2 board.
Signed-off-by David Engraf <[email protected]>
Unfortunately, this leads to the current boot warning:
------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at ../kernel/time/sched_clock.c:179 sched_clock_register+0x4c/0x21c Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.9.4-00041-ge780a8100f0d #1 Hardware name: Atmel SAMA5 [<c01103e4>] (unwind_backtrace) from [<c010d0e4>] (show_stack+0x20/0x24) [<c010d0e4>] (show_stack) from [<c039c130>] (dump_stack+0x24/0x28) [<c039c130>] (dump_stack) from [<c011f7b0>] (__warn+0xf4/0x10c) [<c011f7b0>] (__warn) from [<c011f898>] (warn_slowpath_null+0x30/0x38) [<c011f898>] (warn_slowpath_null) from [<c0c0d2c0>] (sched_clock_register+0x4c/0x21c) [<c0c0d2c0>] (sched_clock_register) from [<c0c345fc>] (tcb_clksrc_init+0x1c8/0x424) [<c0c345fc>] (tcb_clksrc_init) from [<c0101cdc>] (do_one_initcall+0x50/0x184) [<c0101cdc>] (do_one_initcall) from [<c0c00e70>] (kernel_init_freeable+0x13c/0x1e0) [<c0c00e70>] (kernel_init_freeable) from [<c08303ec>] (kernel_init+0x18/0x124) [<c08303ec>] (kernel_init) from [<c0108c34>] (ret_from_fork+0x14/0x20) ---[ end trace 3d13186881cd5c91 ]---
"sched_clock_register" expects to be called with interrupts disabled, but the tcb_clksrc initialization is called as an arch_initcall, which runs too late in the boot sequence.
Best regards,
Signature · 1 line
Romain Izard
Quoted 8 lines · David Engraf
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.Tested on a Atmel SAMA5D2 board.
Signed-off-by David Engraf <[email protected]>---
Nicolas,
if you agree I will take this change.
-- Daniel
Quoted 7 lines · David Engraf
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.Tested on a Atmel SAMA5D2 board.
Signed-off-by David Engraf <[email protected]>
Thanks,
Quoted 57 lines
--- drivers/clocksource/tcb_clksrc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)drivers/clocksource/tcb_clksrc.c +15
-1@@ -10,6 +10,7 @@#include <linux/io.h> #include <linux/platform_device.h> #include <linux/atmel_tc.h> +#include <linux/sched_clock.h> /* @@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)return (upper <<16 ) | lower; } -static u64 tc_get_cycles32 (struct clocksource *cs) +static u32 tc_get_cv32 (void ) {return __raw_readl (tcaddr +ATMEL_TC_REG (0 ,CV )); } +static u64 tc_get_cycles32 (struct clocksource *cs) +{ +return tc_get_cv32 (); +} +static struct clocksource clksrc = { .name ="tcb_clksrc" , .rating =200 ,@@ -69,6 +75,11 @@ static struct clocksource clksrc = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static u64 notrace tc_read_sched_clock(void) +{ +return tc_get_cv32 (); +} +#ifdef CONFIG_GENERIC_CLOCKEVENTS struct tc_clkevt_device {@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void) clksrc.read = tc_get_cycles32;/* setup ony channel 0 */ tcb_setup_single_chan (tc, best_divisor_idx); + +/* register sched_clock on chips with single 32 bit counter */ +sched_clock_register (tc_read_sched_clock,32 , divided_rate); }else {/* tclib will give us three clocks no matter what the * underlying platform supports.
Signature · 1 line
Nicolas Ferre
Quoted 5 lines · Daniel Lezcano
Quoted 4 lines · David Engraf
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for
sched_clockwhich is much more accurate than the jiffies implementation.
Quoted 8 lines
Quoted 4 lines
Tested on a Atmel SAMA5D2 board.
Signed-off-by David Engraf <[email protected]>---
Nicolas,
if you agree I will take this change.
Absolutely. I've just added the Ack.
Thanks for the head-up. Bye,
Signature · 1 line
Nicolas Ferre