aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/cpufreq.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-03-10 14:44:47 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-03-10 14:44:47 -0500
commitadaf9fcd136970e480d7ca834c0cf25ce922ea74 (patch)
tree36183592da27e413b79f60705132ed84dd34006e /drivers/cpufreq/cpufreq.c
parent08f511fd41c3afe303eb9b41bff0570f7c1b6937 (diff)
cpufreq: Move scheduler-related code to the sched directory
Create cpufreq.c under kernel/sched/ and move the cpufreq code related to the scheduler to that file and to sched.h. Redefine cpufreq_update_util() as a static inline function to avoid function calls at its call sites in the scheduler code (as suggested by Peter Zijlstra). Also move the definition of struct update_util_data and declaration of cpufreq_set_update_util_data() from include/linux/cpufreq.h to include/linux/sched.h. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r--drivers/cpufreq/cpufreq.c53
1 files changed, 0 insertions, 53 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 6eca12ab71d7..58e1a39b4d22 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -103,59 +103,6 @@ static struct cpufreq_driver *cpufreq_driver;
103static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 103static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
104static DEFINE_RWLOCK(cpufreq_driver_lock); 104static DEFINE_RWLOCK(cpufreq_driver_lock);
105 105
106static DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);
107
108/**
109 * cpufreq_set_update_util_data - Populate the CPU's update_util_data pointer.
110 * @cpu: The CPU to set the pointer for.
111 * @data: New pointer value.
112 *
113 * Set and publish the update_util_data pointer for the given CPU. That pointer
114 * points to a struct update_util_data object containing a callback function
115 * to call from cpufreq_update_util(). That function will be called from an RCU
116 * read-side critical section, so it must not sleep.
117 *
118 * Callers must use RCU-sched callbacks to free any memory that might be
119 * accessed via the old update_util_data pointer or invoke synchronize_sched()
120 * right after this function to avoid use-after-free.
121 */
122void cpufreq_set_update_util_data(int cpu, struct update_util_data *data)
123{
124 if (WARN_ON(data && !data->func))
125 return;
126
127 rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);
128}
129EXPORT_SYMBOL_GPL(cpufreq_set_update_util_data);
130
131/**
132 * cpufreq_update_util - Take a note about CPU utilization changes.
133 * @time: Current time.
134 * @util: Current utilization.
135 * @max: Utilization ceiling.
136 *
137 * This function is called by the scheduler on every invocation of
138 * update_load_avg() on the CPU whose utilization is being updated.
139 *
140 * It can only be called from RCU-sched read-side critical sections.
141 */
142void cpufreq_update_util(u64 time, unsigned long util, unsigned long max)
143{
144 struct update_util_data *data;
145
146#ifdef CONFIG_LOCKDEP
147 WARN_ON(debug_locks && !rcu_read_lock_sched_held());
148#endif
149
150 data = rcu_dereference_sched(*this_cpu_ptr(&cpufreq_update_util_data));
151 /*
152 * If this isn't inside of an RCU-sched read-side critical section, data
153 * may become NULL after the check below.
154 */
155 if (data)
156 data->func(data, time, util, max);
157}
158
159/* Flag to suspend/resume CPUFreq governors */ 106/* Flag to suspend/resume CPUFreq governors */
160static bool cpufreq_suspended; 107static bool cpufreq_suspended;
161 108