Release 4.11 drivers/cpuidle/governors/ladder.c
/*
* ladder.c - the residency ladder algorithm
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
* Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
*
* (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
* Shaohua Li <shaohua.li@intel.com>
* Adam Belay <abelay@novell.com>
*
* This code is licenced under the GPL.
*/
#include <linux/kernel.h>
#include <linux/cpuidle.h>
#include <linux/pm_qos.h>
#include <linux/jiffies.h>
#include <linux/tick.h>
#include <asm/io.h>
#include <linux/uaccess.h>
#define PROMOTION_COUNT 4
#define DEMOTION_COUNT 1
struct ladder_device_state {
struct {
u32 promotion_count;
u32 demotion_count;
u32 promotion_time;
u32 demotion_time;
}
threshold;
struct {
int promotion_count;
int demotion_count;
}
stats;
};
struct ladder_device {
struct ladder_device_state states[CPUIDLE_STATE_MAX];
int last_state_idx;
};
static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
/**
* ladder_do_selection - prepares private data for a state change
* @ldev: the ladder device
* @old_idx: the current state index
* @new_idx: the new target state index
*/
static inline void ladder_do_selection(struct ladder_device *ldev,
int old_idx, int new_idx)
{
ldev->states[old_idx].stats.promotion_count = 0;
ldev->states[old_idx].stats.demotion_count = 0;
ldev->last_state_idx = new_idx;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Len Brown | 50 | 100.00% | 1 | 100.00% |
Total | 50 | 100.00% | 1 | 100.00% |
/**
* ladder_select_state - selects the next state to enter
* @drv: cpuidle driver
* @dev: the CPU
*/
static int ladder_select_state(struct cpuidle_driver *drv,
struct cpuidle_device *dev)
{
struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
struct ladder_device_state *last_state;
int last_residency, last_idx = ldev->last_state_idx;
int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
/* Special case when user has set very strict latency requirement */
if (unlikely(latency_req == 0)) {
ladder_do_selection(ldev, last_idx, 0);
return 0;
}
last_state = &ldev->states[last_idx];
last_residency = cpuidle_get_last_residency(dev) - drv->states[last_idx].exit_latency;
/* consider promotion */
if (last_idx < drv->state_count - 1 &&
!drv->states[last_idx + 1].disabled &&
!dev->states_usage[last_idx + 1].disable &&
last_residency > last_state->threshold.promotion_time &&
drv->states[last_idx + 1].exit_latency <= latency_req) {
last_state->stats.promotion_count++;
last_state->stats.demotion_count = 0;
if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
ladder_do_selection(ldev, last_idx, last_idx + 1);
return last_idx + 1;
}
}
/* consider demotion */
if (last_idx > CPUIDLE_DRIVER_STATE_START &&
(drv->states[last_idx].disabled ||
dev->states_usage[last_idx].disable ||
drv->states[last_idx].exit_latency > latency_req)) {
int i;
for (i = last_idx - 1; i > CPUIDLE_DRIVER_STATE_START; i--) {
if (drv->states[i].exit_latency <= latency_req)
break;
}
ladder_do_selection(ldev, last_idx, i);
return i;
}
if (last_idx > CPUIDLE_DRIVER_STATE_START &&
last_residency < last_state->threshold.demotion_time) {
last_state->stats.demotion_count++;
last_state->stats.promotion_count = 0;
if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) {
ladder_do_selection(ldev, last_idx, last_idx - 1);
return last_idx - 1;
}
}
/* otherwise remain at the current state */
return last_idx;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Len Brown | 204 | 57.14% | 1 | 12.50% |
Venkatesh Pallipadi | 96 | 26.89% | 2 | 25.00% |
Carsten Emde | 23 | 6.44% | 1 | 12.50% |
Rafael J. Wysocki | 21 | 5.88% | 1 | 12.50% |
Deepthi Dharwar | 10 | 2.80% | 1 | 12.50% |
Christoph Lameter | 2 | 0.56% | 1 | 12.50% |
Mark Gross | 1 | 0.28% | 1 | 12.50% |
Total | 357 | 100.00% | 8 | 100.00% |
/**
* ladder_enable_device - setup for the governor
* @drv: cpuidle driver
* @dev: the CPU
*/
static int ladder_enable_device(struct cpuidle_driver *drv,
struct cpuidle_device *dev)
{
int i;
struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu);
struct ladder_device_state *lstate;
struct cpuidle_state *state;
ldev->last_state_idx = CPUIDLE_DRIVER_STATE_START;
for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
state = &drv->states[i];
lstate = &ldev->states[i];
lstate->stats.promotion_count = 0;
lstate->stats.demotion_count = 0;
lstate->threshold.promotion_count = PROMOTION_COUNT;
lstate->threshold.demotion_count = DEMOTION_COUNT;
if (i < drv->state_count - 1)
lstate->threshold.promotion_time = state->exit_latency;
if (i > CPUIDLE_DRIVER_STATE_START)
lstate->threshold.demotion_time = state->exit_latency;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Len Brown | 147 | 93.04% | 1 | 25.00% |
Deepthi Dharwar | 8 | 5.06% | 1 | 25.00% |
Mohammad Merajul Islam Molla | 2 | 1.27% | 1 | 25.00% |
Venkatesh Pallipadi | 1 | 0.63% | 1 | 25.00% |
Total | 158 | 100.00% | 4 | 100.00% |
/**
* ladder_reflect - update the correct last_state_idx
* @dev: the CPU
* @index: the index of actual state entered
*/
static void ladder_reflect(struct cpuidle_device *dev, int index)
{
struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
if (index > 0)
ldev->last_state_idx = index;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Deepthi Dharwar | 35 | 94.59% | 1 | 50.00% |
Christoph Lameter | 2 | 5.41% | 1 | 50.00% |
Total | 37 | 100.00% | 2 | 100.00% |
static struct cpuidle_governor ladder_governor = {
.name = "ladder",
.rating = 10,
.enable = ladder_enable_device,
.select = ladder_select_state,
.reflect = ladder_reflect,
};
/**
* init_ladder - initializes the governor
*/
static int __init init_ladder(void)
{
/*
* When NO_HZ is disabled, or when booting with nohz=off, the ladder
* governor is better so give it a higher rating than the menu
* governor.
*/
if (!tick_nohz_enabled)
ladder_governor.rating = 25;
return cpuidle_register_governor(&ladder_governor);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Len Brown | 16 | 57.14% | 1 | 50.00% |
Jean Delvare | 12 | 42.86% | 1 | 50.00% |
Total | 28 | 100.00% | 2 | 100.00% |
postcore_initcall(init_ladder);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Len Brown | 534 | 70.36% | 1 | 7.14% |
Venkatesh Pallipadi | 97 | 12.78% | 2 | 14.29% |
Deepthi Dharwar | 59 | 7.77% | 2 | 14.29% |
Carsten Emde | 23 | 3.03% | 1 | 7.14% |
Rafael J. Wysocki | 21 | 2.77% | 1 | 7.14% |
Jean Delvare | 15 | 1.98% | 1 | 7.14% |
Christoph Lameter | 4 | 0.53% | 1 | 7.14% |
Mohammad Merajul Islam Molla | 2 | 0.26% | 1 | 7.14% |
Daniel Lezcano | 1 | 0.13% | 1 | 7.14% |
Jean Pihet | 1 | 0.13% | 1 | 7.14% |
Mark Gross | 1 | 0.13% | 1 | 7.14% |
Linus Torvalds | 1 | 0.13% | 1 | 7.14% |
Total | 759 | 100.00% | 14 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.