clocksources/clockevents improvements
cover clocksources/clockevents improvements
The series provides a few improvements to the core code of clocksources and clockevents.
1) Better layout and cacheline alignment of the hotpath data in both data structures
2) Get rid of the hardcoded 5 seconds sleep limit in clocksources
3) Provide a generic configuration and registration interface for clockevents which does all the common math tasks so we can remove copied code all over the place
4) Provide a function to reconfigure an active clock event device. Needed by devices which are affected by frequency scaling.
The last two patches are x86 specific and make use of the new config_register() functions.
Thanks,
tglx
PATCH 1/7 clocksource: Restructure clocksource struct members
An embedded and charset-unspecified text was scrubbed...
Name: clocksource-better-layout.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/a74334d0/attachment.ksh>
PATCH 2/7 clocksource: Get rid of the hardcoded 5 seconds sleep time limit
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: clocksource-make-shift-mult-calc-more-clever.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/38e016ce/attachment.ksh>
Re: [patch 2/7] clocksource: Get rid of the hardcoded 5 seconds sleep time limit
Quoted 45 lines · Thomas Gleixner
plain text document attachment (clocksource-make-shift-mult-calc-more-clever.patch)
Slow clocksources can have a way longer sleep time than 5 seconds and even fast ones can easily cope with 600 seconds and still maintain proper accuracy.Signed-off-by Thomas Gleixner <[email protected]>--- kernel/time/clocksource.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)Index:
linux-2.6-tip/kernel/time/clocksource.c
===================================================================kernel/time/clocksource.c +2
-16@@ -626,19 +626,6 @@ static void clocksource_enqueue(struct clist_add (&cs->list, entry); } - -/* -* Maximum time we expect to go between ticks. This includes idle -* tickless time. It provides the trade off between selecting a -* mult/shift pair that is very precise but can only handle a short -* period of time, vs. a mult/shift pair that can handle long periods -* of time but isn't as precise. -* -* This is a subsystem constant, and actual hardware limitations -* may override it (ie: clocksources that wrap every 3 seconds). -*/ -#define MAX_UPDATE_LENGTH 5/* Seconds */ -/** * __clocksource_updatefreq_scale - Used update clocksource with new freq * @t: clocksource to be registered @@ -652,15 +639,28 @@ static void clocksource_enqueue(struct c*/ void __clocksource_updatefreq_scale (struct clocksource *cs,u32 scale,u32 freq) { +unsigned long sec; +/* -* Ideally we want to use some of the limits used in -* clocksource_max_deferment, to provide a more informed -* MAX_UPDATE_LENGTH. But for now this just gets the
kernel/time/clocksource.c static void clocksource_enqueue(struct c · line 653
Quoted 10 lines
kernel/time/clocksource.c +8
-1-* register interface working properly. +* Calc the maximum number of seconds which we can run before +* wrapping around. For clocksources which have a mask > 32bit +* we need to limit the max sleep time to have a good +* conversion precision. 10 minutes is still a reasonable +* amount. That results in a shift value of 24 for a +* clocksource with mask >= 40bit and f >= 4GHz. That maps to +* ~ 0.06ppm granularity for NTP. We apply the same 12.5% +* margin as we do in clocksource_max_deferment() */
So, its not clear to me that the 12.5% margin really needed, since we take it out when we calculate clocksource_max_deferment(). Although with or without the margin I get the same mult/shift/max_idle_ns values for the hardware I'm testing.
Another nice detail from the change: It doesn't affect clocksources that normally wrap quickly:
Without your patch:
--------------
JDB: hpet mult: 2684354560 shift: 26 max_idle: 83214991360
JDB: acpi_pm mult: 2343484437 shift: 23 max_idle: 4540500826
JDB: tsc mult: 1342183991 shift: 31 max_idle: 2600481483
With your patch:
---------------
JDB: hpet mult: 2684354560 shift: 26 max_idle: 83214991360
JDB: acpi_pm mult: 2343484437 shift: 23 max_idle: 4540500826
JDB: tsc mult: 10485812 shift: 24 max_idle: 332861616128
Although interestingly 332 secs calculated for the max idle is more then 12% off of 600.
Quoted 5 lines
kernel/time/clocksource.c +5
-0+ sec = (cs->mask - (cs->mask >>5 )); +do_div (sec, freq); +do_div (sec, scale); +if (!sec) + sec =1 ;
kernel/time/clocksource.c static void clocksource_enqueue(struct c · line 666
Quoted 10 lines
kernel/time/clocksource.c +4
-2+else if (sec >600 && cs->mask >UINT_MAX ) + sec =600 ; +clocks_calc_mult_shift (&cs->mult, &cs->shift, freq, -NSEC_PER_SEC /scale, -MAX_UPDATE_LENGTH *scale); +NSEC_PER_SEC / scale, sec * scale); cs->max_idle_ns =clocksource_max_deferment (cs); }EXPORT_SYMBOL_GPL (__clocksource_updatefreq_scale);
Overall it looks good. I'm doing some NTP testing with the TSC shift change to make sure we don't get any odd side effects. I'll let you know how those go.
thanks
-john
Re: [patch 2/7] clocksource: Get rid of the hardcoded 5 seconds sleep time limit
Quoted 29 lines · John Stultz
Review
Quoted 13 lines · Thomas Gleixner
(quoted diff) +8
-4- * Ideally we want to use some of the limits used in - * clocksource_max_deferment, to provide a more informed - * MAX_UPDATE_LENGTH. But for now this just gets the - * register interface working properly. + * Calc the maximum number of seconds which we can run before + * wrapping around. For clocksources which have a mask > 32bit + * we need to limit the max sleep time to have a good + * conversion precision. 10 minutes is still a reasonable + * amount. That results in a shift value of 24 for a + * clocksource with mask >= 40bit and f >= 4GHz. That maps to + * ~ 0.06ppm granularity for NTP. We apply the same 12.5% + * margin as we do in clocksource_max_deferment() */So, its not clear to me that the 12.5% margin really needed, since we take it out when we calculate
clocksource_max_deferment(). Although with or without the margin I get the same mult/shift/max_idle_ns values for the hardware I'm testing.Another nice detail from the change: It doesn't affect clocksources that normally wrap quickly:
Without your patch:
--------------
JDB: hpet mult: 2684354560 shift: 26max_idle: 83214991360
JDB:acpi_pmmult: 2343484437 shift: 23max_idle: 4540500826
JDB: tsc mult: 1342183991 shift: 31max_idle: 2600481483
Quoted 8 lines
With your patch:
---------------
JDB: hpet mult: 2684354560 shift: 26max_idle: 83214991360
JDB:acpi_pmmult: 2343484437 shift: 23max_idle: 4540500826
JDB: tsc mult: 10485812 shift: 24max_idle: 332861616128Although interestingly 332 secs calculated for the max idle is more then 12% off of 600.
We probably need to look at the math of clocksource_max_deferment() again.
Quoted 3 lines
Overall it looks good. I'm doing some NTP testing with the TSC shift change to make sure we don't get any odd side effects. I'll let you know how those go.
Ok.
Thanks,
tglx
Re: [patch 2/7] clocksource: Get rid of the hardcoded 5 seconds sleep time limit
In reply to John StultzQuoted 3 lines · John Stultz
Overall it looks good. I'm doing some NTP testing with the TSC shift change to make sure we don't get any odd side effects. I'll let you know how those go.
So from overnight testing all looks well.
thanks
-john
PATCH 3/7 clockevents: Restructure clock_event_device members
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: ce-better-layout.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/bdcd4ee4/attachment.ksh>
PATCH 4/7 clockevents: Provide combined configure and register function
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: ce-add-register-if.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/c76bd52d/attachment.ksh>
Re: [patch 4/7] clockevents: Provide combined configure and register function
Review
Quoted 3 lines · Thomas Gleixner
(quoted diff) +3
-0+extern void clockevents_config_and_register(struct clock_event_device *dev, + u32 freq, unsigned long min_delta, + unsigned long max_delta);
might be worth collecting these fields into a clocksource_params structure:
struct clocksource_params {
u32 freq;
unsigned long min_delta;
unsigned long max_delta;
};That way the initialization API looks even more streamlined:
extern void
clockevents_config_and_register(struct clock_event_device *dev,
struct clocksource_params params);
and could be extended in the future, without having to update every single clocksource driver again.
But a good first step in any case:
Thanks,
Ingo
Re: [patch 4/7] clockevents: Provide combined configure and register function
Quoted 15 lines · Ingo Molnar
Review
Quoted 3 lines · Thomas Gleixner
(quoted diff) +3
-0+extern void clockevents_config_and_register(struct clock_event_device *dev, + u32 freq, unsigned long min_delta, + unsigned long max_delta);might be worth collecting these fields into a
clocksource_paramsstructure:struct clocksource_params { u32 freq; unsigned long min_delta; unsigned long max_delta; };
Quoted 8 lines
That way the initialization API looks even more streamlined:
extern void
clockevents_config_and_register(structclock_event_device*dev,struct clocksource_params params);and could be extended in the future, without having to update every single clocksource driver again.
Though it's unlikely that we have more params int the foreseeable future and it's more code in the clock events registration sites as you have to do:
struct param par;
par.freq = f;
par.min_delta = x;
par.max_delta = y;
clockevents_config_and_register(&dev, &p);instead of having a single line.
When the need arises we still can do
__clockevents_config_and_register(struct clock_event_device *dev,
struct clocksource_params params);
and have the current function as a wrapper around it.
Thanks,
tglx
Re: [patch 4/7] clockevents: Provide combined configure and register function
Quoted 30 lines · Thomas Gleixner
Quoted 15 lines · Ingo Molnar
Review
Quoted 3 lines · Thomas Gleixner
(quoted diff) +3
-0+extern void clockevents_config_and_register(struct clock_event_device *dev, + u32 freq, unsigned long min_delta, + unsigned long max_delta);might be worth collecting these fields into a
clocksource_paramsstructure:struct clocksource_params { u32 freq; unsigned long min_delta; unsigned long max_delta; };Quoted 8 lines
That way the initialization API looks even more streamlined:
extern void
clockevents_config_and_register(structclock_event_device*dev,struct clocksource_params params);and could be extended in the future, without having to update every single clocksource driver again.
Though it's unlikely that we have more params int the foreseeable future and it's more code in the clock events registration sites as you have to do:
Quoted 8 lines
struct param par; par.freq = f; par.min_delta = x; par.max_delta = y; clockevents_config_and_register(&dev, &p);instead of having a single line.
Indeed that looks uglish.
Quoted 6 lines
When the need arises we still can do
__clockevents_config_and_register(struct
clock_event_device*dev,
structclocksource_paramsparams);and have the current function as a wrapper around it.
Okay, you are right.
Thanks,
Ingo
PATCH 5/7 clockevents: Provide interface to reconfigure an active clock event device
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: re-arm-twd-adjust-localtimer-frequency-withcpufreqnotifiers.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/ae8880bd/attachment.ksh>
Re: [patch 5/7] clockevents: Provide interface to reconfigure an active clock event device
2011/5/18 Thomas Gleixner <[email protected]>:
Quoted 6 lines
Some ARM SoCs have clock event devices which have their frequency modified due to frequency scaling. Provide an interface which allows to reconfigure an active device. After reconfiguration reprogram the current pending event.
Signed-off-by Thomas Gleixner <[email protected]>
Thanks for fixing this much needed function Thomas! Linus Walleij
Re: [patch 5/7] clockevents: Provide interface to reconfigure an active clock event device
In reply to Thomas GleixnerQuoted 33 lines · Thomas Gleixner
Some ARM SoCs have clock event devices which have their frequency modified due to frequency scaling. Provide an interface which allows to reconfigure an active device. After reconfiguration reprogram the current pending event.
Signed-off-by Thomas Gleixner <[email protected]>--- include/linux/clockchips.h | 2 ++ kernel/time/clockevents.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+)Index:
linux-2.6-tip/include/linux/clockchips.h
===================================================================include/linux/clockchips.h +2
-0@@ -132,6 +132,8 @@ extern void clockevents_config_and_regis u32 freq, unsigned long min_delta, unsigned long max_delta); +extern int clockevents_reconfigure (struct clock_event_device *ce,u32 freq); +extern void clockevents_exchange_device (struct clock_event_device *old,struct clock_event_device *new); extern void clockevents_set_mode(struct clock_event_device *dev,Index:
linux-2.6-tip/kernel/time/clockevents.c
===================================================================kernel/time/clockevents.c +1
-0@@ -238,6 +238,26 @@ void clockevents_config_and_register(strclockevents_register_device (dev); } +/**
kernel/time/clockevents.c void clockevents_config_and_register(str · line 251
Quoted 10 lines
kernel/time/clockevents.c +10
-0+* clockevents_reconfigure - Reconfigure and reprogram a clock event device. +* @dev: device to modify +* @freq: new device frequency +* +* Reconfigure and reprogram a clock event device in oneshot +* mode. Must be called on the cpu for which the device delivers per +* cpu timer events with interrupts disabled! Returns 0 on success, +* -ETIME when the event is in the past. +*/ +int clockevents_reconfigure (struct clock_event_device *dev,u32 freq)
This too could use a struct clockevents_params perhaps - and would only use params.freq for now but might be extended in the future.
But i'm fine with this API as well:
Thanks,
Ingo
Re: [patch 5/7] clockevents: Provide interface to reconfigure an active clock event device
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Thomas Gleixner
+ */
+intclockevents_reconfigure(struct clock_event_device *dev, u32 freq)This too could use a struct
clockevents_paramsperhaps - and would only use params.freq for now but might be extended in the future.But i'm fine with this API as well:
I agree for the config_register interface, but here we really just want to update the frequency and not change any other parameter.
Thanks,
tglx
Re: [patch 5/7] clockevents: Provide interface to reconfigure an active clock event device
Quoted 5 lines · Thomas Gleixner
Quoted 4 lines · Ingo Molnar
Quoted 2 lines · Thomas Gleixner
+ */
+intclockevents_reconfigure(struct clock_event_device *dev, u32 freq)
Quoted 7 lines
Quoted 4 lines
This too could use a struct
clockevents_paramsperhaps - and would only use params.freq for now but might be extended in the future.But i'm fine with this API as well:
I agree for the
config_registerinterface, but here we really just want to update the frequency and not change any other parameter.
ok, fair enough - in that case i'd suggest making that property explicitly visible in the API name, via something like:
int clockevents_set_freq(struct clock_event_device *dev, u32 freq)
That way it's obvious at first sight what this does:
clockevents_set_freq(dev, 1000000);
Versus:
clockevents_reconfigure(dev, 1000000);
Thanks,
Ingo
PATCH 6/7 x86: Convert PIT to clockevents_config_and_register()
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: x86-pit-convert-ce.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/5e3ec5d1/attachment.ksh>
PATCH 7/7 x86: hpet: Cleanup the clockevents init and register code
In reply to Thomas GleixnerAn embedded and charset-unspecified text was scrubbed...
Name: x86-hept-convert.patch
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20110518/8c05ec70/attachment.ksh>
Re: [patch 7/7] x86: hpet: Cleanup the clockevents init and register code
Review int __init hpet_enable(void) · line 843
Quoted 10 lines · Thomas Gleixner
(quoted diff) +6
-0@@ -884,6 +835,14 @@ int __init hpet_enable(void) goto out_nohpet; /* + * The period is a femto seconds value. Convert it to a + * frequency. + */ + freq = FSEC_PER_SEC; + do_div(freq, hpet_period); + hpet_freq = freq;
Something i just noticed: with a typical hpet frequency of around 14 MHz we get a period of 71428571 femtoseconds.
Our HPET_MAX_PERIOD is 100000000 at the moment, so our limits look like this:
100000
71428571
100000000
Note how close the max period (lowest frequency) is to our typical value!
So if there's a 10 MHz hpet somewhere, with just slightly below spec, we'd fail due to:
if (hpet_period < HPET_MIN_PERIOD || hpet_period > HPET_MAX_PERIOD)
goto out_nohpet;unless i got my numbers wrong it might be worth upping the max period to 1000000000, to allow down to 1 MHz hpet frequencies. Or at least up it enough to make 10 MHz possible modulo small noise.
Patch looks good:
Thanks,
Ingo
Quoted 12 lines · Thomas Gleixner
The series provides a few improvements to the core code of clocksources and clockevents.
1) Better layout and cacheline alignment of the hotpath data in both data structures
2) Get rid of the hardcoded 5 seconds sleep limit in clocksources
3) Provide a generic configuration and registration interface for clockevents which does all the common math tasks so we can remove copied code all over the place
Quoted 5 lines
4) Provide a function to reconfigure an active clock event device. Needed by devices which are affected by frequency scaling.
The last two patches are x86 specific and make use of the new
config_register()functions.
Nice! Other than the comments i made for specific patches it's looking good to me:
Thanks,
Ingo