diff options
author | Alex Frid <afrid@nvidia.com> | 2011-10-05 21:20:21 -0700 |
---|---|---|
committer | Varun Wadekar <vwadekar@nvidia.com> | 2011-12-08 18:08:31 +0530 |
commit | 33c9bbe38a93f618c543754b06d05f976b88c0f2 (patch) | |
tree | e5f05d582473ad4a42a44e974ce242631dce674b /arch/arm/mach-tegra/cpu-tegra.c | |
parent | 62ac221dc0af840669df22aa2646c26baed4cb6f (diff) |
ARM: tegra: power: Limit CPU rate on system EDP alarm
System electrical design point (EDP) alarm is generated when system
power source (battery) over-current is detected.
Part of the system EDP management is CPU frequency capping added by
this commit. Maximum CPU clock frequency is pre-determined depending
on number of CPU cores on-line. It is combined with CPU regulator EDP
limit and applied to final CPU rate; CPU voltage is scaled down by
DVFS, respectively. The system EDP limit of CPU rate is removed after
alarm is canceled.
EDP event can be emulated via debugfs entry /d/cpu-tegra/edp_alarm.
(cherry picked from commit fa673d27766ff9513139e94a498e4c24827d7c57)
arm: tegra: power: Removed erroneous ';'
(cherry picked from commit b4b404381b2d1823b7c127858950f853428fe3b5)
Change-Id: I60ec0e87f9442b698a8824895aac0a1f955565b4
Signed-off-by: Alex Frid <afrid@nvidia.com>
Reviewed-on: http://git-master/r/67823
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>
Diffstat (limited to 'arch/arm/mach-tegra/cpu-tegra.c')
-rw-r--r-- | arch/arm/mach-tegra/cpu-tegra.c | 164 |
1 files changed, 113 insertions, 51 deletions
diff --git a/arch/arm/mach-tegra/cpu-tegra.c b/arch/arm/mach-tegra/cpu-tegra.c index d6793f87cc5f..5599c298ac5b 100644 --- a/arch/arm/mach-tegra/cpu-tegra.c +++ b/arch/arm/mach-tegra/cpu-tegra.c @@ -139,43 +139,16 @@ static ssize_t show_throttle(struct cpufreq_policy *policy, char *buf) } cpufreq_freq_attr_ro(throttle); - -#ifdef CONFIG_DEBUG_FS - -static struct dentry *cpu_tegra_debugfs_root; - -static int __init tegra_cpu_debug_init(void) -{ - cpu_tegra_debugfs_root = debugfs_create_dir("cpu-tegra", 0); - - if (!cpu_tegra_debugfs_root) - return -ENOMEM; - - if (tegra_throttle_debug_init(cpu_tegra_debugfs_root)) - goto err_out; - - return 0; - -err_out: - debugfs_remove_recursive(cpu_tegra_debugfs_root); - return -ENOMEM; - -} - -static void __exit tegra_cpu_debug_exit(void) -{ - debugfs_remove_recursive(cpu_tegra_debugfs_root); -} - -late_initcall(tegra_cpu_debug_init); -module_exit(tegra_cpu_debug_exit); -#endif /* CONFIG_DEBUG_FS */ #endif /* CONFIG_TEGRA_THERMAL_THROTTLE */ #ifdef CONFIG_TEGRA_EDP_LIMITS static const struct tegra_edp_limits *cpu_edp_limits; static int cpu_edp_limits_size; + +static const unsigned int *system_edp_limits; +static bool system_edp_alarm; + static int edp_thermal_index; static cpumask_t edp_cpumask; static unsigned int edp_limit; @@ -185,22 +158,29 @@ unsigned int tegra_get_edp_limit(void) return edp_limit; } -static void edp_update_limit(void) +static unsigned int edp_predict_limit(unsigned int cpus) { - unsigned int limit = cpumask_weight(&edp_cpumask); -#ifndef CONFIG_TEGRA_EDP_EXACT_FREQ - int i; -#endif + unsigned int limit = 0; - if (!cpu_edp_limits) - return; + BUG_ON(cpus == 0); + if (cpu_edp_limits) { + BUG_ON(edp_thermal_index >= cpu_edp_limits_size); + limit = cpu_edp_limits[edp_thermal_index].freq_limits[cpus - 1]; + } + if (system_edp_limits && system_edp_alarm) + limit = min(limit, system_edp_limits[cpus - 1]); + + return limit; +} + +static void edp_update_limit(void) +{ + unsigned int limit = edp_predict_limit(cpumask_weight(&edp_cpumask)); - BUG_ON((edp_thermal_index >= cpu_edp_limits_size) || (limit == 0)); #ifdef CONFIG_TEGRA_EDP_EXACT_FREQ - edp_limit = cpu_edp_limits[edp_thermal_index].freq_limits[limit - 1]; + edp_limit = limit; #else - limit = cpu_edp_limits[edp_thermal_index].freq_limits[limit - 1]; - + unsigned int i; for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { if (freq_table[i].frequency > limit) { break; @@ -213,7 +193,7 @@ static void edp_update_limit(void) static unsigned int edp_governor_speed(unsigned int requested_speed) { - if ((!cpu_edp_limits) || (requested_speed <= edp_limit)) + if ((!edp_limit) || (requested_speed <= edp_limit)) return requested_speed; else return edp_limit; @@ -257,6 +237,26 @@ int tegra_edp_update_thermal_zone(int temperature) } EXPORT_SYMBOL_GPL(tegra_edp_update_thermal_zone); +int tegra_system_edp_alarm(bool alarm) +{ + int ret = -ENODEV; + + mutex_lock(&tegra_cpu_lock); + system_edp_alarm = alarm; + + /* Update cpu rate if cpufreq (at least on cpu0) is already started + and cancel emergency throttling after edp limit is applied */ + if (target_cpu_speed[0]) { + edp_update_limit(); + ret = tegra_cpu_set_speed_cap(NULL); + if (!ret && alarm) + tegra_edp_throttle_cpu_now(0); + } + mutex_unlock(&tegra_cpu_lock); + + return ret; +} + bool tegra_cpu_edp_favor_up(unsigned int n, int mp_overhead) { unsigned int current_limit, next_limit; @@ -267,10 +267,10 @@ bool tegra_cpu_edp_favor_up(unsigned int n, int mp_overhead) if (n >= ARRAY_SIZE(cpu_edp_limits->freq_limits)) return false; - current_limit = cpu_edp_limits[edp_thermal_index].freq_limits[n-1]; - next_limit = cpu_edp_limits[edp_thermal_index].freq_limits[n]; + current_limit = edp_predict_limit(n); + next_limit = edp_predict_limit(n + 1); - return ((next_limit * (n + 1)) > + return ((next_limit * (n + 1)) >= (current_limit * n * (100 + mp_overhead) / 100)); } @@ -284,8 +284,8 @@ bool tegra_cpu_edp_favor_down(unsigned int n, int mp_overhead) if (n > ARRAY_SIZE(cpu_edp_limits->freq_limits)) return true; - current_limit = cpu_edp_limits[edp_thermal_index].freq_limits[n-1]; - next_limit = cpu_edp_limits[edp_thermal_index].freq_limits[n-2]; + current_limit = edp_predict_limit(n); + next_limit = edp_predict_limit(n - 1); return ((next_limit * (n - 1) * (100 + mp_overhead) / 100)) > (current_limit * n); @@ -335,9 +335,10 @@ static struct notifier_block tegra_cpu_edp_notifier = { static void tegra_cpu_edp_init(bool resume) { + tegra_get_system_edp_limits(&system_edp_limits); tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size); - if (!cpu_edp_limits) { + if (!(cpu_edp_limits || system_edp_limits)) { if (!resume) pr_info("cpu-tegra: no EDP table is provided\n"); return; @@ -359,19 +360,80 @@ static void tegra_cpu_edp_init(bool resume) static void tegra_cpu_edp_exit(void) { - if (!cpu_edp_limits) + if (!(cpu_edp_limits || system_edp_limits)) return; unregister_hotcpu_notifier(&tegra_cpu_edp_notifier); } -#else /* CONFIG_TEGRA_EDP_LIMITS */ +#ifdef CONFIG_DEBUG_FS + +static int system_edp_alarm_get(void *data, u64 *val) +{ + *val = (u64)system_edp_alarm; + return 0; +} +static int system_edp_alarm_set(void *data, u64 val) +{ + if (val > 1) { /* emulate emergency throttling */ + tegra_edp_throttle_cpu_now(val); + return 0; + } + return tegra_system_edp_alarm((bool)val); +} +DEFINE_SIMPLE_ATTRIBUTE(system_edp_alarm_fops, + system_edp_alarm_get, system_edp_alarm_set, "%llu\n"); +static int __init tegra_edp_debug_init(struct dentry *cpu_tegra_debugfs_root) +{ + if (!debugfs_create_file("edp_alarm", 0644, cpu_tegra_debugfs_root, + NULL, &system_edp_alarm_fops)) + return -ENOMEM; + + return 0; +} +#endif + +#else /* CONFIG_TEGRA_EDP_LIMITS */ #define edp_governor_speed(requested_speed) (requested_speed) #define tegra_cpu_edp_init(resume) #define tegra_cpu_edp_exit() +#define tegra_edp_debug_init(cpu_tegra_debugfs_root) (0) #endif /* CONFIG_TEGRA_EDP_LIMITS */ +#ifdef CONFIG_DEBUG_FS + +static struct dentry *cpu_tegra_debugfs_root; + +static int __init tegra_cpu_debug_init(void) +{ + cpu_tegra_debugfs_root = debugfs_create_dir("cpu-tegra", 0); + + if (!cpu_tegra_debugfs_root) + return -ENOMEM; + + if (tegra_throttle_debug_init(cpu_tegra_debugfs_root)) + goto err_out; + + if (tegra_edp_debug_init(cpu_tegra_debugfs_root)) + goto err_out; + + return 0; + +err_out: + debugfs_remove_recursive(cpu_tegra_debugfs_root); + return -ENOMEM; +} + +static void __exit tegra_cpu_debug_exit(void) +{ + debugfs_remove_recursive(cpu_tegra_debugfs_root); +} + +late_initcall(tegra_cpu_debug_init); +module_exit(tegra_cpu_debug_exit); +#endif /* CONFIG_DEBUG_FS */ + int tegra_verify_speed(struct cpufreq_policy *policy) { return cpufreq_frequency_table_verify(policy, freq_table); |