cpufreq.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | cpufreq.c (6019d23a73c79fe4b0f531b0e968b14e1d6f50f1) |
---|---|
1/* 2 * linux/drivers/cpufreq/cpufreq.c 3 * 4 * Copyright (C) 2001 Russell King 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org> 7 * 8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> --- 24 unchanged lines hidden (view full) --- 33 34static LIST_HEAD(cpufreq_policy_list); 35 36static inline bool policy_is_inactive(struct cpufreq_policy *policy) 37{ 38 return cpumask_empty(policy->cpus); 39} 40 | 1/* 2 * linux/drivers/cpufreq/cpufreq.c 3 * 4 * Copyright (C) 2001 Russell King 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org> 7 * 8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> --- 24 unchanged lines hidden (view full) --- 33 34static LIST_HEAD(cpufreq_policy_list); 35 36static inline bool policy_is_inactive(struct cpufreq_policy *policy) 37{ 38 return cpumask_empty(policy->cpus); 39} 40 |
41static bool suitable_policy(struct cpufreq_policy *policy, bool active) 42{ 43 return active == !policy_is_inactive(policy); 44} 45 46/* Finds Next Acive/Inactive policy */ 47static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy, 48 bool active) 49{ 50 do { 51 policy = list_next_entry(policy, policy_list); 52 53 /* No more policies in the list */ 54 if (&policy->policy_list == &cpufreq_policy_list) 55 return NULL; 56 } while (!suitable_policy(policy, active)); 57 58 return policy; 59} 60 61static struct cpufreq_policy *first_policy(bool active) 62{ 63 struct cpufreq_policy *policy; 64 65 /* No policies in the list */ 66 if (list_empty(&cpufreq_policy_list)) 67 return NULL; 68 69 policy = list_first_entry(&cpufreq_policy_list, typeof(*policy), 70 policy_list); 71 72 if (!suitable_policy(policy, active)) 73 policy = next_policy(policy, active); 74 75 return policy; 76} 77 | |
78/* Macros to iterate over CPU policies */ | 41/* Macros to iterate over CPU policies */ |
79#define for_each_suitable_policy(__policy, __active) \ 80 for (__policy = first_policy(__active); \ 81 __policy; \ 82 __policy = next_policy(__policy, __active)) | 42#define for_each_suitable_policy(__policy, __active) \ 43 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \ 44 if ((__active) == !policy_is_inactive(__policy)) |
83 84#define for_each_active_policy(__policy) \ 85 for_each_suitable_policy(__policy, true) 86#define for_each_inactive_policy(__policy) \ 87 for_each_suitable_policy(__policy, false) 88 89#define for_each_policy(__policy) \ 90 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) --- 722 unchanged lines hidden (view full) --- 813 814static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) 815{ 816 struct cpufreq_policy *policy = to_policy(kobj); 817 struct freq_attr *fattr = to_attr(attr); 818 ssize_t ret; 819 820 down_read(&policy->rwsem); | 45 46#define for_each_active_policy(__policy) \ 47 for_each_suitable_policy(__policy, true) 48#define for_each_inactive_policy(__policy) \ 49 for_each_suitable_policy(__policy, false) 50 51#define for_each_policy(__policy) \ 52 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) --- 722 unchanged lines hidden (view full) --- 775 776static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) 777{ 778 struct cpufreq_policy *policy = to_policy(kobj); 779 struct freq_attr *fattr = to_attr(attr); 780 ssize_t ret; 781 782 down_read(&policy->rwsem); |
821 822 if (fattr->show) 823 ret = fattr->show(policy, buf); 824 else 825 ret = -EIO; 826 | 783 ret = fattr->show(policy, buf); |
827 up_read(&policy->rwsem); 828 829 return ret; 830} 831 832static ssize_t store(struct kobject *kobj, struct attribute *attr, 833 const char *buf, size_t count) 834{ 835 struct cpufreq_policy *policy = to_policy(kobj); 836 struct freq_attr *fattr = to_attr(attr); 837 ssize_t ret = -EINVAL; 838 839 get_online_cpus(); 840 | 784 up_read(&policy->rwsem); 785 786 return ret; 787} 788 789static ssize_t store(struct kobject *kobj, struct attribute *attr, 790 const char *buf, size_t count) 791{ 792 struct cpufreq_policy *policy = to_policy(kobj); 793 struct freq_attr *fattr = to_attr(attr); 794 ssize_t ret = -EINVAL; 795 796 get_online_cpus(); 797 |
841 if (!cpu_online(policy->cpu)) 842 goto unlock; 843 844 down_write(&policy->rwsem); 845 846 if (fattr->store) | 798 if (cpu_online(policy->cpu)) { 799 down_write(&policy->rwsem); |
847 ret = fattr->store(policy, buf, count); | 800 ret = fattr->store(policy, buf, count); |
848 else 849 ret = -EIO; | 801 up_write(&policy->rwsem); 802 } |
850 | 803 |
851 up_write(&policy->rwsem); 852unlock: | |
853 put_online_cpus(); 854 855 return ret; 856} 857 858static void cpufreq_sysfs_release(struct kobject *kobj) 859{ 860 struct cpufreq_policy *policy = to_policy(kobj); --- 93 unchanged lines hidden (view full) --- 954 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); 955 if (ret) 956 return ret; 957 } 958 959 return cpufreq_add_dev_symlink(policy); 960} 961 | 804 put_online_cpus(); 805 806 return ret; 807} 808 809static void cpufreq_sysfs_release(struct kobject *kobj) 810{ 811 struct cpufreq_policy *policy = to_policy(kobj); --- 93 unchanged lines hidden (view full) --- 905 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); 906 if (ret) 907 return ret; 908 } 909 910 return cpufreq_add_dev_symlink(policy); 911} 912 |
913__weak struct cpufreq_governor *cpufreq_default_governor(void) 914{ 915 return NULL; 916} 917 |
|
962static int cpufreq_init_policy(struct cpufreq_policy *policy) 963{ 964 struct cpufreq_governor *gov = NULL; 965 struct cpufreq_policy new_policy; 966 967 memcpy(&new_policy, policy, sizeof(*policy)); 968 969 /* Update governor of new_policy to the governor used before hotplug */ 970 gov = find_governor(policy->last_governor); | 918static int cpufreq_init_policy(struct cpufreq_policy *policy) 919{ 920 struct cpufreq_governor *gov = NULL; 921 struct cpufreq_policy new_policy; 922 923 memcpy(&new_policy, policy, sizeof(*policy)); 924 925 /* Update governor of new_policy to the governor used before hotplug */ 926 gov = find_governor(policy->last_governor); |
971 if (gov) | 927 if (gov) { |
972 pr_debug("Restoring governor %s for cpu %d\n", 973 policy->governor->name, policy->cpu); | 928 pr_debug("Restoring governor %s for cpu %d\n", 929 policy->governor->name, policy->cpu); |
974 else 975 gov = CPUFREQ_DEFAULT_GOVERNOR; | 930 } else { 931 gov = cpufreq_default_governor(); 932 if (!gov) 933 return -ENODATA; 934 } |
976 977 new_policy.governor = gov; 978 979 /* Use the default policy if there is no last_policy. */ 980 if (cpufreq_driver->setpolicy) { 981 if (policy->last_policy) 982 new_policy.policy = policy->last_policy; 983 else --- 857 unchanged lines hidden (view full) --- 1841 return retval; 1842} 1843 1844int __cpufreq_driver_target(struct cpufreq_policy *policy, 1845 unsigned int target_freq, 1846 unsigned int relation) 1847{ 1848 unsigned int old_target_freq = target_freq; | 935 936 new_policy.governor = gov; 937 938 /* Use the default policy if there is no last_policy. */ 939 if (cpufreq_driver->setpolicy) { 940 if (policy->last_policy) 941 new_policy.policy = policy->last_policy; 942 else --- 857 unchanged lines hidden (view full) --- 1800 return retval; 1801} 1802 1803int __cpufreq_driver_target(struct cpufreq_policy *policy, 1804 unsigned int target_freq, 1805 unsigned int relation) 1806{ 1807 unsigned int old_target_freq = target_freq; |
1849 int retval = -EINVAL; | 1808 struct cpufreq_frequency_table *freq_table; 1809 int index, retval; |
1850 1851 if (cpufreq_disabled()) 1852 return -ENODEV; 1853 1854 /* Make sure that target_freq is within supported range */ 1855 if (target_freq > policy->max) 1856 target_freq = policy->max; 1857 if (target_freq < policy->min) --- 10 unchanged lines hidden (view full) --- 1868 */ 1869 if (target_freq == policy->cur) 1870 return 0; 1871 1872 /* Save last value to restore later on errors */ 1873 policy->restore_freq = policy->cur; 1874 1875 if (cpufreq_driver->target) | 1810 1811 if (cpufreq_disabled()) 1812 return -ENODEV; 1813 1814 /* Make sure that target_freq is within supported range */ 1815 if (target_freq > policy->max) 1816 target_freq = policy->max; 1817 if (target_freq < policy->min) --- 10 unchanged lines hidden (view full) --- 1828 */ 1829 if (target_freq == policy->cur) 1830 return 0; 1831 1832 /* Save last value to restore later on errors */ 1833 policy->restore_freq = policy->cur; 1834 1835 if (cpufreq_driver->target) |
1876 retval = cpufreq_driver->target(policy, target_freq, relation); 1877 else if (cpufreq_driver->target_index) { 1878 struct cpufreq_frequency_table *freq_table; 1879 int index; | 1836 return cpufreq_driver->target(policy, target_freq, relation); |
1880 | 1837 |
1881 freq_table = cpufreq_frequency_get_table(policy->cpu); 1882 if (unlikely(!freq_table)) { 1883 pr_err("%s: Unable to find freq_table\n", __func__); 1884 goto out; 1885 } | 1838 if (!cpufreq_driver->target_index) 1839 return -EINVAL; |
1886 | 1840 |
1887 retval = cpufreq_frequency_table_target(policy, freq_table, 1888 target_freq, relation, &index); 1889 if (unlikely(retval)) { 1890 pr_err("%s: Unable to find matching freq\n", __func__); 1891 goto out; 1892 } | 1841 freq_table = cpufreq_frequency_get_table(policy->cpu); 1842 if (unlikely(!freq_table)) { 1843 pr_err("%s: Unable to find freq_table\n", __func__); 1844 return -EINVAL; 1845 } |
1893 | 1846 |
1894 if (freq_table[index].frequency == policy->cur) { 1895 retval = 0; 1896 goto out; 1897 } 1898 1899 retval = __target_index(policy, freq_table, index); | 1847 retval = cpufreq_frequency_table_target(policy, freq_table, target_freq, 1848 relation, &index); 1849 if (unlikely(retval)) { 1850 pr_err("%s: Unable to find matching freq\n", __func__); 1851 return retval; |
1900 } 1901 | 1852 } 1853 |
1902out: 1903 return retval; | 1854 if (freq_table[index].frequency == policy->cur) 1855 return 0; 1856 1857 return __target_index(policy, freq_table, index); |
1904} 1905EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1906 1907int cpufreq_driver_target(struct cpufreq_policy *policy, 1908 unsigned int target_freq, 1909 unsigned int relation) 1910{ 1911 int ret = -EINVAL; 1912 1913 down_write(&policy->rwsem); 1914 1915 ret = __cpufreq_driver_target(policy, target_freq, relation); 1916 1917 up_write(&policy->rwsem); 1918 1919 return ret; 1920} 1921EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1922 | 1858} 1859EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1860 1861int cpufreq_driver_target(struct cpufreq_policy *policy, 1862 unsigned int target_freq, 1863 unsigned int relation) 1864{ 1865 int ret = -EINVAL; 1866 1867 down_write(&policy->rwsem); 1868 1869 ret = __cpufreq_driver_target(policy, target_freq, relation); 1870 1871 up_write(&policy->rwsem); 1872 1873 return ret; 1874} 1875EXPORT_SYMBOL_GPL(cpufreq_driver_target); 1876 |
1877__weak struct cpufreq_governor *cpufreq_fallback_governor(void) 1878{ 1879 return NULL; 1880} 1881 |
|
1923static int __cpufreq_governor(struct cpufreq_policy *policy, 1924 unsigned int event) 1925{ 1926 int ret; 1927 | 1882static int __cpufreq_governor(struct cpufreq_policy *policy, 1883 unsigned int event) 1884{ 1885 int ret; 1886 |
1928 /* Only must be defined when default governor is known to have latency 1929 restrictions, like e.g. conservative or ondemand. 1930 That this is the case is already ensured in Kconfig 1931 */ 1932#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE 1933 struct cpufreq_governor *gov = &cpufreq_gov_performance; 1934#else 1935 struct cpufreq_governor *gov = NULL; 1936#endif 1937 | |
1938 /* Don't start any governor operations if we are entering suspend */ 1939 if (cpufreq_suspended) 1940 return 0; 1941 /* 1942 * Governor might not be initiated here if ACPI _PPC changed 1943 * notification happened, so check it. 1944 */ 1945 if (!policy->governor) 1946 return -EINVAL; 1947 1948 if (policy->governor->max_transition_latency && 1949 policy->cpuinfo.transition_latency > 1950 policy->governor->max_transition_latency) { | 1887 /* Don't start any governor operations if we are entering suspend */ 1888 if (cpufreq_suspended) 1889 return 0; 1890 /* 1891 * Governor might not be initiated here if ACPI _PPC changed 1892 * notification happened, so check it. 1893 */ 1894 if (!policy->governor) 1895 return -EINVAL; 1896 1897 if (policy->governor->max_transition_latency && 1898 policy->cpuinfo.transition_latency > 1899 policy->governor->max_transition_latency) { |
1951 if (!gov) 1952 return -EINVAL; 1953 else { | 1900 struct cpufreq_governor *gov = cpufreq_fallback_governor(); 1901 1902 if (gov) { |
1954 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n", 1955 policy->governor->name, gov->name); 1956 policy->governor = gov; | 1903 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n", 1904 policy->governor->name, gov->name); 1905 policy->governor = gov; |
1906 } else { 1907 return -EINVAL; |
|
1957 } 1958 } 1959 1960 if (event == CPUFREQ_GOV_POLICY_INIT) 1961 if (!try_module_get(policy->governor->owner)) 1962 return -EINVAL; 1963 1964 pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event); --- 414 unchanged lines hidden (view full) --- 2379 *********************************************************************/ 2380 2381/** 2382 * cpufreq_register_driver - register a CPU Frequency driver 2383 * @driver_data: A struct cpufreq_driver containing the values# 2384 * submitted by the CPU Frequency driver. 2385 * 2386 * Registers a CPU Frequency driver to this core code. This code | 1908 } 1909 } 1910 1911 if (event == CPUFREQ_GOV_POLICY_INIT) 1912 if (!try_module_get(policy->governor->owner)) 1913 return -EINVAL; 1914 1915 pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event); --- 414 unchanged lines hidden (view full) --- 2330 *********************************************************************/ 2331 2332/** 2333 * cpufreq_register_driver - register a CPU Frequency driver 2334 * @driver_data: A struct cpufreq_driver containing the values# 2335 * submitted by the CPU Frequency driver. 2336 * 2337 * Registers a CPU Frequency driver to this core code. This code |
2387 * returns zero on success, -EBUSY when another driver got here first | 2338 * returns zero on success, -EEXIST when another driver got here first |
2388 * (and isn't unregistered in the meantime). 2389 * 2390 */ 2391int cpufreq_register_driver(struct cpufreq_driver *driver_data) 2392{ 2393 unsigned long flags; 2394 int ret; 2395 --- 123 unchanged lines hidden --- | 2339 * (and isn't unregistered in the meantime). 2340 * 2341 */ 2342int cpufreq_register_driver(struct cpufreq_driver *driver_data) 2343{ 2344 unsigned long flags; 2345 int ret; 2346 --- 123 unchanged lines hidden --- |