Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge back cpufreq material for 6.16

+215 -288
+2 -5
drivers/cpufreq/amd-pstate.c
··· 808 808 sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu); 809 809 } 810 810 811 - static void amd_pstate_update_limits(unsigned int cpu) 811 + static void amd_pstate_update_limits(struct cpufreq_policy *policy) 812 812 { 813 - struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu); 814 813 struct amd_cpudata *cpudata; 815 814 u32 prev_high = 0, cur_high = 0; 816 815 bool highest_perf_changed = false; 816 + unsigned int cpu = policy->cpu; 817 817 818 818 if (!amd_pstate_prefcore) 819 - return; 820 - 821 - if (!policy) 822 819 return; 823 820 824 821 if (amd_get_highest_perf(cpu, &cur_high))
+188 -250
drivers/cpufreq/cpufreq.c
··· 255 255 } 256 256 EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 257 257 258 - /** 259 - * cpufreq_cpu_release - Unlock a policy and decrement its usage counter. 260 - * @policy: cpufreq policy returned by cpufreq_cpu_acquire(). 261 - */ 262 - void cpufreq_cpu_release(struct cpufreq_policy *policy) 263 - { 264 - if (WARN_ON(!policy)) 265 - return; 266 - 267 - lockdep_assert_held(&policy->rwsem); 268 - 269 - up_write(&policy->rwsem); 270 - 271 - cpufreq_cpu_put(policy); 272 - } 273 - 274 - /** 275 - * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it. 276 - * @cpu: CPU to find the policy for. 277 - * 278 - * Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and 279 - * if the policy returned by it is not NULL, acquire its rwsem for writing. 280 - * Return the policy if it is active or release it and return NULL otherwise. 281 - * 282 - * The policy returned by this function has to be released with the help of 283 - * cpufreq_cpu_release() in order to release its rwsem and balance its usage 284 - * counter properly. 285 - */ 286 - struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu) 287 - { 288 - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 289 - 290 - if (!policy) 291 - return NULL; 292 - 293 - down_write(&policy->rwsem); 294 - 295 - if (policy_is_inactive(policy)) { 296 - cpufreq_cpu_release(policy); 297 - return NULL; 298 - } 299 - 300 - return policy; 301 - } 302 - 303 258 /********************************************************************* 304 259 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 305 260 *********************************************************************/ ··· 591 636 return sysfs_emit(buf, "%d\n", policy->boost_enabled); 592 637 } 593 638 639 + static int policy_set_boost(struct cpufreq_policy *policy, bool enable) 640 + { 641 + int ret; 642 + 643 + if (policy->boost_enabled == enable) 644 + return 0; 645 + 646 + policy->boost_enabled = enable; 647 + 648 + ret = cpufreq_driver->set_boost(policy, enable); 649 + if (ret) 650 + policy->boost_enabled = !policy->boost_enabled; 651 + 652 + return ret; 653 + } 654 + 594 655 static ssize_t store_local_boost(struct cpufreq_policy *policy, 595 656 const char *buf, size_t count) 596 657 { ··· 622 651 if (!policy->boost_supported) 623 652 return -EINVAL; 624 653 625 - if (policy->boost_enabled == enable) 626 - return count; 627 - 628 - policy->boost_enabled = enable; 629 - 630 654 cpus_read_lock(); 631 - ret = cpufreq_driver->set_boost(policy, enable); 655 + ret = policy_set_boost(policy, enable); 632 656 cpus_read_unlock(); 633 657 634 - if (ret) { 635 - policy->boost_enabled = !policy->boost_enabled; 636 - return ret; 637 - } 658 + if (!ret) 659 + return count; 638 660 639 - return count; 661 + return ret; 640 662 } 641 663 642 664 static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost); ··· 989 1025 { 990 1026 struct cpufreq_policy *policy = to_policy(kobj); 991 1027 struct freq_attr *fattr = to_attr(attr); 992 - ssize_t ret = -EBUSY; 993 1028 994 1029 if (!fattr->show) 995 1030 return -EIO; 996 1031 997 - down_read(&policy->rwsem); 998 - if (likely(!policy_is_inactive(policy))) 999 - ret = fattr->show(policy, buf); 1000 - up_read(&policy->rwsem); 1032 + guard(cpufreq_policy_read)(policy); 1001 1033 1002 - return ret; 1034 + if (likely(!policy_is_inactive(policy))) 1035 + return fattr->show(policy, buf); 1036 + 1037 + return -EBUSY; 1003 1038 } 1004 1039 1005 1040 static ssize_t store(struct kobject *kobj, struct attribute *attr, ··· 1006 1043 { 1007 1044 struct cpufreq_policy *policy = to_policy(kobj); 1008 1045 struct freq_attr *fattr = to_attr(attr); 1009 - ssize_t ret = -EBUSY; 1010 1046 1011 1047 if (!fattr->store) 1012 1048 return -EIO; 1013 1049 1014 - down_write(&policy->rwsem); 1015 - if (likely(!policy_is_inactive(policy))) 1016 - ret = fattr->store(policy, buf, count); 1017 - up_write(&policy->rwsem); 1050 + guard(cpufreq_policy_write)(policy); 1018 1051 1019 - return ret; 1052 + if (likely(!policy_is_inactive(policy))) 1053 + return fattr->store(policy, buf, count); 1054 + 1055 + return -EBUSY; 1020 1056 } 1021 1057 1022 1058 static void cpufreq_sysfs_release(struct kobject *kobj) ··· 1173 1211 if (cpumask_test_cpu(cpu, policy->cpus)) 1174 1212 return 0; 1175 1213 1176 - down_write(&policy->rwsem); 1214 + guard(cpufreq_policy_write)(policy); 1215 + 1177 1216 if (has_target()) 1178 1217 cpufreq_stop_governor(policy); 1179 1218 ··· 1185 1222 if (ret) 1186 1223 pr_err("%s: Failed to start governor\n", __func__); 1187 1224 } 1188 - up_write(&policy->rwsem); 1225 + 1189 1226 return ret; 1190 1227 } 1191 1228 ··· 1205 1242 container_of(work, struct cpufreq_policy, update); 1206 1243 1207 1244 pr_debug("handle_update for cpu %u called\n", policy->cpu); 1208 - down_write(&policy->rwsem); 1245 + 1246 + guard(cpufreq_policy_write)(policy); 1247 + 1209 1248 refresh_frequency_limits(policy); 1210 - up_write(&policy->rwsem); 1211 1249 } 1212 1250 1213 1251 static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, ··· 1234 1270 struct kobject *kobj; 1235 1271 struct completion *cmp; 1236 1272 1237 - down_write(&policy->rwsem); 1238 - cpufreq_stats_free_table(policy); 1239 - kobj = &policy->kobj; 1240 - cmp = &policy->kobj_unregister; 1241 - up_write(&policy->rwsem); 1273 + scoped_guard(cpufreq_policy_write, policy) { 1274 + cpufreq_stats_free_table(policy); 1275 + kobj = &policy->kobj; 1276 + cmp = &policy->kobj_unregister; 1277 + } 1242 1278 kobject_put(kobj); 1243 1279 1244 1280 /* ··· 1314 1350 init_waitqueue_head(&policy->transition_wait); 1315 1351 INIT_WORK(&policy->update, handle_update); 1316 1352 1317 - policy->cpu = cpu; 1318 1353 return policy; 1319 1354 1320 1355 err_min_qos_notifier: ··· 1382 1419 kfree(policy); 1383 1420 } 1384 1421 1385 - static int cpufreq_online(unsigned int cpu) 1422 + static int cpufreq_policy_online(struct cpufreq_policy *policy, 1423 + unsigned int cpu, bool new_policy) 1386 1424 { 1387 - struct cpufreq_policy *policy; 1388 - bool new_policy; 1389 1425 unsigned long flags; 1390 1426 unsigned int j; 1391 1427 int ret; 1392 1428 1393 - pr_debug("%s: bringing CPU%u online\n", __func__, cpu); 1429 + guard(cpufreq_policy_write)(policy); 1394 1430 1395 - /* Check if this CPU already has a policy to manage it */ 1396 - policy = per_cpu(cpufreq_cpu_data, cpu); 1397 - if (policy) { 1398 - WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); 1399 - if (!policy_is_inactive(policy)) 1400 - return cpufreq_add_policy_cpu(policy, cpu); 1401 - 1402 - /* This is the only online CPU for the policy. Start over. */ 1403 - new_policy = false; 1404 - down_write(&policy->rwsem); 1405 - policy->cpu = cpu; 1406 - policy->governor = NULL; 1407 - } else { 1408 - new_policy = true; 1409 - policy = cpufreq_policy_alloc(cpu); 1410 - if (!policy) 1411 - return -ENOMEM; 1412 - down_write(&policy->rwsem); 1413 - } 1431 + policy->cpu = cpu; 1432 + policy->governor = NULL; 1414 1433 1415 1434 if (!new_policy && cpufreq_driver->online) { 1416 1435 /* Recover policy->cpus using related_cpus */ ··· 1415 1470 if (ret) { 1416 1471 pr_debug("%s: %d: initialization failed\n", __func__, 1417 1472 __LINE__); 1418 - goto out_free_policy; 1473 + goto out_clear_policy; 1419 1474 } 1420 1475 1421 1476 /* ··· 1566 1621 goto out_destroy_policy; 1567 1622 } 1568 1623 1569 - up_write(&policy->rwsem); 1570 - 1571 - kobject_uevent(&policy->kobj, KOBJ_ADD); 1572 - 1573 - /* Callback for handling stuff after policy is ready */ 1574 - if (cpufreq_driver->ready) 1575 - cpufreq_driver->ready(policy); 1576 - 1577 - /* Register cpufreq cooling only for a new policy */ 1578 - if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) 1579 - policy->cdev = of_cpufreq_cooling_register(policy); 1580 - 1581 - /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ 1582 - if (cpufreq_driver->set_boost && policy->boost_supported && 1583 - policy->boost_enabled != cpufreq_boost_enabled()) { 1584 - policy->boost_enabled = cpufreq_boost_enabled(); 1585 - ret = cpufreq_driver->set_boost(policy, policy->boost_enabled); 1586 - if (ret) { 1587 - /* If the set_boost fails, the online operation is not affected */ 1588 - pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu, 1589 - str_enable_disable(policy->boost_enabled)); 1590 - policy->boost_enabled = !policy->boost_enabled; 1591 - } 1592 - } 1593 - 1594 - pr_debug("initialization complete\n"); 1595 - 1596 1624 return 0; 1597 1625 1598 1626 out_destroy_policy: ··· 1580 1662 if (cpufreq_driver->exit) 1581 1663 cpufreq_driver->exit(policy); 1582 1664 1583 - out_free_policy: 1665 + out_clear_policy: 1584 1666 cpumask_clear(policy->cpus); 1585 - up_write(&policy->rwsem); 1586 1667 1587 - cpufreq_policy_free(policy); 1588 1668 return ret; 1669 + } 1670 + 1671 + static int cpufreq_online(unsigned int cpu) 1672 + { 1673 + struct cpufreq_policy *policy; 1674 + bool new_policy; 1675 + int ret; 1676 + 1677 + pr_debug("%s: bringing CPU%u online\n", __func__, cpu); 1678 + 1679 + /* Check if this CPU already has a policy to manage it */ 1680 + policy = per_cpu(cpufreq_cpu_data, cpu); 1681 + if (policy) { 1682 + WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); 1683 + if (!policy_is_inactive(policy)) 1684 + return cpufreq_add_policy_cpu(policy, cpu); 1685 + 1686 + /* This is the only online CPU for the policy. Start over. */ 1687 + new_policy = false; 1688 + } else { 1689 + new_policy = true; 1690 + policy = cpufreq_policy_alloc(cpu); 1691 + if (!policy) 1692 + return -ENOMEM; 1693 + } 1694 + 1695 + ret = cpufreq_policy_online(policy, cpu, new_policy); 1696 + if (ret) { 1697 + cpufreq_policy_free(policy); 1698 + return ret; 1699 + } 1700 + 1701 + kobject_uevent(&policy->kobj, KOBJ_ADD); 1702 + 1703 + /* Callback for handling stuff after policy is ready */ 1704 + if (cpufreq_driver->ready) 1705 + cpufreq_driver->ready(policy); 1706 + 1707 + /* Register cpufreq cooling only for a new policy */ 1708 + if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver)) 1709 + policy->cdev = of_cpufreq_cooling_register(policy); 1710 + 1711 + /* 1712 + * Let the per-policy boost flag mirror the cpufreq_driver boost during 1713 + * initialization for a new policy. For an existing policy, maintain the 1714 + * previous boost value unless global boost is disabled. 1715 + */ 1716 + if (cpufreq_driver->set_boost && policy->boost_supported && 1717 + (new_policy || !cpufreq_boost_enabled())) { 1718 + ret = policy_set_boost(policy, cpufreq_boost_enabled()); 1719 + if (ret) { 1720 + /* If the set_boost fails, the online operation is not affected */ 1721 + pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu, 1722 + str_enable_disable(cpufreq_boost_enabled())); 1723 + } 1724 + } 1725 + 1726 + pr_debug("initialization complete\n"); 1727 + 1728 + return 0; 1589 1729 } 1590 1730 1591 1731 /** ··· 1733 1757 return 0; 1734 1758 } 1735 1759 1736 - down_write(&policy->rwsem); 1760 + guard(cpufreq_policy_write)(policy); 1737 1761 1738 1762 __cpufreq_offline(cpu, policy); 1739 1763 1740 - up_write(&policy->rwsem); 1741 1764 return 0; 1742 1765 } 1743 1766 ··· 1753 1778 if (!policy) 1754 1779 return; 1755 1780 1756 - down_write(&policy->rwsem); 1781 + scoped_guard(cpufreq_policy_write, policy) { 1782 + if (cpu_online(cpu)) 1783 + __cpufreq_offline(cpu, policy); 1757 1784 1758 - if (cpu_online(cpu)) 1759 - __cpufreq_offline(cpu, policy); 1785 + remove_cpu_dev_symlink(policy, cpu, dev); 1760 1786 1761 - remove_cpu_dev_symlink(policy, cpu, dev); 1787 + if (!cpumask_empty(policy->real_cpus)) 1788 + return; 1762 1789 1763 - if (!cpumask_empty(policy->real_cpus)) { 1764 - up_write(&policy->rwsem); 1765 - return; 1790 + /* 1791 + * Unregister cpufreq cooling once all the CPUs of the policy 1792 + * are removed. 1793 + */ 1794 + if (cpufreq_thermal_control_enabled(cpufreq_driver)) { 1795 + cpufreq_cooling_unregister(policy->cdev); 1796 + policy->cdev = NULL; 1797 + } 1798 + 1799 + /* We did light-weight exit earlier, do full tear down now */ 1800 + if (cpufreq_driver->offline && cpufreq_driver->exit) 1801 + cpufreq_driver->exit(policy); 1766 1802 } 1767 - 1768 - /* 1769 - * Unregister cpufreq cooling once all the CPUs of the policy are 1770 - * removed. 1771 - */ 1772 - if (cpufreq_thermal_control_enabled(cpufreq_driver)) { 1773 - cpufreq_cooling_unregister(policy->cdev); 1774 - policy->cdev = NULL; 1775 - } 1776 - 1777 - /* We did light-weight exit earlier, do full tear down now */ 1778 - if (cpufreq_driver->offline && cpufreq_driver->exit) 1779 - cpufreq_driver->exit(policy); 1780 - 1781 - up_write(&policy->rwsem); 1782 1803 1783 1804 cpufreq_policy_free(policy); 1784 1805 } ··· 1845 1874 */ 1846 1875 unsigned int cpufreq_quick_get(unsigned int cpu) 1847 1876 { 1848 - struct cpufreq_policy *policy; 1849 - unsigned int ret_freq = 0; 1877 + struct cpufreq_policy *policy __free(put_cpufreq_policy) = NULL; 1850 1878 unsigned long flags; 1851 1879 1852 1880 read_lock_irqsave(&cpufreq_driver_lock, flags); 1853 1881 1854 1882 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { 1855 - ret_freq = cpufreq_driver->get(cpu); 1883 + unsigned int ret_freq = cpufreq_driver->get(cpu); 1884 + 1856 1885 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1886 + 1857 1887 return ret_freq; 1858 1888 } 1859 1889 1860 1890 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1861 1891 1862 1892 policy = cpufreq_cpu_get(cpu); 1863 - if (policy) { 1864 - ret_freq = policy->cur; 1865 - cpufreq_cpu_put(policy); 1866 - } 1893 + if (policy) 1894 + return policy->cur; 1867 1895 1868 - return ret_freq; 1896 + return 0; 1869 1897 } 1870 1898 EXPORT_SYMBOL(cpufreq_quick_get); 1871 1899 ··· 1876 1906 */ 1877 1907 unsigned int cpufreq_quick_get_max(unsigned int cpu) 1878 1908 { 1879 - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 1880 - unsigned int ret_freq = 0; 1909 + struct cpufreq_policy *policy __free(put_cpufreq_policy); 1881 1910 1882 - if (policy) { 1883 - ret_freq = policy->max; 1884 - cpufreq_cpu_put(policy); 1885 - } 1911 + policy = cpufreq_cpu_get(cpu); 1912 + if (policy) 1913 + return policy->max; 1886 1914 1887 - return ret_freq; 1915 + return 0; 1888 1916 } 1889 1917 EXPORT_SYMBOL(cpufreq_quick_get_max); 1890 1918 ··· 1894 1926 */ 1895 1927 __weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu) 1896 1928 { 1897 - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 1898 - unsigned int ret_freq = 0; 1929 + struct cpufreq_policy *policy __free(put_cpufreq_policy); 1899 1930 1900 - if (policy) { 1901 - ret_freq = policy->cpuinfo.max_freq; 1902 - cpufreq_cpu_put(policy); 1903 - } 1931 + policy = cpufreq_cpu_get(cpu); 1932 + if (policy) 1933 + return policy->cpuinfo.max_freq; 1904 1934 1905 - return ret_freq; 1935 + return 0; 1906 1936 } 1907 1937 EXPORT_SYMBOL(cpufreq_get_hw_max_freq); 1908 1938 ··· 1920 1954 */ 1921 1955 unsigned int cpufreq_get(unsigned int cpu) 1922 1956 { 1923 - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 1924 - unsigned int ret_freq = 0; 1957 + struct cpufreq_policy *policy __free(put_cpufreq_policy); 1925 1958 1926 - if (policy) { 1927 - down_read(&policy->rwsem); 1928 - if (cpufreq_driver->get) 1929 - ret_freq = __cpufreq_get(policy); 1930 - up_read(&policy->rwsem); 1959 + policy = cpufreq_cpu_get(cpu); 1960 + if (!policy) 1961 + return 0; 1931 1962 1932 - cpufreq_cpu_put(policy); 1933 - } 1963 + guard(cpufreq_policy_read)(policy); 1934 1964 1935 - return ret_freq; 1965 + if (cpufreq_driver->get) 1966 + return __cpufreq_get(policy); 1967 + 1968 + return 0; 1936 1969 } 1937 1970 EXPORT_SYMBOL(cpufreq_get); 1938 1971 ··· 1990 2025 1991 2026 for_each_active_policy(policy) { 1992 2027 if (has_target()) { 1993 - down_write(&policy->rwsem); 1994 - cpufreq_stop_governor(policy); 1995 - up_write(&policy->rwsem); 2028 + scoped_guard(cpufreq_policy_write, policy) { 2029 + cpufreq_stop_governor(policy); 2030 + } 1996 2031 } 1997 2032 1998 2033 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) ··· 2033 2068 pr_err("%s: Failed to resume driver: %s\n", __func__, 2034 2069 cpufreq_driver->name); 2035 2070 } else if (has_target()) { 2036 - down_write(&policy->rwsem); 2037 - ret = cpufreq_start_governor(policy); 2038 - up_write(&policy->rwsem); 2071 + scoped_guard(cpufreq_policy_write, policy) { 2072 + ret = cpufreq_start_governor(policy); 2073 + } 2039 2074 2040 2075 if (ret) 2041 2076 pr_err("%s: Failed to start governor for CPU%u's policy\n", ··· 2403 2438 unsigned int target_freq, 2404 2439 unsigned int relation) 2405 2440 { 2406 - int ret; 2441 + guard(cpufreq_policy_write)(policy); 2407 2442 2408 - down_write(&policy->rwsem); 2409 - 2410 - ret = __cpufreq_driver_target(policy, target_freq, relation); 2411 - 2412 - up_write(&policy->rwsem); 2413 - 2414 - return ret; 2443 + return __cpufreq_driver_target(policy, target_freq, relation); 2415 2444 } 2416 2445 EXPORT_SYMBOL_GPL(cpufreq_driver_target); 2417 2446 ··· 2577 2618 * POLICY INTERFACE * 2578 2619 *********************************************************************/ 2579 2620 2580 - /** 2581 - * cpufreq_get_policy - get the current cpufreq_policy 2582 - * @policy: struct cpufreq_policy into which the current cpufreq_policy 2583 - * is written 2584 - * @cpu: CPU to find the policy for 2585 - * 2586 - * Reads the current cpufreq policy. 2587 - */ 2588 - int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) 2589 - { 2590 - struct cpufreq_policy *cpu_policy; 2591 - if (!policy) 2592 - return -EINVAL; 2593 - 2594 - cpu_policy = cpufreq_cpu_get(cpu); 2595 - if (!cpu_policy) 2596 - return -EINVAL; 2597 - 2598 - memcpy(policy, cpu_policy, sizeof(*policy)); 2599 - 2600 - cpufreq_cpu_put(cpu_policy); 2601 - return 0; 2602 - } 2603 - EXPORT_SYMBOL(cpufreq_get_policy); 2604 - 2605 2621 DEFINE_PER_CPU(unsigned long, cpufreq_pressure); 2606 2622 2607 2623 /** ··· 2727 2793 return ret; 2728 2794 } 2729 2795 2796 + static void cpufreq_policy_refresh(struct cpufreq_policy *policy) 2797 + { 2798 + guard(cpufreq_policy_write)(policy); 2799 + 2800 + /* 2801 + * BIOS might change freq behind our back 2802 + * -> ask driver for current freq and notify governors about a change 2803 + */ 2804 + if (cpufreq_driver->get && has_target() && 2805 + (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) 2806 + return; 2807 + 2808 + refresh_frequency_limits(policy); 2809 + } 2810 + 2730 2811 /** 2731 2812 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy. 2732 2813 * @cpu: CPU to re-evaluate the policy for. ··· 2753 2804 */ 2754 2805 void cpufreq_update_policy(unsigned int cpu) 2755 2806 { 2756 - struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); 2807 + struct cpufreq_policy *policy __free(put_cpufreq_policy); 2757 2808 2809 + policy = cpufreq_cpu_get(cpu); 2758 2810 if (!policy) 2759 2811 return; 2760 2812 2761 - /* 2762 - * BIOS might change freq behind our back 2763 - * -> ask driver for current freq and notify governors about a change 2764 - */ 2765 - if (cpufreq_driver->get && has_target() && 2766 - (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) 2767 - goto unlock; 2768 - 2769 - refresh_frequency_limits(policy); 2770 - 2771 - unlock: 2772 - cpufreq_cpu_release(policy); 2813 + cpufreq_policy_refresh(policy); 2773 2814 } 2774 2815 EXPORT_SYMBOL(cpufreq_update_policy); 2775 2816 ··· 2768 2829 * @cpu: CPU to update the policy limits for. 2769 2830 * 2770 2831 * Invoke the driver's ->update_limits callback if present or call 2771 - * cpufreq_update_policy() for @cpu. 2832 + * cpufreq_policy_refresh() for @cpu. 2772 2833 */ 2773 2834 void cpufreq_update_limits(unsigned int cpu) 2774 2835 { ··· 2779 2840 return; 2780 2841 2781 2842 if (cpufreq_driver->update_limits) 2782 - cpufreq_driver->update_limits(cpu); 2843 + cpufreq_driver->update_limits(policy); 2783 2844 else 2784 - cpufreq_update_policy(cpu); 2845 + cpufreq_policy_refresh(policy); 2785 2846 } 2786 2847 EXPORT_SYMBOL_GPL(cpufreq_update_limits); 2787 2848 ··· 2815 2876 unsigned long flags; 2816 2877 int ret = 0; 2817 2878 2818 - if (cpufreq_driver->boost_enabled == state) 2819 - return 0; 2879 + /* 2880 + * Don't compare 'cpufreq_driver->boost_enabled' with 'state' here to 2881 + * make sure all policies are in sync with global boost flag. 2882 + */ 2820 2883 2821 2884 write_lock_irqsave(&cpufreq_driver_lock, flags); 2822 2885 cpufreq_driver->boost_enabled = state; ··· 2829 2888 if (!policy->boost_supported) 2830 2889 continue; 2831 2890 2832 - policy->boost_enabled = state; 2833 - ret = cpufreq_driver->set_boost(policy, state); 2834 - if (ret) { 2835 - policy->boost_enabled = !policy->boost_enabled; 2891 + ret = policy_set_boost(policy, state); 2892 + if (ret) 2836 2893 goto err_reset_state; 2837 - } 2838 2894 } 2839 2895 cpus_read_unlock(); 2840 2896
+18 -29
drivers/cpufreq/intel_pstate.c
··· 1356 1356 cpufreq_update_policy(cpu); 1357 1357 } 1358 1358 1359 - static void __intel_pstate_update_max_freq(struct cpudata *cpudata, 1360 - struct cpufreq_policy *policy) 1359 + static void __intel_pstate_update_max_freq(struct cpufreq_policy *policy, 1360 + struct cpudata *cpudata) 1361 1361 { 1362 + guard(cpufreq_policy_write)(policy); 1363 + 1362 1364 if (hwp_active) 1363 1365 intel_pstate_get_hwp_cap(cpudata); 1364 1366 ··· 1370 1368 refresh_frequency_limits(policy); 1371 1369 } 1372 1370 1373 - static void intel_pstate_update_limits(unsigned int cpu) 1371 + static bool intel_pstate_update_max_freq(struct cpudata *cpudata) 1374 1372 { 1375 - struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); 1376 - struct cpudata *cpudata; 1373 + struct cpufreq_policy *policy __free(put_cpufreq_policy); 1377 1374 1375 + policy = cpufreq_cpu_get(cpudata->cpu); 1378 1376 if (!policy) 1379 - return; 1377 + return false; 1380 1378 1381 - cpudata = all_cpu_data[cpu]; 1379 + __intel_pstate_update_max_freq(policy, cpudata); 1382 1380 1383 - __intel_pstate_update_max_freq(cpudata, policy); 1381 + return true; 1382 + } 1384 1383 1385 - /* Prevent the driver from being unregistered now. */ 1386 - mutex_lock(&intel_pstate_driver_lock); 1384 + static void intel_pstate_update_limits(struct cpufreq_policy *policy) 1385 + { 1386 + struct cpudata *cpudata = all_cpu_data[policy->cpu]; 1387 1387 1388 - cpufreq_cpu_release(policy); 1388 + __intel_pstate_update_max_freq(policy, cpudata); 1389 1389 1390 1390 hybrid_update_capacity(cpudata); 1391 - 1392 - mutex_unlock(&intel_pstate_driver_lock); 1393 1391 } 1394 1392 1395 1393 static void intel_pstate_update_limits_for_all(void) 1396 1394 { 1397 1395 int cpu; 1398 1396 1399 - for_each_possible_cpu(cpu) { 1400 - struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); 1401 - 1402 - if (!policy) 1403 - continue; 1404 - 1405 - __intel_pstate_update_max_freq(all_cpu_data[cpu], policy); 1406 - 1407 - cpufreq_cpu_release(policy); 1408 - } 1397 + for_each_possible_cpu(cpu) 1398 + intel_pstate_update_max_freq(all_cpu_data[cpu]); 1409 1399 1410 1400 mutex_lock(&hybrid_capacity_lock); 1411 1401 ··· 1837 1843 { 1838 1844 struct cpudata *cpudata = 1839 1845 container_of(to_delayed_work(work), struct cpudata, hwp_notify_work); 1840 - struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpudata->cpu); 1841 1846 1842 - if (policy) { 1843 - __intel_pstate_update_max_freq(cpudata, policy); 1844 - 1845 - cpufreq_cpu_release(policy); 1846 - 1847 + if (intel_pstate_update_max_freq(cpudata)) { 1847 1848 /* 1848 1849 * The driver will not be unregistered while this function is 1849 1850 * running, so update the capacity without acquiring the driver
+7 -4
include/linux/cpufreq.h
··· 170 170 struct notifier_block nb_max; 171 171 }; 172 172 173 + DEFINE_GUARD(cpufreq_policy_write, struct cpufreq_policy *, 174 + down_write(&_T->rwsem), up_write(&_T->rwsem)) 175 + 176 + DEFINE_GUARD(cpufreq_policy_read, struct cpufreq_policy *, 177 + down_read(&_T->rwsem), up_read(&_T->rwsem)) 178 + 173 179 /* 174 180 * Used for passing new cpufreq policy data to the cpufreq driver's ->verify() 175 181 * callback for sanitization. That callback is only expected to modify the min ··· 241 235 242 236 u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy); 243 237 244 - struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu); 245 - void cpufreq_cpu_release(struct cpufreq_policy *policy); 246 - int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu); 247 238 void refresh_frequency_limits(struct cpufreq_policy *policy); 248 239 void cpufreq_update_policy(unsigned int cpu); 249 240 void cpufreq_update_limits(unsigned int cpu); ··· 398 395 unsigned int (*get)(unsigned int cpu); 399 396 400 397 /* Called to update policy limits on firmware notifications. */ 401 - void (*update_limits)(unsigned int cpu); 398 + void (*update_limits)(struct cpufreq_policy *policy); 402 399 403 400 /* optional */ 404 401 int (*bios_limit)(int cpu, unsigned int *limit);