diff mbox

[08/14] timer: Export next wake up of a CPU

Message ID 1466624209-27432-9-git-send-email-lina.iyer@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Lina Iyer June 22, 2016, 7:36 p.m. UTC
Knowing the sleep length of the CPU is useful for the power state
determination on idle. However, when the common sleep time between
multiple CPUs is needed, the sleep length of a CPU is not useful.

By reading the next wake up event of a CPU, governors can determine the
first CPU to wake up (due to timer) amongst a cluster of CPUs and the
sleep time available between the last CPU to idle and the first CPU to
resume. This information is useful to determine if the caches and other
common hardware blocks can also be put in idle during this common period
of inactivity.

Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Lina Iyer <lina.iyer@linaro.org>
---
 include/linux/tick.h     | 10 ++++++++++
 kernel/time/tick-sched.c | 13 +++++++++++++
 2 files changed, 23 insertions(+)

Comments

Kevin Hilman July 26, 2016, 6:26 p.m. UTC | #1
Lina Iyer <lina.iyer@linaro.org> writes:

> Knowing the sleep length of the CPU is useful for the power state
> determination on idle. However, when the common sleep time between
> multiple CPUs is needed, the sleep length of a CPU is not useful.

You need more about "why" it's not useful.  e.g. CPU sleep length is
relative to when that CPU entered idle, whereas when trying to determine
cluster sleep time, absolute times are needed, like dev->next_event.

> By reading the next wake up event of a CPU, governors can determine the
> first CPU to wake up (due to timer) amongst a cluster of CPUs and the
> sleep time available between the last CPU to idle and the first CPU to
> resume. This information is useful to determine if the caches and other
> common hardware blocks can also be put in idle during this common period
> of inactivity.
>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Lina Iyer <lina.iyer@linaro.org>

Otherwise, looks OK to me.

Reviewed-by: Kevin Hilman <khilman@baylibre.com>

> ---
>  include/linux/tick.h     | 10 ++++++++++
>  kernel/time/tick-sched.c | 13 +++++++++++++
>  2 files changed, 23 insertions(+)
>
> diff --git a/include/linux/tick.h b/include/linux/tick.h
> index 62be0786..9535141 100644
> --- a/include/linux/tick.h
> +++ b/include/linux/tick.h
> @@ -117,6 +117,7 @@ extern void tick_nohz_idle_enter(void);
>  extern void tick_nohz_idle_exit(void);
>  extern void tick_nohz_irq_exit(void);
>  extern ktime_t tick_nohz_get_sleep_length(void);
> +extern ktime_t tick_nohz_get_next_wakeup(int cpu);
>  extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
>  extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
>  #else /* !CONFIG_NO_HZ_COMMON */
> @@ -131,6 +132,15 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
>  
>  	return len;
>  }
> +
> +static inline ktime_t tick_nohz_get_next_wakeup(int cpu)
> +{
> +	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
> +
> +	/* Next wake up is the tick period, assume it starts now */
> +	return ktime_add(len, ktime_get());
> +}
> +
>  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
>  static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
>  #endif /* !CONFIG_NO_HZ_COMMON */
> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
> index 536ada8..addf3235 100644
> --- a/kernel/time/tick-sched.c
> +++ b/kernel/time/tick-sched.c
> @@ -979,6 +979,19 @@ ktime_t tick_nohz_get_sleep_length(void)
>  	return ts->sleep_length;
>  }
>  
> +/**
> + * tick_nohz_get_next_wakeup - return the next wake up of the CPU
> + *
> + * Called with interrupts disabled on the cpu
> + */
> +ktime_t tick_nohz_get_next_wakeup(int cpu)
> +{
> +	struct clock_event_device *dev =
> +			per_cpu(tick_cpu_device.evtdev, cpu);
> +
> +	return dev->next_event;
> +}
> +
>  static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
>  {
>  #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
Thomas Gleixner July 27, 2016, 9:14 a.m. UTC | #2
On Wed, 22 Jun 2016, Lina Iyer wrote:
> +static inline ktime_t tick_nohz_get_next_wakeup(int cpu)
> +{
> +	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
> +
> +	/* Next wake up is the tick period, assume it starts now */
> +	return ktime_add(len, ktime_get());

  return tick_next_period;

Will tell you the point where the next tick interrupt is due.

> +}
> +
>  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
>  static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
>  #endif /* !CONFIG_NO_HZ_COMMON */
> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
> index 536ada8..addf3235 100644
> --- a/kernel/time/tick-sched.c
> +++ b/kernel/time/tick-sched.c
> @@ -979,6 +979,19 @@ ktime_t tick_nohz_get_sleep_length(void)
>  	return ts->sleep_length;
>  }
>  
> +/**
> + * tick_nohz_get_next_wakeup - return the next wake up of the CPU
> + *
> + * Called with interrupts disabled on the cpu

So why are you handing in the (undocumented) cpu argument if its called on
that cpu anyway?

> + */
> +ktime_t tick_nohz_get_next_wakeup(int cpu)
> +{
> +	struct clock_event_device *dev =
> +			per_cpu(tick_cpu_device.evtdev, cpu);
> +
> +	return dev->next_event;

Then this becomes

     return __this_cpu_read(tick_cpu_device.evtdev)->nextevt;

Thanks,

	tglx
Lina Iyer July 27, 2016, 3:04 p.m. UTC | #3
On Wed, Jul 27 2016 at 03:16 -0600, Thomas Gleixner wrote:
>On Wed, 22 Jun 2016, Lina Iyer wrote:
>> +static inline ktime_t tick_nohz_get_next_wakeup(int cpu)
>> +{
>> +	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
>> +
>> +	/* Next wake up is the tick period, assume it starts now */
>> +	return ktime_add(len, ktime_get());
>
>  return tick_next_period;
>
>Will tell you the point where the next tick interrupt is due.
>
That definitely is better, will change.

>> +}
>> +
>>  static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
>>  static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
>>  #endif /* !CONFIG_NO_HZ_COMMON */
>> diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
>> index 536ada8..addf3235 100644
>> --- a/kernel/time/tick-sched.c
>> +++ b/kernel/time/tick-sched.c
>> @@ -979,6 +979,19 @@ ktime_t tick_nohz_get_sleep_length(void)
>>  	return ts->sleep_length;
>>  }
>>
>> +/**
>> + * tick_nohz_get_next_wakeup - return the next wake up of the CPU
>> + *
>> + * Called with interrupts disabled on the cpu
>
>So why are you handing in the (undocumented) cpu argument if its called on
>that cpu anyway?
>
Oh, my comment is very misleading. The function may be called from any
CPU for any other CPU. It should be more like "Called when the
interrupts are disabled on the CPU". I guess that doesn't make sense
either. I will remove this comment.

Thanks,
Lina

>> + */
>> +ktime_t tick_nohz_get_next_wakeup(int cpu)
>> +{
>> +	struct clock_event_device *dev =
>> +			per_cpu(tick_cpu_device.evtdev, cpu);
>> +
>> +	return dev->next_event;
>
>Then this becomes
>
>     return __this_cpu_read(tick_cpu_device.evtdev)->nextevt;
>
>Thanks,
>
>	tglx
diff mbox

Patch

diff --git a/include/linux/tick.h b/include/linux/tick.h
index 62be0786..9535141 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -117,6 +117,7 @@  extern void tick_nohz_idle_enter(void);
 extern void tick_nohz_idle_exit(void);
 extern void tick_nohz_irq_exit(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
+extern ktime_t tick_nohz_get_next_wakeup(int cpu);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
 extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
 #else /* !CONFIG_NO_HZ_COMMON */
@@ -131,6 +132,15 @@  static inline ktime_t tick_nohz_get_sleep_length(void)
 
 	return len;
 }
+
+static inline ktime_t tick_nohz_get_next_wakeup(int cpu)
+{
+	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
+
+	/* Next wake up is the tick period, assume it starts now */
+	return ktime_add(len, ktime_get());
+}
+
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
 static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
 #endif /* !CONFIG_NO_HZ_COMMON */
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 536ada8..addf3235 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -979,6 +979,19 @@  ktime_t tick_nohz_get_sleep_length(void)
 	return ts->sleep_length;
 }
 
+/**
+ * tick_nohz_get_next_wakeup - return the next wake up of the CPU
+ *
+ * Called with interrupts disabled on the cpu
+ */
+ktime_t tick_nohz_get_next_wakeup(int cpu)
+{
+	struct clock_event_device *dev =
+			per_cpu(tick_cpu_device.evtdev, cpu);
+
+	return dev->next_event;
+}
+
 static void tick_nohz_account_idle_ticks(struct tick_sched *ts)
 {
 #ifndef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE