···3232static int enabled_devices;3333static int off __read_mostly;3434static int initialized __read_mostly;3535+static bool use_deepest_state __read_mostly;35363637int cpuidle_disabled(void)3738{···6665}67666867/**6969- * cpuidle_enabled - check if the cpuidle framework is ready7070- * @dev: cpuidle device for this cpu7171- * @drv: cpuidle driver for this cpu6868+ * cpuidle_use_deepest_state - Enable/disable the "deepest idle" mode.6969+ * @enable: Whether enable or disable the feature.7270 *7373- * Return 0 on success, otherwise:7474- * -NODEV : the cpuidle framework is not available7575- * -EBUSY : the cpuidle framework is not initialized7171+ * If the "deepest idle" mode is enabled, cpuidle will ignore the governor and7272+ * always use the state with the greatest exit latency (out of the states that7373+ * are not disabled).7474+ *7575+ * This function can only be called after cpuidle_pause() to avoid races.7676 */7777-int cpuidle_enabled(struct cpuidle_driver *drv, struct cpuidle_device *dev)7777+void cpuidle_use_deepest_state(bool enable)7878{7979- if (off || !initialized)8080- return -ENODEV;7979+ use_deepest_state = enable;8080+}81818282- if (!drv || !dev || !dev->enabled)8383- return -EBUSY;8282+/**8383+ * cpuidle_find_deepest_state - Find the state of the greatest exit latency.8484+ * @drv: cpuidle driver for a given CPU.8585+ * @dev: cpuidle device for a given CPU.8686+ */8787+static int cpuidle_find_deepest_state(struct cpuidle_driver *drv,8888+ struct cpuidle_device *dev)8989+{9090+ unsigned int latency_req = 0;9191+ int i, ret = CPUIDLE_DRIVER_STATE_START - 1;84928585- return 0;9393+ for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {9494+ struct cpuidle_state *s = &drv->states[i];9595+ struct cpuidle_state_usage *su = &dev->states_usage[i];9696+9797+ if (s->disabled || su->disable || s->exit_latency <= latency_req)9898+ continue;9999+100100+ latency_req = s->exit_latency;101101+ ret = i;102102+ }103103+ return ret;86104}8710588106/**···158138 */159139int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)160140{141141+ if (off || !initialized)142142+ return -ENODEV;143143+144144+ if (!drv || !dev || !dev->enabled)145145+ return -EBUSY;146146+147147+ if (unlikely(use_deepest_state))148148+ return cpuidle_find_deepest_state(drv, dev);149149+161150 return cpuidle_curr_governor->select(drv, dev);162151}163152···198169 */199170void cpuidle_reflect(struct cpuidle_device *dev, int index)200171{201201- if (cpuidle_curr_governor->reflect)172172+ if (cpuidle_curr_governor->reflect && !unlikely(use_deepest_state))202173 cpuidle_curr_governor->reflect(dev, index);203174}204175
+9-8
drivers/cpuidle/governors/menu.c
···296296 data->needs_update = 0;297297 }298298299299- data->last_state_idx = 0;299299+ data->last_state_idx = CPUIDLE_DRIVER_STATE_START - 1;300300301301 /* Special case when user has set very strict latency requirement */302302 if (unlikely(latency_req == 0))···309309310310311311 data->bucket = which_bucket(data->next_timer_us);312312-313313- /*314314- * if the correction factor is 0 (eg first time init or cpu hotplug315315- * etc), we actually want to start out with a unity factor.316316- */317317- if (data->correction_factor[data->bucket] == 0)318318- data->correction_factor[data->bucket] = RESOLUTION * DECAY;319312320313 /*321314 * Force the result of multiplication to be 64 bits even if both···459466 struct cpuidle_device *dev)460467{461468 struct menu_device *data = &per_cpu(menu_devices, dev->cpu);469469+ int i;462470463471 memset(data, 0, sizeof(struct menu_device));472472+473473+ /*474474+ * if the correction factor is 0 (eg first time init or cpu hotplug475475+ * etc), we actually want to start out with a unity factor.476476+ */477477+ for(i = 0; i < BUCKETS; i++)478478+ data->correction_factor[i] = RESOLUTION * DECAY;464479465480 return 0;466481}
···101101 rcu_idle_enter();102102103103 /*104104- * Check if the cpuidle framework is ready, otherwise fallback105105- * to the default arch specific idle method104104+ * Ask the cpuidle framework to choose a convenient idle state.105105+ * Fall back to the default arch specific idle method on errors.106106 */107107- ret = cpuidle_enabled(drv, dev);107107+ next_state = cpuidle_select(drv, dev);108108109109- if (!ret) {110110- /*111111- * Ask the governor to choose an idle state it thinks112112- * it is convenient to go to. There is *always* a113113- * convenient idle state114114- */115115- next_state = cpuidle_select(drv, dev);116116-109109+ ret = next_state;110110+ if (ret >= 0) {117111 /*118112 * The idle task must be scheduled, it is pointless to119113 * go to idle, just update no idle residency and get···134140 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,135141 &dev->cpu);136142137137- if (!ret) {143143+ if (ret >= 0) {138144 trace_cpu_idle_rcuidle(next_state, dev->cpu);139145140146 /*···169175 * We can't use the cpuidle framework, let's use the default170176 * idle routine171177 */172172- if (ret)178178+ if (ret < 0)173179 arch_cpu_idle();174180175181 __current_set_polling();