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
83 unsigned int use_deepest_state:1;83 unsigned int use_deepest_state:1;
84 unsigned int poll_time_limit:1;84 unsigned int poll_time_limit:1;
85 unsigned int cpu;85 unsigned int cpu;
86 ktime_t next_hrtimer;
86 87
87 int last_residency;88 int last_residency;
88 struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];89 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
122extern void tick_nohz_idle_exit(void);122extern void tick_nohz_idle_exit(void);
123extern void tick_nohz_irq_exit(void);123extern void tick_nohz_irq_exit(void);
124extern bool tick_nohz_idle_got_tick(void);124extern bool tick_nohz_idle_got_tick(void);
125extern ktime_t tick_nohz_get_next_hrtimer(void);
125extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);126extern ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next);
126extern unsigned long tick_nohz_get_idle_calls(void);127extern unsigned long tick_nohz_get_idle_calls(void);
127extern unsigned long tick_nohz_get_idle_calls_cpu(int cpu);128extern 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
145static inline void tick_nohz_idle_enter(void) { }146static inline void tick_nohz_idle_enter(void) { }
146static inline void tick_nohz_idle_exit(void) { }147static inline void tick_nohz_idle_exit(void) { }
147static inline bool tick_nohz_idle_got_tick(void) { return false; }148static inline bool tick_nohz_idle_got_tick(void) { return false; }
148 149static 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}
149static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)154static inline ktime_t tick_nohz_get_sleep_length(ktime_t *delta_next)
150{155{
151 *delta_next = TICK_NSEC;156 *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