cpufreq-elementalx: update and clean up

Signed-off-by: flar2 <asegaert@gmail.com>
This commit is contained in:
flar2 2014-03-11 20:21:33 -04:00 committed by followmsi
parent 94e5db7850
commit a7bf46a8a9

View file

@ -38,7 +38,7 @@ static int g_count = 0;
#define DEF_SAMPLING_RATE (30000)
#define DEF_FREQUENCY_DOWN_DIFFERENTIAL (10)
#define DEF_FREQUENCY_UP_THRESHOLD (80)
#define DEF_FREQUENCY_UP_THRESHOLD (90)
#define DEF_SAMPLING_DOWN_FACTOR (1)
#define MAX_SAMPLING_DOWN_FACTOR (100000)
#define MICRO_FREQUENCY_DOWN_DIFFERENTIAL (3)
@ -47,11 +47,10 @@ static int g_count = 0;
#define MIN_FREQUENCY_UP_THRESHOLD (11)
#define MAX_FREQUENCY_UP_THRESHOLD (100)
#define MIN_FREQUENCY_DOWN_DIFFERENTIAL (1)
#define DBS_INPUT_EVENT_MIN_FREQ (1026000)
#define DEF_UI_DYNAMIC_SAMPLING_RATE (10000)
#define DBS_UI_SAMPLING_MIN_TIMEOUT (30)
#define DBS_UI_SAMPLING_MAX_TIMEOUT (1000)
#define DBS_UI_SAMPLING_TIMEOUT (80)
#define UI_DYNAMIC_SAMPLING_RATE (15000)
#define INPUT_EVENT_MIN_TIMEOUT (0)
#define INPUT_EVENT_MAX_TIMEOUT (3000)
#define INPUT_EVENT_TIMEOUT (1000)
#define DBS_SWITCH_MODE_TIMEOUT (1000)
#define DEF_GBOOST_THRESHOLD (49)
@ -114,14 +113,10 @@ static spinlock_t input_boost_lock;
static bool input_event_boost = false;
static unsigned long input_event_boost_expired = 0;
#ifdef CONFIG_EARLYSUSPEND_BOOST_CPU_SPEED
extern int has_boost_cpu_func;
#endif
#define TABLE_SIZE 5
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)
#define FREQ_NEED_BURST(x) (x < 600000 ? 1 : 0)
#define FREQ_NEED_BURST(x) (x < 600000 ? 1 : 0)
static struct cpufreq_frequency_table *tbl = NULL;
static unsigned int *tblmap[TABLE_SIZE] __read_mostly;
@ -151,7 +146,7 @@ static struct dbs_tuners {
unsigned int two_phase_freq;
unsigned int origin_sampling_rate;
unsigned int ui_sampling_rate;
unsigned int ui_timeout;
unsigned int input_event_timeout;
unsigned int enable_boost_cpu;
int gboost;
unsigned int gboost_threshold;
@ -167,23 +162,13 @@ static struct dbs_tuners {
.sync_freq = 0,
.optimal_freq = 0,
.two_phase_freq = 0,
.ui_sampling_rate = DEF_UI_DYNAMIC_SAMPLING_RATE,
.ui_timeout = DBS_UI_SAMPLING_TIMEOUT,
.ui_sampling_rate = UI_DYNAMIC_SAMPLING_RATE,
.input_event_timeout = INPUT_EVENT_TIMEOUT,
.enable_boost_cpu = 1,
.gboost = 1,
.gboost_threshold = DEF_GBOOST_THRESHOLD,
};
bool is_elementalx_locked(void)
{
if((dbs_tuners_ins.powersave_bias == POWERSAVE_BIAS_MAXLEVEL) ||
(dbs_tuners_ins.powersave_bias == POWERSAVE_BIAS_MINLEVEL))
return true;
else
return false;
}
EXPORT_SYMBOL(is_elementalx_locked);
static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
{
u64 idle_time;
@ -420,9 +405,9 @@ static void update_sampling_rate(unsigned int new_rate)
}
}
show_one(ui_timeout, ui_timeout);
show_one(input_event_timeout, input_event_timeout);
static ssize_t store_ui_timeout(struct kobject *a, struct attribute *b,
static ssize_t store_input_event_timeout(struct kobject *a, struct attribute *b,
const char *buf, size_t count)
{
unsigned int input;
@ -431,13 +416,13 @@ static ssize_t store_ui_timeout(struct kobject *a, struct attribute *b,
if (ret != 1)
return -EINVAL;
input = max(input, (unsigned int)DBS_UI_SAMPLING_MIN_TIMEOUT);
dbs_tuners_ins.ui_timeout = min(input, (unsigned int)DBS_UI_SAMPLING_MAX_TIMEOUT);
input = max(input, (unsigned int)INPUT_EVENT_MIN_TIMEOUT);
dbs_tuners_ins.input_event_timeout = min(input, (unsigned int)INPUT_EVENT_MAX_TIMEOUT);
return count;
}
static int two_phase_freq_array[NR_CPUS] = {[0 ... NR_CPUS-1] = 0} ;
static int two_phase_freq_array[NR_CPUS] = {[0 ... NR_CPUS-1] = 1350000} ;
static ssize_t show_two_phase_freq
(struct kobject *kobj, struct attribute *attr, char *buf)
@ -474,7 +459,7 @@ static ssize_t store_two_phase_freq(struct kobject *a, struct attribute *b,
return count;
}
static int input_event_min_freq_array[NR_CPUS] = {[0 ... NR_CPUS-1] = DBS_INPUT_EVENT_MIN_FREQ} ;
static int input_event_min_freq_array[NR_CPUS] = {1350000, 1026000, 1026000, 1026000} ;
static ssize_t show_input_event_min_freq
(struct kobject *kobj, struct attribute *attr, char *buf)
@ -810,9 +795,7 @@ static ssize_t store_enable_boost_cpu(struct kobject *a, struct attribute *b,
return -EINVAL;
dbs_tuners_ins.enable_boost_cpu = (input > 0 ? input : 0);
#ifdef CONFIG_EARLYSUSPEND_BOOST_CPU_SPEED
has_boost_cpu_func = (unsigned int) dbs_tuners_ins.enable_boost_cpu;
#endif
return count;
}
@ -858,7 +841,7 @@ define_one_global_rw(sync_freq);
define_one_global_rw(two_phase_freq);
define_one_global_rw(input_event_min_freq);
define_one_global_rw(ui_sampling_rate);
define_one_global_rw(ui_timeout);
define_one_global_rw(input_event_timeout);
define_one_global_rw(enable_boost_cpu);
define_one_global_rw(gboost);
define_one_global_rw(gboost_threshold);
@ -879,7 +862,7 @@ static struct attribute *dbs_attributes[] = {
&two_phase_freq.attr,
&input_event_min_freq.attr,
&ui_sampling_rate.attr,
&ui_timeout.attr,
&input_event_timeout.attr,
&enable_boost_cpu.attr,
&gboost.attr,
&gboost_threshold.attr,
@ -1065,6 +1048,22 @@ int input_event_boosted(void)
return 0;
}
static void boost_min_freq(int min_freq)
{
int i;
struct cpu_dbs_info_s *dbs_info;
for_each_online_cpu(i) {
dbs_info = &per_cpu(od_cpu_dbs_info, i);
if (dbs_info->cur_policy
&& dbs_info->cur_policy->cur < min_freq) {
dbs_info->input_event_freq = min_freq;
wake_up_process(per_cpu(up_task, i));
}
}
}
static unsigned int get_cpu_current_load(unsigned int j, unsigned int *record)
{
@ -1186,7 +1185,7 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
//gboost
if (graphics_boost == 0 && dbs_tuners_ins.gboost ) {
if (graphics_boost == 0 || g_count > 30 ) {
if (max_load_freq > dbs_tuners_ins.up_threshold * policy->cur) {
@ -1252,6 +1251,7 @@ if (graphics_boost == 0 && dbs_tuners_ins.gboost ) {
}
}
//graphics boost
if (dbs_tuners_ins.gboost) {
if (counter > 0) {
counter--;
@ -1260,10 +1260,6 @@ if (dbs_tuners_ins.gboost) {
phase = 0;
}
}
}
//graphics boost
if (dbs_tuners_ins.gboost) {
if (g_count < 100 && graphics_boost < 2) {
++g_count;
@ -1272,7 +1268,7 @@ if (dbs_tuners_ins.gboost) {
--g_count;
}
if (graphics_boost == 0 && g_count > 80) {
if (graphics_boost == 0 && g_count > 90) {
if (dbs_tuners_ins.up_threshold != dbs_tuners_ins.gboost_threshold)
old_up_threshold = dbs_tuners_ins.up_threshold;
dbs_tuners_ins.up_threshold = dbs_tuners_ins.gboost_threshold;
@ -1280,9 +1276,8 @@ if (dbs_tuners_ins.gboost) {
if (dbs_tuners_ins.up_threshold == dbs_tuners_ins.gboost_threshold)
dbs_tuners_ins.up_threshold = old_up_threshold;
}
if (g_count > 30) {
input_event_boost = true;
input_event_boost_expired = jiffies + usecs_to_jiffies(dbs_tuners_ins.sampling_rate * 2);
if (g_count > 40) {
boost_min_freq(1026000);
}
}
//end
@ -1293,6 +1288,8 @@ if (dbs_tuners_ins.gboost) {
if (policy->cur < dbs_tuners_ins.sync_freq)
dbs_freq_increase(policy, cur_load,
dbs_tuners_ins.sync_freq);
else
trace_cpufreq_interactive_already (policy->cpu, cur_load, policy->cur,policy->cur);
return;
}
@ -1301,6 +1298,8 @@ if (dbs_tuners_ins.gboost) {
if (policy->cur < dbs_tuners_ins.optimal_freq)
dbs_freq_increase(policy, cur_load,
dbs_tuners_ins.optimal_freq);
else
trace_cpufreq_interactive_already (policy->cpu, cur_load, policy->cur,policy->cur);
return;
}
}
@ -1427,8 +1426,6 @@ static int should_io_be_busy(void)
static void dbs_input_event(struct input_handle *handle, unsigned int type,
unsigned int code, int value)
{
int i;
struct cpu_dbs_info_s *dbs_info;
unsigned long flags;
int input_event_min_freq;
@ -1438,11 +1435,10 @@ static void dbs_input_event(struct input_handle *handle, unsigned int type,
return;
}
if (type == EV_SYN && code == SYN_REPORT) {
if (dbs_tuners_ins.input_event_timeout == 0)
return;
dbs_tuners_ins.powersave_bias = 0;
}
else if (type == EV_ABS && code == ABS_MT_TRACKING_ID) {
if (type == EV_ABS && code == ABS_MT_TRACKING_ID) {
if (value != -1) {
@ -1454,24 +1450,16 @@ static void dbs_input_event(struct input_handle *handle, unsigned int type,
spin_lock_irqsave(&input_boost_lock, flags);
input_event_boost = true;
input_event_boost_expired = jiffies + usecs_to_jiffies(dbs_tuners_ins.sampling_rate * 2);
input_event_boost_expired = jiffies + usecs_to_jiffies(dbs_tuners_ins.input_event_timeout * 1000);
spin_unlock_irqrestore(&input_boost_lock, flags);
for_each_online_cpu(i) {
dbs_info = &per_cpu(od_cpu_dbs_info, i);
if (dbs_info->cur_policy
&& dbs_info->cur_policy->cur < input_event_min_freq) {
dbs_info->input_event_freq = input_event_min_freq;
wake_up_process(per_cpu(up_task, i));
}
}
boost_min_freq(input_event_min_freq);
}
else {
if (likely(input_event_counter > 0))
input_event_counter--;
else
pr_warning("dbs_input_event: Touch isn't paired!\n");
pr_debug("dbs_input_event: Touch isn't paired!\n");
switch_turbo_mode(DBS_SWITCH_MODE_TIMEOUT);
@ -1479,26 +1467,12 @@ static void dbs_input_event(struct input_handle *handle, unsigned int type,
}
}
static int input_dev_filter(const char *input_dev_name)
{
if (strstr(input_dev_name, "touchscreen") ||
strstr(input_dev_name, "keypad")) {
return 0;
} else {
return 1;
}
}
static int dbs_input_connect(struct input_handler *handler,
struct input_dev *dev, const struct input_device_id *id)
{
struct input_handle *handle;
int error;
if (input_dev_filter(dev->name))
return -ENODEV;
handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
if (!handle)
return -ENOMEM;
@ -1564,13 +1538,7 @@ static struct input_handler dbs_input_handler = {
.id_table = dbs_ids,
};
int set_input_event_min_freq(int cpufreq)
{
int i = 0;
for ( i = 0 ; i < NR_CPUS; i++)
input_event_min_freq_array[i] = cpufreq;
return 0;
}
void set_input_event_min_freq_by_cpu ( int cpu_nr, int cpufreq){
input_event_min_freq_array[cpu_nr-1] = cpufreq;
@ -1607,11 +1575,6 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
this_dbs_info->cpu = cpu;
this_dbs_info->rate_mult = 1;
elementalx_powersave_bias_init_cpu(cpu);
set_two_phase_freq(1026000);
set_input_event_min_freq_by_cpu(1, 1026000);
set_input_event_min_freq_by_cpu(2, 1026000);
set_input_event_min_freq_by_cpu(3, 810000);
set_input_event_min_freq_by_cpu(4, 810000);
if (dbs_enable == 1) {
unsigned int latency;
@ -1767,10 +1730,6 @@ static int __init cpufreq_gov_dbs_init(void)
MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10);
}
#ifdef CONFIG_EARLYSUSPEND_BOOST_CPU_SPEED
has_boost_cpu_func = (unsigned int) dbs_tuners_ins.enable_boost_cpu;
#endif
spin_lock_init(&input_boost_lock);
for_each_possible_cpu(i) {