Commit 7e6fdd4b authored by Rajagopal Venkat's avatar Rajagopal Venkat Committed by Rafael J. Wysocki

PM / devfreq: Core updates to support devices which can idle

Prepare devfreq core framework to support devices which
can idle. When device idleness is detected perhaps through
runtime-pm, need some mechanism to suspend devfreq load
monitoring and resume back when device is online. Present
code continues monitoring unless device is removed from
devfreq core.

This patch introduces following design changes,

 - use per device work instead of global work to monitor device
   load. This enables suspend/resume of device devfreq and
   reduces monitoring code complexity.
 - decouple delayed work based load monitoring logic from core
   by introducing helpers functions to be used by governors. This
   provides flexibility for governors either to use delayed work
   based monitoring functions or to implement their own mechanism.
 - devfreq core interacts with governors via events to perform
   specific actions. These events include start/stop devfreq.
   This sets ground for adding suspend/resume events.

The devfreq apis are not modified and are kept intact.
Signed-off-by: default avatarRajagopal Venkat <rajagopal.venkat@linaro.org>
Acked-by: default avatarMyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 77b67063
......@@ -21,14 +21,6 @@ Description:
The /sys/class/devfreq/.../cur_freq shows the current
frequency of the corresponding devfreq object.
What: /sys/class/devfreq/.../central_polling
Date: September 2011
Contact: MyungJoo Ham <myungjoo.ham@samsung.com>
Description:
The /sys/class/devfreq/.../central_polling shows whether
the devfreq ojbect is using devfreq-provided central
polling mechanism or not.
What: /sys/class/devfreq/.../polling_interval
Date: September 2011
Contact: MyungJoo Ham <myungjoo.ham@samsung.com>
......
This diff is collapsed.
......@@ -18,7 +18,18 @@
#define to_devfreq(DEV) container_of((DEV), struct devfreq, dev)
/* Devfreq events */
#define DEVFREQ_GOV_START 0x1
#define DEVFREQ_GOV_STOP 0x2
#define DEVFREQ_GOV_INTERVAL 0x3
/* Caution: devfreq->lock must be locked before calling update_devfreq */
extern int update_devfreq(struct devfreq *devfreq);
extern void devfreq_monitor_start(struct devfreq *devfreq);
extern void devfreq_monitor_stop(struct devfreq *devfreq);
extern void devfreq_monitor_suspend(struct devfreq *devfreq);
extern void devfreq_monitor_resume(struct devfreq *devfreq);
extern void devfreq_interval_update(struct devfreq *devfreq,
unsigned int *delay);
#endif /* _GOVERNOR_H */
......@@ -26,14 +26,22 @@ static int devfreq_performance_func(struct devfreq *df,
return 0;
}
static int performance_init(struct devfreq *devfreq)
static int devfreq_performance_handler(struct devfreq *devfreq,
unsigned int event, void *data)
{
return update_devfreq(devfreq);
int ret = 0;
if (event == DEVFREQ_GOV_START) {
mutex_lock(&devfreq->lock);
ret = update_devfreq(devfreq);
mutex_unlock(&devfreq->lock);
}
return ret;
}
const struct devfreq_governor devfreq_performance = {
.name = "performance",
.init = performance_init,
.get_target_freq = devfreq_performance_func,
.no_central_polling = true,
.event_handler = devfreq_performance_handler,
};
......@@ -23,14 +23,22 @@ static int devfreq_powersave_func(struct devfreq *df,
return 0;
}
static int powersave_init(struct devfreq *devfreq)
static int devfreq_powersave_handler(struct devfreq *devfreq,
unsigned int event, void *data)
{
return update_devfreq(devfreq);
int ret = 0;
if (event == DEVFREQ_GOV_START) {
mutex_lock(&devfreq->lock);
ret = update_devfreq(devfreq);
mutex_unlock(&devfreq->lock);
}
return ret;
}
const struct devfreq_governor devfreq_powersave = {
.name = "powersave",
.init = powersave_init,
.get_target_freq = devfreq_powersave_func,
.no_central_polling = true,
.event_handler = devfreq_powersave_handler,
};
......@@ -12,6 +12,7 @@
#include <linux/errno.h>
#include <linux/devfreq.h>
#include <linux/math64.h>
#include "governor.h"
/* Default constants for DevFreq-Simple-Ondemand (DFSO) */
#define DFSO_UPTHRESHOLD (90)
......@@ -88,7 +89,30 @@ static int devfreq_simple_ondemand_func(struct devfreq *df,
return 0;
}
static int devfreq_simple_ondemand_handler(struct devfreq *devfreq,
unsigned int event, void *data)
{
switch (event) {
case DEVFREQ_GOV_START:
devfreq_monitor_start(devfreq);
break;
case DEVFREQ_GOV_STOP:
devfreq_monitor_stop(devfreq);
break;
case DEVFREQ_GOV_INTERVAL:
devfreq_interval_update(devfreq, (unsigned int *)data);
break;
default:
break;
}
return 0;
}
const struct devfreq_governor devfreq_simple_ondemand = {
.name = "simple_ondemand",
.get_target_freq = devfreq_simple_ondemand_func,
.event_handler = devfreq_simple_ondemand_handler,
};
......@@ -116,10 +116,27 @@ static void userspace_exit(struct devfreq *devfreq)
devfreq->data = NULL;
}
static int devfreq_userspace_handler(struct devfreq *devfreq,
unsigned int event, void *data)
{
int ret = 0;
switch (event) {
case DEVFREQ_GOV_START:
ret = userspace_init(devfreq);
break;
case DEVFREQ_GOV_STOP:
userspace_exit(devfreq);
break;
default:
break;
}
return ret;
}
const struct devfreq_governor devfreq_userspace = {
.name = "userspace",
.get_target_freq = devfreq_userspace_func,
.init = userspace_init,
.exit = userspace_exit,
.no_central_polling = true,
.event_handler = devfreq_userspace_handler,
};
......@@ -91,25 +91,18 @@ struct devfreq_dev_profile {
* status of the device (load = busy_time / total_time).
* If no_central_polling is set, this callback is called
* only with update_devfreq() notified by OPP.
* @init Called when the devfreq is being attached to a device
* @exit Called when the devfreq is being removed from a
* device. Governor should stop any internal routines
* before return because related data may be
* freed after exit().
* @no_central_polling Do not use devfreq's central polling mechanism.
* When this is set, devfreq will not call
* get_target_freq with devfreq_monitor(). However,
* devfreq will call get_target_freq with
* devfreq_update() notified by OPP framework.
* @event_handler Callback for devfreq core framework to notify events
* to governors. Events include per device governor
* init and exit, opp changes out of devfreq, suspend
* and resume of per device devfreq during device idle.
*
* Note that the callbacks are called with devfreq->lock locked by devfreq.
*/
struct devfreq_governor {
const char name[DEVFREQ_NAME_LEN];
int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
int (*init)(struct devfreq *this);
void (*exit)(struct devfreq *this);
const bool no_central_polling;
int (*event_handler)(struct devfreq *devfreq,
unsigned int event, void *data);
};
/**
......@@ -124,18 +117,13 @@ struct devfreq_governor {
* @nb notifier block used to notify devfreq object that it should
* reevaluate operable frequencies. Devfreq users may use
* devfreq.nb to the corresponding register notifier call chain.
* @polling_jiffies interval in jiffies.
* @work delayed work for load monitoring.
* @previous_freq previously configured frequency value.
* @next_polling the number of remaining jiffies to poll with
* "devfreq_monitor" executions to reevaluate
* frequency/voltage of the device. Set by
* profile's polling_ms interval.
* @data Private data of the governor. The devfreq framework does not
* touch this.
* @being_removed a flag to mark that this object is being removed in
* order to prevent trying to remove the object multiple times.
* @min_freq Limit minimum frequency requested by user (0: none)
* @max_freq Limit maximum frequency requested by user (0: none)
* @stop_polling devfreq polling status of a device.
*
* This structure stores the devfreq information for a give device.
*
......@@ -153,17 +141,15 @@ struct devfreq {
struct devfreq_dev_profile *profile;
const struct devfreq_governor *governor;
struct notifier_block nb;
struct delayed_work work;
unsigned long polling_jiffies;
unsigned long previous_freq;
unsigned int next_polling;
void *data; /* private data for governors */
bool being_removed;
unsigned long min_freq;
unsigned long max_freq;
bool stop_polling;
};
#if defined(CONFIG_PM_DEVFREQ)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment