Skip to contentSkip to conversation

clockevents: Ignore C3STOP when CPUIdle is disabled

PATCH/RFC Magnus Damm 2 participants 9 messages Jun 18, 2013 – Jun 19, 2013

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

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Not-Yet-Signed-off-by Magnus Damm <[email protected]>

---

An earlier ARM arch timer specific version of this patch was posted yesterday as:
"[PATCH/RFC] arm: arch_timer: Do not set C3STOP in case CPU_IDLE=n"

Many thanks to Mark Rutland for his kind feedback.

 kernel/time/tick-broadcast.c |    8 ++++----
 kernel/time/tick-common.c    |    2 +-
 kernel/time/tick-internal.h  |   11 +++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -4
@@ -71,7 +71,7 @@ int tick_check_broadcast_device(struct c
 	if ((dev->features & CLOCK_EVT_FEAT_DUMMY) ||
 	    (tick_broadcast_device.evtdev &&
 	     tick_broadcast_device.evtdev->rating >= dev->rating) ||
-	     (dev->features & CLOCK_EVT_FEAT_C3STOP))
+	     tick_device_may_c3stop(dev))
 		return 0;
 
 	clockevents_exchange_device(tick_broadcast_device.evtdev, dev);
@@ -146,7 +146,7 @@ int tick_device_uses_broadcast(struct cl
 		 * feature and the cpu is marked in the broadcast mask
 		 * then clear the broadcast bit.
 		 */
-		if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+		if (!tick_device_may_c3stop(dev)) {
 			int cpu = smp_processor_id();
 			cpumask_clear_cpu(cpu, tick_broadcast_mask);
 			tick_broadcast_clear_oneshot(cpu);
@@ -270,7 +270,7 @@ static void tick_do_broadcast_on_off(uns
 	/*
 	 * Is the device not affected by the powerstate ?
 	 */
-	if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!dev || !tick_device_may_c3stop(dev))
 		goto out;
 
 	if (!tick_device_is_functional(dev))
@@ -568,7 +568,7 @@ void tick_broadcast_oneshot_control(unsi
 	td = &per_cpu(tick_cpu_device, cpu);
 	dev = td->evtdev;
 
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return;
 
 	bc = tick_broadcast_device.evtdev;
kernel/time/tick-common.c +1 -1
@@ -52,7 +52,7 @@ int tick_is_oneshot_available(void)
 
 	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
 		return 0;
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return 1;
 	return tick_broadcast_oneshot_available();
 }
kernel/time/tick-internal.h +11 -0
@@ -141,6 +141,17 @@ static inline int tick_device_is_functio
 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
 }
 
+/*
+ * Check, if the device has C3STOP behavior and CPU Idle is enabled
+ */
+static inline bool tick_device_may_c3stop(struct clock_event_device *dev)
+{
+	/* The C3 sleep mode can only trigger when CPU Idle is enabled,
+	 * so if CPU Idle is disabled then the C3STOP flag can be ignored */
+	return (IS_ENABLED(CONFIG_CPU_IDLE) &&
+		(dev->features & CLOCK_EVT_FEAT_C3STOP));
+}
+
 #endif
 
 extern void do_timer(unsigned long ticks);
#1 lore raw
Quoted 24 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

Quoted 7 lines

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Do we need a broadcast timer when cpuidle is not compiled in the kernel ?

Quoted 89 lines
Not-Yet-Signed-off-by Magnus Damm <[email protected]>

---

An earlier ARM arch timer specific version of this patch was posted yesterday as:
"[PATCH/RFC] arm: arch_timer: Do not set C3STOP in case CPU_IDLE=n"

Many thanks to Mark Rutland for his kind feedback.

 kernel/time/tick-broadcast.c |    8 ++++----
 kernel/time/tick-common.c    |    2 +-
 kernel/time/tick-internal.h  |   11 +++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -4
@@ -71,7 +71,7 @@ int tick_check_broadcast_device(struct c
 	if ((dev->features & CLOCK_EVT_FEAT_DUMMY) ||
 	    (tick_broadcast_device.evtdev &&
 	     tick_broadcast_device.evtdev->rating >= dev->rating) ||
-	     (dev->features & CLOCK_EVT_FEAT_C3STOP))
+	     tick_device_may_c3stop(dev))
 		return 0;
 
 	clockevents_exchange_device(tick_broadcast_device.evtdev, dev);
@@ -146,7 +146,7 @@ int tick_device_uses_broadcast(struct cl
 		 * feature and the cpu is marked in the broadcast mask
 		 * then clear the broadcast bit.
 		 */
-		if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+		if (!tick_device_may_c3stop(dev)) {
 			int cpu = smp_processor_id();
 			cpumask_clear_cpu(cpu, tick_broadcast_mask);
 			tick_broadcast_clear_oneshot(cpu);
@@ -270,7 +270,7 @@ static void tick_do_broadcast_on_off(uns
 	/*
 	 * Is the device not affected by the powerstate ?
 	 */
-	if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!dev || !tick_device_may_c3stop(dev))
 		goto out;
 
 	if (!tick_device_is_functional(dev))
@@ -568,7 +568,7 @@ void tick_broadcast_oneshot_control(unsi
 	td = &per_cpu(tick_cpu_device, cpu);
 	dev = td->evtdev;
 
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return;
 
 	bc = tick_broadcast_device.evtdev;
kernel/time/tick-common.c +1 -1
@@ -52,7 +52,7 @@ int tick_is_oneshot_available(void)
 
 	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
 		return 0;
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return 1;
 	return tick_broadcast_oneshot_available();
 }
kernel/time/tick-internal.h +11 -1
@@ -141,6 +141,17 @@ static inline int tick_device_is_functio
 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
 }
 
+/*
+ * Check, if the device has C3STOP behavior and CPU Idle is enabled
+ */
+static inline bool tick_device_may_c3stop(struct clock_event_device *dev)
+{
+	/* The C3 sleep mode can only trigger when CPU Idle is enabled,
+	 * so if CPU Idle is disabled then the C3STOP flag can be ignored */
+	return (IS_ENABLED(CONFIG_CPU_IDLE) &&
+		(dev->features & CLOCK_EVT_FEAT_C3STOP));
+}
+
 #endif
 
 extern void do_timer(unsigned long ticks);
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

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
#2 lore raw
Quoted 30 lines · Daniel Lezcano
Quoted 29 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

Quoted 4 lines
Quoted 2 lines

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Do we need a broadcast timer when cpuidle is not compiled in the kernel ?

Yes, if there is no per-cpu timer available. It depends on what the SMP support code for a particular SoC or architecture happen to enable.

/ magnus

#3 lore raw
Quoted 32 lines · Magnus Damm
Quoted 30 lines · Daniel Lezcano
Quoted 29 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Do we need a broadcast timer when cpuidle is not compiled in the kernel ?

Yes, if there is no per-cpu timer available. It depends on what the SMP support code for a particular SoC or architecture happen to enable.

Ok thanks for the information.

There is here a multiple occurrence of the information "the timer will stop when power is saved": CLOCK_EVT_FEAT_C3STOP and CPUIDLE_FLAG_TIMER_STOP, so I am wondering if some code simplification couldn't be done before your patch.

The function:

tick_broadcast_oneshot_control is called from clockevents_notify. This one is called from the cpuidle framework or the back-end cpuidle driver. The caller knows the timer will be stop and this is why it is switching to the broadcast mode. But we have a sanity check in tick_broadcast_oneshot_control function:

        if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
                return;

In other words, CPUIDLE_FLAG_TIMER_STOP will tell the framework to call clockevents_notify and the tick broadcast code will re-check the device will effectively go down. IMHO, we can get rid of this check.

The same happens for the tick_do_broadcast_on_off function.

That reduces the number of C3STOP usage.

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
#6 lore raw
In reply to Magnus Damm
Quoted 98 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Not-Yet-Signed-off-by Magnus Damm <[email protected]>

---

An earlier ARM arch timer specific version of this patch was posted yesterday as:
"[PATCH/RFC] arm: arch_timer: Do not set C3STOP in case CPU_IDLE=n"

Many thanks to Mark Rutland for his kind feedback.

 kernel/time/tick-broadcast.c |    8 ++++----
 kernel/time/tick-common.c    |    2 +-
 kernel/time/tick-internal.h  |   11 +++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -4
@@ -71,7 +71,7 @@ int tick_check_broadcast_device(struct c
 	if ((dev->features & CLOCK_EVT_FEAT_DUMMY) ||
 	    (tick_broadcast_device.evtdev &&
 	     tick_broadcast_device.evtdev->rating >= dev->rating) ||
-	     (dev->features & CLOCK_EVT_FEAT_C3STOP))
+	     tick_device_may_c3stop(dev))
 		return 0;
 
 	clockevents_exchange_device(tick_broadcast_device.evtdev, dev);
@@ -146,7 +146,7 @@ int tick_device_uses_broadcast(struct cl
 		 * feature and the cpu is marked in the broadcast mask
 		 * then clear the broadcast bit.
 		 */
-		if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+		if (!tick_device_may_c3stop(dev)) {
 			int cpu = smp_processor_id();
 			cpumask_clear_cpu(cpu, tick_broadcast_mask);
 			tick_broadcast_clear_oneshot(cpu);
@@ -270,7 +270,7 @@ static void tick_do_broadcast_on_off(uns
 	/*
 	 * Is the device not affected by the powerstate ?
 	 */
-	if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!dev || !tick_device_may_c3stop(dev))
 		goto out;
 
 	if (!tick_device_is_functional(dev))
@@ -568,7 +568,7 @@ void tick_broadcast_oneshot_control(unsi
 	td = &per_cpu(tick_cpu_device, cpu);
 	dev = td->evtdev;
 
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return;
 
 	bc = tick_broadcast_device.evtdev;
kernel/time/tick-common.c +1 -1
@@ -52,7 +52,7 @@ int tick_is_oneshot_available(void)
 
 	if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
 		return 0;
-	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+	if (!tick_device_may_c3stop(dev))
 		return 1;
 	return tick_broadcast_oneshot_available();
 }

kernel/time/tick-internal.h static inline int tick_device_is_functio · line 147

Quoted 7 lines
kernel/time/tick-internal.h +4 -0
@@ -141,6 +141,17 @@ static inline int tick_device_is_functio
 	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
 }
 
+/*
+ * Check, if the device has C3STOP behavior and CPU Idle is enabled
+ */
+static inline bool tick_device_may_c3stop(struct clock_event_device *dev)

I prefer tick_device_is_reliable(struct clock_event_device *dev).

kernel/time/tick-internal.h static inline int tick_device_is_functio · line 153

Quoted 6 lines
kernel/time/tick-internal.h +6 -0
+{
+	/* The C3 sleep mode can only trigger when CPU Idle is enabled,
+	 * so if CPU Idle is disabled then the C3STOP flag can be ignored */
+	return (IS_ENABLED(CONFIG_CPU_IDLE) &&
+		(dev->features & CLOCK_EVT_FEAT_C3STOP));
+}

Preferably you may use the format:

#ifdef CONFIG_CPU_IDLE
static inline bool tick_device_is_reliable(struct clock_event_device *dev)

{
	return dev->features & CLOCK_EVT_FEAT_C3STOP;
}
#else
static inline bool tick_device_is_reliable(struct clock_event_device *dev)
{
	return true;
}

#endif

to conform the header style format already present in the file.

Quoted 7 lines
kernel/time/tick-internal.h +0 -1
 extern void do_timer(unsigned long ticks);
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

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
#4 lore raw
In reply to Daniel Lezcano

Hi Daniel,

Quoted 36 lines · Daniel Lezcano
Quoted 35 lines · Magnus Damm
Quoted 33 lines · Daniel Lezcano
Quoted 31 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Do we need a broadcast timer when cpuidle is not compiled in the kernel ?

Yes, if there is no per-cpu timer available. It depends on what the SMP support code for a particular SoC or architecture happen to enable.

Ok thanks for the information.

No problem. Thanks for your comments!

Quoted 4 lines

There is here a multiple occurrence of the information "the timer will stop when power is saved": CLOCK_EVT_FEAT_C3STOP and CPUIDLE_FLAG_TIMER_STOP, so I am wondering if some code simplification couldn't be done before your patch.

I'm sure it's possible to rearrange things in many ways, and the area that you point out indeed seems to have some overlap. Somehow describing which timers that stop during what CPUIdle sleep state would be nice to have. Also, today clock event drivers simply state C3STOP but there may be shallow sleep modes where the timer doesn't have to stop. It all seems a bit coarse grained to me as-is.

Quoted 11 lines

The function:

tick_broadcast_oneshot_control is called from clockevents_notify. This one is called from the cpuidle framework or the back-end cpuidle driver. The caller knows the timer will be stop and this is why it is switching to the broadcast mode. But we have a sanity check in tick_broadcast_oneshot_control function:

        if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
                return;
Quoted 7 lines

In other words, CPUIDLE_FLAG_TIMER_STOP will tell the framework to call clockevents_notify and the tick broadcast code will re-check the device will effectively go down. IMHO, we can get rid of this check.

The same happens for the tick_do_broadcast_on_off function.

That reduces the number of C3STOP usage.

That may very well be the case. Care to hack up a patch? =)

The goal with this patch is simply to make it possible to use high resolution timers if CPUIdle is disabled. Right now the ARM architected timer is sort of optimized for power, so it sets the C3STOP flag to say that on some SoCs during some sleep modes these timers may stop. My point is that this flag doesn't matter as long as CPUIdle is disabled.

Thanks,

/ magnus

#7 lore raw
In reply to Daniel Lezcano

Hi Daniel,

Quoted 102 lines · Daniel Lezcano
Quoted 101 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Not-Yet-Signed-off-by Magnus Damm <[email protected]>

---

An earlier ARM arch timer specific version of this patch was posted yesterday as:
"[PATCH/RFC] arm: arch_timer: Do not set C3STOP in case CPU_IDLE=n"

Many thanks to Mark Rutland for his kind feedback.

 kernel/time/tick-broadcast.c |    8 ++++----
 kernel/time/tick-common.c    |    2 +-
 kernel/time/tick-internal.h  |   11 +++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c 2013-06-18 15:36:21.000000000 +0900 renamed from kernel/time/tick-broadcast.c +4 -4
@@ -71,7 +71,7 @@ int tick_check_broadcast_device(struct c
      if ((dev->features & CLOCK_EVT_FEAT_DUMMY) ||
          (tick_broadcast_device.evtdev &&
           tick_broadcast_device.evtdev->rating >= dev->rating) ||
-          (dev->features & CLOCK_EVT_FEAT_C3STOP))
+          tick_device_may_c3stop(dev))
              return 0;
 
      clockevents_exchange_device(tick_broadcast_device.evtdev, dev);
@@ -146,7 +146,7 @@ int tick_device_uses_broadcast(struct cl
               * feature and the cpu is marked in the broadcast mask
               * then clear the broadcast bit.
               */
-             if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+             if (!tick_device_may_c3stop(dev)) {
                      int cpu = smp_processor_id();
                      cpumask_clear_cpu(cpu, tick_broadcast_mask);
                      tick_broadcast_clear_oneshot(cpu);
@@ -270,7 +270,7 @@ static void tick_do_broadcast_on_off(uns
      /*
       * Is the device not affected by the powerstate ?
       */
-     if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!dev || !tick_device_may_c3stop(dev))
              goto out;
 
      if (!tick_device_is_functional(dev))
@@ -568,7 +568,7 @@ void tick_broadcast_oneshot_control(unsi
      td = &per_cpu(tick_cpu_device, cpu);
      dev = td->evtdev;
 
-     if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!tick_device_may_c3stop(dev))
              return;
 
      bc = tick_broadcast_device.evtdev;
kernel/time/tick-common.c 2013-06-18 15:36:29.000000000 +0900 renamed from kernel/time/tick-common.c +1 -1
@@ -52,7 +52,7 @@ int tick_is_oneshot_available(void)
 
      if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
              return 0;
-     if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!tick_device_may_c3stop(dev))
              return 1;
      return tick_broadcast_oneshot_available();
 }
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +0 -0
@@ -141,6 +141,17 @@ static inline int tick_device_is_functio
      return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
 }
 
Quoted 6 lines

kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 static inline int tick_device_is_functio · line 147

Quoted 4 lines
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +4 -0
+/*
+ * Check, if the device has C3STOP behavior and CPU Idle is enabled
+ */
+static inline bool tick_device_may_c3stop(struct clock_event_device *dev)

I prefer tick_device_is_reliable(struct clock_event_device *dev).

Sure. I took the name from the flag, thought that made it easy to follow.

I wonder what the timekeeping maintainers prefer?

Quoted 19 lines

kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 static inline int tick_device_is_functio · line 153

Quoted 6 lines
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +6 -0
+{
+     /* The C3 sleep mode can only trigger when CPU Idle is enabled,
+      * so if CPU Idle is disabled then the C3STOP flag can be ignored */
+     return (IS_ENABLED(CONFIG_CPU_IDLE) &&
+             (dev->features & CLOCK_EVT_FEAT_C3STOP));
+}

Preferably you may use the format:

#ifdef CONFIG_CPU_IDLE
static inline bool tick_device_is_reliable(struct clock_event_device *dev)

{
        return dev->features & CLOCK_EVT_FEAT_C3STOP;
}
#else
static inline bool tick_device_is_reliable(struct clock_event_device *dev)
{
        return true;
}
Quoted 3 lines

#endif

to conform the header style format already present in the file.

I agree with you about following the same style. Actually, I wrote the code to follow the code right above the function, but I decided to return bool instead of int. I don't mind so much in general though, except trying to keep the code at least half well-commented and relatively compact.

So regarding stylistic things, sure, we can move around things. Question is just if this is acceptable or not. =)

Thanks,

/ magnus

#8 lore raw
Quoted 113 lines · Magnus Damm

Hi Daniel,

Quoted 102 lines · Daniel Lezcano
Quoted 101 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Not-Yet-Signed-off-by Magnus Damm <[email protected]>

---

An earlier ARM arch timer specific version of this patch was posted yesterday as:
"[PATCH/RFC] arm: arch_timer: Do not set C3STOP in case CPU_IDLE=n"

Many thanks to Mark Rutland for his kind feedback.

 kernel/time/tick-broadcast.c |    8 ++++----
 kernel/time/tick-common.c    |    2 +-
 kernel/time/tick-internal.h  |   11 +++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c 2013-06-18 15:36:21.000000000 +0900 renamed from kernel/time/tick-broadcast.c +4 -4
@@ -71,7 +71,7 @@ int tick_check_broadcast_device(struct c
      if ((dev->features & CLOCK_EVT_FEAT_DUMMY) ||
          (tick_broadcast_device.evtdev &&
           tick_broadcast_device.evtdev->rating >= dev->rating) ||
-          (dev->features & CLOCK_EVT_FEAT_C3STOP))
+          tick_device_may_c3stop(dev))
              return 0;
 
      clockevents_exchange_device(tick_broadcast_device.evtdev, dev);
@@ -146,7 +146,7 @@ int tick_device_uses_broadcast(struct cl
               * feature and the cpu is marked in the broadcast mask
               * then clear the broadcast bit.
               */
-             if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
+             if (!tick_device_may_c3stop(dev)) {
                      int cpu = smp_processor_id();
                      cpumask_clear_cpu(cpu, tick_broadcast_mask);
                      tick_broadcast_clear_oneshot(cpu);
@@ -270,7 +270,7 @@ static void tick_do_broadcast_on_off(uns
      /*
       * Is the device not affected by the powerstate ?
       */
-     if (!dev || !(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!dev || !tick_device_may_c3stop(dev))
              goto out;
 
      if (!tick_device_is_functional(dev))
@@ -568,7 +568,7 @@ void tick_broadcast_oneshot_control(unsi
      td = &per_cpu(tick_cpu_device, cpu);
      dev = td->evtdev;
 
-     if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!tick_device_may_c3stop(dev))
              return;
 
      bc = tick_broadcast_device.evtdev;
kernel/time/tick-common.c 2013-06-18 15:36:29.000000000 +0900 renamed from kernel/time/tick-common.c +1 -1
@@ -52,7 +52,7 @@ int tick_is_oneshot_available(void)
 
      if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT))
              return 0;
-     if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
+     if (!tick_device_may_c3stop(dev))
              return 1;
      return tick_broadcast_oneshot_available();
 }
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +0 -0
@@ -141,6 +141,17 @@ static inline int tick_device_is_functio
      return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
 }
 
Quoted 6 lines

kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 static inline int tick_device_is_functio · line 147

Quoted 4 lines
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +4 -0
+/*
+ * Check, if the device has C3STOP behavior and CPU Idle is enabled
+ */
+static inline bool tick_device_may_c3stop(struct clock_event_device *dev)

I prefer tick_device_is_reliable(struct clock_event_device *dev).

Quoted 3 lines

Sure. I took the name from the flag, thought that made it easy to follow.

I wonder what the timekeeping maintainers prefer?

Personally, I would prefer tick_device_is_reliable function instead of c3stop because this one is coming from the C-state Intel semantic. On the other architectures, the C-state does not make sense and, especially for ARM, you can have idle state corresponding to the index #1 where the timer is shutdown. This comment also apply to CLOCK_EVT_FEAT_C3STOP ... but this is diverging from the purpose of your patch.

Quoted 31 lines
Quoted 19 lines

kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 static inline int tick_device_is_functio · line 153

Quoted 6 lines
kernel/time/tick-internal.h 2013-06-18 15:40:10.000000000 +0900 renamed from kernel/time/tick-internal.h +6 -0
+{
+     /* The C3 sleep mode can only trigger when CPU Idle is enabled,
+      * so if CPU Idle is disabled then the C3STOP flag can be ignored */
+     return (IS_ENABLED(CONFIG_CPU_IDLE) &&
+             (dev->features & CLOCK_EVT_FEAT_C3STOP));
+}

Preferably you may use the format:

#ifdef CONFIG_CPU_IDLE
static inline bool tick_device_is_reliable(struct clock_event_device *dev)

{
        return dev->features & CLOCK_EVT_FEAT_C3STOP;
}
#else
static inline bool tick_device_is_reliable(struct clock_event_device *dev)
{
        return true;
}
Quoted 3 lines

#endif

to conform the header style format already present in the file.

I agree with you about following the same style. Actually, I wrote the code to follow the code right above the function, but I decided to return bool instead of int. I don't mind so much in general though, except trying to keep the code at least half well-commented and relatively compact.

So regarding stylistic things, sure, we can move around things. Question is just if this is acceptable or not. =)

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
#5 lore raw
In reply to Magnus Damm
Quoted 77 lines · Magnus Damm

Hi Daniel,

Quoted 36 lines · Daniel Lezcano
Quoted 35 lines · Magnus Damm
Quoted 33 lines · Daniel Lezcano
Quoted 31 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Introduce the function tick_device_may_c3stop() that ignores the C3STOP flag in case CPUIdle is disabled.

The C3STOP flag tells the system that a clock event device may be stopped during deep sleep, but if this will happen or not depends on things like if CPUIdle is enabled and if a CPUIdle driver is available.

This patch assumes that if CPUIdle is disabled then the sleep mode triggering C3STOP will never be entered. So by ignoring C3STOP when CPUIdle is disabled then it becomes possible to use high resolution timers with only per-cpu local timers - regardless if they have the C3STOP flag set or not.

Observed on the r8a73a4 SoC that at this point only uses ARM architected timers for clock event and clock sources.

Without this patch high resolution timers are run time disabled on the r8a73a4 SoC - this regardless of CPUIdle is disabled or not.

The less short term fix is to add support for more timers on the r8a73a4 SoC, but until CPUIdle support is enabled it must be possible to use high resoultion timers without additional timers.

I'd like to hear some feedback and also test this on more systems before merging the code, see the non-SOB below.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Do we need a broadcast timer when cpuidle is not compiled in the kernel ?

Yes, if there is no per-cpu timer available. It depends on what the SMP support code for a particular SoC or architecture happen to enable.

Ok thanks for the information.

No problem. Thanks for your comments!

Quoted 4 lines

There is here a multiple occurrence of the information "the timer will stop when power is saved": CLOCK_EVT_FEAT_C3STOP and CPUIDLE_FLAG_TIMER_STOP, so I am wondering if some code simplification couldn't be done before your patch.

I'm sure it's possible to rearrange things in many ways, and the area that you point out indeed seems to have some overlap. Somehow describing which timers that stop during what CPUIdle sleep state would be nice to have. Also, today clock event drivers simply state C3STOP but there may be shallow sleep modes where the timer doesn't have to stop. It all seems a bit coarse grained to me as-is.

Quoted 15 lines

The function:

tick_broadcast_oneshot_control is called from clockevents_notify. This one is called from the cpuidle framework or the back-end cpuidle driver. The caller knows the timer will be stop and this is why it is switching to the broadcast mode. But we have a sanity check in tick_broadcast_oneshot_control function:

        if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
                return;

In other words, CPUIDLE_FLAG_TIMER_STOP will tell the framework to call clockevents_notify and the tick broadcast code will re-check the device will effectively go down. IMHO, we can get rid of this check.

Quoted 5 lines
Quoted 3 lines

The same happens for the tick_do_broadcast_on_off function.

That reduces the number of C3STOP usage.

That may very well be the case. Care to hack up a patch? =)

No problem, I will write one as soon as I can.

Quoted 6 lines

The goal with this patch is simply to make it possible to use high resolution timers if CPUIdle is disabled. Right now the ARM architected timer is sort of optimized for power, so it sets the C3STOP flag to say that on some SoCs during some sleep modes these timers may stop. My point is that this flag doesn't matter as long as CPUIdle is disabled.

Yes, I understand. That makes sense.

Thanks
-- Daniel

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