long d_actual, d_reference;
struct msr actual, reference;
struct cpu_data_t *data = &per_cpu(cpu_data, policy->cpu);
- struct dbs_data *od_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *od_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = od_data->tuners;
struct od_cpu_dbs_info_s *od_info =
dbs_governor_of(policy)->get_cpu_dbs_info_s(policy->cpu);
{
struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
/*
static unsigned int cs_dbs_timer(struct cpufreq_policy *policy)
{
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
dbs_check_cpu(policy);
{
int cpu = policy->cpu;
struct dbs_governor *gov = dbs_governor_of(policy);
- struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
unsigned int sampling_rate;
j_cdbs->prev_cpu_idle = cur_idle_time;
if (ignore_nice) {
+ struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
u64 cur_nice;
unsigned long cur_nice_jiffies;
}
}
-static int alloc_policy_dbs_info(struct cpufreq_policy *policy,
- struct dbs_governor *gov)
+static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,
+ struct dbs_governor *gov)
{
struct policy_dbs_info *policy_dbs;
int j;
/* Allocate memory for the common information for policy->cpus */
policy_dbs = kzalloc(sizeof(*policy_dbs), GFP_KERNEL);
if (!policy_dbs)
- return -ENOMEM;
+ return NULL;
/* Set policy_dbs for all CPUs, online+offline */
for_each_cpu(j, policy->related_cpus)
atomic_set(&policy_dbs->skip_work, 0);
init_irq_work(&policy_dbs->irq_work, dbs_irq_work);
INIT_WORK(&policy_dbs->work, dbs_work_handler);
- return 0;
+ return policy_dbs;
}
static void free_policy_dbs_info(struct cpufreq_policy *policy,
{
struct dbs_governor *gov = dbs_governor_of(policy);
struct dbs_data *dbs_data = gov->gdbs_data;
+ struct policy_dbs_info *policy_dbs;
unsigned int latency;
int ret;
if (policy->governor_data)
return -EBUSY;
- if (dbs_data) {
- if (WARN_ON(have_governor_per_policy()))
- return -EINVAL;
-
- ret = alloc_policy_dbs_info(policy, gov);
- if (ret)
- return ret;
+ policy_dbs = alloc_policy_dbs_info(policy, gov);
+ if (!policy_dbs)
+ return -ENOMEM;
+ if (dbs_data) {
+ if (WARN_ON(have_governor_per_policy())) {
+ ret = -EINVAL;
+ goto free_policy_dbs_info;
+ }
dbs_data->usage_count++;
- policy->governor_data = dbs_data;
+ policy_dbs->dbs_data = dbs_data;
+ policy->governor_data = policy_dbs;
return 0;
}
dbs_data = kzalloc(sizeof(*dbs_data), GFP_KERNEL);
- if (!dbs_data)
- return -ENOMEM;
-
- ret = alloc_policy_dbs_info(policy, gov);
- if (ret)
- goto free_dbs_data;
+ if (!dbs_data) {
+ ret = -ENOMEM;
+ goto free_policy_dbs_info;
+ }
dbs_data->usage_count = 1;
if (!have_governor_per_policy())
gov->gdbs_data = dbs_data;
- policy->governor_data = dbs_data;
+ policy_dbs->dbs_data = dbs_data;
+ policy->governor_data = policy_dbs;
ret = sysfs_create_group(get_governor_parent_kobj(policy),
get_sysfs_attr(gov));
if (!have_governor_per_policy())
gov->gdbs_data = NULL;
gov->exit(dbs_data, !policy->governor->initialized);
+ kfree(dbs_data);
+
free_policy_dbs_info:
free_policy_dbs_info(policy, gov);
-free_dbs_data:
- kfree(dbs_data);
return ret;
}
static int cpufreq_governor_exit(struct cpufreq_policy *policy)
{
struct dbs_governor *gov = dbs_governor_of(policy);
- struct dbs_data *dbs_data = policy->governor_data;
- struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
/* State should be equivalent to INIT */
- if (!cdbs->policy_dbs || cdbs->policy_dbs->policy)
+ if (policy_dbs->policy)
return -EBUSY;
if (!--dbs_data->usage_count) {
static int cpufreq_governor_start(struct cpufreq_policy *policy)
{
struct dbs_governor *gov = dbs_governor_of(policy);
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
unsigned int sampling_rate, ignore_nice, j, cpu = policy->cpu;
- struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(cpu);
- struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
int io_busy = 0;
if (!policy->cur)
return -EINVAL;
/* State should be equivalent to INIT */
- if (!policy_dbs || policy_dbs->policy)
+ if (policy_dbs->policy)
return -EBUSY;
if (gov->governor == GOV_CONSERVATIVE) {
static int cpufreq_governor_stop(struct cpufreq_policy *policy)
{
- struct dbs_governor *gov = dbs_governor_of(policy);
- struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
- struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
/* State should be equivalent to START */
- if (!policy_dbs || !policy_dbs->policy)
+ if (!policy_dbs->policy)
return -EBUSY;
gov_cancel_work(policy_dbs);
static int cpufreq_governor_limits(struct cpufreq_policy *policy)
{
- struct dbs_governor *gov = dbs_governor_of(policy);
- struct cpu_dbs_info *cdbs = gov->get_cpu_cdbs(policy->cpu);
- struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
/* State should be equivalent to START */
- if (!policy_dbs || !policy_dbs->policy)
+ if (!policy_dbs->policy)
return -EBUSY;
mutex_lock(&policy_dbs->timer_mutex);
static ssize_t show_##file_name##_gov_pol \
(struct cpufreq_policy *policy, char *buf) \
{ \
- struct dbs_data *dbs_data = policy->governor_data; \
+ struct policy_dbs_info *policy_dbs = policy->governor_data; \
+ struct dbs_data *dbs_data = policy_dbs->dbs_data; \
struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \
return sprintf(buf, "%u\n", tuners->file_name); \
}
static ssize_t store_##file_name##_gov_pol \
(struct cpufreq_policy *policy, const char *buf, size_t count) \
{ \
- struct dbs_data *dbs_data = policy->governor_data; \
- return store_##file_name(dbs_data, buf, count); \
+ struct policy_dbs_info *policy_dbs = policy->governor_data; \
+ return store_##file_name(policy_dbs->dbs_data, buf, count); \
}
#define show_store_one(_gov, file_name) \
* cs_*: Conservative governor
*/
+/* Governor demand based switching data (per-policy or global). */
+struct dbs_data {
+ unsigned int min_sampling_rate;
+ int usage_count;
+ void *tuners;
+};
+
/* Common to all CPUs of a policy */
struct policy_dbs_info {
struct cpufreq_policy *policy;
atomic_t skip_work;
struct irq_work irq_work;
struct work_struct work;
+ /* dbs_data may be shared between multiple policy objects */
+ struct dbs_data *dbs_data;
};
static inline void gov_update_sample_delay(struct policy_dbs_info *policy_dbs,
};
/* Common Governor data across policies */
-struct dbs_data;
struct dbs_governor {
struct cpufreq_governor gov;
return container_of(policy->governor, struct dbs_governor, gov);
}
-/* Governor Per policy data */
-struct dbs_data {
- unsigned int min_sampling_rate;
- int usage_count;
- void *tuners;
-};
-
/* Governor specific ops, will be passed to dbs_data->gov_ops */
struct od_ops {
void (*powersave_bias_init_cpu)(int cpu);
static ssize_t show_sampling_rate_min_gov_pol \
(struct cpufreq_policy *policy, char *buf) \
{ \
- struct dbs_data *dbs_data = policy->governor_data; \
+ struct policy_dbs_info *policy_dbs = policy->governor_data; \
+ struct dbs_data *dbs_data = policy_dbs->dbs_data; \
return sprintf(buf, "%u\n", dbs_data->min_sampling_rate); \
}
unsigned int jiffies_total, jiffies_hi, jiffies_lo;
struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info,
policy->cpu);
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
if (!dbs_info->freq_table) {
static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
{
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
if (od_tuners->powersave_bias)
static void od_check_cpu(int cpu, unsigned int load)
{
struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, cpu);
- struct cpufreq_policy *policy = dbs_info->cdbs.policy_dbs->policy;
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = dbs_info->cdbs.policy_dbs;
+ struct cpufreq_policy *policy = policy_dbs->policy;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
dbs_info->freq_lo = 0;
static unsigned int od_dbs_timer(struct cpufreq_policy *policy)
{
- struct dbs_data *dbs_data = policy->governor_data;
+ struct policy_dbs_info *policy_dbs = policy->governor_data;
+ struct dbs_data *dbs_data = policy_dbs->dbs_data;
struct od_cpu_dbs_info_s *dbs_info = &per_cpu(od_cpu_dbs_info, policy->cpu);
struct od_dbs_tuners *od_tuners = dbs_data->tuners;
int delay = 0, sample_type = dbs_info->sample_type;
* policy will be governed by dbs_data, otherwise there can be
* multiple policies that are governed by the same dbs_data.
*/
- if (dbs_data == policy->governor_data) {
+ if (dbs_data == policy_dbs->dbs_data) {
mutex_lock(&policy_dbs->timer_mutex);
/*
* On 32-bit architectures this may race with the
if (policy->governor != CPU_FREQ_GOV_ONDEMAND)
continue;
- dbs_data = policy->governor_data;
+ dbs_data = policy_dbs->dbs_data;
od_tuners = dbs_data->tuners;
od_tuners->powersave_bias = default_powersave_bias;
}