diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2018-12-12 16:51:04 +0100 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2018-12-27 15:51:37 +0100 |
commit | eca8b839d92c150a57963547867251b4a8614d9b (patch) | |
tree | 36941781fad6015b69496e03fcf44d4bae1e72d4 | |
parent | 17838a143b3dc1573556c90f04e4c4b741042169 (diff) |
kernel/tick-sched: Provide a function to return the next timer event deadline
This function returns when an interrupt is supposed to happen on the
current CPU.
TODO: Consolidate with the very similar function below.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r-- | include/linux/timer.h | 2 | ||||
-rw-r--r-- | kernel/irq/predictor.c | 0 | ||||
-rw-r--r-- | kernel/time/tick-sched.c | 32 |
3 files changed, 34 insertions, 0 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h index 7b066fd38248..d66475263a63 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -204,6 +204,8 @@ unsigned long __round_jiffies_up_relative(unsigned long j, int cpu); unsigned long round_jiffies_up(unsigned long j); unsigned long round_jiffies_up_relative(unsigned long j); +u64 timer_next_event(void); + #ifdef CONFIG_HOTPLUG_CPU int timers_prepare_cpu(unsigned int cpu); int timers_dead_cpu(unsigned int cpu); diff --git a/kernel/irq/predictor.c b/kernel/irq/predictor.c new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/kernel/irq/predictor.c diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 69e673b88474..a1356e2fd0ee 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -16,6 +16,7 @@ #include <linux/hrtimer.h> #include <linux/interrupt.h> #include <linux/kernel_stat.h> +#include <linux/ktime.h> #include <linux/percpu.h> #include <linux/nmi.h> #include <linux/profile.h> @@ -1025,6 +1026,37 @@ bool tick_nohz_idle_got_tick(void) return false; } +/* + * timer_next_event - return the next timer deadline + */ +u64 timer_next_event(void) +{ + struct clock_event_device *dev; + struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + int cpu = smp_processor_id(); + ktime_t next_event = KTIME_MAX; + ktime_t ne; + + dev = __this_cpu_read(tick_cpu_device.evtdev); + + ne = dev->next_event; + if (ne < next_event) + next_event = ne; + + ne = tick_nohz_next_event(ts, cpu); + if (!ne) + goto out; + + if (ne < next_event) + next_event = ne; + + ne = hrtimer_next_event_without(&ts->sched_timer); + if (ne < next_event) + next_event = ne; +out: + return ktime_to_ns(next_event); +} + /** * tick_nohz_get_sleep_length - return the expected length of the current sleep * @delta_next: duration until the next event if the tick cannot be stopped |