Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  drivers/cpufreq/cpufreq_ondemand.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C)  2001 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *            (C)  2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *                      Jun Nakajima <jun.nakajima@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/percpu-defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "cpufreq_ondemand.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /* On-demand governor macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define DEF_FREQUENCY_UP_THRESHOLD		(80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DEF_SAMPLING_DOWN_FACTOR		(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MAX_SAMPLING_DOWN_FACTOR		(100000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define MICRO_FREQUENCY_UP_THRESHOLD		(95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define MICRO_FREQUENCY_MIN_SAMPLE_RATE		(10000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MIN_FREQUENCY_UP_THRESHOLD		(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define MAX_FREQUENCY_UP_THRESHOLD		(100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static struct od_ops od_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned int default_powersave_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * Not all CPUs want IO time to be accounted as busy; this depends on how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * efficient idling at a higher frequency/voltage is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Pavel Machek says this is not so for various generations of AMD and old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Intel systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Mike Chan (android.com) claims this is also not true for ARM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * Because of this, whitelist specific known (series) of CPUs by default, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * leave all others up to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int should_io_be_busy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #if defined(CONFIG_X86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	 * For Intel, Core 2 (model 15) and later have an efficient idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			boot_cpu_data.x86 == 6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			boot_cpu_data.x86_model >= 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * Find right freq to be set now with powersave_bias on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * Returns the freq_hi to be used right now and will set freq_hi_delay_us,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * freq_lo, and freq_lo_delay_us in percpu area for averaging freqs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static unsigned int generic_powersave_bias_target(struct cpufreq_policy *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		unsigned int freq_next, unsigned int relation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	unsigned int freq_req, freq_reduc, freq_avg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	unsigned int freq_hi, freq_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned int delay_hi_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct policy_dbs_info *policy_dbs = policy->governor_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct cpufreq_frequency_table *freq_table = policy->freq_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!freq_table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		dbs_info->freq_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		dbs_info->freq_lo_delay_us = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		return freq_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	index = cpufreq_frequency_table_target(policy, freq_next, relation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	freq_req = freq_table[index].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	freq_reduc = freq_req * od_tuners->powersave_bias / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	freq_avg = freq_req - freq_reduc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/* Find freq bounds for freq_avg in freq_table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	index = cpufreq_table_find_index_h(policy, freq_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	freq_lo = freq_table[index].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	index = cpufreq_table_find_index_l(policy, freq_avg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	freq_hi = freq_table[index].frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/* Find out how long we have to be in hi and lo freqs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (freq_hi == freq_lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		dbs_info->freq_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		dbs_info->freq_lo_delay_us = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return freq_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	delay_hi_us = (freq_avg - freq_lo) * dbs_data->sampling_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	delay_hi_us += (freq_hi - freq_lo) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	delay_hi_us /= freq_hi - freq_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	dbs_info->freq_hi_delay_us = delay_hi_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	dbs_info->freq_lo = freq_lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	dbs_info->freq_lo_delay_us = dbs_data->sampling_rate - delay_hi_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return freq_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void ondemand_powersave_bias_init(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct od_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	dbs_info->freq_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void dbs_freq_increase(struct cpufreq_policy *policy, unsigned int freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct policy_dbs_info *policy_dbs = policy->governor_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (od_tuners->powersave_bias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		freq = od_ops.powersave_bias_target(policy, freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				CPUFREQ_RELATION_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	else if (policy->cur == policy->max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	__cpufreq_driver_target(policy, freq, od_tuners->powersave_bias ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			CPUFREQ_RELATION_L : CPUFREQ_RELATION_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * Every sampling_rate, we check, if current idle time is less than 20%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * (default), then we try to increase frequency. Else, we adjust the frequency
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * proportional to load.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void od_update(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct policy_dbs_info *policy_dbs = policy->governor_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	unsigned int load = dbs_update(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	dbs_info->freq_lo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* Check for frequency increase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (load > dbs_data->up_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		/* If switching to max speed, apply sampling_down_factor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		if (policy->cur < policy->max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			policy_dbs->rate_mult = dbs_data->sampling_down_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		dbs_freq_increase(policy, policy->max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		/* Calculate the next frequency proportional to load */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		unsigned int freq_next, min_f, max_f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		min_f = policy->cpuinfo.min_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		max_f = policy->cpuinfo.max_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		freq_next = min_f + load * (max_f - min_f) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		/* No longer fully busy, reset rate_mult */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		policy_dbs->rate_mult = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (od_tuners->powersave_bias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			freq_next = od_ops.powersave_bias_target(policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 								 freq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 								 CPUFREQ_RELATION_L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		__cpufreq_driver_target(policy, freq_next, CPUFREQ_RELATION_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static unsigned int od_dbs_update(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct policy_dbs_info *policy_dbs = policy->governor_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct dbs_data *dbs_data = policy_dbs->dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct od_policy_dbs_info *dbs_info = to_dbs_info(policy_dbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int sample_type = dbs_info->sample_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/* Common NORMAL_SAMPLE setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	dbs_info->sample_type = OD_NORMAL_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * OD_SUB_SAMPLE doesn't make sense if sample_delay_ns is 0, so ignore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * it then.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (sample_type == OD_SUB_SAMPLE && policy_dbs->sample_delay_ns > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		__cpufreq_driver_target(policy, dbs_info->freq_lo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					CPUFREQ_RELATION_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return dbs_info->freq_lo_delay_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	od_update(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (dbs_info->freq_lo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* Setup SUB_SAMPLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		dbs_info->sample_type = OD_SUB_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return dbs_info->freq_hi_delay_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return dbs_data->sampling_rate * policy_dbs->rate_mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /************************** sysfs interface ************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static struct dbs_governor od_dbs_gov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static ssize_t store_io_is_busy(struct gov_attr_set *attr_set, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	unsigned int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ret = sscanf(buf, "%u", &input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	dbs_data->io_is_busy = !!input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	/* we need to re-evaluate prev_cpu_idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	gov_update_cpu_data(dbs_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static ssize_t store_up_threshold(struct gov_attr_set *attr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	ret = sscanf(buf, "%u", &input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (ret != 1 || input > MAX_FREQUENCY_UP_THRESHOLD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			input < MIN_FREQUENCY_UP_THRESHOLD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	dbs_data->up_threshold = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static ssize_t store_sampling_down_factor(struct gov_attr_set *attr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct policy_dbs_info *policy_dbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	unsigned int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	ret = sscanf(buf, "%u", &input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	dbs_data->sampling_down_factor = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* Reset down sampling multiplier in case it was active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	list_for_each_entry(policy_dbs, &attr_set->policy_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		 * Doing this without locking might lead to using different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 * rate_mult values in od_update() and od_dbs_update().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		mutex_lock(&policy_dbs->update_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		policy_dbs->rate_mult = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		mutex_unlock(&policy_dbs->update_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static ssize_t store_ignore_nice_load(struct gov_attr_set *attr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	unsigned int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ret = sscanf(buf, "%u", &input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (input > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		input = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (input == dbs_data->ignore_nice_load) { /* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	dbs_data->ignore_nice_load = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	/* we need to re-evaluate prev_cpu_idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	gov_update_cpu_data(dbs_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static ssize_t store_powersave_bias(struct gov_attr_set *attr_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct dbs_data *dbs_data = to_dbs_data(attr_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	struct od_dbs_tuners *od_tuners = dbs_data->tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	struct policy_dbs_info *policy_dbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	unsigned int input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	ret = sscanf(buf, "%u", &input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (input > 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		input = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	od_tuners->powersave_bias = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	list_for_each_entry(policy_dbs, &attr_set->policy_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		ondemand_powersave_bias_init(policy_dbs->policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) gov_show_one_common(sampling_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) gov_show_one_common(up_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) gov_show_one_common(sampling_down_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) gov_show_one_common(ignore_nice_load);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) gov_show_one_common(io_is_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) gov_show_one(od, powersave_bias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) gov_attr_rw(sampling_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) gov_attr_rw(io_is_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) gov_attr_rw(up_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) gov_attr_rw(sampling_down_factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) gov_attr_rw(ignore_nice_load);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) gov_attr_rw(powersave_bias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static struct attribute *od_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	&sampling_rate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	&up_threshold.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	&sampling_down_factor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	&ignore_nice_load.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	&powersave_bias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	&io_is_busy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /************************** sysfs end ************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static struct policy_dbs_info *od_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct od_policy_dbs_info *dbs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	dbs_info = kzalloc(sizeof(*dbs_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return dbs_info ? &dbs_info->policy_dbs : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static void od_free(struct policy_dbs_info *policy_dbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	kfree(to_dbs_info(policy_dbs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int od_init(struct dbs_data *dbs_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	struct od_dbs_tuners *tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	u64 idle_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	tuners = kzalloc(sizeof(*tuners), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (!tuners)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	cpu = get_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	idle_time = get_cpu_idle_time_us(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	put_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (idle_time != -1ULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		/* Idle micro accounting is supported. Use finer thresholds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		dbs_data->up_threshold = MICRO_FREQUENCY_UP_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		dbs_data->up_threshold = DEF_FREQUENCY_UP_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	dbs_data->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	dbs_data->ignore_nice_load = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	tuners->powersave_bias = default_powersave_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	dbs_data->io_is_busy = should_io_be_busy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	dbs_data->tuners = tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void od_exit(struct dbs_data *dbs_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	kfree(dbs_data->tuners);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static void od_start(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	struct od_policy_dbs_info *dbs_info = to_dbs_info(policy->governor_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	dbs_info->sample_type = OD_NORMAL_SAMPLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	ondemand_powersave_bias_init(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static struct od_ops od_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	.powersave_bias_target = generic_powersave_bias_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static struct dbs_governor od_dbs_gov = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	.gov = CPUFREQ_DBS_GOVERNOR_INITIALIZER("ondemand"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	.kobj_type = { .default_attrs = od_attributes },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	.gov_dbs_update = od_dbs_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	.alloc = od_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	.free = od_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	.init = od_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	.exit = od_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	.start = od_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define CPU_FREQ_GOV_ONDEMAND	(od_dbs_gov.gov)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static void od_set_powersave_bias(unsigned int powersave_bias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	cpumask_t done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	default_powersave_bias = powersave_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	cpumask_clear(&done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	get_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	for_each_online_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		struct cpufreq_policy *policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		struct policy_dbs_info *policy_dbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		struct dbs_data *dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		struct od_dbs_tuners *od_tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		if (cpumask_test_cpu(cpu, &done))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		policy = cpufreq_cpu_get_raw(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		if (!policy || policy->governor != &CPU_FREQ_GOV_ONDEMAND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		policy_dbs = policy->governor_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		if (!policy_dbs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		cpumask_or(&done, &done, policy->cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		dbs_data = policy_dbs->dbs_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		od_tuners = dbs_data->tuners;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		od_tuners->powersave_bias = default_powersave_bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	put_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) void od_register_powersave_bias_handler(unsigned int (*f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		(struct cpufreq_policy *, unsigned int, unsigned int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		unsigned int powersave_bias)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	od_ops.powersave_bias_target = f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	od_set_powersave_bias(powersave_bias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) void od_unregister_powersave_bias_handler(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	od_ops.powersave_bias_target = generic_powersave_bias_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	od_set_powersave_bias(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	"Low Latency Frequency Transition capable processors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct cpufreq_governor *cpufreq_default_governor(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	return &CPU_FREQ_GOV_ONDEMAND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) cpufreq_governor_init(CPU_FREQ_GOV_ONDEMAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) cpufreq_governor_exit(CPU_FREQ_GOV_ONDEMAND);