Skip to contentSkip to conversation

twd: Allow twd rescaling to match cpu frequency

PATCH In review Colin Cross 4 participants 6 messages Sep 2, 2010 – Nov 17, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 twd: Allow twd rescaling to match cpu frequency

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 relation between the cpu clock and the TWD clock, required to be an integer divider

Quoted 1 line

= 2 by the ARM spec. It also provides a function to be

called from cpufreq drivers to set the prescaler whenever the cpu frequency changes.

Also fixes a typo in the printk of the calibrated frequency.

Change-Id I45c76ae1ed501c40b94709c15834c8a0b6116c84
---
 arch/arm/include/asm/smp_twd.h |   19 +++++++++++++
 arch/arm/kernel/smp_twd.c      |   57 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 72 insertions(+), 4 deletions(-)
arch/arm/include/asm/smp_twd.h +19 -0
index 634f357..79aebe2 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,22 @@ void twd_timer_stop(void);
 int twd_timer_ack(void);
 void twd_timer_setup(struct clock_event_device *);
 
+/*
+ * Use this setup function on systems where the cpu clock frequency may
+ * change.  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.
+ */
+void twd_timer_setup_scalable(struct clock_event_device *,
+	unsigned long target_rate, unsigned int periphclk_prescaler);
+
+/*
+ * Recalculate the twd prescaler value when the cpu frequency changes. To
+ * prevent early timer interrupts, must be called before changing the cpu
+ * frequency if the frequency is increasing, or after if the frequency is
+ * decreasing.
+ */
+void twd_recalc_prescaler(unsigned long new_rate);
+
 #endif
arch/arm/kernel/smp_twd.c +53 -4

94 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

Hi Colin,

2010/9/2 Colin Cross <[email protected]>:

Quoted 6 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.

Quoted 6 lines

This patch provides a new initialization function that takes a target TWD frequency and the relation between the cpu clock and the TWD clock, required to be an integer divider

Quoted 1 line

= 2 by the ARM spec. ?It also provides a function to be

called from cpufreq drivers to set the prescaler whenever the cpu frequency changes.

What's the status of this patch?

We have basically the same problem so we'd really like a generic solution to this problem.

Our only comment is that we cannot see the reason for not using the CPUfreq notifiers as most scaling code is, but I assume there is some specific reason for this?

Unless something holds this back, could you post it to Russells patch tracker, we might have an add-on patch for the U8500 later.

Yours,
Linus Walleij

#2 lore raw

Hi,

Don't forget the other patches to make this work:

[ARM] twd: Always calibrate local timer [ARM] twd: Fix updating control register in set_mode [ARM] twd: Fix prescaler getting cleared by set_mode

/Harald Gustafsson
________________________________________
From: Linus Walleij [linus.ml.walleij at gmail.com]
Sent: Friday, November 12, 2010 1:39 PM
To: Colin Cross
Cc: linux-kernel at vger.kernel.org; linux-arm-kernel at lists.infradead.org; Russell King; srinidhi kasagar; Varun Swara; Catalin Marinas; Harald Gustafsson; Rickard ANDERSSON
Subject: Re: [PATCH] [ARM] twd: Allow twd rescaling to match cpu frequency

Hi Colin,

2010/9/2 Colin Cross <[email protected]>:

Quoted 6 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.

Quoted 6 lines

This patch provides a new initialization function that takes a target TWD frequency and the relation between the cpu clock and the TWD clock, required to be an integer divider

Quoted 1 line

= 2 by the ARM spec. It also provides a function to be

called from cpufreq drivers to set the prescaler whenever the cpu frequency changes.

What's the status of this patch?

We have basically the same problem so we'd really like a generic solution to this problem.

Our only comment is that we cannot see the reason for not using the CPUfreq notifiers as most scaling code is, but I assume there is some specific reason for this?

Unless something holds this back, could you post it to Russells patch tracker, we might have an add-on patch for the U8500 later.

Yours,
Linus Walleij

#3 lore raw
Quoted 7 lines · Harald Gustafsson

Hi,

Don't forget the other patches to make this work:

[ARM] twd: Always calibrate local timer [ARM] twd: Fix updating control register in set_mode [ARM] twd: Fix prescaler getting cleared by set_mode

... which have never been posted to this mailing list, so no one here knows of them.

#4 lore raw
Quoted 9 lines
Quoted 4 lines

Don't forget the other patches to make this work:

[ARM] twd: Always calibrate local timer [ARM] twd: Fix updating control register in set_mode [ARM] twd: Fix prescaler

getting cleared

Quoted 1 line

by set_mode

... which have never been posted to this mailing list, so no one here knows of them.

They are on the tegra branch git also authored by Colin. So I would suggest that Colin make all the changes into a new patch.

http://android.git.kernel.org/?p=kernel%2Ftegra.git&a=search&h=refs%2Fheads%2Flinux-tegra-2.6.35&st=commit&s=twd

/Harald

#5 lore raw
Quoted 7 lines · Harald Gustafsson
Quoted 7 lines
Quoted 4 lines

Don't forget the other patches to make this work:

[ARM] twd: Always calibrate local timer [ARM] twd: Fix updating control register in set_mode [ARM] twd: Fix prescaler

getting cleared

Quoted 1 line

by set_mode

Quoted 8 lines
Quoted 2 lines

... which have never been posted to this mailing list, so no one here knows of them.

They are on the tegra branch git also authored by Colin. So I would suggest that Colin make all the changes into a new patch.

http://android.git.kernel.org/?p=kernel%2Ftegra.git&a=search&h=refs%2Fheads%2Flinux-tegra-2.6.35&st=commit&s=twd

/Harald

I'm not happy with the current implementation, which is why it hasn't been posted. I'm planning to rewrite it with cpufreq notifiers, but that brings us back to the periphclk divider problem discussed in
http://comments.gmane.org/gmane.linux.ports.arm.kernel/91827

If the frequency is going to change, using clk_get_rate on periphclk is not sufficient, because the clock will not have been updated when the prechange cpufreq notifier is called. If the cpu frequency is increasing, the twd divider must be recalculated before the frequency changes to avoid timers expiring early. Either the clock used by the twd driver must be updated before prechange notifiers and after postchange notifiers, which is difficult to fit in to all the different implementations of the clock api, or the twd driver needs to know the ratio between the cpu frequency and the periphclk frequency.