History

cpuidle: Export the next timer expiration for CPUs

To be able to predict the sleep duration for a CPU entering idle, it is essential to know the expiration time of the next timer. Both the teo and the menu cpuidle governors already use this information for CPU idle state selection. Moving forward, a similar prediction needs to be made for a group of idle CPUs rather than for a single one and the following changes implement a new genpd governor for that purpose. In order to support that feature, add a new function called tick_nohz_get_next_hrtimer() that will return the next hrtimer expiration time of a given CPU to be invoked after deciding whether or not to stop the scheduler tick on that CPU. Make the cpuidle core call tick_nohz_get_next_hrtimer() right before invoking the ->enter() callback provided by the cpuidle driver for the given state and store its return value in the per-CPU struct cpuidle_device, so as to make it available to code outside of cpuidle. Note that at the point when cpuidle calls tick_nohz_get_next_hrtimer(), the governor's ->select() callback has already returned and indicated whether or not the tick should be stopped, so in fact the value returned by tick_nohz_get_next_hrtimer() always is the next hrtimer expiration time for the given CPU, possibly including the tick (if it hasn't been stopped).

Ulf Hansson committed 7 years ago

Commit 6f9b83a1 parent eb594b74 files · +36 −3Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/cpuidle.h +1 −0
  2. include/linux/tick.h +6 −1
include/linux/cpuidle.h+1−0
@@ -83,6 +83,7 @@ struct cpuidle_device { · 82 unmodified lines
8383 unsigned int use_deepest_state:1;
8484 unsigned int poll_time_limit:1;
8585 unsigned int cpu;
86+ ktime_t next_hrtimer;
8687
8788 int last_residency;
8889 struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];
include/linux/tick.h+6−1
@@ -122,6 +122,7 @@ extern void tick_nohz_idle_enter(void); · 121 unmodified lines
122122 extern void tick_nohz_idle_exit(void);
123123 extern void tick_nohz_irq_exit(void);
124124 extern bool tick_nohz_idle_got_tick(void);
125+extern ktime_t tick_nohz_get_next_hrtimer(void);
125126 extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);
126127 extern unsigned long tick_nohz_get_idle_calls(void);
127128 extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu);
@@ -145,7 +146,11 @@ static inline void tick_nohz_idle_restart_tick(void) { } · 17 unmodified lines
145146 static inline void tick_nohz_idle_enter(void) { }
146147 static inline void tick_nohz_idle_exit(void) { }
147148 static inline bool tick_nohz_idle_got_tick(void) { return false; }
148−
149+static inline ktime_t tick_nohz_get_next_hrtimer(void)
150+{
151+ /* Next wake up is the tick period, assume it starts now */
152+ return ktime_add(ktime_get(), TICK_NSEC);
153+}
149154 static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)
150155 {
151156 *delta_next = TICK_NSEC;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t