From 102a0743326a03cd1a1202ceda21e175b7d3575c Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Tue, 20 Feb 2024 01:20:52 +0000
Subject: [PATCH] add new system file

---
 kernel/drivers/cpufreq/cpufreq_interactive.c |  210 ++++-----------------------------------------------
 1 files changed, 19 insertions(+), 191 deletions(-)

diff --git a/kernel/drivers/cpufreq/cpufreq_interactive.c b/kernel/drivers/cpufreq/cpufreq_interactive.c
index d9c8c7d..a486993 100644
--- a/kernel/drivers/cpufreq/cpufreq_interactive.c
+++ b/kernel/drivers/cpufreq/cpufreq_interactive.c
@@ -37,7 +37,6 @@
 #include <linux/slab.h>
 #include <uapi/linux/sched/types.h>
 #include <linux/sched/clock.h>
-#include <soc/rockchip/rockchip_system_monitor.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/cpufreq_interactive.h>
@@ -101,7 +100,6 @@
 	int touchboostpulse_duration_val;
 	/* End time of touchboost pulse in ktime converted to usecs */
 	u64 touchboostpulse_endtime;
-	bool touchboost, is_touchboosted;
 #endif
 	bool boosted;
 
@@ -128,7 +126,6 @@
 	struct interactive_policy *ipolicy;
 
 	struct irq_work irq_work;
-	struct irq_work boost_irq_work;
 	u64 last_sample_time;
 	unsigned long next_sample_jiffies;
 	bool work_in_progress;
@@ -151,9 +148,6 @@
 	u64 pol_hispeed_val_time; /* policy hispeed_validate_time */
 	u64 loc_hispeed_val_time; /* per-cpu hispeed_validate_time */
 	int cpu;
-	unsigned int task_boost_freq;
-	unsigned long task_boost_util;
-	u64 task_boos_endtime;
 };
 
 static DEFINE_PER_CPU(struct interactive_cpu, interactive_cpu);
@@ -429,9 +423,6 @@
 	    new_freq < tunables->touchboost_freq) {
 		new_freq = tunables->touchboost_freq;
 	}
-	if ((now < icpu->task_boos_endtime) && (new_freq < icpu->task_boost_freq)) {
-		new_freq = icpu->task_boost_freq;
-	}
 #endif
 	if (policy->cur >= tunables->hispeed_freq &&
 	    new_freq > policy->cur &&
@@ -522,8 +513,7 @@
 			sampling_rate = icpu->ipolicy->tunables->sampling_rate;
 			icpu->last_sample_time = local_clock();
 			icpu->next_sample_jiffies = usecs_to_jiffies(sampling_rate) + jiffies;
-			icpu->work_in_progress = true;
-			irq_work_queue_on(&icpu->irq_work, icpu->cpu);
+			cpufreq_interactive_update(icpu);
 		}
 	}
 
@@ -609,44 +599,7 @@
 	for_each_cpu(cpu, &tmp_mask) {
 		struct interactive_cpu *icpu = &per_cpu(interactive_cpu, cpu);
 		struct cpufreq_policy *policy;
-#ifdef CONFIG_ARCH_ROCKCHIP
-		struct interactive_tunables *tunables;
-		bool update_policy = false;
-		u64 now;
 
-		now = ktime_to_us(ktime_get());
-		if (!down_read_trylock(&icpu->enable_sem))
-			continue;
-
-		if (!icpu->ipolicy) {
-			up_read(&icpu->enable_sem);
-			continue;
-		}
-
-		tunables = icpu->ipolicy->tunables;
-		if (!tunables) {
-			up_read(&icpu->enable_sem);
-			continue;
-		}
-
-		if (tunables->touchboost &&
-		    now > tunables->touchboostpulse_endtime) {
-			tunables->touchboost = false;
-			rockchip_monitor_clear_boosted();
-			update_policy = true;
-		}
-
-		if (!tunables->is_touchboosted && tunables->touchboost) {
-			rockchip_monitor_set_boosted();
-			update_policy = true;
-		}
-
-		tunables->is_touchboosted = tunables->touchboost;
-
-		up_read(&icpu->enable_sem);
-		if (update_policy)
-			cpufreq_update_policy(cpu);
-#endif
 		policy = cpufreq_cpu_get(cpu);
 		if (!policy)
 			continue;
@@ -716,25 +669,31 @@
 					unsigned long val, void *data)
 {
 	struct cpufreq_freqs *freq = data;
-	struct interactive_cpu *icpu = &per_cpu(interactive_cpu, freq->cpu);
+	struct cpufreq_policy *policy = freq->policy;
+	struct interactive_cpu *icpu;
 	unsigned long flags;
+	int cpu;
 
 	if (val != CPUFREQ_POSTCHANGE)
 		return 0;
 
-	if (!down_read_trylock(&icpu->enable_sem))
-		return 0;
+	for_each_cpu(cpu, policy->cpus) {
+		icpu = &per_cpu(interactive_cpu, cpu);
 
-	if (!icpu->ipolicy) {
+		if (!down_read_trylock(&icpu->enable_sem))
+			continue;
+
+		if (!icpu->ipolicy) {
+			up_read(&icpu->enable_sem);
+			continue;
+		}
+
+		spin_lock_irqsave(&icpu->load_lock, flags);
+		update_load(icpu, cpu);
+		spin_unlock_irqrestore(&icpu->load_lock, flags);
+
 		up_read(&icpu->enable_sem);
-		return 0;
 	}
-
-	spin_lock_irqsave(&icpu->load_lock, flags);
-	update_load(icpu, freq->cpu);
-	spin_unlock_irqrestore(&icpu->load_lock, flags);
-
-	up_read(&icpu->enable_sem);
 
 	return 0;
 }
@@ -1052,44 +1011,6 @@
 	return count;
 }
 
-static ssize_t store_touchboost_freq(struct gov_attr_set *attr_set,
-				     const char *buf, size_t count)
-{
-	struct interactive_tunables *tunables = to_tunables(attr_set);
-	unsigned long val;
-	int ret;
-
-	ret = kstrtoul(buf, 0, &val);
-	if (ret < 0)
-		return ret;
-
-	tunables->touchboost_freq = val;
-
-	return count;
-}
-
-static ssize_t show_touchboost_duration(struct gov_attr_set *attr_set, char *buf)
-{
-	struct interactive_tunables *tunables = to_tunables(attr_set);
-
-	return sprintf(buf, "%d\n", tunables->touchboostpulse_duration_val);
-}
-
-static ssize_t store_touchboost_duration(struct gov_attr_set *attr_set,
-					 const char *buf, size_t count)
-{
-	struct interactive_tunables *tunables = to_tunables(attr_set);
-	int val, ret;
-
-	ret = kstrtoint(buf, 0, &val);
-	if (ret < 0)
-		return ret;
-
-	tunables->touchboostpulse_duration_val = val;
-
-	return count;
-}
-
 show_one(hispeed_freq, "%u");
 show_one(go_hispeed_load, "%lu");
 show_one(min_sample_time, "%lu");
@@ -1097,7 +1018,6 @@
 show_one(boost, "%u");
 show_one(boostpulse_duration, "%u");
 show_one(io_is_busy, "%u");
-show_one(touchboost_freq, "%lu");
 
 gov_attr_rw(target_loads);
 gov_attr_rw(above_hispeed_delay);
@@ -1110,8 +1030,6 @@
 gov_attr_wo(boostpulse);
 gov_attr_rw(boostpulse_duration);
 gov_attr_rw(io_is_busy);
-gov_attr_rw(touchboost_freq);
-gov_attr_rw(touchboost_duration);
 
 static struct attribute *interactive_attributes[] = {
 	&target_loads.attr,
@@ -1125,8 +1043,6 @@
 	&boostpulse.attr,
 	&boostpulse_duration.attr,
 	&io_is_busy.attr,
-	&touchboost_freq.attr,
-	&touchboost_duration.attr,
 	NULL
 };
 
@@ -1220,15 +1136,12 @@
 	for_each_cpu(i, policy->cpus)
 		cpufreq_remove_update_util_hook(i);
 
-	synchronize_sched();
+	synchronize_rcu();
 }
 
 static void icpu_cancel_work(struct interactive_cpu *icpu)
 {
 	irq_work_sync(&icpu->irq_work);
-#ifdef CONFIG_ARCH_ROCKCHIP
-	irq_work_sync(&icpu->boost_irq_work);
-#endif
 	icpu->work_in_progress = false;
 	del_timer_sync(&icpu->slack_timer);
 }
@@ -1328,7 +1241,6 @@
 			cpumask_set_cpu(i, &speedchange_cpumask);
 			pcpu->loc_hispeed_val_time =
 					ktime_to_us(ktime_get());
-			tunables->touchboost = true;
 			anyboost = 1;
 		}
 
@@ -1454,83 +1366,6 @@
 		tunables->attr_set = attr_set;
 	}
 }
-
-static unsigned int get_freq_for_util(struct cpufreq_policy *policy, unsigned long util)
-{
-	struct cpufreq_frequency_table *pos;
-	unsigned long max_cap, cur_cap;
-	unsigned int freq = 0;
-
-	max_cap = arch_scale_cpu_capacity(NULL, policy->cpu);
-	cpufreq_for_each_valid_entry(pos, policy->freq_table) {
-		freq = pos->frequency;
-
-		cur_cap = max_cap * freq / policy->max;
-		if (cur_cap > util)
-			break;
-	}
-
-	return freq;
-}
-
-static void task_boost_irq_work(struct irq_work *irq_work)
-{
-	struct interactive_cpu *pcpu;
-	struct interactive_policy *ipolicy;
-	unsigned long flags[2];
-	u64 now, prev_boos_endtime;
-	unsigned int boost_freq;
-
-	pcpu = container_of(irq_work, struct interactive_cpu, boost_irq_work);
-	if (!down_read_trylock(&pcpu->enable_sem))
-		return;
-
-	ipolicy = pcpu->ipolicy;
-	if (!ipolicy)
-		goto out;
-
-	if (ipolicy->policy->cur == ipolicy->policy->max)
-		goto out;
-
-	now = ktime_to_us(ktime_get());
-	prev_boos_endtime = pcpu->task_boos_endtime;;
-	pcpu->task_boos_endtime = now + ipolicy->tunables->sampling_rate;
-	boost_freq = get_freq_for_util(ipolicy->policy, pcpu->task_boost_util);
-	if ((now < prev_boos_endtime) && (boost_freq <= pcpu->task_boost_freq))
-		goto out;
-	pcpu->task_boost_freq = boost_freq;
-
-	spin_lock_irqsave(&speedchange_cpumask_lock, flags[0]);
-	spin_lock_irqsave(&pcpu->target_freq_lock, flags[1]);
-	if (pcpu->target_freq < pcpu->task_boost_freq) {
-		pcpu->target_freq = pcpu->task_boost_freq;
-		cpumask_set_cpu(pcpu->cpu, &speedchange_cpumask);
-		wake_up_process(speedchange_task);
-	}
-	spin_unlock_irqrestore(&pcpu->target_freq_lock, flags[1]);
-	spin_unlock_irqrestore(&speedchange_cpumask_lock, flags[0]);
-
-out:
-	up_read(&pcpu->enable_sem);
-}
-
-extern unsigned long capacity_curr_of(int cpu);
-
-void cpufreq_task_boost(int cpu, unsigned long util)
-{
-	struct interactive_cpu *pcpu = &per_cpu(interactive_cpu, cpu);
-	unsigned long cap, min_util;
-
-	if (!speedchange_task)
-		return;
-
-	min_util = util + (util >> 2);
-	cap = capacity_curr_of(cpu);
-	if (min_util > cap) {
-		pcpu->task_boost_util = min_util;
-		irq_work_queue(&pcpu->boost_irq_work);
-	}
-}
 #endif
 
 int cpufreq_interactive_init(struct cpufreq_policy *policy)
@@ -1639,10 +1474,6 @@
 		idle_notifier_unregister(&cpufreq_interactive_idle_nb);
 #ifdef CONFIG_ARCH_ROCKCHIP
 		input_unregister_handler(&cpufreq_interactive_input_handler);
-		if (tunables->touchboost) {
-			tunables->touchboost = false;
-			rockchip_monitor_clear_boosted();
-		}
 #endif
 	}
 
@@ -1763,9 +1594,6 @@
 		icpu = &per_cpu(interactive_cpu, cpu);
 
 		init_irq_work(&icpu->irq_work, irq_work);
-#ifdef CONFIG_ARCH_ROCKCHIP
-		init_irq_work(&icpu->boost_irq_work, task_boost_irq_work);
-#endif
 		spin_lock_init(&icpu->load_lock);
 		spin_lock_init(&icpu->target_freq_lock);
 		init_rwsem(&icpu->enable_sem);

--
Gitblit v1.6.2