Skip to content

Commit a465d38

Browse files
committed
Merge branches 'pm-devfreq', 'pm-avs' and 'pm-tools'
* pm-devfreq: PM / devfreq: add devfreq_suspend/resume() functions PM / devfreq: add support for suspend/resume of a devfreq device PM / devfreq: refactor set_target frequency function * pm-avs: PM / AVS: SmartReflex: Switch to SPDX Licence ID PM / AVS: SmartReflex: NULL check before some freeing functions is not needed PM / AVS: SmartReflex: remove unused function * pm-tools: tools/power/x86/intel_pstate_tracer: Fix non root execution for post processing a trace file tools/power turbostat: consolidate duplicate model numbers tools/power turbostat: fix goldmont C-state limit decoding cpupower : Auto-completion for cpupower tool tools/power turbostat: reduce debug output tools/power turbosat: fix AMD APIC-id output
4 parents 442a5d0 + 2c3b046 + f9dca0f + 584923e commit a465d38

File tree

8 files changed

+378
-164
lines changed

8 files changed

+378
-164
lines changed

drivers/devfreq/devfreq.c

Lines changed: 121 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,44 @@ static int devfreq_notify_transition(struct devfreq *devfreq,
285285
return 0;
286286
}
287287

288+
static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
289+
u32 flags)
290+
{
291+
struct devfreq_freqs freqs;
292+
unsigned long cur_freq;
293+
int err = 0;
294+
295+
if (devfreq->profile->get_cur_freq)
296+
devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
297+
else
298+
cur_freq = devfreq->previous_freq;
299+
300+
freqs.old = cur_freq;
301+
freqs.new = new_freq;
302+
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
303+
304+
err = devfreq->profile->target(devfreq->dev.parent, &new_freq, flags);
305+
if (err) {
306+
freqs.new = cur_freq;
307+
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
308+
return err;
309+
}
310+
311+
freqs.new = new_freq;
312+
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
313+
314+
if (devfreq_update_status(devfreq, new_freq))
315+
dev_err(&devfreq->dev,
316+
"Couldn't update frequency transition information.\n");
317+
318+
devfreq->previous_freq = new_freq;
319+
320+
if (devfreq->suspend_freq)
321+
devfreq->resume_freq = cur_freq;
322+
323+
return err;
324+
}
325+
288326
/* Load monitoring helper functions for governors use */
289327

290328
/**
@@ -296,8 +334,7 @@ static int devfreq_notify_transition(struct devfreq *devfreq,
296334
*/
297335
int update_devfreq(struct devfreq *devfreq)
298336
{
299-
struct devfreq_freqs freqs;
300-
unsigned long freq, cur_freq, min_freq, max_freq;
337+
unsigned long freq, min_freq, max_freq;
301338
int err = 0;
302339
u32 flags = 0;
303340

@@ -333,31 +370,8 @@ int update_devfreq(struct devfreq *devfreq)
333370
flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */
334371
}
335372

336-
if (devfreq->profile->get_cur_freq)
337-
devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
338-
else
339-
cur_freq = devfreq->previous_freq;
373+
return devfreq_set_target(devfreq, freq, flags);
340374

341-
freqs.old = cur_freq;
342-
freqs.new = freq;
343-
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
344-
345-
err = devfreq->profile->target(devfreq->dev.parent, &freq, flags);
346-
if (err) {
347-
freqs.new = cur_freq;
348-
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
349-
return err;
350-
}
351-
352-
freqs.new = freq;
353-
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
354-
355-
if (devfreq_update_status(devfreq, freq))
356-
dev_err(&devfreq->dev,
357-
"Couldn't update frequency transition information.\n");
358-
359-
devfreq->previous_freq = freq;
360-
return err;
361375
}
362376
EXPORT_SYMBOL(update_devfreq);
363377

@@ -657,6 +671,9 @@ struct devfreq *devfreq_add_device(struct device *dev,
657671
}
658672
devfreq->max_freq = devfreq->scaling_max_freq;
659673

674+
devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev);
675+
atomic_set(&devfreq->suspend_count, 0);
676+
660677
dev_set_name(&devfreq->dev, "devfreq%d",
661678
atomic_inc_return(&devfreq_no));
662679
err = device_register(&devfreq->dev);
@@ -857,14 +874,28 @@ EXPORT_SYMBOL(devm_devfreq_remove_device);
857874
*/
858875
int devfreq_suspend_device(struct devfreq *devfreq)
859876
{
877+
int ret;
878+
860879
if (!devfreq)
861880
return -EINVAL;
862881

863-
if (!devfreq->governor)
882+
if (atomic_inc_return(&devfreq->suspend_count) > 1)
864883
return 0;
865884

866-
return devfreq->governor->event_handler(devfreq,
867-
DEVFREQ_GOV_SUSPEND, NULL);
885+
if (devfreq->governor) {
886+
ret = devfreq->governor->event_handler(devfreq,
887+
DEVFREQ_GOV_SUSPEND, NULL);
888+
if (ret)
889+
return ret;
890+
}
891+
892+
if (devfreq->suspend_freq) {
893+
ret = devfreq_set_target(devfreq, devfreq->suspend_freq, 0);
894+
if (ret)
895+
return ret;
896+
}
897+
898+
return 0;
868899
}
869900
EXPORT_SYMBOL(devfreq_suspend_device);
870901

@@ -878,17 +909,75 @@ EXPORT_SYMBOL(devfreq_suspend_device);
878909
*/
879910
int devfreq_resume_device(struct devfreq *devfreq)
880911
{
912+
int ret;
913+
881914
if (!devfreq)
882915
return -EINVAL;
883916

884-
if (!devfreq->governor)
917+
if (atomic_dec_return(&devfreq->suspend_count) >= 1)
885918
return 0;
886919

887-
return devfreq->governor->event_handler(devfreq,
888-
DEVFREQ_GOV_RESUME, NULL);
920+
if (devfreq->resume_freq) {
921+
ret = devfreq_set_target(devfreq, devfreq->resume_freq, 0);
922+
if (ret)
923+
return ret;
924+
}
925+
926+
if (devfreq->governor) {
927+
ret = devfreq->governor->event_handler(devfreq,
928+
DEVFREQ_GOV_RESUME, NULL);
929+
if (ret)
930+
return ret;
931+
}
932+
933+
return 0;
889934
}
890935
EXPORT_SYMBOL(devfreq_resume_device);
891936

937+
/**
938+
* devfreq_suspend() - Suspend devfreq governors and devices
939+
*
940+
* Called during system wide Suspend/Hibernate cycles for suspending governors
941+
* and devices preserving the state for resume. On some platforms the devfreq
942+
* device must have precise state (frequency) after resume in order to provide
943+
* fully operating setup.
944+
*/
945+
void devfreq_suspend(void)
946+
{
947+
struct devfreq *devfreq;
948+
int ret;
949+
950+
mutex_lock(&devfreq_list_lock);
951+
list_for_each_entry(devfreq, &devfreq_list, node) {
952+
ret = devfreq_suspend_device(devfreq);
953+
if (ret)
954+
dev_err(&devfreq->dev,
955+
"failed to suspend devfreq device\n");
956+
}
957+
mutex_unlock(&devfreq_list_lock);
958+
}
959+
960+
/**
961+
* devfreq_resume() - Resume devfreq governors and devices
962+
*
963+
* Called during system wide Suspend/Hibernate cycle for resuming governors and
964+
* devices that are suspended with devfreq_suspend().
965+
*/
966+
void devfreq_resume(void)
967+
{
968+
struct devfreq *devfreq;
969+
int ret;
970+
971+
mutex_lock(&devfreq_list_lock);
972+
list_for_each_entry(devfreq, &devfreq_list, node) {
973+
ret = devfreq_resume_device(devfreq);
974+
if (ret)
975+
dev_warn(&devfreq->dev,
976+
"failed to resume devfreq device\n");
977+
}
978+
mutex_unlock(&devfreq_list_lock);
979+
}
980+
892981
/**
893982
* devfreq_add_governor() - Add devfreq governor
894983
* @governor: the devfreq governor to be added

drivers/power/avs/smartreflex.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: GPL-2.0
12
/*
23
* OMAP SmartReflex Voltage Control
34
*
@@ -11,10 +12,6 @@
1112
*
1213
* Copyright (C) 2007 Texas Instruments, Inc.
1314
* Lesly A M <x0080970@ti.com>
14-
*
15-
* This program is free software; you can redistribute it and/or modify
16-
* it under the terms of the GNU General Public License version 2 as
17-
* published by the Free Software Foundation.
1815
*/
1916

2017
#include <linux/module.h>
@@ -37,7 +34,6 @@
3734
static LIST_HEAD(sr_list);
3835

3936
static struct omap_sr_class_data *sr_class;
40-
static struct omap_sr_pmic_data *sr_pmic_data;
4137
static struct dentry *sr_dbg_dir;
4238

4339
static inline void sr_write_reg(struct omap_sr *sr, unsigned offset, u32 value)
@@ -780,25 +776,6 @@ void omap_sr_disable_reset_volt(struct voltagedomain *voltdm)
780776
sr_class->disable(sr, 1);
781777
}
782778

783-
/**
784-
* omap_sr_register_pmic() - API to register pmic specific info.
785-
* @pmic_data: The structure containing pmic specific data.
786-
*
787-
* This API is to be called from the PMIC specific code to register with
788-
* smartreflex driver pmic specific info. Currently the only info required
789-
* is the smartreflex init on the PMIC side.
790-
*/
791-
void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data)
792-
{
793-
if (!pmic_data) {
794-
pr_warn("%s: Trying to register NULL PMIC data structure with smartreflex\n",
795-
__func__);
796-
return;
797-
}
798-
799-
sr_pmic_data = pmic_data;
800-
}
801-
802779
/* PM Debug FS entries to enable and disable smartreflex. */
803780
static int omap_sr_autocomp_show(void *data, u64 *val)
804781
{
@@ -1010,8 +987,7 @@ static int omap_sr_remove(struct platform_device *pdev)
1010987

1011988
if (sr_info->autocomp_active)
1012989
sr_stop_vddautocomp(sr_info);
1013-
if (sr_info->dbg_dir)
1014-
debugfs_remove_recursive(sr_info->dbg_dir);
990+
debugfs_remove_recursive(sr_info->dbg_dir);
1015991

1016992
pm_runtime_disable(&pdev->dev);
1017993
list_del(&sr_info->node);
@@ -1065,17 +1041,6 @@ static int __init sr_init(void)
10651041
{
10661042
int ret = 0;
10671043

1068-
/*
1069-
* sr_init is a late init. If by then a pmic specific API is not
1070-
* registered either there is no need for anything to be done on
1071-
* the PMIC side or somebody has forgotten to register a PMIC
1072-
* handler. Warn for the second condition.
1073-
*/
1074-
if (sr_pmic_data && sr_pmic_data->sr_pmic_init)
1075-
sr_pmic_data->sr_pmic_init();
1076-
else
1077-
pr_warn("%s: No PMIC hook to init smartreflex\n", __func__);
1078-
10791044
ret = platform_driver_register(&smartreflex_driver);
10801045
if (ret) {
10811046
pr_err("%s: platform driver register failed for SR\n",

include/linux/devfreq.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ struct devfreq_dev_profile {
131131
* @scaling_min_freq: Limit minimum frequency requested by OPP interface
132132
* @scaling_max_freq: Limit maximum frequency requested by OPP interface
133133
* @stop_polling: devfreq polling status of a device.
134+
* @suspend_freq: frequency of a device set during suspend phase.
135+
* @resume_freq: frequency of a device set in resume phase.
136+
* @suspend_count: suspend requests counter for a device.
134137
* @total_trans: Number of devfreq transitions
135138
* @trans_table: Statistics of devfreq transitions
136139
* @time_in_state: Statistics of devfreq states
@@ -167,6 +170,10 @@ struct devfreq {
167170
unsigned long scaling_max_freq;
168171
bool stop_polling;
169172

173+
unsigned long suspend_freq;
174+
unsigned long resume_freq;
175+
atomic_t suspend_count;
176+
170177
/* information for device frequency transition */
171178
unsigned int total_trans;
172179
unsigned int *trans_table;
@@ -198,6 +205,9 @@ extern void devm_devfreq_remove_device(struct device *dev,
198205
extern int devfreq_suspend_device(struct devfreq *devfreq);
199206
extern int devfreq_resume_device(struct devfreq *devfreq);
200207

208+
extern void devfreq_suspend(void);
209+
extern void devfreq_resume(void);
210+
201211
/**
202212
* update_devfreq() - Reevaluate the device and configure frequency
203213
* @devfreq: the devfreq device
@@ -324,6 +334,9 @@ static inline int devfreq_resume_device(struct devfreq *devfreq)
324334
return 0;
325335
}
326336

337+
static inline void devfreq_suspend(void) {}
338+
static inline void devfreq_resume(void) {}
339+
327340
static inline struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
328341
unsigned long *freq, u32 flags)
329342
{

include/linux/power/smartreflex.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
12
/*
23
* OMAP Smartreflex Defines and Routines
34
*
@@ -11,10 +12,6 @@
1112
*
1213
* Copyright (C) 2007 Texas Instruments, Inc.
1314
* Lesly A M <x0080970@ti.com>
14-
*
15-
* This program is free software; you can redistribute it and/or modify
16-
* it under the terms of the GNU General Public License version 2 as
17-
* published by the Free Software Foundation.
1815
*/
1916

2017
#ifndef __POWER_SMARTREFLEX_H
@@ -303,9 +300,6 @@ void omap_sr_enable(struct voltagedomain *voltdm);
303300
void omap_sr_disable(struct voltagedomain *voltdm);
304301
void omap_sr_disable_reset_volt(struct voltagedomain *voltdm);
305302

306-
/* API to register the pmic specific data with the smartreflex driver. */
307-
void omap_sr_register_pmic(struct omap_sr_pmic_data *pmic_data);
308-
309303
/* Smartreflex driver hooks to be called from Smartreflex class driver */
310304
int sr_enable(struct omap_sr *sr, unsigned long volt);
311305
void sr_disable(struct omap_sr *sr);
@@ -320,7 +314,5 @@ static inline void omap_sr_enable(struct voltagedomain *voltdm) {}
320314
static inline void omap_sr_disable(struct voltagedomain *voltdm) {}
321315
static inline void omap_sr_disable_reset_volt(
322316
struct voltagedomain *voltdm) {}
323-
static inline void omap_sr_register_pmic(
324-
struct omap_sr_pmic_data *pmic_data) {}
325317
#endif
326318
#endif

tools/power/cpupower/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ endif
8989
localedir ?= /usr/share/locale
9090
docdir ?= /usr/share/doc/packages/cpupower
9191
confdir ?= /etc/
92+
bash_completion_dir ?= /usr/share/bash-completion/completions
9293

9394
# Toolchain: what tools do we use, and what options do they need:
9495

9596
CP = cp -fpR
9697
INSTALL = /usr/bin/install -c
9798
INSTALL_PROGRAM = ${INSTALL}
9899
INSTALL_DATA = ${INSTALL} -m 644
99-
INSTALL_SCRIPT = ${INSTALL_PROGRAM}
100+
#bash completion scripts get sourced and so they should be rw only.
101+
INSTALL_SCRIPT = ${INSTALL} -m 644
100102

101103
# If you are running a cross compiler, you may want to set this
102104
# to something more interesting, like "arm-linux-". If you want
@@ -288,6 +290,8 @@ install-lib:
288290
install-tools:
289291
$(INSTALL) -d $(DESTDIR)${bindir}
290292
$(INSTALL_PROGRAM) $(OUTPUT)cpupower $(DESTDIR)${bindir}
293+
$(INSTALL) -d $(DESTDIR)${bash_completion_dir}
294+
$(INSTALL_SCRIPT) cpupower-completion.sh '$(DESTDIR)${bash_completion_dir}/cpupower'
291295

292296
install-man:
293297
$(INSTALL_DATA) -D man/cpupower.1 $(DESTDIR)${mandir}/man1/cpupower.1

0 commit comments

Comments
 (0)