···808808 sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu);809809}810810811811-static void amd_pstate_update_limits(unsigned int cpu)811811+static void amd_pstate_update_limits(struct cpufreq_policy *policy)812812{813813- struct cpufreq_policy *policy __free(put_cpufreq_policy) = cpufreq_cpu_get(cpu);814813 struct amd_cpudata *cpudata;815814 u32 prev_high = 0, cur_high = 0;816815 bool highest_perf_changed = false;816816+ unsigned int cpu = policy->cpu;817817818818 if (!amd_pstate_prefcore)819819- return;820820-821821- if (!policy)822819 return;823820824821 if (amd_get_highest_perf(cpu, &cur_high))
+188-250
drivers/cpufreq/cpufreq.c
···255255}256256EXPORT_SYMBOL_GPL(cpufreq_cpu_put);257257258258-/**259259- * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.260260- * @policy: cpufreq policy returned by cpufreq_cpu_acquire().261261- */262262-void cpufreq_cpu_release(struct cpufreq_policy *policy)263263-{264264- if (WARN_ON(!policy))265265- return;266266-267267- lockdep_assert_held(&policy->rwsem);268268-269269- up_write(&policy->rwsem);270270-271271- cpufreq_cpu_put(policy);272272-}273273-274274-/**275275- * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.276276- * @cpu: CPU to find the policy for.277277- *278278- * Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and279279- * if the policy returned by it is not NULL, acquire its rwsem for writing.280280- * Return the policy if it is active or release it and return NULL otherwise.281281- *282282- * The policy returned by this function has to be released with the help of283283- * cpufreq_cpu_release() in order to release its rwsem and balance its usage284284- * counter properly.285285- */286286-struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu)287287-{288288- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);289289-290290- if (!policy)291291- return NULL;292292-293293- down_write(&policy->rwsem);294294-295295- if (policy_is_inactive(policy)) {296296- cpufreq_cpu_release(policy);297297- return NULL;298298- }299299-300300- return policy;301301-}302302-303258/*********************************************************************304259 * EXTERNALLY AFFECTING FREQUENCY CHANGES *305260 *********************************************************************/···591636 return sysfs_emit(buf, "%d\n", policy->boost_enabled);592637}593638639639+static int policy_set_boost(struct cpufreq_policy *policy, bool enable)640640+{641641+ int ret;642642+643643+ if (policy->boost_enabled == enable)644644+ return 0;645645+646646+ policy->boost_enabled = enable;647647+648648+ ret = cpufreq_driver->set_boost(policy, enable);649649+ if (ret)650650+ policy->boost_enabled = !policy->boost_enabled;651651+652652+ return ret;653653+}654654+594655static ssize_t store_local_boost(struct cpufreq_policy *policy,595656 const char *buf, size_t count)596657{···622651 if (!policy->boost_supported)623652 return -EINVAL;624653625625- if (policy->boost_enabled == enable)626626- return count;627627-628628- policy->boost_enabled = enable;629629-630654 cpus_read_lock();631631- ret = cpufreq_driver->set_boost(policy, enable);655655+ ret = policy_set_boost(policy, enable);632656 cpus_read_unlock();633657634634- if (ret) {635635- policy->boost_enabled = !policy->boost_enabled;636636- return ret;637637- }658658+ if (!ret)659659+ return count;638660639639- return count;661661+ return ret;640662}641663642664static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);···9891025{9901026 struct cpufreq_policy *policy = to_policy(kobj);9911027 struct freq_attr *fattr = to_attr(attr);992992- ssize_t ret = -EBUSY;99310289941029 if (!fattr->show)9951030 return -EIO;9961031997997- down_read(&policy->rwsem);998998- if (likely(!policy_is_inactive(policy)))999999- ret = fattr->show(policy, buf);10001000- up_read(&policy->rwsem);10321032+ guard(cpufreq_policy_read)(policy);1001103310021002- return ret;10341034+ if (likely(!policy_is_inactive(policy)))10351035+ return fattr->show(policy, buf);10361036+10371037+ return -EBUSY;10031038}1004103910051040static ssize_t store(struct kobject *kobj, struct attribute *attr,···10061043{10071044 struct cpufreq_policy *policy = to_policy(kobj);10081045 struct freq_attr *fattr = to_attr(attr);10091009- ssize_t ret = -EBUSY;1010104610111047 if (!fattr->store)10121048 return -EIO;1013104910141014- down_write(&policy->rwsem);10151015- if (likely(!policy_is_inactive(policy)))10161016- ret = fattr->store(policy, buf, count);10171017- up_write(&policy->rwsem);10501050+ guard(cpufreq_policy_write)(policy);1018105110191019- return ret;10521052+ if (likely(!policy_is_inactive(policy)))10531053+ return fattr->store(policy, buf, count);10541054+10551055+ return -EBUSY;10201056}1021105710221058static void cpufreq_sysfs_release(struct kobject *kobj)···11731211 if (cpumask_test_cpu(cpu, policy->cpus))11741212 return 0;1175121311761176- down_write(&policy->rwsem);12141214+ guard(cpufreq_policy_write)(policy);12151215+11771216 if (has_target())11781217 cpufreq_stop_governor(policy);11791218···11851222 if (ret)11861223 pr_err("%s: Failed to start governor\n", __func__);11871224 }11881188- up_write(&policy->rwsem);12251225+11891226 return ret;11901227}11911228···12051242 container_of(work, struct cpufreq_policy, update);1206124312071244 pr_debug("handle_update for cpu %u called\n", policy->cpu);12081208- down_write(&policy->rwsem);12451245+12461246+ guard(cpufreq_policy_write)(policy);12471247+12091248 refresh_frequency_limits(policy);12101210- up_write(&policy->rwsem);12111249}1212125012131251static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq,···12341270 struct kobject *kobj;12351271 struct completion *cmp;1236127212371237- down_write(&policy->rwsem);12381238- cpufreq_stats_free_table(policy);12391239- kobj = &policy->kobj;12401240- cmp = &policy->kobj_unregister;12411241- up_write(&policy->rwsem);12731273+ scoped_guard(cpufreq_policy_write, policy) {12741274+ cpufreq_stats_free_table(policy);12751275+ kobj = &policy->kobj;12761276+ cmp = &policy->kobj_unregister;12771277+ }12421278 kobject_put(kobj);1243127912441280 /*···13141350 init_waitqueue_head(&policy->transition_wait);13151351 INIT_WORK(&policy->update, handle_update);1316135213171317- policy->cpu = cpu;13181353 return policy;1319135413201355err_min_qos_notifier:···13821419 kfree(policy);13831420}1384142113851385-static int cpufreq_online(unsigned int cpu)14221422+static int cpufreq_policy_online(struct cpufreq_policy *policy,14231423+ unsigned int cpu, bool new_policy)13861424{13871387- struct cpufreq_policy *policy;13881388- bool new_policy;13891425 unsigned long flags;13901426 unsigned int j;13911427 int ret;1392142813931393- pr_debug("%s: bringing CPU%u online\n", __func__, cpu);14291429+ guard(cpufreq_policy_write)(policy);1394143013951395- /* Check if this CPU already has a policy to manage it */13961396- policy = per_cpu(cpufreq_cpu_data, cpu);13971397- if (policy) {13981398- WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));13991399- if (!policy_is_inactive(policy))14001400- return cpufreq_add_policy_cpu(policy, cpu);14011401-14021402- /* This is the only online CPU for the policy. Start over. */14031403- new_policy = false;14041404- down_write(&policy->rwsem);14051405- policy->cpu = cpu;14061406- policy->governor = NULL;14071407- } else {14081408- new_policy = true;14091409- policy = cpufreq_policy_alloc(cpu);14101410- if (!policy)14111411- return -ENOMEM;14121412- down_write(&policy->rwsem);14131413- }14311431+ policy->cpu = cpu;14321432+ policy->governor = NULL;1414143314151434 if (!new_policy && cpufreq_driver->online) {14161435 /* Recover policy->cpus using related_cpus */···14151470 if (ret) {14161471 pr_debug("%s: %d: initialization failed\n", __func__,14171472 __LINE__);14181418- goto out_free_policy;14731473+ goto out_clear_policy;14191474 }1420147514211476 /*···15661621 goto out_destroy_policy;15671622 }1568162315691569- up_write(&policy->rwsem);15701570-15711571- kobject_uevent(&policy->kobj, KOBJ_ADD);15721572-15731573- /* Callback for handling stuff after policy is ready */15741574- if (cpufreq_driver->ready)15751575- cpufreq_driver->ready(policy);15761576-15771577- /* Register cpufreq cooling only for a new policy */15781578- if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver))15791579- policy->cdev = of_cpufreq_cooling_register(policy);15801580-15811581- /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */15821582- if (cpufreq_driver->set_boost && policy->boost_supported &&15831583- policy->boost_enabled != cpufreq_boost_enabled()) {15841584- policy->boost_enabled = cpufreq_boost_enabled();15851585- ret = cpufreq_driver->set_boost(policy, policy->boost_enabled);15861586- if (ret) {15871587- /* If the set_boost fails, the online operation is not affected */15881588- pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu,15891589- str_enable_disable(policy->boost_enabled));15901590- policy->boost_enabled = !policy->boost_enabled;15911591- }15921592- }15931593-15941594- pr_debug("initialization complete\n");15951595-15961624 return 0;1597162515981626out_destroy_policy:···15801662 if (cpufreq_driver->exit)15811663 cpufreq_driver->exit(policy);1582166415831583-out_free_policy:16651665+out_clear_policy:15841666 cpumask_clear(policy->cpus);15851585- up_write(&policy->rwsem);1586166715871587- cpufreq_policy_free(policy);15881668 return ret;16691669+}16701670+16711671+static int cpufreq_online(unsigned int cpu)16721672+{16731673+ struct cpufreq_policy *policy;16741674+ bool new_policy;16751675+ int ret;16761676+16771677+ pr_debug("%s: bringing CPU%u online\n", __func__, cpu);16781678+16791679+ /* Check if this CPU already has a policy to manage it */16801680+ policy = per_cpu(cpufreq_cpu_data, cpu);16811681+ if (policy) {16821682+ WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));16831683+ if (!policy_is_inactive(policy))16841684+ return cpufreq_add_policy_cpu(policy, cpu);16851685+16861686+ /* This is the only online CPU for the policy. Start over. */16871687+ new_policy = false;16881688+ } else {16891689+ new_policy = true;16901690+ policy = cpufreq_policy_alloc(cpu);16911691+ if (!policy)16921692+ return -ENOMEM;16931693+ }16941694+16951695+ ret = cpufreq_policy_online(policy, cpu, new_policy);16961696+ if (ret) {16971697+ cpufreq_policy_free(policy);16981698+ return ret;16991699+ }17001700+17011701+ kobject_uevent(&policy->kobj, KOBJ_ADD);17021702+17031703+ /* Callback for handling stuff after policy is ready */17041704+ if (cpufreq_driver->ready)17051705+ cpufreq_driver->ready(policy);17061706+17071707+ /* Register cpufreq cooling only for a new policy */17081708+ if (new_policy && cpufreq_thermal_control_enabled(cpufreq_driver))17091709+ policy->cdev = of_cpufreq_cooling_register(policy);17101710+17111711+ /*17121712+ * Let the per-policy boost flag mirror the cpufreq_driver boost during17131713+ * initialization for a new policy. For an existing policy, maintain the17141714+ * previous boost value unless global boost is disabled.17151715+ */17161716+ if (cpufreq_driver->set_boost && policy->boost_supported &&17171717+ (new_policy || !cpufreq_boost_enabled())) {17181718+ ret = policy_set_boost(policy, cpufreq_boost_enabled());17191719+ if (ret) {17201720+ /* If the set_boost fails, the online operation is not affected */17211721+ pr_info("%s: CPU%d: Cannot %s BOOST\n", __func__, policy->cpu,17221722+ str_enable_disable(cpufreq_boost_enabled()));17231723+ }17241724+ }17251725+17261726+ pr_debug("initialization complete\n");17271727+17281728+ return 0;15891729}1590173015911731/**···17331757 return 0;17341758 }1735175917361736- down_write(&policy->rwsem);17601760+ guard(cpufreq_policy_write)(policy);1737176117381762 __cpufreq_offline(cpu, policy);1739176317401740- up_write(&policy->rwsem);17411764 return 0;17421765}17431766···17531778 if (!policy)17541779 return;1755178017561756- down_write(&policy->rwsem);17811781+ scoped_guard(cpufreq_policy_write, policy) {17821782+ if (cpu_online(cpu))17831783+ __cpufreq_offline(cpu, policy);1757178417581758- if (cpu_online(cpu))17591759- __cpufreq_offline(cpu, policy);17851785+ remove_cpu_dev_symlink(policy, cpu, dev);1760178617611761- remove_cpu_dev_symlink(policy, cpu, dev);17871787+ if (!cpumask_empty(policy->real_cpus))17881788+ return;1762178917631763- if (!cpumask_empty(policy->real_cpus)) {17641764- up_write(&policy->rwsem);17651765- return;17901790+ /*17911791+ * Unregister cpufreq cooling once all the CPUs of the policy17921792+ * are removed.17931793+ */17941794+ if (cpufreq_thermal_control_enabled(cpufreq_driver)) {17951795+ cpufreq_cooling_unregister(policy->cdev);17961796+ policy->cdev = NULL;17971797+ }17981798+17991799+ /* We did light-weight exit earlier, do full tear down now */18001800+ if (cpufreq_driver->offline && cpufreq_driver->exit)18011801+ cpufreq_driver->exit(policy);17661802 }17671767-17681768- /*17691769- * Unregister cpufreq cooling once all the CPUs of the policy are17701770- * removed.17711771- */17721772- if (cpufreq_thermal_control_enabled(cpufreq_driver)) {17731773- cpufreq_cooling_unregister(policy->cdev);17741774- policy->cdev = NULL;17751775- }17761776-17771777- /* We did light-weight exit earlier, do full tear down now */17781778- if (cpufreq_driver->offline && cpufreq_driver->exit)17791779- cpufreq_driver->exit(policy);17801780-17811781- up_write(&policy->rwsem);1782180317831804 cpufreq_policy_free(policy);17841805}···18451874 */18461875unsigned int cpufreq_quick_get(unsigned int cpu)18471876{18481848- struct cpufreq_policy *policy;18491849- unsigned int ret_freq = 0;18771877+ struct cpufreq_policy *policy __free(put_cpufreq_policy) = NULL;18501878 unsigned long flags;1851187918521880 read_lock_irqsave(&cpufreq_driver_lock, flags);1853188118541882 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) {18551855- ret_freq = cpufreq_driver->get(cpu);18831883+ unsigned int ret_freq = cpufreq_driver->get(cpu);18841884+18561885 read_unlock_irqrestore(&cpufreq_driver_lock, flags);18861886+18571887 return ret_freq;18581888 }1859188918601890 read_unlock_irqrestore(&cpufreq_driver_lock, flags);1861189118621892 policy = cpufreq_cpu_get(cpu);18631863- if (policy) {18641864- ret_freq = policy->cur;18651865- cpufreq_cpu_put(policy);18661866- }18931893+ if (policy)18941894+ return policy->cur;1867189518681868- return ret_freq;18961896+ return 0;18691897}18701898EXPORT_SYMBOL(cpufreq_quick_get);18711899···18761906 */18771907unsigned int cpufreq_quick_get_max(unsigned int cpu)18781908{18791879- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);18801880- unsigned int ret_freq = 0;19091909+ struct cpufreq_policy *policy __free(put_cpufreq_policy);1881191018821882- if (policy) {18831883- ret_freq = policy->max;18841884- cpufreq_cpu_put(policy);18851885- }19111911+ policy = cpufreq_cpu_get(cpu);19121912+ if (policy)19131913+ return policy->max;1886191418871887- return ret_freq;19151915+ return 0;18881916}18891917EXPORT_SYMBOL(cpufreq_quick_get_max);18901918···18941926 */18951927__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)18961928{18971897- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);18981898- unsigned int ret_freq = 0;19291929+ struct cpufreq_policy *policy __free(put_cpufreq_policy);1899193019001900- if (policy) {19011901- ret_freq = policy->cpuinfo.max_freq;19021902- cpufreq_cpu_put(policy);19031903- }19311931+ policy = cpufreq_cpu_get(cpu);19321932+ if (policy)19331933+ return policy->cpuinfo.max_freq;1904193419051905- return ret_freq;19351935+ return 0;19061936}19071937EXPORT_SYMBOL(cpufreq_get_hw_max_freq);19081938···19201954 */19211955unsigned int cpufreq_get(unsigned int cpu)19221956{19231923- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);19241924- unsigned int ret_freq = 0;19571957+ struct cpufreq_policy *policy __free(put_cpufreq_policy);1925195819261926- if (policy) {19271927- down_read(&policy->rwsem);19281928- if (cpufreq_driver->get)19291929- ret_freq = __cpufreq_get(policy);19301930- up_read(&policy->rwsem);19591959+ policy = cpufreq_cpu_get(cpu);19601960+ if (!policy)19611961+ return 0;1931196219321932- cpufreq_cpu_put(policy);19331933- }19631963+ guard(cpufreq_policy_read)(policy);1934196419351935- return ret_freq;19651965+ if (cpufreq_driver->get)19661966+ return __cpufreq_get(policy);19671967+19681968+ return 0;19361969}19371970EXPORT_SYMBOL(cpufreq_get);19381971···1990202519912026 for_each_active_policy(policy) {19922027 if (has_target()) {19931993- down_write(&policy->rwsem);19941994- cpufreq_stop_governor(policy);19951995- up_write(&policy->rwsem);20282028+ scoped_guard(cpufreq_policy_write, policy) {20292029+ cpufreq_stop_governor(policy);20302030+ }19962031 }1997203219982033 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))···20332068 pr_err("%s: Failed to resume driver: %s\n", __func__,20342069 cpufreq_driver->name);20352070 } else if (has_target()) {20362036- down_write(&policy->rwsem);20372037- ret = cpufreq_start_governor(policy);20382038- up_write(&policy->rwsem);20712071+ scoped_guard(cpufreq_policy_write, policy) {20722072+ ret = cpufreq_start_governor(policy);20732073+ }2039207420402075 if (ret)20412076 pr_err("%s: Failed to start governor for CPU%u's policy\n",···24032438 unsigned int target_freq,24042439 unsigned int relation)24052440{24062406- int ret;24412441+ guard(cpufreq_policy_write)(policy);2407244224082408- down_write(&policy->rwsem);24092409-24102410- ret = __cpufreq_driver_target(policy, target_freq, relation);24112411-24122412- up_write(&policy->rwsem);24132413-24142414- return ret;24432443+ return __cpufreq_driver_target(policy, target_freq, relation);24152444}24162445EXPORT_SYMBOL_GPL(cpufreq_driver_target);24172446···25772618 * POLICY INTERFACE *25782619 *********************************************************************/2579262025802580-/**25812581- * cpufreq_get_policy - get the current cpufreq_policy25822582- * @policy: struct cpufreq_policy into which the current cpufreq_policy25832583- * is written25842584- * @cpu: CPU to find the policy for25852585- *25862586- * Reads the current cpufreq policy.25872587- */25882588-int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)25892589-{25902590- struct cpufreq_policy *cpu_policy;25912591- if (!policy)25922592- return -EINVAL;25932593-25942594- cpu_policy = cpufreq_cpu_get(cpu);25952595- if (!cpu_policy)25962596- return -EINVAL;25972597-25982598- memcpy(policy, cpu_policy, sizeof(*policy));25992599-26002600- cpufreq_cpu_put(cpu_policy);26012601- return 0;26022602-}26032603-EXPORT_SYMBOL(cpufreq_get_policy);26042604-26052621DEFINE_PER_CPU(unsigned long, cpufreq_pressure);2606262226072623/**···27272793 return ret;27282794}2729279527962796+static void cpufreq_policy_refresh(struct cpufreq_policy *policy)27972797+{27982798+ guard(cpufreq_policy_write)(policy);27992799+28002800+ /*28012801+ * BIOS might change freq behind our back28022802+ * -> ask driver for current freq and notify governors about a change28032803+ */28042804+ if (cpufreq_driver->get && has_target() &&28052805+ (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))28062806+ return;28072807+28082808+ refresh_frequency_limits(policy);28092809+}28102810+27302811/**27312812 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.27322813 * @cpu: CPU to re-evaluate the policy for.···27532804 */27542805void cpufreq_update_policy(unsigned int cpu)27552806{27562756- struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);28072807+ struct cpufreq_policy *policy __free(put_cpufreq_policy);2757280828092809+ policy = cpufreq_cpu_get(cpu);27582810 if (!policy)27592811 return;2760281227612761- /*27622762- * BIOS might change freq behind our back27632763- * -> ask driver for current freq and notify governors about a change27642764- */27652765- if (cpufreq_driver->get && has_target() &&27662766- (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))27672767- goto unlock;27682768-27692769- refresh_frequency_limits(policy);27702770-27712771-unlock:27722772- cpufreq_cpu_release(policy);28132813+ cpufreq_policy_refresh(policy);27732814}27742815EXPORT_SYMBOL(cpufreq_update_policy);27752816···27682829 * @cpu: CPU to update the policy limits for.27692830 *27702831 * Invoke the driver's ->update_limits callback if present or call27712771- * cpufreq_update_policy() for @cpu.28322832+ * cpufreq_policy_refresh() for @cpu.27722833 */27732834void cpufreq_update_limits(unsigned int cpu)27742835{···27792840 return;2780284127812842 if (cpufreq_driver->update_limits)27822782- cpufreq_driver->update_limits(cpu);28432843+ cpufreq_driver->update_limits(policy);27832844 else27842784- cpufreq_update_policy(cpu);28452845+ cpufreq_policy_refresh(policy);27852846}27862847EXPORT_SYMBOL_GPL(cpufreq_update_limits);27872848···28152876 unsigned long flags;28162877 int ret = 0;2817287828182818- if (cpufreq_driver->boost_enabled == state)28192819- return 0;28792879+ /*28802880+ * Don't compare 'cpufreq_driver->boost_enabled' with 'state' here to28812881+ * make sure all policies are in sync with global boost flag.28822882+ */2820288328212884 write_lock_irqsave(&cpufreq_driver_lock, flags);28222885 cpufreq_driver->boost_enabled = state;···28292888 if (!policy->boost_supported)28302889 continue;2831289028322832- policy->boost_enabled = state;28332833- ret = cpufreq_driver->set_boost(policy, state);28342834- if (ret) {28352835- policy->boost_enabled = !policy->boost_enabled;28912891+ ret = policy_set_boost(policy, state);28922892+ if (ret)28362893 goto err_reset_state;28372837- }28382894 }28392895 cpus_read_unlock();28402896
+18-29
drivers/cpufreq/intel_pstate.c
···13561356 cpufreq_update_policy(cpu);13571357}1358135813591359-static void __intel_pstate_update_max_freq(struct cpudata *cpudata,13601360- struct cpufreq_policy *policy)13591359+static void __intel_pstate_update_max_freq(struct cpufreq_policy *policy,13601360+ struct cpudata *cpudata)13611361{13621362+ guard(cpufreq_policy_write)(policy);13631363+13621364 if (hwp_active)13631365 intel_pstate_get_hwp_cap(cpudata);13641366···13701368 refresh_frequency_limits(policy);13711369}1372137013731373-static void intel_pstate_update_limits(unsigned int cpu)13711371+static bool intel_pstate_update_max_freq(struct cpudata *cpudata)13741372{13751375- struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);13761376- struct cpudata *cpudata;13731373+ struct cpufreq_policy *policy __free(put_cpufreq_policy);1377137413751375+ policy = cpufreq_cpu_get(cpudata->cpu);13781376 if (!policy)13791379- return;13771377+ return false;1380137813811381- cpudata = all_cpu_data[cpu];13791379+ __intel_pstate_update_max_freq(policy, cpudata);1382138013831383- __intel_pstate_update_max_freq(cpudata, policy);13811381+ return true;13821382+}1384138313851385- /* Prevent the driver from being unregistered now. */13861386- mutex_lock(&intel_pstate_driver_lock);13841384+static void intel_pstate_update_limits(struct cpufreq_policy *policy)13851385+{13861386+ struct cpudata *cpudata = all_cpu_data[policy->cpu];1387138713881388- cpufreq_cpu_release(policy);13881388+ __intel_pstate_update_max_freq(policy, cpudata);1389138913901390 hybrid_update_capacity(cpudata);13911391-13921392- mutex_unlock(&intel_pstate_driver_lock);13931391}1394139213951393static void intel_pstate_update_limits_for_all(void)13961394{13971395 int cpu;1398139613991399- for_each_possible_cpu(cpu) {14001400- struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);14011401-14021402- if (!policy)14031403- continue;14041404-14051405- __intel_pstate_update_max_freq(all_cpu_data[cpu], policy);14061406-14071407- cpufreq_cpu_release(policy);14081408- }13971397+ for_each_possible_cpu(cpu)13981398+ intel_pstate_update_max_freq(all_cpu_data[cpu]);1409139914101400 mutex_lock(&hybrid_capacity_lock);14111401···18371843{18381844 struct cpudata *cpudata =18391845 container_of(to_delayed_work(work), struct cpudata, hwp_notify_work);18401840- struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpudata->cpu);1841184618421842- if (policy) {18431843- __intel_pstate_update_max_freq(cpudata, policy);18441844-18451845- cpufreq_cpu_release(policy);18461846-18471847+ if (intel_pstate_update_max_freq(cpudata)) {18471848 /*18481849 * The driver will not be unregistered while this function is18491850 * running, so update the capacity without acquiring the driver
+7-4
include/linux/cpufreq.h
···170170 struct notifier_block nb_max;171171};172172173173+DEFINE_GUARD(cpufreq_policy_write, struct cpufreq_policy *,174174+ down_write(&_T->rwsem), up_write(&_T->rwsem))175175+176176+DEFINE_GUARD(cpufreq_policy_read, struct cpufreq_policy *,177177+ down_read(&_T->rwsem), up_read(&_T->rwsem))178178+173179/*174180 * Used for passing new cpufreq policy data to the cpufreq driver's ->verify()175181 * callback for sanitization. That callback is only expected to modify the min···241235242236u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy);243237244244-struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu);245245-void cpufreq_cpu_release(struct cpufreq_policy *policy);246246-int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu);247238void refresh_frequency_limits(struct cpufreq_policy *policy);248239void cpufreq_update_policy(unsigned int cpu);249240void cpufreq_update_limits(unsigned int cpu);···398395 unsigned int (*get)(unsigned int cpu);399396400397 /* Called to update policy limits on firmware notifications. */401401- void (*update_limits)(unsigned int cpu);398398+ void (*update_limits)(struct cpufreq_policy *policy);402399403400 /* optional */404401 int (*bios_limit)(int cpu, unsigned int *limit);