Blame view

drivers/cpuidle/governor.c 2.47 KB
4f86d3a8e   Len Brown   cpuidle: consolid...
1
2
3
4
5
6
7
8
9
  /*
   * governor.c - governor support
   *
   * (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.
   */
0fc784fb0   Rafael J. Wysocki   cpuidle: governor...
10
  #include <linux/cpu.h>
4f86d3a8e   Len Brown   cpuidle: consolid...
11
  #include <linux/cpuidle.h>
0fc784fb0   Rafael J. Wysocki   cpuidle: governor...
12
13
  #include <linux/mutex.h>
  #include <linux/pm_qos.h>
4f86d3a8e   Len Brown   cpuidle: consolid...
14
15
16
17
18
19
20
21
22
23
  
  #include "cpuidle.h"
  
  LIST_HEAD(cpuidle_governors);
  struct cpuidle_governor *cpuidle_curr_governor;
  
  /**
   * __cpuidle_find_governor - finds a governor of the specified name
   * @str: the name
   *
21ae2956c   Uwe Kleine-König   tree-wide: fix ty...
24
   * Must be called with cpuidle_lock acquired.
4f86d3a8e   Len Brown   cpuidle: consolid...
25
26
27
28
29
30
   */
  static struct cpuidle_governor * __cpuidle_find_governor(const char *str)
  {
  	struct cpuidle_governor *gov;
  
  	list_for_each_entry(gov, &cpuidle_governors, governor_list)
913366409   Rasmus Villemoes   cpuidle: Replace ...
31
  		if (!strncasecmp(str, gov->name, CPUIDLE_NAME_LEN))
4f86d3a8e   Len Brown   cpuidle: consolid...
32
33
34
35
36
37
38
39
  			return gov;
  
  	return NULL;
  }
  
  /**
   * cpuidle_switch_governor - changes the governor
   * @gov: the new target governor
21ae2956c   Uwe Kleine-König   tree-wide: fix ty...
40
   * Must be called with cpuidle_lock acquired.
4f86d3a8e   Len Brown   cpuidle: consolid...
41
42
43
44
   */
  int cpuidle_switch_governor(struct cpuidle_governor *gov)
  {
  	struct cpuidle_device *dev;
3cfd68b5b   gaurav jindal   cpuidle: Avoid NU...
45
46
  	if (!gov)
  		return -EINVAL;
4f86d3a8e   Len Brown   cpuidle: consolid...
47
48
49
50
51
52
53
54
  	if (gov == cpuidle_curr_governor)
  		return 0;
  
  	cpuidle_uninstall_idle_handler();
  
  	if (cpuidle_curr_governor) {
  		list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
  			cpuidle_disable_device(dev);
4f86d3a8e   Len Brown   cpuidle: consolid...
55
56
57
58
59
  	}
  
  	cpuidle_curr_governor = gov;
  
  	if (gov) {
4f86d3a8e   Len Brown   cpuidle: consolid...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  		list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
  			cpuidle_enable_device(dev);
  		cpuidle_install_idle_handler();
  		printk(KERN_INFO "cpuidle: using governor %s
  ", gov->name);
  	}
  
  	return 0;
  }
  
  /**
   * cpuidle_register_governor - registers a governor
   * @gov: the governor
   */
  int cpuidle_register_governor(struct cpuidle_governor *gov)
  {
  	int ret = -EEXIST;
  
  	if (!gov || !gov->select)
  		return -EINVAL;
62027aea2   Len Brown   cpuidle: create b...
80
81
  	if (cpuidle_disabled())
  		return -ENODEV;
4f86d3a8e   Len Brown   cpuidle: consolid...
82
83
84
85
86
87
88
89
90
91
92
93
  	mutex_lock(&cpuidle_lock);
  	if (__cpuidle_find_governor(gov->name) == NULL) {
  		ret = 0;
  		list_add_tail(&gov->governor_list, &cpuidle_governors);
  		if (!cpuidle_curr_governor ||
  		    cpuidle_curr_governor->rating < gov->rating)
  			cpuidle_switch_governor(gov);
  	}
  	mutex_unlock(&cpuidle_lock);
  
  	return ret;
  }
0fc784fb0   Rafael J. Wysocki   cpuidle: governor...
94
95
96
97
98
99
100
101
102
103
104
105
106
  
  /**
   * cpuidle_governor_latency_req - Compute a latency constraint for CPU
   * @cpu: Target CPU
   */
  int cpuidle_governor_latency_req(unsigned int cpu)
  {
  	int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
  	struct device *device = get_cpu_device(cpu);
  	int device_req = dev_pm_qos_raw_read_value(device);
  
  	return device_req < global_req ? device_req : global_req;
  }