Skip to contentSkip to conversation

ARM: twd: Adjust localtimer frequency with cpufreq notifiers

PATCH In review Colin Cross 8 participants 24 messages Nov 18, 2010 – May 16, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: twd: Adjust localtimer frequency with cpufreq notifiers

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

This patch provides a new initialization function that takes a target TWD frequency and the ratio between the cpu clock and the TWD clock, specified as an integer divider >= 2 in the Cortex A9 MPCore TRM, and 2 in the ARM11 MPCore TRM. It also registers a cpufreq notifier that adjusts the prescaler when the cpu frequency changes.

---
 arch/arm/include/asm/smp_twd.h |   11 ++++
 arch/arm/kernel/smp_twd.c      |  106 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 109 insertions(+), 8 deletions(-)
arch/arm/include/asm/smp_twd.h +11 -0
index 634f357..5119763 100644
@@ -17,6 +17,7 @@
 #define TWD_TIMER_CONTROL_ONESHOT	(0 << 1)
 #define TWD_TIMER_CONTROL_PERIODIC	(1 << 1)
 #define TWD_TIMER_CONTROL_IT_ENABLE	(1 << 2)
+#define TWD_TIMER_CONTROL_PRESCALE_MASK	(0xFF << 8)
 
 struct clock_event_device;
 
@@ -26,4 +27,14 @@ void twd_timer_stop(void);
 int twd_timer_ack(void);
 void twd_timer_setup(struct clock_event_device *);
 
+/*
+ * Use this setup function on systems that support cpufreq.
+ * periphclk_prescaler is the fixed divider value between the cpu
+ * clock and the PERIPHCLK clock that feeds the TWD.  target_rate should be
+ * low enough that the prescaler can accurately reach the target rate from the
+ * lowest cpu frequency, but high enough to give a reasonable timer accuracy.
+ */
+void twd_timer_setup_scalable(struct clock_event_device *,
+	unsigned long target_rate, unsigned int periphclk_prescaler);
+
 #endif
arch/arm/kernel/smp_twd.c +98 -8

166 lines not on this page · raw message

Signature · 1 line
1.7.3.1
Tested-by on v1 1/1
#1 lore raw

2010/11/18 Colin Cross <[email protected]>:

Quoted 5 lines

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

We are using this with some custom hooks for the U8500.

Martin Persson can probably provide an additional Tested-by from ST-Ericsson if it helps.

Colin are you merging this patch for 2.6.39 through Russells tracker or pull request? It's an important patch for us.

Yours,
Linus Walleij

Tested-by
#2 lore raw

We've seen no problems using this patch and have been grateful for it's existence. So I'm happy to put:

Tested-by martin.persson at stericsson.com

/Martin

Quoted 20 lines · Linus Walleij

2010/11/18 Colin Cross<[email protected]>:

Quoted 5 lines

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

We are using this with some custom hooks for the U8500.

Martin Persson can probably provide an additional Tested-by from ST-Ericsson if it helps.

Colin are you merging this patch for 2.6.39 through Russells tracker or pull request? It's an important patch for us.

Yours,
Linus Walleij

#3 lore raw
Quoted 31 lines · martin persson

We've seen no problems using this patch and have been grateful for it's existence. So I'm happy to put:

Tested-by martin.persson at stericsson.com

/Martin

Quoted 22 lines · Linus Walleij

2010/11/18 Colin Cross<[email protected]>:

Quoted 5 lines

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

We are using this with some custom hooks for the U8500.

Martin Persson can probably provide an additional Tested-by from ST-Ericsson if it helps.

Colin are you merging this patch for 2.6.39 through Russells tracker or pull request? It's an important patch for us.

Yours,
Linus Walleij

I never got any responses, and it conflicts with Rob Herring's patch 6434/1, although that has not been applied. Russell, do you want this in the patch tracker?

#4 lore raw
Quoted 30 lines · Colin Cross
Quoted 28 lines · martin persson

We've seen no problems using this patch and have been grateful for it's existence. So I'm happy to put:

Tested-by martin.persson at stericsson.com

/Martin

Quoted 20 lines · Linus Walleij

2010/11/18 Colin Cross<[email protected]>:

Quoted 5 lines

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

We are using this with some custom hooks for the U8500.

Martin Persson can probably provide an additional Tested-by from ST-Ericsson if it helps.

Colin are you merging this patch for 2.6.39 through Russells tracker or pull request? It's an important patch for us.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Yours,
Linus Walleij

I never got any responses, and it conflicts with Rob Herring's patch 6434/1, although that has not been applied. Russell, do you want this in the patch tracker?

Russell wanted to move over completely to using the clock api rather than making clock api usage optional and this was dependent on his init_early changes for Realview/Versatile. So I need to update the patches based on that.

I think a cleaner solution for this is platforms should define a clock for the local timer and the notifier can just get the clock rate again. But these clocks have to be implemented first on all platforms using local timer to make it unconditional, and I don't have the clock tree knowledge of all those platforms.

Rob

#5 lore raw
Quoted 46 lines · Rob Herring
Quoted 32 lines · Colin Cross
Quoted 29 lines · On Fri, Mar 4, 2011 at 2:27 AM, martin persson <[email protected]>…

We've seen no problems using this patch and have been grateful for it's existence. So I'm happy to put:

Tested-by martin.persson at stericsson.com

/Martin

Quoted 20 lines · Linus Walleij

2010/11/18 Colin Cross<[email protected]>:

Quoted 5 lines

The clock to the ARM TWD local timer scales with the cpu frequency. To allow the cpu frequency to change while maintaining a constant TWD frequency, pick a lower target frequency for the TWD and use the prescaler to divide down to the closest lower frequency.

We are using this with some custom hooks for the U8500.

Martin Persson can probably provide an additional Tested-by from ST-Ericsson if it helps.

Colin are you merging this patch for 2.6.39 through Russells tracker or pull request? It's an important patch for us.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Yours,
Linus Walleij

I never got any responses, and it conflicts with Rob Herring's patch 6434/1, although that has not been applied. ?Russell, do you want this in the patch tracker?

Russell wanted to move over completely to using the clock api rather than making clock api usage optional and this was dependent on his init_early changes for Realview/Versatile. So I need to update the patches based on that.

Quoted 8 lines

I think a cleaner solution for this is platforms should define a clock for the local timer and the notifier can just get the clock rate again. But these clocks have to be implemented first on all platforms using local timer to make it unconditional, and I don't have the clock tree knowledge of all those platforms.

Rob

Using a clock along with the cpufreq notifiers would simplify my patch some. Maybe we can use the traction this patch has among platforms that use the twd to get the necessary clocks added. Can you post a version of your patch that assumes the presence of a twd clock, and I'll work on getting the necessary clocks added and updating my patch on top of yours?

#6 lore raw

RE: [PATCH] ARM: twd: Adjust localtimer frequency with cpufreqnotifiers

Collin, Rob,

Quoted 12 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux- arm-kernel-bounces at lists.infradead.org] On Behalf Of Colin Cross
Sent: Saturday, March 05, 2011 3:03 AM
To: Rob Herring
Cc: Russell King; Srinidhi KASAGAR; Harald Gustafsson; Linus Walleij; linux-kernel at vger.kernel.org; Rickard ANDERSSON; Varun Swara; Catalin Marinas; martin persson; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH] ARM: twd: Adjust localtimer frequency with cpufreqnotifiers

[...]

Quoted 9 lines

Using a clock along with the cpufreq notifiers would simplify my patch
some. Maybe we can use the traction this patch has among platforms that use the twd to get the necessary clocks added. Can you post a version of your patch that assumes the presence of a twd clock, and I'll work on getting the necessary clocks added and updating my patch on top of yours?

Some time back I also fixed the TWD scaling problem based on more or less similar idea of pre-scaler and CPUFREQ notifiers. Rob's clock idea was neat and useful to re-calibration

While doing this patch for OMAP I also found that CPUFREQ notifiers does delays scaling timer frequency and there is a tick deviation(3-4 ms) around 1st tick and last tick around twd rescaling.

Another issue was not able to select higher fixed twd rate and found fix for the same.

Regards,
Santosh

#7 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency with cpufreqnotifiers

Quoted 4 lines · Santosh Shilimkar

While doing this patch for OMAP I also found that CPUFREQ notifiers does delays scaling timer frequency and there is a tick deviation(3-4 ms) around 1st tick and last tick around twd rescaling.

Is this caused by ticks that have been programmed already (based on the previous frequency) when the scaling takes effect? (That's most likely I think.)

The latter could be fixed by simply calling schedule() for each CPU connected in the same core as the TWD at the end of twd_update_cpu_frequency(), couldn't it?

Colin what do you say?

Quoted 2 lines

Another issue was not able to select higher fixed twd rate and found fix for the same.

Can you send out the patch?

Yours,
Linus Walleij

#8 lore raw

RE: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 15 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux- arm-kernel-bounces at lists.infradead.org] On Behalf Of Linus Walleij
Sent: Sunday, March 06, 2011 5:37 PM
To: Santosh Shilimkar
Cc: Russell King; Srinidhi KASAGAR; Harald Gustafsson; Linus Walleij; linux-kernel at vger.kernel.org; Rickard ANDERSSON; martin persson; Colin Cross; Varun Swara; Catalin Marinas; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

On Sat, Mar 5, 2011 at 9:19 AM, Santosh Shilimkar
<[email protected]> wrote:

Quoted 9 lines
Quoted 4 lines

While doing this patch for OMAP I also found that CPUFREQ notifiers does delays scaling timer frequency and there is a tick deviation(3-4 ms) around 1st tick and last tick around twd rescaling.

Is this caused by ticks that have been programmed already (based on the previous frequency) when the scaling takes effect? (That's most likely I think.)

That's correct Linus. I noticed that Collin's patch reduces that problem a bit. In my patch I was always leaving the scaling to post notifier which actually aggravates the scenario.

Quoted 5 lines

The latter could be fixed by simply calling schedule() for each CPU connected in the same core as the TWD at the end of twd_update_cpu_frequency(), couldn't it?

I don't think schedule will do any difference here because it's the actual tick duration which getting changed. The tick does happen as per the timer load value. Now it all depends at what point time in tick window the timer scaling happens.

Quoted 7 lines

Colin what do you say?

Quoted 2 lines

Another issue was not able to select higher fixed twd rate and found fix for the same.

Can you send out the patch?

Sure. May be let's get all these twd scaling patches on the list. Rob's clock patches, Collin's notifier patch. And then I shall post the fix on top of that.

Regards,
Santosh

#9 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 20 lines · Santosh Shilimkar
Quoted 20 lines

-----Original Message-----
From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux- arm-kernel-bounces at lists.infradead.org] On Behalf Of Linus Walleij
Sent: Sunday, March 06, 2011 5:37 PM
To: Santosh Shilimkar
Cc: Russell King; Srinidhi KASAGAR; Harald Gustafsson; Linus Walleij; linux-kernel at vger.kernel.org; Rickard ANDERSSON; martin persson; Colin Cross; Varun Swara; Catalin Marinas; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 4 lines · Santosh Shilimkar

While doing this patch for OMAP I also found that CPUFREQ notifiers does delays scaling timer frequency and there is a tick deviation(3-4 ms) around 1st tick and last tick around twd rescaling.

Quoted 7 lines
Quoted 4 lines

Is this caused by ticks that have been programmed already (based on the previous frequency) when the scaling takes effect? (That's most likely I think.)

That's correct Linus. I noticed that Collin's patch reduces that problem a bit. In my patch I was always leaving the scaling to post notifier which actually aggravates the scenario.

If you always scale in the post notifier, you will end up with delays that are too short when the cpu frequency increases before the scaling is decreased.

A large tick deviation is unexpected - the timer value doesn't need to be reprogrammed, we are adjusting a prescaler between the cpu clock and the counter so that the counter always increments at the same frequency. The only inaccuracy occurs between when the prescaler is reprogrammed and the clock frequency changes, where it counts at the wrong frequency. This time should hopefully be very short.

On Tegra, the worst case transition is from the lowest frequency, 54MHz, to the highest frequency, 250 MHz. Assuming a 1MHz twd rate, the prescaler goes from 54 to 250. If the time between changing the prescaler and clock is 3 ms (1 ms for the pll to lock, 2 ms worst case waiting for the IPI to the other cpu), the timer will increment 648 times (3 ms * 54 MHz / 250) instead of 3000 times (3 ms * 250 Mhz / 250), delaying the next tick by 2.3 ms.

Quoted 5 lines
Quoted 5 lines

The latter could be fixed by simply calling schedule() for each CPU connected in the same core as the TWD at the end of twd_update_cpu_frequency(), couldn't it?

Quoted 8 lines

I don't think schedule will do any difference here because it's the actual tick duration which getting changed. The tick does happen as per the timer load value. Now it all depends at what point time in tick window the timer scaling happens.

Quoted 2 lines

Colin what do you say?

You can't call schedule, interrupts are disabled. You may be able to reprogram the clockevents based on the clocksource. Is there any way for a clockevent to invalidate the current event and ask for it to be reprogrammed?

Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

Another issue was not able to select higher fixed twd rate and found fix for the same.

Can you send out the patch?

Sure. May be let's get all these twd scaling patches on the list. Rob's clock patches, Collin's notifier patch. And then I shall post the fix on top of that.

Regards,
Santosh

#10 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 3 lines · Colin Cross

Is there any way
for a clockevent to invalidate the current event and ask for it to be reprogrammed?

TGLX will know for sure... Thomas?

(This is inside a CPUfreq hook for a localtimer for the record.)

Yours,
Linus Walleij

#11 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

2011/3/6 Linus Walleij <[email protected]>:

Quoted 9 lines · Colin Cross
Quoted 4 lines

Is there any way
for a clockevent to invalidate the current event and ask for it to be reprogrammed?

TGLX will know for sure... Thomas?

(This is inside a CPUfreq hook for a localtimer for the record.)

I discussed this briefly with TGLX at the UDS here and he's confident we could add some nifty feature to reprogram an event. I dare not try to guess where the code would sit or how it'd look...

Yours,
Linus Walleij

#12 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 7 lines · Linus Walleij

2011/3/6 Linus Walleij <[email protected]>:

Quoted 6 lines · Colin Cross
Quoted 4 lines

Is there any way
for a clockevent to invalidate the current event and ask for it to be reprogrammed?

Quoted 7 lines
Quoted 3 lines

TGLX will know for sure... Thomas?

(This is inside a CPUfreq hook for a localtimer for the record.)

I discussed this briefly with TGLX at the UDS here and he's confident we could add some nifty feature to reprogram an event. I dare not try to guess where the code would sit or how it'd look...

Does the following work for you ?

Thanks,

tglx

---------->
Subject: clock-ev-reconf.patch
From: Thomas Gleixner <[email protected]>
Date: Fri, 13 May 2011 10:53:13 +0200

---
 include/linux/clockchips.h |    2 ++
 kernel/time/clockevents.c  |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/linux/clockchips.h +2 -0
Index: linux-2.6/include/linux/clockchips.h
===================================================================
@@ -132,6 +132,8 @@ extern int clockevents_program_event(str
 
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 
+extern int clockevents_reconfigure(struct clock_event_device *ce, u32 freq, u32 minsec);
+
 static inline void
 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 {
kernel/time/clockevents.c +24 -0
Index: linux-2.6/kernel/time/clockevents.c
===================================================================
@@ -133,6 +133,30 @@ int clockevents_program_event(struct clo
 }
 
 /**
+ * clockevents_reconfigure - Reconfigure and reprogram a clock event device.
+ * @dev:	device to modify
+ * @freq:	new device frequency
+ * @secr:	guaranteed runtime conversion range in seconds
+ *
+ * Reconfigure and reprogram a clock event device in oneshot
+ * mode. Must only be called from low level idle code where
+ * interaction with hrtimers/nohz code etc. is not possible and
+ * guaranteed not to conflict. Must be called with interrupts
+ * disabled!
+ * Returns 0 on success, -ETIME when the event is in the past or
+ * -EINVAL when called with invalid parameters.
+ */
+int clockevents_reconfigure(struct clock_event_device *dev, u32 freq, u32 secr)
+{
+	if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
+		return -EINVAL;
+
+	clockevents_calc_mult_shift(dev, freq, secr ? secr : 1);
+
+	return clockevents_program_event(dev, dev->next_event, ktime_get());
+}
+
+/**
  * clockevents_register_notifier - register a clock events change listener
  */
 int clockevents_register_notifier(struct notifier_block *nb)
#13 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

2011/5/13 Thomas Gleixner <[email protected]>:

Quoted 1 line

Does the following work for you ?

This patch is interesting because it uses calc_mult_shift() and the current localtimer driver for TWD (arch/arm/kernel/smp_twd.c) still uses hardcoded mult+shift.

So this patch in combination with TGLX add-on in the CPUfreq path would eliminate the need of using the prescaler at all, which is a more appealing solution to me for one, since it results in less code.

Colin, do you think it will work? Or was there some specific reason to use a dynamic prescaler instead of doing things like this?

Yours,
Linus Walleij

#14 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 3 lines · Linus Walleij

This patch is interesting because it uses calc_mult_shift() and the current localtimer driver for TWD (arch/arm/kernel/smp_twd.c) still uses hardcoded mult+shift.

I don't think there's any reason it uses a hard coded shift, just that's what was the norm when the code was originally written. It (and many other clock event code) probably could do with an update.

#15 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

In reply to Linus Walleij
Quoted 8 lines · Linus Walleij

2011/5/13 Thomas Gleixner <[email protected]>:

Quoted 1 line

Does the following work for you ?

This patch is interesting because it uses calc_mult_shift() and the current localtimer driver for TWD (arch/arm/kernel/smp_twd.c) still uses hardcoded mult+shift.

Quoted 6 lines

So this patch in combination with TGLX add-on in the CPUfreq path would eliminate the need of using the prescaler at all, which is a more appealing solution to me for one, since it results in less code.

Colin, do you think it will work? Or was there some specific reason to use a dynamic prescaler instead of doing things like this?

This sounds much better than the dynamic prescaler. Using the prescaler causes issues with accuracy and resolution that this avoids.

#16 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

In reply to Thomas Gleixner
Quoted 1 line · Thomas Gleixner

Does the following work for you ?

Not if the comments are accurate.

Quoted 41 lines

Thanks,

? ? ? ?tglx

---------->
Subject: clock-ev-reconf.patch
From: Thomas Gleixner <[email protected]>
Date: Fri, 13 May 2011 10:53:13 +0200

---
?include/linux/clockchips.h | ? ?2 ++ ?kernel/time/clockevents.c ?| ? 24 ++++++++++++++++++++++++ ?2 files changed, 26 insertions(+)

Index: linux-2.6/include/linux/clockchips.h
===================================================================

include/linux/clockchips.h +2 -0
@@ -132,6 +132,8 @@ extern int clockevents_program_event(str
 
 ?extern void clockevents_handle_noop(struct clock_event_device *dev);
 
+extern int clockevents_reconfigure(struct clock_event_device *ce, u32 freq, u32 minsec);
+

?static inline void
?clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec) ?{
Index: linux-2.6/kernel/time/clockevents.c
===================================================================

kernel/time/clockevents.c +0 -0
@@ -133,6 +133,30 @@ int clockevents_program_event(struct clo
 ?}
 

?/**
+ * clockevents_reconfigure - Reconfigure and reprogram a clock event device.
+ * @dev: ? ? ? device to modify
+ * @freq: ? ? ?new device frequency
+ * @secr: ? ? ?guaranteed runtime conversion range in seconds
+ *

Quoted 8 lines

+ * Reconfigure and reprogram a clock event device in oneshot
+ * mode. Must only be called from low level idle code where
+ * interaction with hrtimers/nohz code etc. is not possible and
+ * guaranteed not to conflict. Must be called with interrupts
+ * disabled!
+ * Returns 0 on success, -ETIME when the event is in the past or
+ * -EINVAL when called with invalid parameters.
+ */

We need to call this from a cpufreq notifier with interrupts disabled, not from idle.

Quoted 15 lines
kernel/time/clockevents.c +11 -0
+int clockevents_reconfigure(struct clock_event_device *dev, u32 freq, u32 secr)
+{
+ ? ? ? if (dev->mode != CLOCK_EVT_MODE_ONESHOT)
+ ? ? ? ? ? ? ? return -EINVAL;
+
+ ? ? ? clockevents_calc_mult_shift(dev, freq, secr ? secr : 1);
+
+ ? ? ? return clockevents_program_event(dev, dev->next_event, ktime_get());
+}
+
+/**

?* clockevents_register_notifier - register a clock events change listener ?*/
?int clockevents_register_notifier(struct notifier_block *nb)

#17 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 15 lines · Colin Cross
Quoted 6 lines · Thomas Gleixner

?/**
+ * clockevents_reconfigure - Reconfigure and reprogram a clock event device.
+ * @dev: ? ? ? device to modify
+ * @freq: ? ? ?new device frequency
+ * @secr: ? ? ?guaranteed runtime conversion range in seconds
+ *

Quoted 8 lines

+ * Reconfigure and reprogram a clock event device in oneshot
+ * mode. Must only be called from low level idle code where
+ * interaction with hrtimers/nohz code etc. is not possible and
+ * guaranteed not to conflict. Must be called with interrupts
+ * disabled!
+ * Returns 0 on success, -ETIME when the event is in the past or
+ * -EINVAL when called with invalid parameters.
+ */

Quoted 2 lines

We need to call this from a cpufreq notifier with interrupts disabled, not from idle.

That works as well. Comments needs update. The important thing is that neither a timer interrupt nor a hrtimer function should interfere on that very cpu.

Thanks,

tglx

#18 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 16 lines · Thomas Gleixner
Quoted 15 lines · Colin Cross
Quoted 14 lines · Thomas Gleixner

/**
+ * clockevents_reconfigure - Reconfigure and reprogram a clock event device.

+ * @dev:       device to modify
+ * @freq:      new device frequency
+ * @secr:      guaranteed runtime conversion range in seconds

+ *
+ * Reconfigure and reprogram a clock event device in oneshot
+ * mode. Must only be called from low level idle code where
+ * interaction with hrtimers/nohz code etc. is not possible and
+ * guaranteed not to conflict. Must be called with interrupts
+ * disabled!
+ * Returns 0 on success, -ETIME when the event is in the past or
+ * -EINVAL when called with invalid parameters.
+ */

Quoted 7 lines
Quoted 2 lines

We need to call this from a cpufreq notifier with interrupts disabled, not from idle.

That works as well. Comments needs update. The important thing is that neither a timer interrupt nor a hrtimer function should interfere on that very cpu.

The new interface certainly better than the TWD PRE-SCALER method.

Thanks for this Thomas.

Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Since there is need to call this API in interrupt disable context, does it make sense to take care of it inside the API itself instead of relying on caller fn ?

The arch's where the per CPU TWD's share clock, per-cpu clock-events should be reconfigured on all CPUs, whenever the parent(CPU) clock has changed using some thing like smp_call_function_any() etc. Is that right understanding?

At least this is how I did twd pre-scaler based fn for OMAP.

Regards
Santosh

#19 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 6 lines · Santosh Shilimkar

On 5/14/2011 9:21 PM, Thomas Gleixner wrote:
Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Yes.

Quoted 3 lines

Since there is need to call this API in interrupt disable context, does it make sense to take care of it inside the API itself instead of relying on caller fn ?

Hmm, no strong opinion

Quoted 4 lines

The arch's where the per CPU TWD's share clock, per-cpu clock-events should be reconfigured on all CPUs, whenever the parent(CPU) clock has changed using some thing like smp_call_function_any() etc. Is that right understanding?

Yes. If that's a common requirement we should move that to core code.

Thanks,

tglx

#20 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 9 lines · Thomas Gleixner
Quoted 6 lines · Santosh Shilimkar

On 5/14/2011 9:21 PM, Thomas Gleixner wrote:
Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Yes.

Is it safe to only call it in POST? If the frequency is increasing, and the TWD is not updated until after the CPU frequency has changed, it is possible for a clockevent to fire too early. Will that cause problems, or does the clockevent code check against a clocksource to ensure the desired time has been reached? If that is OK, it drastically simplifies the code, because the driver only needs to know the current TWD frequency, not predict a future TWD frequency.

Quoted 5 lines
Quoted 3 lines

Since there is need to call this API in interrupt disable context, does it make sense to take care of it inside the API itself instead of relying on caller fn ?

Hmm, no strong opinion

For SMP TWD, the caller will always be in interrupt disabled mode, because the cpufreq notifier will get called on a random cpu, so smp_call_function_single will be used to transition to the correct cpu, which disables interrupts.

Quoted 6 lines
Quoted 4 lines

The arch's where the per CPU TWD's share clock, per-cpu clock-events should be reconfigured on all CPUs, whenever the parent(CPU) clock has changed using some thing like smp_call_function_any() etc. Is that right understanding?

Yes. If that's a common requirement we should move that to core code.

Santosh, are you suggesting the TWD be updated from the clock framework instead of the cpufreq notifier?

I believe ARMv7 requires all CPUs to run at the same frequency, so it would be possible to do this in the core code somewhere, but A15 has fixed frequency counters, and all SMP Cortex-A9s I've seen use the SMP TWD driver, so in practice this may end up being the only user.

It would be possible for the clockevent to have a flag CLOCKEVENT_EVT_FEAT_SCALES_WITH_CPU, which registers a cpufreq notifier, if there were any other users.

#21 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 11 lines · Colin Cross
Quoted 9 lines · Thomas Gleixner
Quoted 6 lines · Santosh Shilimkar

On 5/14/2011 9:21 PM, Thomas Gleixner wrote:
Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Yes.

Quoted 7 lines

Is it safe to only call it in POST? If the frequency is increasing, and the TWD is not updated until after the CPU frequency has changed, it is possible for a clockevent to fire too early. Will that cause problems, or does the clockevent code check against a clocksource to ensure the desired time has been reached? If that is OK, it drastically simplifies the code, because the driver only needs to know the current TWD frequency, not predict a future TWD frequency.

Yes, the hrtimer code checks against current time, so if it fires too early it rearms the timer.

Thanks,

tglx

#22 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

In reply to Colin Cross
Quoted 11 lines · Colin Cross
Quoted 9 lines · Thomas Gleixner
Quoted 6 lines · Santosh Shilimkar

On 5/14/2011 9:21 PM, Thomas Gleixner wrote:
Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Yes.

Quoted 8 lines

Is it safe to only call it in POST? If the frequency is increasing, and the TWD is not updated until after the CPU frequency has changed, it is possible for a clockevent to fire too early. Will that cause problems, or does the clockevent code check against a clocksource to ensure the desired time has been reached? If that is OK, it drastically simplifies the code, because the driver only needs to know the current TWD frequency, not predict a future TWD frequency.

This was the exact reason I asked this question. As discussed earlier on this thread, we observed drift in ticks especially at lowest and highest clock-points. But they way I understood is clockevents_reconfigure() will block those additional ticks at least during the reconfiguration of the clock-event.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Since there is need to call this API in interrupt disable context, does it make sense to take care of it inside the API itself instead of relying on caller fn ?

Hmm, no strong opinion

For SMP TWD, the caller will always be in interrupt disabled mode, because the cpufreq notifier will get called on a random cpu, so smp_call_function_single will be used to transition to the correct cpu, which disables interrupts.

Ok. So it's indirectly taken care then.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

The arch's where the per CPU TWD's share clock, per-cpu clock-events should be reconfigured on all CPUs, whenever the parent(CPU) clock has changed using some thing like smp_call_function_any() etc. Is that right understanding?

Yes. If that's a common requirement we should move that to core code.

Santosh, are you suggesting the TWD be updated from the clock framework instead of the cpufreq notifier?

That's where I was kind of leaning to. Basically doing this in common core code at one place and possibly outside the ARM TWD library. You might get same requirement on other arch's in future.

Quoted 5 lines

I believe ARMv7 requires all CPUs to run at the same frequency, so it would be possible to do this in the core code somewhere, but A15 has fixed frequency counters, and all SMP Cortex-A9s I've seen use the SMP TWD driver, so in practice this may end up being the only user.

Yes but the code managing the architectural timer(A15) and TWD(A9) is different. But I understand your point about the usage and it might be limited to CA9 at this point of time.

Quoted 4 lines

It would be possible for the clockevent to have a flag CLOCKEVENT_EVT_FEAT_SCALES_WITH_CPU, which registers a cpufreq notifier, if there were any other users.

Something like this is better to get better clarity on the hardware behavior. O.w we will have piece of code in TWD library which needs proper documentation about the usage of likes of smp_call_function_single().

Regards
Santosh

#23 lore raw

Re: [PATCH] ARM: twd: Adjust localtimer frequency withcpufreqnotifiers

Quoted 49 lines · Santosh Shilimkar
Quoted 15 lines · Colin Cross
Quoted 11 lines · On Mon, May 16, 2011 at 7:44 AM, Thomas Gleixner<[email protected]> ?wrote:
Quoted 7 lines · Santosh Shilimkar

On 5/14/2011 9:21 PM, Thomas Gleixner wrote:
Just for my understanding, the clockevents_reconfigure() needs to be called with interrupts disabled on that CPU as part of the CPUFREQ notifiers. I assume the right place is do it in POST notifier after the CPU clock and hence TWD clock is updated. Is that right ?

Yes.

Quoted 8 lines

Is it safe to only call it in POST? ?If the frequency is increasing, and the TWD is not updated until after the CPU frequency has changed, it is possible for a clockevent to fire too early. ?Will that cause problems, or does the clockevent code check against a clocksource to ensure the desired time has been reached? ?If that is OK, it drastically simplifies the code, because the driver only needs to know the current TWD frequency, not predict a future TWD frequency.

This was the exact reason I asked this question. As discussed earlier on this thread, we observed drift in ticks especially at lowest and highest clock-points. But they way I understood is clockevents_reconfigure() will block those additional ticks at least during the reconfiguration of the clock-event.

Quoted 11 lines
Quoted 5 lines
Quoted 3 lines

Since there is need to call this API in interrupt disable context, does it make sense to take care of it inside the API itself instead of relying on caller fn ?

Hmm, no strong opinion

For SMP TWD, the caller will always be in interrupt disabled mode, because the cpufreq notifier will get called on a random cpu, so smp_call_function_single will be used to transition to the correct cpu, which disables interrupts.

Ok. So it's indirectly taken care then.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The arch's where the per CPU TWD's share clock, per-cpu clock-events should be reconfigured on all CPUs, whenever the parent(CPU) clock has changed using some thing like smp_call_function_any() etc. Is that right understanding?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Yes. If that's a common requirement we should move that to core code.

Santosh, are you suggesting the TWD be updated from the clock framework instead of the cpufreq notifier?

That's where I was kind of leaning to. Basically doing this in common core code at one place and possibly outside the ARM TWD library. You might get same requirement on other arch's in future.

But right now, there is no common clock place, and even if there was, there is no plan that I know of for a clock notifier, which is what would be required here.

Quoted 14 lines
Quoted 5 lines

I believe ARMv7 requires all CPUs to run at the same frequency, so it would be possible to do this in the core code somewhere, but A15 has fixed frequency counters, and all SMP Cortex-A9s I've seen use the SMP TWD driver, so in practice this may end up being the only user.

Yes but the code managing the architectural timer(A15) and TWD(A9) is different. But I understand your point about the usage and it might be limited to CA9 at this point of time.

Quoted 5 lines

It would be possible for the clockevent to have a flag CLOCKEVENT_EVT_FEAT_SCALES_WITH_CPU, which registers a cpufreq notifier, if there were any other users.

Quoted 4 lines

Something like this is better to get better clarity on the hardware behavior. O.w we will have piece of code in TWD library which needs proper documentation about the usage of likes of smp_call_function_single().

This is harder than I made it sound, unless the clockevent code took a struct clk as well. Something needs to get the frequency of the smp_twd clock and pass it in to clockevents_reconfigure.

I will post an RFC patch that uses a clock to call clockevents_reconfigure from a cpufreq notifier in smp_twd.c.