From d31aa4ff20b787ad087d9a028fed05ed05579e12 Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Wed, 13 Mar 2019 10:47:12 +0530 Subject: [PATCH] sched: Improve the scheduler This change is for general scheduler improvement. Change-Id: I50d41aa3338803cbd45ff6314b2bb3978c59282b Signed-off-by: Pavankumar Kondeti --- drivers/cpufreq/cpufreq.c | 32 +++++++++++++++++++++++++++++++- drivers/cpufreq/freq_table.c | 3 +++ include/linux/cpufreq.h | 2 ++ include/linux/sched/sysctl.h | 2 +- kernel/compat.c | 2 +- kernel/sched/core.c | 18 ++---------------- kernel/sysctl.c | 9 --------- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index b0e69629e3ba..c4a53ea23f13 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -658,11 +659,40 @@ static ssize_t show_##file_name \ } show_one(cpuinfo_min_freq, cpuinfo.min_freq); -show_one(cpuinfo_max_freq, cpuinfo.max_freq); show_one(cpuinfo_transition_latency, cpuinfo.transition_latency); show_one(scaling_min_freq, min); show_one(scaling_max_freq, max); +unsigned int cpuinfo_max_freq_cached; + +static bool should_use_cached_freq(int cpu) +{ + /* This is a safe check. may not be needed */ + if (!cpuinfo_max_freq_cached) + return false; + + /* + * perfd already configure sched_lib_mask_force to + * 0xf0 from user space. so re-using it. + */ + if (!(BIT(cpu) & sched_lib_mask_force)) + return false; + + return is_sched_lib_based_app(current->pid); +} + +static ssize_t show_cpuinfo_max_freq(struct cpufreq_policy *policy, char *buf) +{ + unsigned int freq = policy->cpuinfo.max_freq; + + if (should_use_cached_freq(policy->cpu)) + freq = cpuinfo_max_freq_cached << 1; + else + freq = policy->cpuinfo.max_freq; + + return scnprintf(buf, PAGE_SIZE, "%u\n", freq); +} + __weak unsigned int arch_freq_get_on_cpu(int cpu) { return 0; diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 3a8cc99e6815..f122289b6271 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c @@ -58,6 +58,9 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, policy->min = policy->cpuinfo.min_freq = min_freq; policy->max = policy->cpuinfo.max_freq = max_freq; + if (max_freq > cpuinfo_max_freq_cached) + cpuinfo_max_freq_cached = max_freq; + if (policy->min == ~0) return -EINVAL; else diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index aa6c347bac70..52ba843aa4cf 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -959,4 +959,6 @@ unsigned int cpufreq_generic_get(unsigned int cpu); int cpufreq_generic_init(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table, unsigned int transition_latency); + +extern unsigned int cpuinfo_max_freq_cached; #endif /* _LINUX_CPUFREQ_H */ diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h index f192598a7526..d23944a33c6e 100644 --- a/include/linux/sched/sysctl.h +++ b/include/linux/sched/sysctl.h @@ -165,7 +165,7 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, #define LIB_PATH_LENGTH 512 extern char sched_lib_name[LIB_PATH_LENGTH]; -extern unsigned int sched_lib_mask_check; extern unsigned int sched_lib_mask_force; +extern bool is_sched_lib_based_app(pid_t pid); #endif /* _LINUX_SCHED_SYSCTL_H */ diff --git a/kernel/compat.c b/kernel/compat.c index ced6a693e253..e4548a9e9c52 100644 --- a/kernel/compat.c +++ b/kernel/compat.c @@ -290,7 +290,7 @@ COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid, if (retval) goto out; - retval = msm_sched_setaffinity(pid, new_mask); + retval = sched_setaffinity(pid, new_mask); out: free_cpumask_var(new_mask); return retval; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4b0dda6bb3b3..97f62cd5d5fe 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5814,9 +5814,8 @@ out_put_task: EXPORT_SYMBOL_GPL(sched_setaffinity); char sched_lib_name[LIB_PATH_LENGTH]; -unsigned int sched_lib_mask_check; unsigned int sched_lib_mask_force; -static inline bool is_sched_lib_based_app(pid_t pid) +bool is_sched_lib_based_app(pid_t pid) { const char *name = NULL; struct vm_area_struct *vma; @@ -5868,19 +5867,6 @@ put_task_struct: return found; } -long msm_sched_setaffinity(pid_t pid, struct cpumask *new_mask) -{ - if (sched_lib_mask_check != 0 && sched_lib_mask_force != 0 && - (cpumask_bits(new_mask)[0] == sched_lib_mask_check) && - is_sched_lib_based_app(pid)) { - - cpumask_t forced_mask = { {sched_lib_mask_force} }; - - cpumask_copy(new_mask, &forced_mask); - } - return sched_setaffinity(pid, new_mask); -} - static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, struct cpumask *new_mask) { @@ -5911,7 +5897,7 @@ SYSCALL_DEFINE3(sched_setaffinity, pid_t, pid, unsigned int, len, retval = get_user_cpu_mask(user_mask_ptr, len, new_mask); if (retval == 0) - retval = msm_sched_setaffinity(pid, new_mask); + retval = sched_setaffinity(pid, new_mask); free_cpumask_var(new_mask); return retval; } diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 0343c0e00601..11df02c5c031 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -823,15 +823,6 @@ static struct ctl_table kern_table[] = { .mode = 0644, .proc_handler = proc_dostring, }, - { - .procname = "sched_lib_mask_check", - .data = &sched_lib_mask_check, - .maxlen = sizeof(unsigned int), - .mode = 0644, - .proc_handler = proc_douintvec_minmax, - .extra1 = &zero, - .extra2 = &two_hundred_fifty_five, - }, { .procname = "sched_lib_mask_force", .data = &sched_lib_mask_force,