Skip to content

Commit 5a4e5b7

Browse files
Quentin Perretdlezcano
authored andcommitted
thermal: cpu_cooling: Make the power-related code depend on IPA
The core CPU cooling infrastructure has power-related functions that have only one client: IPA. Since there can be no user of those functions if IPA is not compiled in, make sure to guard them with checks on CONFIG_THERMAL_GOV_POWER_ALLOCATOR to not waste space unnecessarily. Acked-by: Daniel Lezcano <[email protected]> Acked-by: Viresh Kumar <[email protected]> Suggested-by: Daniel Lezcano <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 27a47e4 commit 5a4e5b7

File tree

1 file changed

+81
-85
lines changed

1 file changed

+81
-85
lines changed

drivers/thermal/cpu_cooling.c

Lines changed: 81 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
*/
4848
struct freq_table {
4949
u32 frequency;
50+
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
5051
u32 power;
52+
#endif
5153
};
5254

5355
/**
@@ -95,8 +97,7 @@ static DEFINE_IDA(cpufreq_ida);
9597
static DEFINE_MUTEX(cooling_list_lock);
9698
static LIST_HEAD(cpufreq_cdev_list);
9799

98-
/* Below code defines functions to be used for cpufreq as cooling device */
99-
100+
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
100101
/**
101102
* get_level: Find the level for a particular frequency
102103
* @cpufreq_cdev: cpufreq_cdev for which the property is required
@@ -265,76 +266,6 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev,
265266
return (raw_cpu_power * cpufreq_cdev->last_load) / 100;
266267
}
267268

268-
/* cpufreq cooling device callback functions are defined below */
269-
270-
/**
271-
* cpufreq_get_max_state - callback function to get the max cooling state.
272-
* @cdev: thermal cooling device pointer.
273-
* @state: fill this variable with the max cooling state.
274-
*
275-
* Callback for the thermal cooling device to return the cpufreq
276-
* max cooling state.
277-
*
278-
* Return: 0 on success, an error code otherwise.
279-
*/
280-
static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
281-
unsigned long *state)
282-
{
283-
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
284-
285-
*state = cpufreq_cdev->max_level;
286-
return 0;
287-
}
288-
289-
/**
290-
* cpufreq_get_cur_state - callback function to get the current cooling state.
291-
* @cdev: thermal cooling device pointer.
292-
* @state: fill this variable with the current cooling state.
293-
*
294-
* Callback for the thermal cooling device to return the cpufreq
295-
* current cooling state.
296-
*
297-
* Return: 0 on success, an error code otherwise.
298-
*/
299-
static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
300-
unsigned long *state)
301-
{
302-
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
303-
304-
*state = cpufreq_cdev->cpufreq_state;
305-
306-
return 0;
307-
}
308-
309-
/**
310-
* cpufreq_set_cur_state - callback function to set the current cooling state.
311-
* @cdev: thermal cooling device pointer.
312-
* @state: set this variable to the current cooling state.
313-
*
314-
* Callback for the thermal cooling device to change the cpufreq
315-
* current cooling state.
316-
*
317-
* Return: 0 on success, an error code otherwise.
318-
*/
319-
static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
320-
unsigned long state)
321-
{
322-
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
323-
324-
/* Request state should be less than max_level */
325-
if (WARN_ON(state > cpufreq_cdev->max_level))
326-
return -EINVAL;
327-
328-
/* Check if the old cooling action is same as new cooling action */
329-
if (cpufreq_cdev->cpufreq_state == state)
330-
return 0;
331-
332-
cpufreq_cdev->cpufreq_state = state;
333-
334-
return freq_qos_update_request(&cpufreq_cdev->qos_req,
335-
cpufreq_cdev->freq_table[state].frequency);
336-
}
337-
338269
/**
339270
* cpufreq_get_requested_power() - get the current power
340271
* @cdev: &thermal_cooling_device pointer
@@ -478,22 +409,84 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
478409
power);
479410
return 0;
480411
}
412+
#endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
413+
414+
/* cpufreq cooling device callback functions are defined below */
415+
416+
/**
417+
* cpufreq_get_max_state - callback function to get the max cooling state.
418+
* @cdev: thermal cooling device pointer.
419+
* @state: fill this variable with the max cooling state.
420+
*
421+
* Callback for the thermal cooling device to return the cpufreq
422+
* max cooling state.
423+
*
424+
* Return: 0 on success, an error code otherwise.
425+
*/
426+
static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
427+
unsigned long *state)
428+
{
429+
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
430+
431+
*state = cpufreq_cdev->max_level;
432+
return 0;
433+
}
434+
435+
/**
436+
* cpufreq_get_cur_state - callback function to get the current cooling state.
437+
* @cdev: thermal cooling device pointer.
438+
* @state: fill this variable with the current cooling state.
439+
*
440+
* Callback for the thermal cooling device to return the cpufreq
441+
* current cooling state.
442+
*
443+
* Return: 0 on success, an error code otherwise.
444+
*/
445+
static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
446+
unsigned long *state)
447+
{
448+
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
449+
450+
*state = cpufreq_cdev->cpufreq_state;
451+
452+
return 0;
453+
}
454+
455+
/**
456+
* cpufreq_set_cur_state - callback function to set the current cooling state.
457+
* @cdev: thermal cooling device pointer.
458+
* @state: set this variable to the current cooling state.
459+
*
460+
* Callback for the thermal cooling device to change the cpufreq
461+
* current cooling state.
462+
*
463+
* Return: 0 on success, an error code otherwise.
464+
*/
465+
static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
466+
unsigned long state)
467+
{
468+
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
469+
470+
/* Request state should be less than max_level */
471+
if (WARN_ON(state > cpufreq_cdev->max_level))
472+
return -EINVAL;
473+
474+
/* Check if the old cooling action is same as new cooling action */
475+
if (cpufreq_cdev->cpufreq_state == state)
476+
return 0;
477+
478+
cpufreq_cdev->cpufreq_state = state;
479+
480+
return freq_qos_update_request(&cpufreq_cdev->qos_req,
481+
cpufreq_cdev->freq_table[state].frequency);
482+
}
481483

482484
/* Bind cpufreq callbacks to thermal cooling device ops */
483485

484486
static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
485-
.get_max_state = cpufreq_get_max_state,
486-
.get_cur_state = cpufreq_get_cur_state,
487-
.set_cur_state = cpufreq_set_cur_state,
488-
};
489-
490-
static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
491487
.get_max_state = cpufreq_get_max_state,
492488
.get_cur_state = cpufreq_get_cur_state,
493489
.set_cur_state = cpufreq_set_cur_state,
494-
.get_requested_power = cpufreq_get_requested_power,
495-
.state2power = cpufreq_state2power,
496-
.power2state = cpufreq_power2state,
497490
};
498491

499492
static unsigned int find_next_max(struct cpufreq_frequency_table *table,
@@ -603,17 +596,20 @@ __cpufreq_cooling_register(struct device_node *np,
603596
pr_debug("%s: freq:%u KHz\n", __func__, freq);
604597
}
605598

599+
cooling_ops = &cpufreq_cooling_ops;
600+
601+
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
606602
if (capacitance) {
607603
ret = update_freq_table(cpufreq_cdev, capacitance);
608604
if (ret) {
609605
cdev = ERR_PTR(ret);
610606
goto remove_ida;
611607
}
612-
613-
cooling_ops = &cpufreq_power_cooling_ops;
614-
} else {
615-
cooling_ops = &cpufreq_cooling_ops;
608+
cooling_ops->get_requested_power = cpufreq_get_requested_power;
609+
cooling_ops->state2power = cpufreq_state2power;
610+
cooling_ops->power2state = cpufreq_power2state;
616611
}
612+
#endif
617613

618614
ret = freq_qos_add_request(&policy->constraints,
619615
&cpufreq_cdev->qos_req, FREQ_QOS_MAX,

0 commit comments

Comments
 (0)