···16611661 hwp_only16621662 Only load intel_pstate on systems which support16631663 hardware P state control (HWP) if available.16641664+ support_acpi_ppc16651665+ Enforce ACPI _PPC performance limits. If the Fixed ACPI16661666+ Description Table, specifies preferred power management16671667+ profile as "Enterprise Server" or "Performance Server",16681668+ then this feature is turned on by default.1664166916651670 intremap= [X86-64, Intel-IOMMU]16661671 on enable Interrupt Remapping (default)
···11-/*22- * CPUFreq support code for SH-Mobile ARM33- *44- * Copyright (C) 2014 Gaku Inami55- *66- * This file is subject to the terms and conditions of the GNU General Public77- * License. See the file "COPYING" in the main directory of this archive88- * for more details.99- */1010-1111-#include <linux/platform_device.h>1212-1313-#include "common.h"1414-1515-int __init shmobile_cpufreq_init(void)1616-{1717- platform_device_register_simple("cpufreq-dt", -1, NULL, 0);1818- return 0;1919-}
···18181919if CPU_FREQ20202121+config CPU_FREQ_GOV_ATTR_SET2222+ bool2323+2124config CPU_FREQ_GOV_COMMON2525+ select CPU_FREQ_GOV_ATTR_SET2226 select IRQ_WORK2327 bool2428···107103 Be aware that not all cpufreq drivers support the conservative108104 governor. If unsure have a look at the help section of the109105 driver. Fallback governor will be the performance governor.106106+107107+config CPU_FREQ_DEFAULT_GOV_SCHEDUTIL108108+ bool "schedutil"109109+ select CPU_FREQ_GOV_SCHEDUTIL110110+ select CPU_FREQ_GOV_PERFORMANCE111111+ help112112+ Use the 'schedutil' CPUFreq governor by default. If unsure,113113+ have a look at the help section of that governor. The fallback114114+ governor will be 'performance'.115115+110116endchoice111117112118config CPU_FREQ_GOV_PERFORMANCE···198184199185 If in doubt, say N.200186187187+config CPU_FREQ_GOV_SCHEDUTIL188188+ tristate "'schedutil' cpufreq policy governor"189189+ depends on CPU_FREQ190190+ select CPU_FREQ_GOV_ATTR_SET191191+ select IRQ_WORK192192+ help193193+ This governor makes decisions based on the utilization data provided194194+ by the scheduler. It sets the CPU frequency to be proportional to195195+ the utilization/capacity ratio coming from the scheduler. If the196196+ utilization is frequency-invariant, the new frequency is also197197+ proportional to the maximum available frequency. If that is not the198198+ case, it is proportional to the current frequency of the CPU. The199199+ frequency tipping point is at utilization/capacity equal to 80% in200200+ both cases.201201+202202+ To compile this driver as a module, choose M here: the module will203203+ be called cpufreq_schedutil.204204+205205+ If in doubt, say N.206206+201207comment "CPU frequency scaling drivers"202208203209config CPUFREQ_DT···225191 depends on HAVE_CLK && OF226192 # if CPU_THERMAL is on and THERMAL=m, CPUFREQ_DT cannot be =y:227193 depends on !CPU_THERMAL || THERMAL194194+ select CPUFREQ_DT_PLATDEV228195 select PM_OPP229196 help230197 This adds a generic DT based cpufreq driver for frequency management.231198 It supports both uniprocessor (UP) and symmetric multiprocessor (SMP)232199 systems which share clock and voltage across all CPUs.200200+201201+ If in doubt, say N.202202+203203+config CPUFREQ_DT_PLATDEV204204+ bool205205+ help206206+ This adds a generic DT based cpufreq platdev driver for frequency207207+ management. This creates a 'cpufreq-dt' platform device, on the208208+ supported platforms.233209234210 If in doubt, say N.235211
-9
drivers/cpufreq/Kconfig.arm
···50505151 If in doubt, say N.52525353-config ARM_HISI_ACPU_CPUFREQ5454- tristate "Hisilicon ACPU CPUfreq driver"5555- depends on ARCH_HISI && CPUFREQ_DT5656- select PM_OPP5757- help5858- This enables the hisilicon ACPU CPUfreq driver.5959-6060- If in doubt, say N.6161-6253config ARM_IMX6Q_CPUFREQ6354 tristate "Freescale i.MX6 cpufreq support"6455 depends on ARCH_MXC
+1
drivers/cpufreq/Kconfig.x86
···55config X86_INTEL_PSTATE66 bool "Intel P state control"77 depends on X8688+ select ACPI_PROCESSOR if ACPI89 help910 This driver provides a P state for Intel core processors.1011 The driver implements an internal governor and will become
···77 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*88 */991010+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1111+1012#include <linux/kernel.h>1113#include <linux/module.h>1214#include <linux/moduleparam.h>···5755MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)");5856MODULE_PARM_DESC(min_fsb,5957 "Minimum FSB to use, if not defined: current FSB - 50");6060-6161-#define PFX "cpufreq-nforce2: "62586359/**6460 * nforce2_calc_fsb - calculate FSB···174174 int pll = 0;175175176176 if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) {177177- printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb);177177+ pr_err("FSB %d is out of range!\n", fsb);178178 return -EINVAL;179179 }180180181181 tfsb = nforce2_fsb_read(0);182182 if (!tfsb) {183183- printk(KERN_ERR PFX "Error while reading the FSB\n");183183+ pr_err("Error while reading the FSB\n");184184 return -EINVAL;185185 }186186···276276 /* local_irq_save(flags); */277277278278 if (nforce2_set_fsb(target_fsb) < 0)279279- printk(KERN_ERR PFX "Changing FSB to %d failed\n",280280- target_fsb);279279+ pr_err("Changing FSB to %d failed\n", target_fsb);281280 else282281 pr_debug("Changed FSB successfully to %d\n",283282 target_fsb);···324325 /* FIX: Get FID from CPU */325326 if (!fid) {326327 if (!cpu_khz) {327327- printk(KERN_WARNING PFX328328- "cpu_khz not set, can't calculate multiplier!\n");328328+ pr_warn("cpu_khz not set, can't calculate multiplier!\n");329329 return -ENODEV;330330 }331331···339341 }340342 }341343342342- printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb,343343- fid / 10, fid % 10);344344+ pr_info("FSB currently at %i MHz, FID %d.%d\n",345345+ fsb, fid / 10, fid % 10);344346345347 /* Set maximum FSB to FSB at boot time */346348 max_fsb = nforce2_fsb_read(1);···399401 if (nforce2_dev == NULL)400402 return -ENODEV;401403402402- printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n",403403- nforce2_dev->revision);404404- printk(KERN_INFO PFX405405- "FSB changing is maybe unstable and can lead to "406406- "crashes and data loss.\n");404404+ pr_info("Detected nForce2 chipset revision %X\n",405405+ nforce2_dev->revision);406406+ pr_info("FSB changing is maybe unstable and can lead to crashes and data loss\n");407407408408 return 0;409409}···419423420424 /* detect chipset */421425 if (nforce2_detect_chipset()) {422422- printk(KERN_INFO PFX "No nForce2 chipset.\n");426426+ pr_info("No nForce2 chipset\n");423427 return -ENODEV;424428 }425429
+141-23
drivers/cpufreq/cpufreq.c
···7878static unsigned int __cpufreq_get(struct cpufreq_policy *policy);7979static int cpufreq_start_governor(struct cpufreq_policy *policy);80808181+static inline int cpufreq_exit_governor(struct cpufreq_policy *policy)8282+{8383+ return cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);8484+}8585+8186/**8287 * Two notifier lists: the "policy" list is involved in the8388 * validation process for a new CPU frequency policy; the···434429}435430EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end);436431432432+/*433433+ * Fast frequency switching status count. Positive means "enabled", negative434434+ * means "disabled" and 0 means "not decided yet".435435+ */436436+static int cpufreq_fast_switch_count;437437+static DEFINE_MUTEX(cpufreq_fast_switch_lock);438438+439439+static void cpufreq_list_transition_notifiers(void)440440+{441441+ struct notifier_block *nb;442442+443443+ pr_info("Registered transition notifiers:\n");444444+445445+ mutex_lock(&cpufreq_transition_notifier_list.mutex);446446+447447+ for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next)448448+ pr_info("%pF\n", nb->notifier_call);449449+450450+ mutex_unlock(&cpufreq_transition_notifier_list.mutex);451451+}452452+453453+/**454454+ * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.455455+ * @policy: cpufreq policy to enable fast frequency switching for.456456+ *457457+ * Try to enable fast frequency switching for @policy.458458+ *459459+ * The attempt will fail if there is at least one transition notifier registered460460+ * at this point, as fast frequency switching is quite fundamentally at odds461461+ * with transition notifiers. Thus if successful, it will make registration of462462+ * transition notifiers fail going forward.463463+ */464464+void cpufreq_enable_fast_switch(struct cpufreq_policy *policy)465465+{466466+ lockdep_assert_held(&policy->rwsem);467467+468468+ if (!policy->fast_switch_possible)469469+ return;470470+471471+ mutex_lock(&cpufreq_fast_switch_lock);472472+ if (cpufreq_fast_switch_count >= 0) {473473+ cpufreq_fast_switch_count++;474474+ policy->fast_switch_enabled = true;475475+ } else {476476+ pr_warn("CPU%u: Fast frequency switching not enabled\n",477477+ policy->cpu);478478+ cpufreq_list_transition_notifiers();479479+ }480480+ mutex_unlock(&cpufreq_fast_switch_lock);481481+}482482+EXPORT_SYMBOL_GPL(cpufreq_enable_fast_switch);483483+484484+/**485485+ * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.486486+ * @policy: cpufreq policy to disable fast frequency switching for.487487+ */488488+void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)489489+{490490+ mutex_lock(&cpufreq_fast_switch_lock);491491+ if (policy->fast_switch_enabled) {492492+ policy->fast_switch_enabled = false;493493+ if (!WARN_ON(cpufreq_fast_switch_count <= 0))494494+ cpufreq_fast_switch_count--;495495+ }496496+ mutex_unlock(&cpufreq_fast_switch_lock);497497+}498498+EXPORT_SYMBOL_GPL(cpufreq_disable_fast_switch);437499438500/*********************************************************************439501 * SYSFS INTERFACE *···13201248 */13211249static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)13221250{12511251+ struct cpufreq_policy *policy;13231252 unsigned cpu = dev->id;13241324- int ret;1325125313261254 dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu);1327125513281328- if (cpu_online(cpu)) {13291329- ret = cpufreq_online(cpu);13301330- } else {13311331- /*13321332- * A hotplug notifier will follow and we will handle it as CPU13331333- * online then. For now, just create the sysfs link, unless13341334- * there is no policy or the link is already present.13351335- */13361336- struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);12561256+ if (cpu_online(cpu))12571257+ return cpufreq_online(cpu);1337125813381338- ret = policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus)13391339- ? add_cpu_dev_symlink(policy, cpu) : 0;13401340- }12591259+ /*12601260+ * A hotplug notifier will follow and we will handle it as CPU online12611261+ * then. For now, just create the sysfs link, unless there is no policy12621262+ * or the link is already present.12631263+ */12641264+ policy = per_cpu(cpufreq_cpu_data, cpu);12651265+ if (!policy || cpumask_test_and_set_cpu(cpu, policy->real_cpus))12661266+ return 0;1341126713421342- return ret;12681268+ return add_cpu_dev_symlink(policy, cpu);13431269}1344127013451271static void cpufreq_offline(unsigned int cpu)···1389131913901320 /* If cpu is last user of policy, free policy */13911321 if (has_target()) {13921392- ret = cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);13221322+ ret = cpufreq_exit_governor(policy);13931323 if (ret)13941324 pr_err("%s: Failed to exit governor\n", __func__);13951325 }···1517144715181448 ret_freq = cpufreq_driver->get(policy->cpu);1519144915201520- /* Updating inactive policies is invalid, so avoid doing that. */15211521- if (unlikely(policy_is_inactive(policy)))14501450+ /*14511451+ * Updating inactive policies is invalid, so avoid doing that. Also14521452+ * if fast frequency switching is used with the given policy, the check14531453+ * against policy->cur is pointless, so skip it in that case too.14541454+ */14551455+ if (unlikely(policy_is_inactive(policy)) || policy->fast_switch_enabled)15221456 return ret_freq;1523145715241458 if (ret_freq && policy->cur &&···1749167517501676 switch (list) {17511677 case CPUFREQ_TRANSITION_NOTIFIER:16781678+ mutex_lock(&cpufreq_fast_switch_lock);16791679+16801680+ if (cpufreq_fast_switch_count > 0) {16811681+ mutex_unlock(&cpufreq_fast_switch_lock);16821682+ return -EBUSY;16831683+ }17521684 ret = srcu_notifier_chain_register(17531685 &cpufreq_transition_notifier_list, nb);16861686+ if (!ret)16871687+ cpufreq_fast_switch_count--;16881688+16891689+ mutex_unlock(&cpufreq_fast_switch_lock);17541690 break;17551691 case CPUFREQ_POLICY_NOTIFIER:17561692 ret = blocking_notifier_chain_register(···1793170917941710 switch (list) {17951711 case CPUFREQ_TRANSITION_NOTIFIER:17121712+ mutex_lock(&cpufreq_fast_switch_lock);17131713+17961714 ret = srcu_notifier_chain_unregister(17971715 &cpufreq_transition_notifier_list, nb);17161716+ if (!ret && !WARN_ON(cpufreq_fast_switch_count >= 0))17171717+ cpufreq_fast_switch_count++;17181718+17191719+ mutex_unlock(&cpufreq_fast_switch_lock);17981720 break;17991721 case CPUFREQ_POLICY_NOTIFIER:18001722 ret = blocking_notifier_chain_unregister(···18181728/*********************************************************************18191729 * GOVERNORS *18201730 *********************************************************************/17311731+17321732+/**17331733+ * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.17341734+ * @policy: cpufreq policy to switch the frequency for.17351735+ * @target_freq: New frequency to set (may be approximate).17361736+ *17371737+ * Carry out a fast frequency switch without sleeping.17381738+ *17391739+ * The driver's ->fast_switch() callback invoked by this function must be17401740+ * suitable for being called from within RCU-sched read-side critical sections17411741+ * and it is expected to select the minimum available frequency greater than or17421742+ * equal to @target_freq (CPUFREQ_RELATION_L).17431743+ *17441744+ * This function must not be called if policy->fast_switch_enabled is unset.17451745+ *17461746+ * Governors calling this function must guarantee that it will never be invoked17471747+ * twice in parallel for the same policy and that it will never be called in17481748+ * parallel with either ->target() or ->target_index() for the same policy.17491749+ *17501750+ * If CPUFREQ_ENTRY_INVALID is returned by the driver's ->fast_switch()17511751+ * callback to indicate an error condition, the hardware configuration must be17521752+ * preserved.17531753+ */17541754+unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,17551755+ unsigned int target_freq)17561756+{17571757+ clamp_val(target_freq, policy->min, policy->max);17581758+17591759+ return cpufreq_driver->fast_switch(policy, target_freq);17601760+}17611761+EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);1821176218221763/* Must set freqs->new to intermediate frequency */18231764static int __target_intermediate(struct cpufreq_policy *policy,···22252104 return ret;22262105 }2227210622282228- ret = cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);21072107+ ret = cpufreq_exit_governor(policy);22292108 if (ret) {22302109 pr_err("%s: Failed to Exit Governor: %s (%d)\n",22312110 __func__, old_gov->name, ret);···22422121 pr_debug("cpufreq: governor change\n");22432122 return 0;22442123 }22452245- cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);21242124+ cpufreq_exit_governor(policy);22462125 }2247212622482127 /* new governor failed, so re-start old one */···2310218923112190 switch (action & ~CPU_TASKS_FROZEN) {23122191 case CPU_ONLINE:21922192+ case CPU_DOWN_FAILED:23132193 cpufreq_online(cpu);23142194 break;2315219523162196 case CPU_DOWN_PREPARE:23172197 cpufreq_offline(cpu);23182318- break;23192319-23202320- case CPU_DOWN_FAILED:23212321- cpufreq_online(cpu);23222198 break;23232199 }23242200 return NOTIFY_OK;
···4343 * This must be called with dbs_data->mutex held, otherwise traversing4444 * policy_dbs_list isn't safe.4545 */4646-ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,4646+ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf,4747 size_t count)4848{4949+ struct dbs_data *dbs_data = to_dbs_data(attr_set);4950 struct policy_dbs_info *policy_dbs;5051 unsigned int rate;5152 int ret;···6059 * We are operating under dbs_data->mutex and so the list and its6160 * entries can't be freed concurrently.6261 */6363- list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list) {6262+ list_for_each_entry(policy_dbs, &attr_set->policy_list, list) {6463 mutex_lock(&policy_dbs->timer_mutex);6564 /*6665 * On 32-bit architectures this may race with the···9796{9897 struct policy_dbs_info *policy_dbs;9998100100- list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list) {9999+ list_for_each_entry(policy_dbs, &dbs_data->attr_set.policy_list, list) {101100 unsigned int j;102101103102 for_each_cpu(j, policy_dbs->policy->cpus) {104103 struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j);105104106106- j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_cpu_wall,105105+ j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time,107106 dbs_data->io_is_busy);108107 if (dbs_data->ignore_nice_load)109108 j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];···111110 }112111}113112EXPORT_SYMBOL_GPL(gov_update_cpu_data);114114-115115-static inline struct dbs_data *to_dbs_data(struct kobject *kobj)116116-{117117- return container_of(kobj, struct dbs_data, kobj);118118-}119119-120120-static inline struct governor_attr *to_gov_attr(struct attribute *attr)121121-{122122- return container_of(attr, struct governor_attr, attr);123123-}124124-125125-static ssize_t governor_show(struct kobject *kobj, struct attribute *attr,126126- char *buf)127127-{128128- struct dbs_data *dbs_data = to_dbs_data(kobj);129129- struct governor_attr *gattr = to_gov_attr(attr);130130-131131- return gattr->show(dbs_data, buf);132132-}133133-134134-static ssize_t governor_store(struct kobject *kobj, struct attribute *attr,135135- const char *buf, size_t count)136136-{137137- struct dbs_data *dbs_data = to_dbs_data(kobj);138138- struct governor_attr *gattr = to_gov_attr(attr);139139- int ret = -EBUSY;140140-141141- mutex_lock(&dbs_data->mutex);142142-143143- if (dbs_data->usage_count)144144- ret = gattr->store(dbs_data, buf, count);145145-146146- mutex_unlock(&dbs_data->mutex);147147-148148- return ret;149149-}150150-151151-/*152152- * Sysfs Ops for accessing governor attributes.153153- *154154- * All show/store invocations for governor specific sysfs attributes, will first155155- * call the below show/store callbacks and the attribute specific callback will156156- * be called from within it.157157- */158158-static const struct sysfs_ops governor_sysfs_ops = {159159- .show = governor_show,160160- .store = governor_store,161161-};162113163114unsigned int dbs_update(struct cpufreq_policy *policy)164115{···137184 /* Get Absolute Load */138185 for_each_cpu(j, policy->cpus) {139186 struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j);140140- u64 cur_wall_time, cur_idle_time;141141- unsigned int idle_time, wall_time;187187+ u64 update_time, cur_idle_time;188188+ unsigned int idle_time, time_elapsed;142189 unsigned int load;143190144144- cur_idle_time = get_cpu_idle_time(j, &cur_wall_time, io_busy);191191+ cur_idle_time = get_cpu_idle_time(j, &update_time, io_busy);145192146146- wall_time = cur_wall_time - j_cdbs->prev_cpu_wall;147147- j_cdbs->prev_cpu_wall = cur_wall_time;193193+ time_elapsed = update_time - j_cdbs->prev_update_time;194194+ j_cdbs->prev_update_time = update_time;148195149149- if (cur_idle_time <= j_cdbs->prev_cpu_idle) {150150- idle_time = 0;151151- } else {152152- idle_time = cur_idle_time - j_cdbs->prev_cpu_idle;153153- j_cdbs->prev_cpu_idle = cur_idle_time;154154- }196196+ idle_time = cur_idle_time - j_cdbs->prev_cpu_idle;197197+ j_cdbs->prev_cpu_idle = cur_idle_time;155198156199 if (ignore_nice) {157200 u64 cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];···156207 j_cdbs->prev_cpu_nice = cur_nice;157208 }158209159159- if (unlikely(!wall_time || wall_time < idle_time))210210+ if (unlikely(!time_elapsed || time_elapsed < idle_time))160211 continue;161212162213 /*···177228 *178229 * Detecting this situation is easy: the governor's utilization179230 * update handler would not have run during CPU-idle periods.180180- * Hence, an unusually large 'wall_time' (as compared to the231231+ * Hence, an unusually large 'time_elapsed' (as compared to the181232 * sampling rate) indicates this scenario.182233 *183234 * prev_load can be zero in two cases and we must recalculate it···185236 * - during long idle intervals186237 * - explicitly set to zero187238 */188188- if (unlikely(wall_time > (2 * sampling_rate) &&239239+ if (unlikely(time_elapsed > 2 * sampling_rate &&189240 j_cdbs->prev_load)) {190241 load = j_cdbs->prev_load;191242···196247 */197248 j_cdbs->prev_load = 0;198249 } else {199199- load = 100 * (wall_time - idle_time) / wall_time;250250+ load = 100 * (time_elapsed - idle_time) / time_elapsed;200251 j_cdbs->prev_load = load;201252 }202253···206257 return max_load;207258}208259EXPORT_SYMBOL_GPL(dbs_update);209209-210210-static void gov_set_update_util(struct policy_dbs_info *policy_dbs,211211- unsigned int delay_us)212212-{213213- struct cpufreq_policy *policy = policy_dbs->policy;214214- int cpu;215215-216216- gov_update_sample_delay(policy_dbs, delay_us);217217- policy_dbs->last_sample_time = 0;218218-219219- for_each_cpu(cpu, policy->cpus) {220220- struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu);221221-222222- cpufreq_set_update_util_data(cpu, &cdbs->update_util);223223- }224224-}225225-226226-static inline void gov_clear_update_util(struct cpufreq_policy *policy)227227-{228228- int i;229229-230230- for_each_cpu(i, policy->cpus)231231- cpufreq_set_update_util_data(i, NULL);232232-233233- synchronize_sched();234234-}235235-236236-static void gov_cancel_work(struct cpufreq_policy *policy)237237-{238238- struct policy_dbs_info *policy_dbs = policy->governor_data;239239-240240- gov_clear_update_util(policy_dbs->policy);241241- irq_work_sync(&policy_dbs->irq_work);242242- cancel_work_sync(&policy_dbs->work);243243- atomic_set(&policy_dbs->work_count, 0);244244- policy_dbs->work_in_progress = false;245245-}246260247261static void dbs_work_handler(struct work_struct *work)248262{···294382 irq_work_queue(&policy_dbs->irq_work);295383}296384385385+static void gov_set_update_util(struct policy_dbs_info *policy_dbs,386386+ unsigned int delay_us)387387+{388388+ struct cpufreq_policy *policy = policy_dbs->policy;389389+ int cpu;390390+391391+ gov_update_sample_delay(policy_dbs, delay_us);392392+ policy_dbs->last_sample_time = 0;393393+394394+ for_each_cpu(cpu, policy->cpus) {395395+ struct cpu_dbs_info *cdbs = &per_cpu(cpu_dbs, cpu);396396+397397+ cpufreq_add_update_util_hook(cpu, &cdbs->update_util,398398+ dbs_update_util_handler);399399+ }400400+}401401+402402+static inline void gov_clear_update_util(struct cpufreq_policy *policy)403403+{404404+ int i;405405+406406+ for_each_cpu(i, policy->cpus)407407+ cpufreq_remove_update_util_hook(i);408408+409409+ synchronize_sched();410410+}411411+412412+static void gov_cancel_work(struct cpufreq_policy *policy)413413+{414414+ struct policy_dbs_info *policy_dbs = policy->governor_data;415415+416416+ gov_clear_update_util(policy_dbs->policy);417417+ irq_work_sync(&policy_dbs->irq_work);418418+ cancel_work_sync(&policy_dbs->work);419419+ atomic_set(&policy_dbs->work_count, 0);420420+ policy_dbs->work_in_progress = false;421421+}422422+297423static struct policy_dbs_info *alloc_policy_dbs_info(struct cpufreq_policy *policy,298424 struct dbs_governor *gov)299425{···354404 struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j);355405356406 j_cdbs->policy_dbs = policy_dbs;357357- j_cdbs->update_util.func = dbs_update_util_handler;358407 }359408 return policy_dbs;360409}···402453 policy_dbs->dbs_data = dbs_data;403454 policy->governor_data = policy_dbs;404455405405- mutex_lock(&dbs_data->mutex);406406- dbs_data->usage_count++;407407- list_add(&policy_dbs->list, &dbs_data->policy_dbs_list);408408- mutex_unlock(&dbs_data->mutex);456456+ gov_attr_set_get(&dbs_data->attr_set, &policy_dbs->list);409457 goto out;410458 }411459···412466 goto free_policy_dbs_info;413467 }414468415415- INIT_LIST_HEAD(&dbs_data->policy_dbs_list);416416- mutex_init(&dbs_data->mutex);469469+ gov_attr_set_init(&dbs_data->attr_set, &policy_dbs->list);417470418471 ret = gov->init(dbs_data, !policy->governor->initialized);419472 if (ret)···432487 if (!have_governor_per_policy())433488 gov->gdbs_data = dbs_data;434489490490+ policy_dbs->dbs_data = dbs_data;435491 policy->governor_data = policy_dbs;436492437437- policy_dbs->dbs_data = dbs_data;438438- dbs_data->usage_count = 1;439439- list_add(&policy_dbs->list, &dbs_data->policy_dbs_list);440440-441493 gov->kobj_type.sysfs_ops = &governor_sysfs_ops;442442- ret = kobject_init_and_add(&dbs_data->kobj, &gov->kobj_type,494494+ ret = kobject_init_and_add(&dbs_data->attr_set.kobj, &gov->kobj_type,443495 get_governor_parent_kobj(policy),444496 "%s", gov->gov.name);445497 if (!ret)···465523 struct dbs_governor *gov = dbs_governor_of(policy);466524 struct policy_dbs_info *policy_dbs = policy->governor_data;467525 struct dbs_data *dbs_data = policy_dbs->dbs_data;468468- int count;526526+ unsigned int count;469527470528 /* Protect gov->gdbs_data against concurrent updates. */471529 mutex_lock(&gov_dbs_data_mutex);472530473473- mutex_lock(&dbs_data->mutex);474474- list_del(&policy_dbs->list);475475- count = --dbs_data->usage_count;476476- mutex_unlock(&dbs_data->mutex);531531+ count = gov_attr_set_put(&dbs_data->attr_set, &policy_dbs->list);532532+533533+ policy->governor_data = NULL;477534478535 if (!count) {479479- kobject_put(&dbs_data->kobj);480480-481481- policy->governor_data = NULL;482482-483536 if (!have_governor_per_policy())484537 gov->gdbs_data = NULL;485538486539 gov->exit(dbs_data, policy->governor->initialized == 1);487487- mutex_destroy(&dbs_data->mutex);488540 kfree(dbs_data);489489- } else {490490- policy->governor_data = NULL;491541 }492542493543 free_policy_dbs_info(policy_dbs, gov);···508574509575 for_each_cpu(j, policy->cpus) {510576 struct cpu_dbs_info *j_cdbs = &per_cpu(cpu_dbs, j);511511- unsigned int prev_load;512577513513- j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_cpu_wall, io_busy);514514-515515- prev_load = j_cdbs->prev_cpu_wall - j_cdbs->prev_cpu_idle;516516- j_cdbs->prev_load = 100 * prev_load / (unsigned int)j_cdbs->prev_cpu_wall;578578+ j_cdbs->prev_cpu_idle = get_cpu_idle_time(j, &j_cdbs->prev_update_time, io_busy);579579+ /*580580+ * Make the first invocation of dbs_update() compute the load.581581+ */582582+ j_cdbs->prev_load = 0;517583518584 if (ignore_nice)519585 j_cdbs->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE];
+11-35
drivers/cpufreq/cpufreq_governor.h
···2424#include <linux/module.h>2525#include <linux/mutex.h>26262727-/*2828- * The polling frequency depends on the capability of the processor. Default2929- * polling frequency is 1000 times the transition latency of the processor. The3030- * governor will work on any processor with transition latency <= 10ms, using3131- * appropriate sampling rate.3232- *3333- * For CPUs with transition latency > 10ms (mostly drivers with CPUFREQ_ETERNAL)3434- * this governor will not work. All times here are in us (micro seconds).3535- */3636-#define MIN_SAMPLING_RATE_RATIO (2)3737-#define LATENCY_MULTIPLIER (1000)3838-#define MIN_LATENCY_MULTIPLIER (20)3939-#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)4040-4127/* Ondemand Sampling types */4228enum {OD_NORMAL_SAMPLE, OD_SUB_SAMPLE};4329···38523953/* Governor demand based switching data (per-policy or global). */4054struct dbs_data {4141- int usage_count;5555+ struct gov_attr_set attr_set;4256 void *tuners;4357 unsigned int min_sampling_rate;4458 unsigned int ignore_nice_load;···4660 unsigned int sampling_down_factor;4761 unsigned int up_threshold;4862 unsigned int io_is_busy;4949-5050- struct kobject kobj;5151- struct list_head policy_dbs_list;5252- /*5353- * Protect concurrent updates to governor tunables from sysfs,5454- * policy_dbs_list and usage_count.5555- */5656- struct mutex mutex;5763};58645959-/* Governor's specific attributes */6060-struct dbs_data;6161-struct governor_attr {6262- struct attribute attr;6363- ssize_t (*show)(struct dbs_data *dbs_data, char *buf);6464- ssize_t (*store)(struct dbs_data *dbs_data, const char *buf,6565- size_t count);6666-};6565+static inline struct dbs_data *to_dbs_data(struct gov_attr_set *attr_set)6666+{6767+ return container_of(attr_set, struct dbs_data, attr_set);6868+}67696870#define gov_show_one(_gov, file_name) \6971static ssize_t show_##file_name \7070-(struct dbs_data *dbs_data, char *buf) \7272+(struct gov_attr_set *attr_set, char *buf) \7173{ \7474+ struct dbs_data *dbs_data = to_dbs_data(attr_set); \7275 struct _gov##_dbs_tuners *tuners = dbs_data->tuners; \7376 return sprintf(buf, "%u\n", tuners->file_name); \7477}75787679#define gov_show_one_common(file_name) \7780static ssize_t show_##file_name \7878-(struct dbs_data *dbs_data, char *buf) \8181+(struct gov_attr_set *attr_set, char *buf) \7982{ \8383+ struct dbs_data *dbs_data = to_dbs_data(attr_set); \8084 return sprintf(buf, "%u\n", dbs_data->file_name); \8185}8286···111135/* Per cpu structures */112136struct cpu_dbs_info {113137 u64 prev_cpu_idle;114114- u64 prev_cpu_wall;138138+ u64 prev_update_time;115139 u64 prev_cpu_nice;116140 /*117141 * Used to keep track of load in the previous interval. However, when···160184 (struct cpufreq_policy *, unsigned int, unsigned int),161185 unsigned int powersave_bias);162186void od_unregister_powersave_bias_handler(void);163163-ssize_t store_sampling_rate(struct dbs_data *dbs_data, const char *buf,187187+ssize_t store_sampling_rate(struct gov_attr_set *attr_set, const char *buf,164188 size_t count);165189void gov_update_cpu_data(struct dbs_data *dbs_data);166190#endif /* _CPUFREQ_GOVERNOR_H */
+84
drivers/cpufreq/cpufreq_governor_attr_set.c
···11+/*22+ * Abstract code for CPUFreq governor tunable sysfs attributes.33+ *44+ * Copyright (C) 2016, Intel Corporation55+ * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>66+ *77+ * This program is free software; you can redistribute it and/or modify88+ * it under the terms of the GNU General Public License version 2 as99+ * published by the Free Software Foundation.1010+ */1111+1212+#include "cpufreq_governor.h"1313+1414+static inline struct gov_attr_set *to_gov_attr_set(struct kobject *kobj)1515+{1616+ return container_of(kobj, struct gov_attr_set, kobj);1717+}1818+1919+static inline struct governor_attr *to_gov_attr(struct attribute *attr)2020+{2121+ return container_of(attr, struct governor_attr, attr);2222+}2323+2424+static ssize_t governor_show(struct kobject *kobj, struct attribute *attr,2525+ char *buf)2626+{2727+ struct governor_attr *gattr = to_gov_attr(attr);2828+2929+ return gattr->show(to_gov_attr_set(kobj), buf);3030+}3131+3232+static ssize_t governor_store(struct kobject *kobj, struct attribute *attr,3333+ const char *buf, size_t count)3434+{3535+ struct gov_attr_set *attr_set = to_gov_attr_set(kobj);3636+ struct governor_attr *gattr = to_gov_attr(attr);3737+ int ret;3838+3939+ mutex_lock(&attr_set->update_lock);4040+ ret = attr_set->usage_count ? gattr->store(attr_set, buf, count) : -EBUSY;4141+ mutex_unlock(&attr_set->update_lock);4242+ return ret;4343+}4444+4545+const struct sysfs_ops governor_sysfs_ops = {4646+ .show = governor_show,4747+ .store = governor_store,4848+};4949+EXPORT_SYMBOL_GPL(governor_sysfs_ops);5050+5151+void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node)5252+{5353+ INIT_LIST_HEAD(&attr_set->policy_list);5454+ mutex_init(&attr_set->update_lock);5555+ attr_set->usage_count = 1;5656+ list_add(list_node, &attr_set->policy_list);5757+}5858+EXPORT_SYMBOL_GPL(gov_attr_set_init);5959+6060+void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node)6161+{6262+ mutex_lock(&attr_set->update_lock);6363+ attr_set->usage_count++;6464+ list_add(list_node, &attr_set->policy_list);6565+ mutex_unlock(&attr_set->update_lock);6666+}6767+EXPORT_SYMBOL_GPL(gov_attr_set_get);6868+6969+unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node)7070+{7171+ unsigned int count;7272+7373+ mutex_lock(&attr_set->update_lock);7474+ list_del(list_node);7575+ count = --attr_set->usage_count;7676+ mutex_unlock(&attr_set->update_lock);7777+ if (count)7878+ return count;7979+8080+ kobject_put(&attr_set->kobj);8181+ mutex_destroy(&attr_set->update_lock);8282+ return 0;8383+}8484+EXPORT_SYMBOL_GPL(gov_attr_set_put);
+17-12
drivers/cpufreq/cpufreq_ondemand.c
···207207/************************** sysfs interface ************************/208208static struct dbs_governor od_dbs_gov;209209210210-static ssize_t store_io_is_busy(struct dbs_data *dbs_data, const char *buf,211211- size_t count)210210+static ssize_t store_io_is_busy(struct gov_attr_set *attr_set, const char *buf,211211+ size_t count)212212{213213+ struct dbs_data *dbs_data = to_dbs_data(attr_set);213214 unsigned int input;214215 int ret;215216···225224 return count;226225}227226228228-static ssize_t store_up_threshold(struct dbs_data *dbs_data, const char *buf,229229- size_t count)227227+static ssize_t store_up_threshold(struct gov_attr_set *attr_set,228228+ const char *buf, size_t count)230229{230230+ struct dbs_data *dbs_data = to_dbs_data(attr_set);231231 unsigned int input;232232 int ret;233233 ret = sscanf(buf, "%u", &input);···242240 return count;243241}244242245245-static ssize_t store_sampling_down_factor(struct dbs_data *dbs_data,246246- const char *buf, size_t count)243243+static ssize_t store_sampling_down_factor(struct gov_attr_set *attr_set,244244+ const char *buf, size_t count)247245{246246+ struct dbs_data *dbs_data = to_dbs_data(attr_set);248247 struct policy_dbs_info *policy_dbs;249248 unsigned int input;250249 int ret;···257254 dbs_data->sampling_down_factor = input;258255259256 /* Reset down sampling multiplier in case it was active */260260- list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list) {257257+ list_for_each_entry(policy_dbs, &attr_set->policy_list, list) {261258 /*262259 * Doing this without locking might lead to using different263260 * rate_mult values in od_update() and od_dbs_timer().···270267 return count;271268}272269273273-static ssize_t store_ignore_nice_load(struct dbs_data *dbs_data,274274- const char *buf, size_t count)270270+static ssize_t store_ignore_nice_load(struct gov_attr_set *attr_set,271271+ const char *buf, size_t count)275272{273273+ struct dbs_data *dbs_data = to_dbs_data(attr_set);276274 unsigned int input;277275 int ret;278276···295291 return count;296292}297293298298-static ssize_t store_powersave_bias(struct dbs_data *dbs_data, const char *buf,299299- size_t count)294294+static ssize_t store_powersave_bias(struct gov_attr_set *attr_set,295295+ const char *buf, size_t count)300296{297297+ struct dbs_data *dbs_data = to_dbs_data(attr_set);301298 struct od_dbs_tuners *od_tuners = dbs_data->tuners;302299 struct policy_dbs_info *policy_dbs;303300 unsigned int input;···313308314309 od_tuners->powersave_bias = input;315310316316- list_for_each_entry(policy_dbs, &dbs_data->policy_dbs_list, list)311311+ list_for_each_entry(policy_dbs, &attr_set->policy_list, list)317312 ondemand_powersave_bias_init(policy_dbs->policy);318313319314 return count;
+34-42
drivers/cpufreq/e_powersaver.c
···66 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*77 */8899+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1010+911#include <linux/kernel.h>1012#include <linux/module.h>1113#include <linux/init.h>···2220#include <asm/msr.h>2321#include <asm/tsc.h>24222525-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE2323+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)2624#include <linux/acpi.h>2725#include <acpi/processor.h>2826#endif···35333634struct eps_cpu_data {3735 u32 fsb;3838-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE3636+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)3937 u32 bios_limit;4038#endif4139 struct cpufreq_frequency_table freq_table[];···4846static int voltage_failsafe_off;4947static int set_max_voltage;50485151-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE4949+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)5250static int ignore_acpi_limit;53515452static struct acpi_processor_performance *eps_acpi_cpu_perf;···143141 /* Print voltage and multiplier */144142 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);145143 current_voltage = lo & 0xff;146146- printk(KERN_INFO "eps: Current voltage = %dmV\n",147147- current_voltage * 16 + 700);144144+ pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);148145 current_multiplier = (lo >> 8) & 0xff;149149- printk(KERN_INFO "eps: Current multiplier = %d\n",150150- current_multiplier);146146+ pr_info("Current multiplier = %d\n", current_multiplier);151147 }152148#endif153149 return 0;···166166 dest_state = centaur->freq_table[index].driver_data & 0xffff;167167 ret = eps_set_state(centaur, policy, dest_state);168168 if (ret)169169- printk(KERN_ERR "eps: Timeout!\n");169169+ pr_err("Timeout!\n");170170 return ret;171171}172172···186186 int k, step, voltage;187187 int ret;188188 int states;189189-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE189189+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)190190 unsigned int limit;191191#endif192192···194194 return -ENODEV;195195196196 /* Check brand */197197- printk(KERN_INFO "eps: Detected VIA ");197197+ pr_info("Detected VIA ");198198199199 switch (c->x86_model) {200200 case 10:201201 rdmsr(0x1153, lo, hi);202202 brand = (((lo >> 2) ^ lo) >> 18) & 3;203203- printk(KERN_CONT "Model A ");203203+ pr_cont("Model A ");204204 break;205205 case 13:206206 rdmsr(0x1154, lo, hi);207207 brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff;208208- printk(KERN_CONT "Model D ");208208+ pr_cont("Model D ");209209 break;210210 }211211212212 switch (brand) {213213 case EPS_BRAND_C7M:214214- printk(KERN_CONT "C7-M\n");214214+ pr_cont("C7-M\n");215215 break;216216 case EPS_BRAND_C7:217217- printk(KERN_CONT "C7\n");217217+ pr_cont("C7\n");218218 break;219219 case EPS_BRAND_EDEN:220220- printk(KERN_CONT "Eden\n");220220+ pr_cont("Eden\n");221221 break;222222 case EPS_BRAND_C7D:223223- printk(KERN_CONT "C7-D\n");223223+ pr_cont("C7-D\n");224224 break;225225 case EPS_BRAND_C3:226226- printk(KERN_CONT "C3\n");226226+ pr_cont("C3\n");227227 return -ENODEV;228228 break;229229 }···235235 /* Can be locked at 0 */236236 rdmsrl(MSR_IA32_MISC_ENABLE, val);237237 if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {238238- printk(KERN_INFO "eps: Can't enable Enhanced PowerSaver\n");238238+ pr_info("Can't enable Enhanced PowerSaver\n");239239 return -ENODEV;240240 }241241 }···243243 /* Print voltage and multiplier */244244 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);245245 current_voltage = lo & 0xff;246246- printk(KERN_INFO "eps: Current voltage = %dmV\n",247247- current_voltage * 16 + 700);246246+ pr_info("Current voltage = %dmV\n", current_voltage * 16 + 700);248247 current_multiplier = (lo >> 8) & 0xff;249249- printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier);248248+ pr_info("Current multiplier = %d\n", current_multiplier);250249251250 /* Print limits */252251 max_voltage = hi & 0xff;253253- printk(KERN_INFO "eps: Highest voltage = %dmV\n",254254- max_voltage * 16 + 700);252252+ pr_info("Highest voltage = %dmV\n", max_voltage * 16 + 700);255253 max_multiplier = (hi >> 8) & 0xff;256256- printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier);254254+ pr_info("Highest multiplier = %d\n", max_multiplier);257255 min_voltage = (hi >> 16) & 0xff;258258- printk(KERN_INFO "eps: Lowest voltage = %dmV\n",259259- min_voltage * 16 + 700);256256+ pr_info("Lowest voltage = %dmV\n", min_voltage * 16 + 700);260257 min_multiplier = (hi >> 24) & 0xff;261261- printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier);258258+ pr_info("Lowest multiplier = %d\n", min_multiplier);262259263260 /* Sanity checks */264261 if (current_multiplier == 0 || max_multiplier == 0···273276274277 /* Check for systems using underclocked CPU */275278 if (!freq_failsafe_off && max_multiplier != current_multiplier) {276276- printk(KERN_INFO "eps: Your processor is running at different "277277- "frequency then its maximum. Aborting.\n");278278- printk(KERN_INFO "eps: You can use freq_failsafe_off option "279279- "to disable this check.\n");279279+ pr_info("Your processor is running at different frequency then its maximum. Aborting.\n");280280+ pr_info("You can use freq_failsafe_off option to disable this check.\n");280281 return -EINVAL;281282 }282283 if (!voltage_failsafe_off && max_voltage != current_voltage) {283283- printk(KERN_INFO "eps: Your processor is running at different "284284- "voltage then its maximum. Aborting.\n");285285- printk(KERN_INFO "eps: You can use voltage_failsafe_off "286286- "option to disable this check.\n");284284+ pr_info("Your processor is running at different voltage then its maximum. Aborting.\n");285285+ pr_info("You can use voltage_failsafe_off option to disable this check.\n");287286 return -EINVAL;288287 }289288290289 /* Calc FSB speed */291290 fsb = cpu_khz / current_multiplier;292291293293-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE292292+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)294293 /* Check for ACPI processor speed limit */295294 if (!ignore_acpi_limit && !eps_acpi_init()) {296295 if (!acpi_processor_get_bios_limit(policy->cpu, &limit)) {297297- printk(KERN_INFO "eps: ACPI limit %u.%uGHz\n",296296+ pr_info("ACPI limit %u.%uGHz\n",298297 limit/1000000,299298 (limit%1000000)/10000);300299 eps_acpi_exit(policy);301300 /* Check if max_multiplier is in BIOS limits */302301 if (limit && max_multiplier * fsb > limit) {303303- printk(KERN_INFO "eps: Aborting.\n");302302+ pr_info("Aborting\n");304303 return -EINVAL;305304 }306305 }···312319 v = (set_max_voltage - 700) / 16;313320 /* Check if voltage is within limits */314321 if (v >= min_voltage && v <= max_voltage) {315315- printk(KERN_INFO "eps: Setting %dmV as maximum.\n",316316- v * 16 + 700);322322+ pr_info("Setting %dmV as maximum\n", v * 16 + 700);317323 max_voltage = v;318324 }319325 }···333341334342 /* Copy basic values */335343 centaur->fsb = fsb;336336-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE344344+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)337345 centaur->bios_limit = limit;338346#endif339347···418426MODULE_PARM_DESC(freq_failsafe_off, "Disable current vs max frequency check");419427module_param(voltage_failsafe_off, int, 0644);420428MODULE_PARM_DESC(voltage_failsafe_off, "Disable current vs max voltage check");421421-#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE429429+#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)422430module_param(ignore_acpi_limit, int, 0644);423431MODULE_PARM_DESC(ignore_acpi_limit, "Don't check ACPI's processor speed limit");424432#endif
+3-1
drivers/cpufreq/elanfreq.c
···1616 *1717 */18181919+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt2020+1921#include <linux/kernel.h>2022#include <linux/module.h>2123#include <linux/init.h>···187185static int __init elanfreq_setup(char *str)188186{189187 max_freq = simple_strtoul(str, &str, 0);190190- printk(KERN_WARNING "You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n");188188+ pr_warn("You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n");191189 return 1;192190}193191__setup("elanfreq=", elanfreq_setup);
-42
drivers/cpufreq/hisi-acpu-cpufreq.c
···11-/*22- * Hisilicon Platforms Using ACPU CPUFreq Support33- *44- * Copyright (c) 2015 Hisilicon Limited.55- * Copyright (c) 2015 Linaro Limited.66- *77- * Leo Yan <leo.yan@linaro.org>88- *99- * This program is free software; you can redistribute it and/or modify1010- * it under the terms of the GNU General Public License version 2 as1111- * published by the Free Software Foundation.1212- *1313- * This program is distributed "as is" WITHOUT ANY WARRANTY of any1414- * kind, whether express or implied; without even the implied warranty1515- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1616- * GNU General Public License for more details.1717- */1818-1919-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt2020-2121-#include <linux/err.h>2222-#include <linux/init.h>2323-#include <linux/kernel.h>2424-#include <linux/module.h>2525-#include <linux/of.h>2626-#include <linux/platform_device.h>2727-2828-static int __init hisi_acpu_cpufreq_driver_init(void)2929-{3030- struct platform_device *pdev;3131-3232- if (!of_machine_is_compatible("hisilicon,hi6220"))3333- return -ENODEV;3434-3535- pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0);3636- return PTR_ERR_OR_ZERO(pdev);3737-}3838-module_init(hisi_acpu_cpufreq_driver_init);3939-4040-MODULE_AUTHOR("Leo Yan <leo.yan@linaro.org>");4141-MODULE_DESCRIPTION("Hisilicon acpu cpufreq driver");4242-MODULE_LICENSE("GPL v2");
+5-5
drivers/cpufreq/ia64-acpi-cpufreq.c
···88 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>99 */10101111+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1212+1113#include <linux/kernel.h>1214#include <linux/slab.h>1315#include <linux/module.h>···120118121119 if (ret) {122120 set_cpus_allowed_ptr(current, &saved_mask);123123- printk(KERN_WARNING "get performance failed with error %d\n",124124- ret);121121+ pr_warn("get performance failed with error %d\n", ret);125122 ret = 0;126123 goto migrate_end;127124 }···178177179178 ret = processor_set_pstate(value);180179 if (ret) {181181- printk(KERN_WARNING "Transition failed with error %d\n", ret);180180+ pr_warn("Transition failed with error %d\n", ret);182181 retval = -ENODEV;183182 goto migrate_end;184183 }···292291 /* notify BIOS that we exist */293292 acpi_processor_notify_smm(THIS_MODULE);294293295295- printk(KERN_INFO "acpi-cpufreq: CPU%u - ACPI performance management "296296- "activated.\n", cpu);294294+ pr_info("CPU%u - ACPI performance management activated\n", cpu);297295298296 for (i = 0; i < data->acpi_data.state_count; i++)299297 pr_debug(" %cP%d: %d MHz, %d mW, %d uS, %d uS, 0x%x 0x%x\n",
+188-33
drivers/cpufreq/intel_pstate.c
···1010 * of the License.1111 */12121313+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1414+1315#include <linux/kernel.h>1416#include <linux/kernel_stat.h>1517#include <linux/module.h>···4038#define ATOM_VIDS 0x66b4139#define ATOM_TURBO_RATIOS 0x66c4240#define ATOM_TURBO_VIDS 0x66d4141+4242+#ifdef CONFIG_ACPI4343+#include <acpi/processor.h>4444+#endif43454446#define FRAC_BITS 84547#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)···178172 * @prev_cummulative_iowait: IO Wait time difference from last and179173 * current sample180174 * @sample: Storage for storing last Sample data175175+ * @acpi_perf_data: Stores ACPI perf information read from _PSS176176+ * @valid_pss_table: Set to true for valid ACPI _PSS entries found181177 *182178 * This structure stores per CPU instance data for all CPUs.183179 */···198190 u64 prev_tsc;199191 u64 prev_cummulative_iowait;200192 struct sample sample;193193+#ifdef CONFIG_ACPI194194+ struct acpi_processor_performance acpi_perf_data;195195+ bool valid_pss_table;196196+#endif201197};202198203199static struct cpudata **all_cpu_data;···270258static struct pstate_funcs pstate_funcs;271259static int hwp_active;272260261261+#ifdef CONFIG_ACPI262262+static bool acpi_ppc;263263+#endif273264274265/**275266 * struct perf_limits - Store user and policy limits···346331static struct perf_limits *limits = &powersave_limits;347332#endif348333334334+#ifdef CONFIG_ACPI335335+336336+static bool intel_pstate_get_ppc_enable_status(void)337337+{338338+ if (acpi_gbl_FADT.preferred_profile == PM_ENTERPRISE_SERVER ||339339+ acpi_gbl_FADT.preferred_profile == PM_PERFORMANCE_SERVER)340340+ return true;341341+342342+ return acpi_ppc;343343+}344344+345345+/*346346+ * The max target pstate ratio is a 8 bit value in both PLATFORM_INFO MSR and347347+ * in TURBO_RATIO_LIMIT MSR, which pstate driver stores in max_pstate and348348+ * max_turbo_pstate fields. The PERF_CTL MSR contains 16 bit value for P state349349+ * ratio, out of it only high 8 bits are used. For example 0x1700 is setting350350+ * target ratio 0x17. The _PSS control value stores in a format which can be351351+ * directly written to PERF_CTL MSR. But in intel_pstate driver this shift352352+ * occurs during write to PERF_CTL (E.g. for cores core_set_pstate()).353353+ * This function converts the _PSS control value to intel pstate driver format354354+ * for comparison and assignment.355355+ */356356+static int convert_to_native_pstate_format(struct cpudata *cpu, int index)357357+{358358+ return cpu->acpi_perf_data.states[index].control >> 8;359359+}360360+361361+static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)362362+{363363+ struct cpudata *cpu;364364+ int turbo_pss_ctl;365365+ int ret;366366+ int i;367367+368368+ if (!intel_pstate_get_ppc_enable_status())369369+ return;370370+371371+ cpu = all_cpu_data[policy->cpu];372372+373373+ ret = acpi_processor_register_performance(&cpu->acpi_perf_data,374374+ policy->cpu);375375+ if (ret)376376+ return;377377+378378+ /*379379+ * Check if the control value in _PSS is for PERF_CTL MSR, which should380380+ * guarantee that the states returned by it map to the states in our381381+ * list directly.382382+ */383383+ if (cpu->acpi_perf_data.control_register.space_id !=384384+ ACPI_ADR_SPACE_FIXED_HARDWARE)385385+ goto err;386386+387387+ /*388388+ * If there is only one entry _PSS, simply ignore _PSS and continue as389389+ * usual without taking _PSS into account390390+ */391391+ if (cpu->acpi_perf_data.state_count < 2)392392+ goto err;393393+394394+ pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu);395395+ for (i = 0; i < cpu->acpi_perf_data.state_count; i++) {396396+ pr_debug(" %cP%d: %u MHz, %u mW, 0x%x\n",397397+ (i == cpu->acpi_perf_data.state ? '*' : ' '), i,398398+ (u32) cpu->acpi_perf_data.states[i].core_frequency,399399+ (u32) cpu->acpi_perf_data.states[i].power,400400+ (u32) cpu->acpi_perf_data.states[i].control);401401+ }402402+403403+ /*404404+ * The _PSS table doesn't contain whole turbo frequency range.405405+ * This just contains +1 MHZ above the max non turbo frequency,406406+ * with control value corresponding to max turbo ratio. But407407+ * when cpufreq set policy is called, it will call with this408408+ * max frequency, which will cause a reduced performance as409409+ * this driver uses real max turbo frequency as the max410410+ * frequency. So correct this frequency in _PSS table to411411+ * correct max turbo frequency based on the turbo ratio.412412+ * Also need to convert to MHz as _PSS freq is in MHz.413413+ */414414+ turbo_pss_ctl = convert_to_native_pstate_format(cpu, 0);415415+ if (turbo_pss_ctl > cpu->pstate.max_pstate)416416+ cpu->acpi_perf_data.states[0].core_frequency =417417+ policy->cpuinfo.max_freq / 1000;418418+ cpu->valid_pss_table = true;419419+ pr_info("_PPC limits will be enforced\n");420420+421421+ return;422422+423423+ err:424424+ cpu->valid_pss_table = false;425425+ acpi_processor_unregister_performance(policy->cpu);426426+}427427+428428+static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)429429+{430430+ struct cpudata *cpu;431431+432432+ cpu = all_cpu_data[policy->cpu];433433+ if (!cpu->valid_pss_table)434434+ return;435435+436436+ acpi_processor_unregister_performance(policy->cpu);437437+}438438+439439+#else440440+static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)441441+{442442+}443443+444444+static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)445445+{446446+}447447+#endif448448+349449static inline void pid_reset(struct _pid *pid, int setpoint, int busy,350450 int deadband, int integral) {351451 pid->setpoint = int_tofp(setpoint);···471341472342static inline void pid_p_gain_set(struct _pid *pid, int percent)473343{474474- pid->p_gain = div_fp(int_tofp(percent), int_tofp(100));344344+ pid->p_gain = div_fp(percent, 100);475345}476346477347static inline void pid_i_gain_set(struct _pid *pid, int percent)478348{479479- pid->i_gain = div_fp(int_tofp(percent), int_tofp(100));349349+ pid->i_gain = div_fp(percent, 100);480350}481351482352static inline void pid_d_gain_set(struct _pid *pid, int percent)483353{484484- pid->d_gain = div_fp(int_tofp(percent), int_tofp(100));354354+ pid->d_gain = div_fp(percent, 100);485355}486356487357static signed int pid_calc(struct _pid *pid, int32_t busy)···659529660530 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;661531 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1;662662- turbo_fp = div_fp(int_tofp(no_turbo), int_tofp(total));532532+ turbo_fp = div_fp(no_turbo, total);663533 turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100)));664534 return sprintf(buf, "%u\n", turbo_pct);665535}···701571702572 update_turbo_state();703573 if (limits->turbo_disabled) {704704- pr_warn("intel_pstate: Turbo disabled by BIOS or unavailable on processor\n");574574+ pr_warn("Turbo disabled by BIOS or unavailable on processor\n");705575 return -EPERM;706576 }707577···730600 limits->max_perf_pct);731601 limits->max_perf_pct = max(limits->min_perf_pct,732602 limits->max_perf_pct);733733- limits->max_perf = div_fp(int_tofp(limits->max_perf_pct),734734- int_tofp(100));603603+ limits->max_perf = div_fp(limits->max_perf_pct, 100);735604736605 if (hwp_active)737606 intel_pstate_hwp_set_online_cpus();···754625 limits->min_perf_pct);755626 limits->min_perf_pct = min(limits->max_perf_pct,756627 limits->min_perf_pct);757757- limits->min_perf = div_fp(int_tofp(limits->min_perf_pct),758758- int_tofp(100));628628+ limits->min_perf = div_fp(limits->min_perf_pct, 100);759629760630 if (hwp_active)761631 intel_pstate_hwp_set_online_cpus();···11391011 struct sample *sample = &cpu->sample;11401012 int64_t core_pct;1141101311421142- core_pct = int_tofp(sample->aperf) * int_tofp(100);11431143- core_pct = div64_u64(core_pct, int_tofp(sample->mperf));10141014+ core_pct = sample->aperf * int_tofp(100);10151015+ core_pct = div64_u64(core_pct, sample->mperf);1144101611451017 sample->core_pct_busy = (int32_t)core_pct;11461018}···11891061 cpu->pstate.scaling, cpu->sample.mperf);11901062}1191106310641064+static inline int32_t get_avg_pstate(struct cpudata *cpu)10651065+{10661066+ return div64_u64(cpu->pstate.max_pstate_physical * cpu->sample.aperf,10671067+ cpu->sample.mperf);10681068+}10691069+11921070static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)11931071{11941072 struct sample *sample = &cpu->sample;···12271093 cpu_load = div64_u64(int_tofp(100) * mperf, sample->tsc);12281094 cpu->sample.busy_scaled = cpu_load;1229109512301230- return cpu->pstate.current_pstate - pid_calc(&cpu->pid, cpu_load);10961096+ return get_avg_pstate(cpu) - pid_calc(&cpu->pid, cpu_load);12311097}1232109812331099static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)···12491115 * specified pstate.12501116 */12511117 core_busy = cpu->sample.core_pct_busy;12521252- max_pstate = int_tofp(cpu->pstate.max_pstate_physical);12531253- current_pstate = int_tofp(cpu->pstate.current_pstate);11181118+ max_pstate = cpu->pstate.max_pstate_physical;11191119+ current_pstate = cpu->pstate.current_pstate;12541120 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));1255112112561122 /*···12611127 */12621128 duration_ns = cpu->sample.time - cpu->last_sample_time;12631129 if ((s64)duration_ns > pid_params.sample_rate_ns * 3) {12641264- sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns),12651265- int_tofp(duration_ns));11301130+ sample_ratio = div_fp(pid_params.sample_rate_ns, duration_ns);12661131 core_busy = mul_fp(core_busy, sample_ratio);12671132 } else {12681133 sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc);···1379124613801247 intel_pstate_busy_pid_reset(cpu);1381124813821382- cpu->update_util.func = intel_pstate_update_util;13831383-13841384- pr_debug("intel_pstate: controlling: cpu %d\n", cpunum);12491249+ pr_debug("controlling: cpu %d\n", cpunum);1385125013861251 return 0;13871252}···1402127114031272 /* Prevent intel_pstate_update_util() from using stale data. */14041273 cpu->sample.time = 0;14051405- cpufreq_set_update_util_data(cpu_num, &cpu->update_util);12741274+ cpufreq_add_update_util_hook(cpu_num, &cpu->update_util,12751275+ intel_pstate_update_util);14061276}1407127714081278static void intel_pstate_clear_update_util_hook(unsigned int cpu)14091279{14101410- cpufreq_set_update_util_data(cpu, NULL);12801280+ cpufreq_remove_update_util_hook(cpu);14111281 synchronize_sched();14121282}14131283···1428129614291297static int intel_pstate_set_policy(struct cpufreq_policy *policy)14301298{12991299+ struct cpudata *cpu;13001300+14311301 if (!policy->cpuinfo.max_freq)14321302 return -ENODEV;1433130314341304 intel_pstate_clear_update_util_hook(policy->cpu);1435130513061306+ cpu = all_cpu_data[0];13071307+ if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate) {13081308+ if (policy->max < policy->cpuinfo.max_freq &&13091309+ policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {13101310+ pr_debug("policy->max > max non turbo frequency\n");13111311+ policy->max = policy->cpuinfo.max_freq;13121312+ }13131313+ }13141314+14361315 if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {14371316 limits = &performance_limits;14381317 if (policy->max >= policy->cpuinfo.max_freq) {14391439- pr_debug("intel_pstate: set performance\n");13181318+ pr_debug("set performance\n");14401319 intel_pstate_set_performance_limits(limits);14411320 goto out;14421321 }14431322 } else {14441444- pr_debug("intel_pstate: set powersave\n");13231323+ pr_debug("set powersave\n");14451324 limits = &powersave_limits;14461325 }14471326···14761333 /* Make sure min_perf_pct <= max_perf_pct */14771334 limits->min_perf_pct = min(limits->max_perf_pct, limits->min_perf_pct);1478133514791479- limits->min_perf = div_fp(int_tofp(limits->min_perf_pct),14801480- int_tofp(100));14811481- limits->max_perf = div_fp(int_tofp(limits->max_perf_pct),14821482- int_tofp(100));13361336+ limits->min_perf = div_fp(limits->min_perf_pct, 100);13371337+ limits->max_perf = div_fp(limits->max_perf_pct, 100);1483133814841339 out:14851340 intel_pstate_set_update_util_hook(policy->cpu);···15041363 int cpu_num = policy->cpu;15051364 struct cpudata *cpu = all_cpu_data[cpu_num];1506136515071507- pr_debug("intel_pstate: CPU %d exiting\n", cpu_num);13661366+ pr_debug("CPU %d exiting\n", cpu_num);1508136715091368 intel_pstate_clear_update_util_hook(cpu_num);15101369···15371396 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling;15381397 policy->cpuinfo.max_freq =15391398 cpu->pstate.turbo_pstate * cpu->pstate.scaling;13991399+ intel_pstate_init_acpi_perf_limits(policy);15401400 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;15411401 cpumask_set_cpu(policy->cpu, policy->cpus);14021402+14031403+ return 0;14041404+}14051405+14061406+static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)14071407+{14081408+ intel_pstate_exit_perf_limits(policy);1542140915431410 return 0;15441411}···15571408 .setpolicy = intel_pstate_set_policy,15581409 .get = intel_pstate_get,15591410 .init = intel_pstate_cpu_init,14111411+ .exit = intel_pstate_cpu_exit,15601412 .stop_cpu = intel_pstate_stop_cpu,15611413 .name = "intel_pstate",15621414};···1601145116021452}1603145316041604-#if IS_ENABLED(CONFIG_ACPI)16051605-#include <acpi/processor.h>14541454+#ifdef CONFIG_ACPI1606145516071456static bool intel_pstate_no_acpi_pss(void)16081457{···17571608 if (intel_pstate_platform_pwr_mgmt_exists())17581609 return -ENODEV;1759161017601760- pr_info("Intel P-state driver initializing.\n");16111611+ pr_info("Intel P-state driver initializing\n");1761161217621613 all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus());17631614 if (!all_cpu_data)···17741625 intel_pstate_sysfs_expose_params();1775162617761627 if (hwp_active)17771777- pr_info("intel_pstate: HWP enabled\n");16281628+ pr_info("HWP enabled\n");1778162917791630 return rc;17801631out:···18001651 if (!strcmp(str, "disable"))18011652 no_load = 1;18021653 if (!strcmp(str, "no_hwp")) {18031803- pr_info("intel_pstate: HWP disabled\n");16541654+ pr_info("HWP disabled\n");18041655 no_hwp = 1;18051656 }18061657 if (!strcmp(str, "force"))18071658 force_load = 1;18081659 if (!strcmp(str, "hwp_only"))18091660 hwp_only = 1;16611661+16621662+#ifdef CONFIG_ACPI16631663+ if (!strcmp(str, "support_acpi_ppc"))16641664+ acpi_ppc = true;16651665+#endif16661666+18101667 return 0;18111668}18121669early_param("intel_pstate", intel_pstate_setup);
+35-49
drivers/cpufreq/longhaul.c
···2121 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*2222 */23232424+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt2525+2426#include <linux/kernel.h>2527#include <linux/module.h>2628#include <linux/moduleparam.h>···4139#include <acpi/processor.h>42404341#include "longhaul.h"4444-4545-#define PFX "longhaul: "46424743#define TYPE_LONGHAUL_V1 14844#define TYPE_LONGHAUL_V2 2···347347 freqs.new = calc_speed(longhaul_get_cpu_mult());348348 /* Check if requested frequency is set. */349349 if (unlikely(freqs.new != speed)) {350350- printk(KERN_INFO PFX "Failed to set requested frequency!\n");350350+ pr_info("Failed to set requested frequency!\n");351351 /* Revision ID = 1 but processor is expecting revision key352352 * equal to 0. Jumpers at the bottom of processor will change353353 * multiplier and FSB, but will not change bits in Longhaul354354 * MSR nor enable voltage scaling. */355355 if (!revid_errata) {356356- printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" "357357- "option.\n");356356+ pr_info("Enabling \"Ignore Revision ID\" option\n");358357 revid_errata = 1;359358 msleep(200);360359 goto retry_loop;···363364 * but it doesn't change frequency. I tried poking various364365 * bits in northbridge registers, but without success. */365366 if (longhaul_flags & USE_ACPI_C3) {366366- printk(KERN_INFO PFX "Disabling ACPI C3 support.\n");367367+ pr_info("Disabling ACPI C3 support\n");367368 longhaul_flags &= ~USE_ACPI_C3;368369 if (revid_errata) {369369- printk(KERN_INFO PFX "Disabling \"Ignore "370370- "Revision ID\" option.\n");370370+ pr_info("Disabling \"Ignore Revision ID\" option\n");371371 revid_errata = 0;372372 }373373 msleep(200);···377379 * RevID = 1. RevID errata will make things right. Just378380 * to be 100% sure. */379381 if (longhaul_version == TYPE_LONGHAUL_V2) {380380- printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n");382382+ pr_info("Switching to Longhaul ver. 1\n");381383 longhaul_version = TYPE_LONGHAUL_V1;382384 msleep(200);383385 goto retry_loop;···385387 }386388387389 if (!bm_timeout) {388388- printk(KERN_INFO PFX "Warning: Timeout while waiting for "389389- "idle PCI bus.\n");390390+ pr_info("Warning: Timeout while waiting for idle PCI bus\n");390391 return -EBUSY;391392 }392393···430433 /* Get current frequency */431434 mult = longhaul_get_cpu_mult();432435 if (mult == -1) {433433- printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n");436436+ pr_info("Invalid (reserved) multiplier!\n");434437 return -EINVAL;435438 }436439 fsb = guess_fsb(mult);437440 if (fsb == 0) {438438- printk(KERN_INFO PFX "Invalid (reserved) FSB!\n");441441+ pr_info("Invalid (reserved) FSB!\n");439442 return -EINVAL;440443 }441444 /* Get max multiplier - as we always did.···465468 print_speed(highest_speed/1000));466469467470 if (lowest_speed == highest_speed) {468468- printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n");471471+ pr_info("highestspeed == lowest, aborting\n");469472 return -EINVAL;470473 }471474 if (lowest_speed > highest_speed) {472472- printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",475475+ pr_info("nonsense! lowest (%d > %d) !\n",473476 lowest_speed, highest_speed);474477 return -EINVAL;475478 }···535538536539 rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);537540 if (!(longhaul.bits.RevisionID & 1)) {538538- printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n");541541+ pr_info("Voltage scaling not supported by CPU\n");539542 return;540543 }541544542545 if (!longhaul.bits.VRMRev) {543543- printk(KERN_INFO PFX "VRM 8.5\n");546546+ pr_info("VRM 8.5\n");544547 vrm_mV_table = &vrm85_mV[0];545548 mV_vrm_table = &mV_vrm85[0];546549 } else {547547- printk(KERN_INFO PFX "Mobile VRM\n");550550+ pr_info("Mobile VRM\n");548551 if (cpu_model < CPU_NEHEMIAH)549552 return;550553 vrm_mV_table = &mobilevrm_mV[0];···555558 maxvid = vrm_mV_table[longhaul.bits.MaximumVID];556559557560 if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) {558558- printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "559559- "Voltage scaling disabled.\n",560560- minvid.mV/1000, minvid.mV%1000,561561- maxvid.mV/1000, maxvid.mV%1000);561561+ pr_info("Bogus values Min:%d.%03d Max:%d.%03d - Voltage scaling disabled\n",562562+ minvid.mV/1000, minvid.mV%1000,563563+ maxvid.mV/1000, maxvid.mV%1000);562564 return;563565 }564566565567 if (minvid.mV == maxvid.mV) {566566- printk(KERN_INFO PFX "Claims to support voltage scaling but "567567- "min & max are both %d.%03d. "568568- "Voltage scaling disabled\n",569569- maxvid.mV/1000, maxvid.mV%1000);568568+ pr_info("Claims to support voltage scaling but min & max are both %d.%03d - Voltage scaling disabled\n",569569+ maxvid.mV/1000, maxvid.mV%1000);570570 return;571571 }572572573573 /* How many voltage steps*/574574 numvscales = maxvid.pos - minvid.pos + 1;575575- printk(KERN_INFO PFX576576- "Max VID=%d.%03d "577577- "Min VID=%d.%03d, "578578- "%d possible voltage scales\n",575575+ pr_info("Max VID=%d.%03d Min VID=%d.%03d, %d possible voltage scales\n",579576 maxvid.mV/1000, maxvid.mV%1000,580577 minvid.mV/1000, minvid.mV%1000,581578 numvscales);···608617 pos = minvid.pos;609618 freq_pos->driver_data |= mV_vrm_table[pos] << 8;610619 vid = vrm_mV_table[mV_vrm_table[pos]];611611- printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",620620+ pr_info("f: %d kHz, index: %d, vid: %d mV\n",612621 speed, (int)(freq_pos - longhaul_table), vid.mV);613622 }614623615624 can_scale_voltage = 1;616616- printk(KERN_INFO PFX "Voltage scaling enabled.\n");625625+ pr_info("Voltage scaling enabled\n");617626}618627619628···711720 pci_write_config_byte(dev, reg, pci_cmd);712721 pci_read_config_byte(dev, reg, &pci_cmd);713722 if (!(pci_cmd & 1<<7)) {714714- printk(KERN_ERR PFX715715- "Can't enable access to port 0x22.\n");723723+ pr_err("Can't enable access to port 0x22\n");716724 status = 0;717725 }718726 }···748758 if (pci_cmd & 1 << 7) {749759 pci_read_config_dword(dev, 0x88, &acpi_regs_addr);750760 acpi_regs_addr &= 0xff00;751751- printk(KERN_INFO PFX "ACPI I/O at 0x%x\n",752752- acpi_regs_addr);761761+ pr_info("ACPI I/O at 0x%x\n", acpi_regs_addr);753762 }754763755764 pci_dev_put(dev);···842853 longhaul_version = TYPE_LONGHAUL_V1;843854 }844855845845- printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname);856856+ pr_info("VIA %s CPU detected. ", cpuname);846857 switch (longhaul_version) {847858 case TYPE_LONGHAUL_V1:848859 case TYPE_LONGHAUL_V2:849849- printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version);860860+ pr_cont("Longhaul v%d supported\n", longhaul_version);850861 break;851862 case TYPE_POWERSAVER:852852- printk(KERN_CONT "Powersaver supported.\n");863863+ pr_cont("Powersaver supported\n");853864 break;854865 };855866···878889 if (!(longhaul_flags & USE_ACPI_C3879890 || longhaul_flags & USE_NORTHBRIDGE)880891 && ((pr == NULL) || !(pr->flags.bm_control))) {881881- printk(KERN_ERR PFX882882- "No ACPI support. Unsupported northbridge.\n");892892+ pr_err("No ACPI support: Unsupported northbridge\n");883893 return -ENODEV;884894 }885895886896 if (longhaul_flags & USE_NORTHBRIDGE)887887- printk(KERN_INFO PFX "Using northbridge support.\n");897897+ pr_info("Using northbridge support\n");888898 if (longhaul_flags & USE_ACPI_C3)889889- printk(KERN_INFO PFX "Using ACPI support.\n");899899+ pr_info("Using ACPI support\n");890900891901 ret = longhaul_get_ranges();892902 if (ret != 0)···922934 return -ENODEV;923935924936 if (!enable) {925925- printk(KERN_ERR PFX "Option \"enable\" not set. Aborting.\n");937937+ pr_err("Option \"enable\" not set - Aborting\n");926938 return -ENODEV;927939 }928940#ifdef CONFIG_SMP929941 if (num_online_cpus() > 1) {930930- printk(KERN_ERR PFX "More than 1 CPU detected, "931931- "longhaul disabled.\n");942942+ pr_err("More than 1 CPU detected, longhaul disabled\n");932943 return -ENODEV;933944 }934945#endif935946#ifdef CONFIG_X86_IO_APIC936947 if (cpu_has_apic) {937937- printk(KERN_ERR PFX "APIC detected. Longhaul is currently "938938- "broken in this configuration.\n");948948+ pr_err("APIC detected. Longhaul is currently broken in this configuration.\n");939949 return -ENODEV;940950 }941951#endif···941955 case 6 ... 9:942956 return cpufreq_register_driver(&longhaul_driver);943957 case 10:944944- printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n");958958+ pr_err("Use acpi-cpufreq driver for VIA C7\n");945959 default:946960 ;947961 }
+5-2
drivers/cpufreq/loongson2_cpufreq.c
···1010 * License. See the file "COPYING" in the main directory of this archive1111 * for more details.1212 */1313+1414+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1515+1316#include <linux/cpufreq.h>1417#include <linux/module.h>1518#include <linux/err.h>···79768077 cpuclk = clk_get(NULL, "cpu_clk");8178 if (IS_ERR(cpuclk)) {8282- printk(KERN_ERR "cpufreq: couldn't get CPU clk\n");7979+ pr_err("couldn't get CPU clk\n");8380 return PTR_ERR(cpuclk);8481 }8582···166163 if (ret)167164 return ret;168165169169- pr_info("cpufreq: Loongson-2F CPU frequency driver.\n");166166+ pr_info("Loongson-2F CPU frequency driver\n");170167171168 cpufreq_register_notifier(&loongson2_cpufreq_notifier_block,172169 CPUFREQ_TRANSITION_NOTIFIER);
+6-5
drivers/cpufreq/maple-cpufreq.c
···13131414#undef DEBUG15151616+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1717+1618#include <linux/module.h>1719#include <linux/types.h>1820#include <linux/errno.h>···176174 /* Get first CPU node */177175 cpunode = of_cpu_device_node_get(0);178176 if (cpunode == NULL) {179179- printk(KERN_ERR "cpufreq: Can't find any CPU 0 node\n");177177+ pr_err("Can't find any CPU 0 node\n");180178 goto bail_noprops;181179 }182180···184182 /* we actually don't care on which CPU to access PVR */185183 pvr_hi = PVR_VER(mfspr(SPRN_PVR));186184 if (pvr_hi != 0x3c && pvr_hi != 0x44) {187187- printk(KERN_ERR "cpufreq: Unsupported CPU version (%x)\n",188188- pvr_hi);185185+ pr_err("Unsupported CPU version (%x)\n", pvr_hi);189186 goto bail_noprops;190187 }191188···223222 maple_pmode_cur = -1;224223 maple_scom_switch_freq(maple_scom_query_freq());225224226226- printk(KERN_INFO "Registering Maple CPU frequency driver\n");227227- printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",225225+ pr_info("Registering Maple CPU frequency driver\n");226226+ pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",228227 maple_cpu_freqs[1].frequency/1000,229228 maple_cpu_freqs[0].frequency/1000,230229 maple_cpu_freqs[maple_pmode_cur].frequency/1000);
···1313 * it under the terms of the GNU General Public License version 2 as1414 * published by the Free Software Foundation.1515 */1616+1717+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1818+1619#include <linux/types.h>1720#include <linux/kernel.h>1821#include <linux/sched.h>···166163{167164 mpu_dev = get_cpu_device(0);168165 if (!mpu_dev) {169169- pr_warning("%s: unable to get the mpu device\n", __func__);166166+ pr_warn("%s: unable to get the MPU device\n", __func__);170167 return -EINVAL;171168 }172169173170 mpu_reg = regulator_get(mpu_dev, "vcc");174171 if (IS_ERR(mpu_reg)) {175175- pr_warning("%s: unable to get MPU regulator\n", __func__);172172+ pr_warn("%s: unable to get MPU regulator\n", __func__);176173 mpu_reg = NULL;177174 } else {178175 /*
+5-14
drivers/cpufreq/p4-clockmod.c
···2020 *2121 */22222323+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt2424+2325#include <linux/kernel.h>2426#include <linux/module.h>2527#include <linux/init.h>···3634#include <asm/cpu_device_id.h>37353836#include "speedstep-lib.h"3939-4040-#define PFX "p4-clockmod: "41374238/*4339 * Duty Cycle (3bits), note DC_DISABLE is not specified in···124124{125125 if (c->x86 == 0x06) {126126 if (cpu_has(c, X86_FEATURE_EST))127127- printk_once(KERN_WARNING PFX "Warning: EST-capable "128128- "CPU detected. The acpi-cpufreq module offers "129129- "voltage scaling in addition to frequency "130130- "scaling. You should use that instead of "131131- "p4-clockmod, if possible.\n");127127+ pr_warn_once("Warning: EST-capable CPU detected. The acpi-cpufreq module offers voltage scaling in addition to frequency scaling. You should use that instead of p4-clockmod, if possible.\n");132128 switch (c->x86_model) {133129 case 0x0E: /* Core */134130 case 0x0F: /* Core Duo */···148152 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;149153150154 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {151151- printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "152152- "The speedstep-ich or acpi cpufreq modules offer "153153- "voltage scaling in addition of frequency scaling. "154154- "You should use either one instead of p4-clockmod, "155155- "if possible.\n");155155+ pr_warn("Warning: Pentium 4-M detected. The speedstep-ich or acpi cpufreq modules offer voltage scaling in addition of frequency scaling. You should use either one instead of p4-clockmod, if possible.\n");156156 return speedstep_get_frequency(SPEEDSTEP_CPU_P4M);157157 }158158···257265258266 ret = cpufreq_register_driver(&p4clockmod_driver);259267 if (!ret)260260- printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock "261261- "Modulation available\n");268268+ pr_info("P4/Xeon(TM) CPU On-Demand Clock Modulation available\n");262269263270 return ret;264271}
···12121313#undef DEBUG14141515+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1616+1517#include <linux/module.h>1618#include <linux/types.h>1719#include <linux/errno.h>···140138 usleep_range(1000, 1000);141139 }142140 if (done == 0)143143- printk(KERN_WARNING "cpufreq: Timeout in clock slewing !\n");141141+ pr_warn("Timeout in clock slewing !\n");144142}145143146144···268266 rc = pmf_call_one(pfunc_cpu_setfreq_low, NULL);269267270268 if (rc)271271- printk(KERN_WARNING "cpufreq: pfunc switch error %d\n", rc);269269+ pr_warn("pfunc switch error %d\n", rc);272270273271 /* It's an irq GPIO so we should be able to just block here,274272 * I'll do that later after I've properly tested the IRQ code for···284282 usleep_range(500, 500);285283 }286284 if (done == 0)287287- printk(KERN_WARNING "cpufreq: Timeout in clock slewing !\n");285285+ pr_warn("Timeout in clock slewing !\n");288286289287 /* If frequency is going down, last ramp the voltage */290288 if (speed_mode > g5_pmode_cur)···370368 }371369 pvr_hi = (*valp) >> 16;372370 if (pvr_hi != 0x3c && pvr_hi != 0x44) {373373- printk(KERN_ERR "cpufreq: Unsupported CPU version\n");371371+ pr_err("Unsupported CPU version\n");374372 goto bail_noprops;375373 }376374···405403406404 root = of_find_node_by_path("/");407405 if (root == NULL) {408408- printk(KERN_ERR "cpufreq: Can't find root of "409409- "device tree\n");406406+ pr_err("Can't find root of device tree\n");410407 goto bail_noprops;411408 }412409 pfunc_set_vdnap0 = pmf_find_function(root, "set-vdnap0");···413412 pmf_find_function(root, "slewing-done");414413 if (pfunc_set_vdnap0 == NULL ||415414 pfunc_vdnap0_complete == NULL) {416416- printk(KERN_ERR "cpufreq: Can't find required "417417- "platform function\n");415415+ pr_err("Can't find required platform function\n");418416 goto bail_noprops;419417 }420418···453453 g5_pmode_cur = -1;454454 g5_switch_freq(g5_query_freq());455455456456- printk(KERN_INFO "Registering G5 CPU frequency driver\n");457457- printk(KERN_INFO "Frequency method: %s, Voltage method: %s\n",458458- freq_method, volt_method);459459- printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",456456+ pr_info("Registering G5 CPU frequency driver\n");457457+ pr_info("Frequency method: %s, Voltage method: %s\n",458458+ freq_method, volt_method);459459+ pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",460460 g5_cpu_freqs[1].frequency/1000,461461 g5_cpu_freqs[0].frequency/1000,462462 g5_cpu_freqs[g5_pmode_cur].frequency/1000);···493493 if (cpuid != NULL)494494 eeprom = of_get_property(cpuid, "cpuid", NULL);495495 if (eeprom == NULL) {496496- printk(KERN_ERR "cpufreq: Can't find cpuid EEPROM !\n");496496+ pr_err("Can't find cpuid EEPROM !\n");497497 rc = -ENODEV;498498 goto bail;499499 }···511511 break;512512 }513513 if (hwclock == NULL) {514514- printk(KERN_ERR "cpufreq: Can't find i2c clock chip !\n");514514+ pr_err("Can't find i2c clock chip !\n");515515 rc = -ENODEV;516516 goto bail;517517 }···539539 /* Check we have minimum requirements */540540 if (pfunc_cpu_getfreq == NULL || pfunc_cpu_setfreq_high == NULL ||541541 pfunc_cpu_setfreq_low == NULL || pfunc_slewing_done == NULL) {542542- printk(KERN_ERR "cpufreq: Can't find platform functions !\n");542542+ pr_err("Can't find platform functions !\n");543543 rc = -ENODEV;544544 goto bail;545545 }···567567 /* Get max frequency from device-tree */568568 valp = of_get_property(cpunode, "clock-frequency", NULL);569569 if (!valp) {570570- printk(KERN_ERR "cpufreq: Can't find CPU frequency !\n");570570+ pr_err("Can't find CPU frequency !\n");571571 rc = -ENODEV;572572 goto bail;573573 }···583583584584 /* Check for machines with no useful settings */585585 if (il == ih) {586586- printk(KERN_WARNING "cpufreq: No low frequency mode available"587587- " on this model !\n");586586+ pr_warn("No low frequency mode available on this model !\n");588587 rc = -ENODEV;589588 goto bail;590589 }···594595595596 /* Sanity check */596597 if (min_freq >= max_freq || min_freq < 1000) {597597- printk(KERN_ERR "cpufreq: Can't calculate low frequency !\n");598598+ pr_err("Can't calculate low frequency !\n");598599 rc = -ENXIO;599600 goto bail;600601 }···618619 g5_pmode_cur = -1;619620 g5_switch_freq(g5_query_freq());620621621621- printk(KERN_INFO "Registering G5 CPU frequency driver\n");622622- printk(KERN_INFO "Frequency method: i2c/pfunc, "623623- "Voltage method: %s\n", has_volt ? "i2c/pfunc" : "none");624624- printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",622622+ pr_info("Registering G5 CPU frequency driver\n");623623+ pr_info("Frequency method: i2c/pfunc, Voltage method: %s\n",624624+ has_volt ? "i2c/pfunc" : "none");625625+ pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",625626 g5_cpu_freqs[1].frequency/1000,626627 g5_cpu_freqs[0].frequency/1000,627628 g5_cpu_freqs[g5_pmode_cur].frequency/1000);···653654 /* Get first CPU node */654655 cpunode = of_cpu_device_node_get(0);655656 if (cpunode == NULL) {656656- pr_err("cpufreq: Can't find any CPU node\n");657657+ pr_err("Can't find any CPU node\n");657658 return -ENODEV;658659 }659660
+9-7
drivers/cpufreq/powernow-k6.c
···88 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*99 */10101111+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1212+1113#include <linux/kernel.h>1214#include <linux/module.h>1315#include <linux/init.h>···2422#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long2523 as it is unused */26242727-#define PFX "powernow-k6: "2825static unsigned int busfreq; /* FSB, in 10 kHz */2926static unsigned int max_multiplier;3027···142141{143142144143 if (clock_ratio[best_i].driver_data > max_multiplier) {145145- printk(KERN_ERR PFX "invalid target frequency\n");144144+ pr_err("invalid target frequency\n");146145 return -EINVAL;147146 }148147···176175 max_multiplier = param_max_multiplier;177176 goto have_max_multiplier;178177 }179179- printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");178178+ pr_err("invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");180179 return -EINVAL;181180 }182181183182 if (!max_multiplier) {184184- printk(KERN_WARNING "powernow-k6: unknown frequency %u, cannot determine current multiplier\n", khz);185185- printk(KERN_WARNING "powernow-k6: use module parameters max_multiplier and bus_frequency\n");183183+ pr_warn("unknown frequency %u, cannot determine current multiplier\n",184184+ khz);185185+ pr_warn("use module parameters max_multiplier and bus_frequency\n");186186 return -EOPNOTSUPP;187187 }188188···195193 busfreq = param_busfreq / 10;196194 goto have_busfreq;197195 }198198- printk(KERN_ERR "powernow-k6: invalid bus_frequency parameter, allowed range 50000 - 150000 kHz\n");196196+ pr_err("invalid bus_frequency parameter, allowed range 50000 - 150000 kHz\n");199197 return -EINVAL;200198 }201199···277275 return -ENODEV;278276279277 if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) {280280- printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n");278278+ pr_info("PowerNow IOPORT region already used\n");281279 return -EIO;282280 }283281
+28-42
drivers/cpufreq/powernow-k7.c
···1313 * - We disable half multipliers if ACPI is used on A0 stepping CPUs.1414 */15151616+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1717+1618#include <linux/kernel.h>1719#include <linux/module.h>1820#include <linux/moduleparam.h>···3634#endif37353836#include "powernow-k7.h"3939-4040-#define PFX "powernow: "4141-42374338struct psb_s {4439 u8 signature[10];···126127 maxei = cpuid_eax(0x80000000);127128 if (maxei < 0x80000007) { /* Any powernow info ? */128129#ifdef MODULE129129- printk(KERN_INFO PFX "No powernow capabilities detected\n");130130+ pr_info("No powernow capabilities detected\n");130131#endif131132 return 0;132133 }133134134135 if ((c->x86_model == 6) && (c->x86_mask == 0)) {135135- printk(KERN_INFO PFX "K7 660[A0] core detected, "136136- "enabling errata workarounds\n");136136+ pr_info("K7 660[A0] core detected, enabling errata workarounds\n");137137 have_a0 = 1;138138 }139139···142144 if (!(edx & (1 << 1 | 1 << 2)))143145 return 0;144146145145- printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: ");147147+ pr_info("PowerNOW! Technology present. Can scale: ");146148147149 if (edx & 1 << 1) {148148- printk("frequency");150150+ pr_cont("frequency");149151 can_scale_bus = 1;150152 }151153152154 if ((edx & (1 << 1 | 1 << 2)) == 0x6)153153- printk(" and ");155155+ pr_cont(" and ");154156155157 if (edx & 1 << 2) {156156- printk("voltage");158158+ pr_cont("voltage");157159 can_scale_vid = 1;158160 }159161160160- printk(".\n");162162+ pr_cont("\n");161163 return 1;162164}163165···425427err05:426428 kfree(acpi_processor_perf);427429err0:428428- printk(KERN_WARNING PFX "ACPI perflib can not be used on "429429- "this platform\n");430430+ pr_warn("ACPI perflib can not be used on this platform\n");430431 acpi_processor_perf = NULL;431432 return retval;432433}433434#else434435static int powernow_acpi_init(void)435436{436436- printk(KERN_INFO PFX "no support for ACPI processor found."437437- " Please recompile your kernel with ACPI processor\n");437437+ pr_info("no support for ACPI processor found - please recompile your kernel with ACPI processor\n");438438 return -EINVAL;439439}440440#endif···464468 psb = (struct psb_s *) p;465469 pr_debug("Table version: 0x%x\n", psb->tableversion);466470 if (psb->tableversion != 0x12) {467467- printk(KERN_INFO PFX "Sorry, only v1.2 tables"468468- " supported right now\n");471471+ pr_info("Sorry, only v1.2 tables supported right now\n");469472 return -ENODEV;470473 }471474···476481477482 latency = psb->settlingtime;478483 if (latency < 100) {479479- printk(KERN_INFO PFX "BIOS set settling time "480480- "to %d microseconds. "481481- "Should be at least 100. "482482- "Correcting.\n", latency);484484+ pr_info("BIOS set settling time to %d microseconds. Should be at least 100. Correcting.\n",485485+ latency);483486 latency = 100;484487 }485488 pr_debug("Settling Time: %d microseconds.\n",···509516 p += 2;510517 }511518 }512512- printk(KERN_INFO PFX "No PST tables match this cpuid "513513- "(0x%x)\n", etuple);514514- printk(KERN_INFO PFX "This is indicative of a broken "515515- "BIOS.\n");519519+ pr_info("No PST tables match this cpuid (0x%x)\n",520520+ etuple);521521+ pr_info("This is indicative of a broken BIOS\n");516522517523 return -EINVAL;518524 }···544552 sgtc = 100 * m * latency;545553 sgtc = sgtc / 3;546554 if (sgtc > 0xfffff) {547547- printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc);555555+ pr_warn("SGTC too large %d\n", sgtc);548556 sgtc = 0xfffff;549557 }550558 return sgtc;···566574567575static int acer_cpufreq_pst(const struct dmi_system_id *d)568576{569569- printk(KERN_WARNING PFX570570- "%s laptop with broken PST tables in BIOS detected.\n",577577+ pr_warn("%s laptop with broken PST tables in BIOS detected\n",571578 d->ident);572572- printk(KERN_WARNING PFX573573- "You need to downgrade to 3A21 (09/09/2002), or try a newer "574574- "BIOS than 3A71 (01/20/2003)\n");575575- printk(KERN_WARNING PFX576576- "cpufreq scaling has been disabled as a result of this.\n");579579+ pr_warn("You need to downgrade to 3A21 (09/09/2002), or try a newer BIOS than 3A71 (01/20/2003)\n");580580+ pr_warn("cpufreq scaling has been disabled as a result of this\n");577581 return 0;578582}579583···604616605617 fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.CFID];606618 if (!fsb) {607607- printk(KERN_WARNING PFX "can not determine bus frequency\n");619619+ pr_warn("can not determine bus frequency\n");608620 return -EINVAL;609621 }610622 pr_debug("FSB: %3dMHz\n", fsb/1000);611623612624 if (dmi_check_system(powernow_dmi_table) || acpi_force) {613613- printk(KERN_INFO PFX "PSB/PST known to be broken. "614614- "Trying ACPI instead\n");625625+ pr_info("PSB/PST known to be broken - trying ACPI instead\n");615626 result = powernow_acpi_init();616627 } else {617628 result = powernow_decode_bios(fidvidstatus.bits.MFID,618629 fidvidstatus.bits.SVID);619630 if (result) {620620- printk(KERN_INFO PFX "Trying ACPI perflib\n");631631+ pr_info("Trying ACPI perflib\n");621632 maximum_speed = 0;622633 minimum_speed = -1;623634 latency = 0;624635 result = powernow_acpi_init();625636 if (result) {626626- printk(KERN_INFO PFX627627- "ACPI and legacy methods failed\n");637637+ pr_info("ACPI and legacy methods failed\n");628638 }629639 } else {630640 /* SGTC use the bus clock as timer */631641 latency = fixup_sgtc();632632- printk(KERN_INFO PFX "SGTC: %d\n", latency);642642+ pr_info("SGTC: %d\n", latency);633643 }634644 }635645636646 if (result)637647 return result;638648639639- printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",640640- minimum_speed/1000, maximum_speed/1000);649649+ pr_info("Minimum speed %d MHz - Maximum speed %d MHz\n",650650+ minimum_speed/1000, maximum_speed/1000);641651642652 policy->cpuinfo.transition_latency =643653 cpufreq_scale(2000000UL, fsb, latency);
+256-13
drivers/cpufreq/powernv-cpufreq.c
···3636#include <asm/reg.h>3737#include <asm/smp.h> /* Required for cpu_sibling_mask() in UP configs */3838#include <asm/opal.h>3939+#include <linux/timer.h>39404041#define POWERNV_MAX_PSTATES 2564142#define PMSR_PSAFE_ENABLE (1UL << 30)4243#define PMSR_SPR_EM_DISABLE (1UL << 31)4344#define PMSR_MAX(x) ((x >> 32) & 0xFF)4545+4646+#define MAX_RAMP_DOWN_TIME 51204747+/*4848+ * On an idle system we want the global pstate to ramp-down from max value to4949+ * min over a span of ~5 secs. Also we want it to initially ramp-down slowly and5050+ * then ramp-down rapidly later on.5151+ *5252+ * This gives a percentage rampdown for time elapsed in milliseconds.5353+ * ramp_down_percentage = ((ms * ms) >> 18)5454+ * ~= 3.8 * (sec * sec)5555+ *5656+ * At 0 ms ramp_down_percent = 05757+ * At 5120 ms ramp_down_percent = 1005858+ */5959+#define ramp_down_percent(time) ((time * time) >> 18)6060+6161+/* Interval after which the timer is queued to bring down global pstate */6262+#define GPSTATE_TIMER_INTERVAL 20006363+6464+/**6565+ * struct global_pstate_info - Per policy data structure to maintain history of6666+ * global pstates6767+ * @highest_lpstate: The local pstate from which we are ramping down6868+ * @elapsed_time: Time in ms spent in ramping down from6969+ * highest_lpstate7070+ * @last_sampled_time: Time from boot in ms when global pstates were7171+ * last set7272+ * @last_lpstate,last_gpstate: Last set values for local and global pstates7373+ * @timer: Is used for ramping down if cpu goes idle for7474+ * a long time with global pstate held high7575+ * @gpstate_lock: A spinlock to maintain synchronization between7676+ * routines called by the timer handler and7777+ * governer's target_index calls7878+ */7979+struct global_pstate_info {8080+ int highest_lpstate;8181+ unsigned int elapsed_time;8282+ unsigned int last_sampled_time;8383+ int last_lpstate;8484+ int last_gpstate;8585+ spinlock_t gpstate_lock;8686+ struct timer_list timer;8787+};44884589static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES+1];4690static bool rebooting, throttled, occ_reset;···13793 int nominal;13894 int nr_pstates;13995} powernv_pstate_info;9696+9797+static inline void reset_gpstates(struct cpufreq_policy *policy)9898+{9999+ struct global_pstate_info *gpstates = policy->driver_data;100100+101101+ gpstates->highest_lpstate = 0;102102+ gpstates->elapsed_time = 0;103103+ gpstates->last_sampled_time = 0;104104+ gpstates->last_lpstate = 0;105105+ gpstates->last_gpstate = 0;106106+}140107141108/*142109 * Initialize the freq table based on data obtained···340285struct powernv_smp_call_data {341286 unsigned int freq;342287 int pstate_id;288288+ int gpstate_id;343289};344290345291/*···399343 * (struct powernv_smp_call_data *) and the pstate_id which needs to be set400344 * on this CPU should be present in freq_data->pstate_id.401345 */402402-static void set_pstate(void *freq_data)346346+static void set_pstate(void *data)403347{404348 unsigned long val;405405- unsigned long pstate_ul =406406- ((struct powernv_smp_call_data *) freq_data)->pstate_id;349349+ struct powernv_smp_call_data *freq_data = data;350350+ unsigned long pstate_ul = freq_data->pstate_id;351351+ unsigned long gpstate_ul = freq_data->gpstate_id;407352408353 val = get_pmspr(SPRN_PMCR);409354 val = val & 0x0000FFFFFFFFFFFFULL;410355411356 pstate_ul = pstate_ul & 0xFF;357357+ gpstate_ul = gpstate_ul & 0xFF;412358413359 /* Set both global(bits 56..63) and local(bits 48..55) PStates */414414- val = val | (pstate_ul << 56) | (pstate_ul << 48);360360+ val = val | (gpstate_ul << 56) | (pstate_ul << 48);415361416362 pr_debug("Setting cpu %d pmcr to %016lX\n",417363 raw_smp_processor_id(), val);···482424 }483425}484426427427+/**428428+ * calc_global_pstate - Calculate global pstate429429+ * @elapsed_time: Elapsed time in milliseconds430430+ * @local_pstate: New local pstate431431+ * @highest_lpstate: pstate from which its ramping down432432+ *433433+ * Finds the appropriate global pstate based on the pstate from which its434434+ * ramping down and the time elapsed in ramping down. It follows a quadratic435435+ * equation which ensures that it reaches ramping down to pmin in 5sec.436436+ */437437+static inline int calc_global_pstate(unsigned int elapsed_time,438438+ int highest_lpstate, int local_pstate)439439+{440440+ int pstate_diff;441441+442442+ /*443443+ * Using ramp_down_percent we get the percentage of rampdown444444+ * that we are expecting to be dropping. Difference between445445+ * highest_lpstate and powernv_pstate_info.min will give a absolute446446+ * number of how many pstates we will drop eventually by the end of447447+ * 5 seconds, then just scale it get the number pstates to be dropped.448448+ */449449+ pstate_diff = ((int)ramp_down_percent(elapsed_time) *450450+ (highest_lpstate - powernv_pstate_info.min)) / 100;451451+452452+ /* Ensure that global pstate is >= to local pstate */453453+ if (highest_lpstate - pstate_diff < local_pstate)454454+ return local_pstate;455455+ else456456+ return highest_lpstate - pstate_diff;457457+}458458+459459+static inline void queue_gpstate_timer(struct global_pstate_info *gpstates)460460+{461461+ unsigned int timer_interval;462462+463463+ /*464464+ * Setting up timer to fire after GPSTATE_TIMER_INTERVAL ms, But465465+ * if it exceeds MAX_RAMP_DOWN_TIME ms for ramp down time.466466+ * Set timer such that it fires exactly at MAX_RAMP_DOWN_TIME467467+ * seconds of ramp down time.468468+ */469469+ if ((gpstates->elapsed_time + GPSTATE_TIMER_INTERVAL)470470+ > MAX_RAMP_DOWN_TIME)471471+ timer_interval = MAX_RAMP_DOWN_TIME - gpstates->elapsed_time;472472+ else473473+ timer_interval = GPSTATE_TIMER_INTERVAL;474474+475475+ mod_timer_pinned(&gpstates->timer, jiffies +476476+ msecs_to_jiffies(timer_interval));477477+}478478+479479+/**480480+ * gpstate_timer_handler481481+ *482482+ * @data: pointer to cpufreq_policy on which timer was queued483483+ *484484+ * This handler brings down the global pstate closer to the local pstate485485+ * according quadratic equation. Queues a new timer if it is still not equal486486+ * to local pstate487487+ */488488+void gpstate_timer_handler(unsigned long data)489489+{490490+ struct cpufreq_policy *policy = (struct cpufreq_policy *)data;491491+ struct global_pstate_info *gpstates = policy->driver_data;492492+ int gpstate_id;493493+ unsigned int time_diff = jiffies_to_msecs(jiffies)494494+ - gpstates->last_sampled_time;495495+ struct powernv_smp_call_data freq_data;496496+497497+ if (!spin_trylock(&gpstates->gpstate_lock))498498+ return;499499+500500+ gpstates->last_sampled_time += time_diff;501501+ gpstates->elapsed_time += time_diff;502502+ freq_data.pstate_id = gpstates->last_lpstate;503503+504504+ if ((gpstates->last_gpstate == freq_data.pstate_id) ||505505+ (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME)) {506506+ gpstate_id = freq_data.pstate_id;507507+ reset_gpstates(policy);508508+ gpstates->highest_lpstate = freq_data.pstate_id;509509+ } else {510510+ gpstate_id = calc_global_pstate(gpstates->elapsed_time,511511+ gpstates->highest_lpstate,512512+ freq_data.pstate_id);513513+ }514514+515515+ /*516516+ * If local pstate is equal to global pstate, rampdown is over517517+ * So timer is not required to be queued.518518+ */519519+ if (gpstate_id != freq_data.pstate_id)520520+ queue_gpstate_timer(gpstates);521521+522522+ freq_data.gpstate_id = gpstate_id;523523+ gpstates->last_gpstate = freq_data.gpstate_id;524524+ gpstates->last_lpstate = freq_data.pstate_id;525525+526526+ /* Timer may get migrated to a different cpu on cpu hot unplug */527527+ smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);528528+ spin_unlock(&gpstates->gpstate_lock);529529+}530530+485531/*486532 * powernv_cpufreq_target_index: Sets the frequency corresponding to487533 * the cpufreq table entry indexed by new_index on the cpus in the···595433 unsigned int new_index)596434{597435 struct powernv_smp_call_data freq_data;436436+ unsigned int cur_msec, gpstate_id;437437+ unsigned long flags;438438+ struct global_pstate_info *gpstates = policy->driver_data;598439599440 if (unlikely(rebooting) && new_index != get_nominal_index())600441 return 0;···605440 if (!throttled)606441 powernv_cpufreq_throttle_check(NULL);607442443443+ cur_msec = jiffies_to_msecs(get_jiffies_64());444444+445445+ spin_lock_irqsave(&gpstates->gpstate_lock, flags);608446 freq_data.pstate_id = powernv_freqs[new_index].driver_data;447447+448448+ if (!gpstates->last_sampled_time) {449449+ gpstate_id = freq_data.pstate_id;450450+ gpstates->highest_lpstate = freq_data.pstate_id;451451+ goto gpstates_done;452452+ }453453+454454+ if (gpstates->last_gpstate > freq_data.pstate_id) {455455+ gpstates->elapsed_time += cur_msec -456456+ gpstates->last_sampled_time;457457+458458+ /*459459+ * If its has been ramping down for more than MAX_RAMP_DOWN_TIME460460+ * we should be resetting all global pstate related data. Set it461461+ * equal to local pstate to start fresh.462462+ */463463+ if (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME) {464464+ reset_gpstates(policy);465465+ gpstates->highest_lpstate = freq_data.pstate_id;466466+ gpstate_id = freq_data.pstate_id;467467+ } else {468468+ /* Elaspsed_time is less than 5 seconds, continue to rampdown */469469+ gpstate_id = calc_global_pstate(gpstates->elapsed_time,470470+ gpstates->highest_lpstate,471471+ freq_data.pstate_id);472472+ }473473+ } else {474474+ reset_gpstates(policy);475475+ gpstates->highest_lpstate = freq_data.pstate_id;476476+ gpstate_id = freq_data.pstate_id;477477+ }478478+479479+ /*480480+ * If local pstate is equal to global pstate, rampdown is over481481+ * So timer is not required to be queued.482482+ */483483+ if (gpstate_id != freq_data.pstate_id)484484+ queue_gpstate_timer(gpstates);485485+486486+gpstates_done:487487+ freq_data.gpstate_id = gpstate_id;488488+ gpstates->last_sampled_time = cur_msec;489489+ gpstates->last_gpstate = freq_data.gpstate_id;490490+ gpstates->last_lpstate = freq_data.pstate_id;609491610492 /*611493 * Use smp_call_function to send IPI and execute the···660448 * if current CPU is within policy->cpus (core)661449 */662450 smp_call_function_any(policy->cpus, set_pstate, &freq_data, 1);663663-451451+ spin_unlock_irqrestore(&gpstates->gpstate_lock, flags);664452 return 0;665453}666454667455static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)668456{669669- int base, i;457457+ int base, i, ret;458458+ struct kernfs_node *kn;459459+ struct global_pstate_info *gpstates;670460671461 base = cpu_first_thread_sibling(policy->cpu);672462673463 for (i = 0; i < threads_per_core; i++)674464 cpumask_set_cpu(base + i, policy->cpus);675465676676- if (!policy->driver_data) {466466+ kn = kernfs_find_and_get(policy->kobj.sd, throttle_attr_grp.name);467467+ if (!kn) {677468 int ret;678469679470 ret = sysfs_create_group(&policy->kobj, &throttle_attr_grp);···685470 policy->cpu);686471 return ret;687472 }688688- /*689689- * policy->driver_data is used as a flag for one-time690690- * creation of throttle sysfs files.691691- */692692- policy->driver_data = policy;473473+ } else {474474+ kernfs_put(kn);693475 }694694- return cpufreq_table_validate_and_show(policy, powernv_freqs);476476+477477+ gpstates = kzalloc(sizeof(*gpstates), GFP_KERNEL);478478+ if (!gpstates)479479+ return -ENOMEM;480480+481481+ policy->driver_data = gpstates;482482+483483+ /* initialize timer */484484+ init_timer_deferrable(&gpstates->timer);485485+ gpstates->timer.data = (unsigned long)policy;486486+ gpstates->timer.function = gpstate_timer_handler;487487+ gpstates->timer.expires = jiffies +488488+ msecs_to_jiffies(GPSTATE_TIMER_INTERVAL);489489+ spin_lock_init(&gpstates->gpstate_lock);490490+ ret = cpufreq_table_validate_and_show(policy, powernv_freqs);491491+492492+ if (ret < 0)493493+ kfree(policy->driver_data);494494+495495+ return ret;496496+}497497+498498+static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy)499499+{500500+ /* timer is deleted in cpufreq_cpu_stop() */501501+ kfree(policy->driver_data);502502+503503+ return 0;695504}696505697506static int powernv_cpufreq_reboot_notifier(struct notifier_block *nb,···843604static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)844605{845606 struct powernv_smp_call_data freq_data;607607+ struct global_pstate_info *gpstates = policy->driver_data;846608847609 freq_data.pstate_id = powernv_pstate_info.min;610610+ freq_data.gpstate_id = powernv_pstate_info.min;848611 smp_call_function_single(policy->cpu, set_pstate, &freq_data, 1);612612+ del_timer_sync(&gpstates->timer);849613}850614851615static struct cpufreq_driver powernv_cpufreq_driver = {852616 .name = "powernv-cpufreq",853617 .flags = CPUFREQ_CONST_LOOPS,854618 .init = powernv_cpufreq_cpu_init,619619+ .exit = powernv_cpufreq_cpu_exit,855620 .verify = cpufreq_generic_frequency_table_verify,856621 .target_index = powernv_cpufreq_target_index,857622 .get = powernv_cpufreq_get,
···2929 *3030 */31313232+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt3333+3234#include <linux/kernel.h>3335#include <linux/module.h>3436#include <linux/sched.h>···188186189187 ret = regulator_set_voltage(vcc_core, vmin, vmax);190188 if (ret)191191- pr_err("cpufreq: Failed to set vcc_core in [%dmV..%dmV]\n",192192- vmin, vmax);189189+ pr_err("Failed to set vcc_core in [%dmV..%dmV]\n", vmin, vmax);193190 return ret;194191}195192···196195{197196 vcc_core = regulator_get(NULL, "vcc_core");198197 if (IS_ERR(vcc_core)) {199199- pr_info("cpufreq: Didn't find vcc_core regulator\n");198198+ pr_info("Didn't find vcc_core regulator\n");200199 vcc_core = NULL;201200 } else {202202- pr_info("cpufreq: Found vcc_core regulator\n");201201+ pr_info("Found vcc_core regulator\n");203202 }204203}205204#else···234233{235234 if (!pxa27x_maxfreq) {236235 pxa27x_maxfreq = 416000;237237- printk(KERN_INFO "PXA CPU 27x max frequency not defined "238238- "(pxa27x_maxfreq), assuming pxa271 with %dkHz maxfreq\n",239239- pxa27x_maxfreq);236236+ pr_info("PXA CPU 27x max frequency not defined (pxa27x_maxfreq), assuming pxa271 with %dkHz maxfreq\n",237237+ pxa27x_maxfreq);240238 } else {241239 pxa27x_maxfreq *= 1000;242240 }···408408 */409409 if (cpu_is_pxa25x()) {410410 find_freq_tables(&pxa255_freq_table, &pxa255_freqs);411411- pr_info("PXA255 cpufreq using %s frequency table\n",411411+ pr_info("using %s frequency table\n",412412 pxa255_turbo_table ? "turbo" : "run");413413414414 cpufreq_table_validate_and_show(policy, pxa255_freq_table);···417417 cpufreq_table_validate_and_show(policy, pxa27x_freq_table);418418 }419419420420- printk(KERN_INFO "PXA CPU frequency change support initialized\n");420420+ pr_info("frequency change support initialized\n");421421422422 return 0;423423}
+5-4
drivers/cpufreq/qoriq-cpufreq.c
···301301 return -ENODEV;302302}303303304304-static int __exit qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy)304304+static int qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy)305305{306306 struct cpu_data *data = policy->driver_data;307307308308+ cpufreq_cooling_unregister(data->cdev);308309 kfree(data->pclk);309310 kfree(data->table);310311 kfree(data);···334333 cpud->cdev = of_cpufreq_cooling_register(np,335334 policy->related_cpus);336335337337- if (IS_ERR(cpud->cdev)) {338338- pr_err("Failed to register cooling device cpu%d: %ld\n",336336+ if (IS_ERR(cpud->cdev) && PTR_ERR(cpud->cdev) != -ENOSYS) {337337+ pr_err("cpu%d is not running as cooling device: %ld\n",339338 policy->cpu, PTR_ERR(cpud->cdev));340339341340 cpud->cdev = NULL;···349348 .name = "qoriq_cpufreq",350349 .flags = CPUFREQ_CONST_LOOPS,351350 .init = qoriq_cpufreq_cpu_init,352352- .exit = __exit_p(qoriq_cpufreq_cpu_exit),351351+ .exit = qoriq_cpufreq_cpu_exit,353352 .verify = cpufreq_generic_frequency_table_verify,354353 .target_index = qoriq_cpufreq_target,355354 .get = cpufreq_generic_get,
···1010#ifndef __CPUFREQ_DT_H__1111#define __CPUFREQ_DT_H__12121313+#include <linux/types.h>1414+1315struct cpufreq_dt_platform_data {1416 /*1517 * True when each CPU has its own clock to control its
+54
include/linux/cpufreq.h
···102102 */103103 struct rw_semaphore rwsem;104104105105+ /*106106+ * Fast switch flags:107107+ * - fast_switch_possible should be set by the driver if it can108108+ * guarantee that frequency can be changed on any CPU sharing the109109+ * policy and that the change will affect all of the policy CPUs then.110110+ * - fast_switch_enabled is to be set by governors that support fast111111+ * freqnency switching with the help of cpufreq_enable_fast_switch().112112+ */113113+ bool fast_switch_possible;114114+ bool fast_switch_enabled;115115+105116 /* Synchronization for frequency transitions */106117 bool transition_ongoing; /* Tracks transition status */107118 spinlock_t transition_lock;···167156int cpufreq_update_policy(unsigned int cpu);168157bool have_governor_per_policy(void);169158struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);159159+void cpufreq_enable_fast_switch(struct cpufreq_policy *policy);160160+void cpufreq_disable_fast_switch(struct cpufreq_policy *policy);170161#else171162static inline unsigned int cpufreq_get(unsigned int cpu)172163{···249236 unsigned int relation); /* Deprecated */250237 int (*target_index)(struct cpufreq_policy *policy,251238 unsigned int index);239239+ unsigned int (*fast_switch)(struct cpufreq_policy *policy,240240+ unsigned int target_freq);252241 /*253242 * Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION254243 * unset.···441426#define CPUFREQ_POLICY_POWERSAVE (1)442427#define CPUFREQ_POLICY_PERFORMANCE (2)443428429429+/*430430+ * The polling frequency depends on the capability of the processor. Default431431+ * polling frequency is 1000 times the transition latency of the processor. The432432+ * ondemand governor will work on any processor with transition latency <= 10ms,433433+ * using appropriate sampling rate.434434+ *435435+ * For CPUs with transition latency > 10ms (mostly drivers with CPUFREQ_ETERNAL)436436+ * the ondemand governor will not work. All times here are in us (microseconds).437437+ */438438+#define MIN_SAMPLING_RATE_RATIO (2)439439+#define LATENCY_MULTIPLIER (1000)440440+#define MIN_LATENCY_MULTIPLIER (20)441441+#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)442442+444443/* Governor Events */445444#define CPUFREQ_GOV_START 1446445#define CPUFREQ_GOV_STOP 2···479450};480451481452/* Pass a target to the cpufreq driver */453453+unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,454454+ unsigned int target_freq);482455int cpufreq_driver_target(struct cpufreq_policy *policy,483456 unsigned int target_freq,484457 unsigned int relation);···492461493462struct cpufreq_governor *cpufreq_default_governor(void);494463struct cpufreq_governor *cpufreq_fallback_governor(void);464464+465465+/* Governor attribute set */466466+struct gov_attr_set {467467+ struct kobject kobj;468468+ struct list_head policy_list;469469+ struct mutex update_lock;470470+ int usage_count;471471+};472472+473473+/* sysfs ops for cpufreq governors */474474+extern const struct sysfs_ops governor_sysfs_ops;475475+476476+void gov_attr_set_init(struct gov_attr_set *attr_set, struct list_head *list_node);477477+void gov_attr_set_get(struct gov_attr_set *attr_set, struct list_head *list_node);478478+unsigned int gov_attr_set_put(struct gov_attr_set *attr_set, struct list_head *list_node);479479+480480+/* Governor sysfs attribute */481481+struct governor_attr {482482+ struct attribute attr;483483+ ssize_t (*show)(struct gov_attr_set *attr_set, char *buf);484484+ ssize_t (*store)(struct gov_attr_set *attr_set, const char *buf,485485+ size_t count);486486+};495487496488/*********************************************************************497489 * FREQUENCY TABLE HELPERS *
+4-1
include/linux/sched.h
···32403240 u64 time, unsigned long util, unsigned long max);32413241};3242324232433243-void cpufreq_set_update_util_data(int cpu, struct update_util_data *data);32433243+void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data,32443244+ void (*func)(struct update_util_data *data, u64 time,32453245+ unsigned long util, unsigned long max));32463246+void cpufreq_remove_update_util_hook(int cpu);32443247#endif /* CONFIG_CPU_FREQ */3245324832463249#endif
···1414DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data);15151616/**1717- * cpufreq_set_update_util_data - Populate the CPU's update_util_data pointer.1717+ * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer.1818 * @cpu: The CPU to set the pointer for.1919 * @data: New pointer value.2020+ * @func: Callback function to set for the CPU.2021 *2121- * Set and publish the update_util_data pointer for the given CPU. That pointer2222- * points to a struct update_util_data object containing a callback function2323- * to call from cpufreq_update_util(). That function will be called from an RCU2424- * read-side critical section, so it must not sleep.2222+ * Set and publish the update_util_data pointer for the given CPU.2323+ *2424+ * The update_util_data pointer of @cpu is set to @data and the callback2525+ * function pointer in the target struct update_util_data is set to @func.2626+ * That function will be called by cpufreq_update_util() from RCU-sched2727+ * read-side critical sections, so it must not sleep. @data will always be2828+ * passed to it as the first argument which allows the function to get to the2929+ * target update_util_data structure and its container.3030+ *3131+ * The update_util_data pointer of @cpu must be NULL when this function is3232+ * called or it will WARN() and return with no effect.3333+ */3434+void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data,3535+ void (*func)(struct update_util_data *data, u64 time,3636+ unsigned long util, unsigned long max))3737+{3838+ if (WARN_ON(!data || !func))3939+ return;4040+4141+ if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu)))4242+ return;4343+4444+ data->func = func;4545+ rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);4646+}4747+EXPORT_SYMBOL_GPL(cpufreq_add_update_util_hook);4848+4949+/**5050+ * cpufreq_remove_update_util_hook - Clear the CPU's update_util_data pointer.5151+ * @cpu: The CPU to clear the pointer for.5252+ *5353+ * Clear the update_util_data pointer for the given CPU.2554 *2655 * Callers must use RCU-sched callbacks to free any memory that might be2756 * accessed via the old update_util_data pointer or invoke synchronize_sched()2857 * right after this function to avoid use-after-free.2958 */3030-void cpufreq_set_update_util_data(int cpu, struct update_util_data *data)5959+void cpufreq_remove_update_util_hook(int cpu)3160{3232- if (WARN_ON(data && !data->func))3333- return;3434-3535- rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data);6161+ rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), NULL);3662}3737-EXPORT_SYMBOL_GPL(cpufreq_set_update_util_data);6363+EXPORT_SYMBOL_GPL(cpufreq_remove_update_util_hook);
+530
kernel/sched/cpufreq_schedutil.c
···11+/*22+ * CPUFreq governor based on scheduler-provided CPU utilization data.33+ *44+ * Copyright (C) 2016, Intel Corporation55+ * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>66+ *77+ * This program is free software; you can redistribute it and/or modify88+ * it under the terms of the GNU General Public License version 2 as99+ * published by the Free Software Foundation.1010+ */1111+1212+#include <linux/cpufreq.h>1313+#include <linux/module.h>1414+#include <linux/slab.h>1515+#include <trace/events/power.h>1616+1717+#include "sched.h"1818+1919+struct sugov_tunables {2020+ struct gov_attr_set attr_set;2121+ unsigned int rate_limit_us;2222+};2323+2424+struct sugov_policy {2525+ struct cpufreq_policy *policy;2626+2727+ struct sugov_tunables *tunables;2828+ struct list_head tunables_hook;2929+3030+ raw_spinlock_t update_lock; /* For shared policies */3131+ u64 last_freq_update_time;3232+ s64 freq_update_delay_ns;3333+ unsigned int next_freq;3434+3535+ /* The next fields are only needed if fast switch cannot be used. */3636+ struct irq_work irq_work;3737+ struct work_struct work;3838+ struct mutex work_lock;3939+ bool work_in_progress;4040+4141+ bool need_freq_update;4242+};4343+4444+struct sugov_cpu {4545+ struct update_util_data update_util;4646+ struct sugov_policy *sg_policy;4747+4848+ /* The fields below are only needed when sharing a policy. */4949+ unsigned long util;5050+ unsigned long max;5151+ u64 last_update;5252+};5353+5454+static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);5555+5656+/************************ Governor internals ***********************/5757+5858+static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)5959+{6060+ s64 delta_ns;6161+6262+ if (sg_policy->work_in_progress)6363+ return false;6464+6565+ if (unlikely(sg_policy->need_freq_update)) {6666+ sg_policy->need_freq_update = false;6767+ /*6868+ * This happens when limits change, so forget the previous6969+ * next_freq value and force an update.7070+ */7171+ sg_policy->next_freq = UINT_MAX;7272+ return true;7373+ }7474+7575+ delta_ns = time - sg_policy->last_freq_update_time;7676+ return delta_ns >= sg_policy->freq_update_delay_ns;7777+}7878+7979+static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time,8080+ unsigned int next_freq)8181+{8282+ struct cpufreq_policy *policy = sg_policy->policy;8383+8484+ sg_policy->last_freq_update_time = time;8585+8686+ if (policy->fast_switch_enabled) {8787+ if (sg_policy->next_freq == next_freq) {8888+ trace_cpu_frequency(policy->cur, smp_processor_id());8989+ return;9090+ }9191+ sg_policy->next_freq = next_freq;9292+ next_freq = cpufreq_driver_fast_switch(policy, next_freq);9393+ if (next_freq == CPUFREQ_ENTRY_INVALID)9494+ return;9595+9696+ policy->cur = next_freq;9797+ trace_cpu_frequency(next_freq, smp_processor_id());9898+ } else if (sg_policy->next_freq != next_freq) {9999+ sg_policy->next_freq = next_freq;100100+ sg_policy->work_in_progress = true;101101+ irq_work_queue(&sg_policy->irq_work);102102+ }103103+}104104+105105+/**106106+ * get_next_freq - Compute a new frequency for a given cpufreq policy.107107+ * @policy: cpufreq policy object to compute the new frequency for.108108+ * @util: Current CPU utilization.109109+ * @max: CPU capacity.110110+ *111111+ * If the utilization is frequency-invariant, choose the new frequency to be112112+ * proportional to it, that is113113+ *114114+ * next_freq = C * max_freq * util / max115115+ *116116+ * Otherwise, approximate the would-be frequency-invariant utilization by117117+ * util_raw * (curr_freq / max_freq) which leads to118118+ *119119+ * next_freq = C * curr_freq * util_raw / max120120+ *121121+ * Take C = 1.25 for the frequency tipping point at (util / max) = 0.8.122122+ */123123+static unsigned int get_next_freq(struct cpufreq_policy *policy,124124+ unsigned long util, unsigned long max)125125+{126126+ unsigned int freq = arch_scale_freq_invariant() ?127127+ policy->cpuinfo.max_freq : policy->cur;128128+129129+ return (freq + (freq >> 2)) * util / max;130130+}131131+132132+static void sugov_update_single(struct update_util_data *hook, u64 time,133133+ unsigned long util, unsigned long max)134134+{135135+ struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);136136+ struct sugov_policy *sg_policy = sg_cpu->sg_policy;137137+ struct cpufreq_policy *policy = sg_policy->policy;138138+ unsigned int next_f;139139+140140+ if (!sugov_should_update_freq(sg_policy, time))141141+ return;142142+143143+ next_f = util == ULONG_MAX ? policy->cpuinfo.max_freq :144144+ get_next_freq(policy, util, max);145145+ sugov_update_commit(sg_policy, time, next_f);146146+}147147+148148+static unsigned int sugov_next_freq_shared(struct sugov_policy *sg_policy,149149+ unsigned long util, unsigned long max)150150+{151151+ struct cpufreq_policy *policy = sg_policy->policy;152152+ unsigned int max_f = policy->cpuinfo.max_freq;153153+ u64 last_freq_update_time = sg_policy->last_freq_update_time;154154+ unsigned int j;155155+156156+ if (util == ULONG_MAX)157157+ return max_f;158158+159159+ for_each_cpu(j, policy->cpus) {160160+ struct sugov_cpu *j_sg_cpu;161161+ unsigned long j_util, j_max;162162+ s64 delta_ns;163163+164164+ if (j == smp_processor_id())165165+ continue;166166+167167+ j_sg_cpu = &per_cpu(sugov_cpu, j);168168+ /*169169+ * If the CPU utilization was last updated before the previous170170+ * frequency update and the time elapsed between the last update171171+ * of the CPU utilization and the last frequency update is long172172+ * enough, don't take the CPU into account as it probably is173173+ * idle now.174174+ */175175+ delta_ns = last_freq_update_time - j_sg_cpu->last_update;176176+ if (delta_ns > TICK_NSEC)177177+ continue;178178+179179+ j_util = j_sg_cpu->util;180180+ if (j_util == ULONG_MAX)181181+ return max_f;182182+183183+ j_max = j_sg_cpu->max;184184+ if (j_util * max > j_max * util) {185185+ util = j_util;186186+ max = j_max;187187+ }188188+ }189189+190190+ return get_next_freq(policy, util, max);191191+}192192+193193+static void sugov_update_shared(struct update_util_data *hook, u64 time,194194+ unsigned long util, unsigned long max)195195+{196196+ struct sugov_cpu *sg_cpu = container_of(hook, struct sugov_cpu, update_util);197197+ struct sugov_policy *sg_policy = sg_cpu->sg_policy;198198+ unsigned int next_f;199199+200200+ raw_spin_lock(&sg_policy->update_lock);201201+202202+ sg_cpu->util = util;203203+ sg_cpu->max = max;204204+ sg_cpu->last_update = time;205205+206206+ if (sugov_should_update_freq(sg_policy, time)) {207207+ next_f = sugov_next_freq_shared(sg_policy, util, max);208208+ sugov_update_commit(sg_policy, time, next_f);209209+ }210210+211211+ raw_spin_unlock(&sg_policy->update_lock);212212+}213213+214214+static void sugov_work(struct work_struct *work)215215+{216216+ struct sugov_policy *sg_policy = container_of(work, struct sugov_policy, work);217217+218218+ mutex_lock(&sg_policy->work_lock);219219+ __cpufreq_driver_target(sg_policy->policy, sg_policy->next_freq,220220+ CPUFREQ_RELATION_L);221221+ mutex_unlock(&sg_policy->work_lock);222222+223223+ sg_policy->work_in_progress = false;224224+}225225+226226+static void sugov_irq_work(struct irq_work *irq_work)227227+{228228+ struct sugov_policy *sg_policy;229229+230230+ sg_policy = container_of(irq_work, struct sugov_policy, irq_work);231231+ schedule_work_on(smp_processor_id(), &sg_policy->work);232232+}233233+234234+/************************** sysfs interface ************************/235235+236236+static struct sugov_tunables *global_tunables;237237+static DEFINE_MUTEX(global_tunables_lock);238238+239239+static inline struct sugov_tunables *to_sugov_tunables(struct gov_attr_set *attr_set)240240+{241241+ return container_of(attr_set, struct sugov_tunables, attr_set);242242+}243243+244244+static ssize_t rate_limit_us_show(struct gov_attr_set *attr_set, char *buf)245245+{246246+ struct sugov_tunables *tunables = to_sugov_tunables(attr_set);247247+248248+ return sprintf(buf, "%u\n", tunables->rate_limit_us);249249+}250250+251251+static ssize_t rate_limit_us_store(struct gov_attr_set *attr_set, const char *buf,252252+ size_t count)253253+{254254+ struct sugov_tunables *tunables = to_sugov_tunables(attr_set);255255+ struct sugov_policy *sg_policy;256256+ unsigned int rate_limit_us;257257+258258+ if (kstrtouint(buf, 10, &rate_limit_us))259259+ return -EINVAL;260260+261261+ tunables->rate_limit_us = rate_limit_us;262262+263263+ list_for_each_entry(sg_policy, &attr_set->policy_list, tunables_hook)264264+ sg_policy->freq_update_delay_ns = rate_limit_us * NSEC_PER_USEC;265265+266266+ return count;267267+}268268+269269+static struct governor_attr rate_limit_us = __ATTR_RW(rate_limit_us);270270+271271+static struct attribute *sugov_attributes[] = {272272+ &rate_limit_us.attr,273273+ NULL274274+};275275+276276+static struct kobj_type sugov_tunables_ktype = {277277+ .default_attrs = sugov_attributes,278278+ .sysfs_ops = &governor_sysfs_ops,279279+};280280+281281+/********************** cpufreq governor interface *********************/282282+283283+static struct cpufreq_governor schedutil_gov;284284+285285+static struct sugov_policy *sugov_policy_alloc(struct cpufreq_policy *policy)286286+{287287+ struct sugov_policy *sg_policy;288288+289289+ sg_policy = kzalloc(sizeof(*sg_policy), GFP_KERNEL);290290+ if (!sg_policy)291291+ return NULL;292292+293293+ sg_policy->policy = policy;294294+ init_irq_work(&sg_policy->irq_work, sugov_irq_work);295295+ INIT_WORK(&sg_policy->work, sugov_work);296296+ mutex_init(&sg_policy->work_lock);297297+ raw_spin_lock_init(&sg_policy->update_lock);298298+ return sg_policy;299299+}300300+301301+static void sugov_policy_free(struct sugov_policy *sg_policy)302302+{303303+ mutex_destroy(&sg_policy->work_lock);304304+ kfree(sg_policy);305305+}306306+307307+static struct sugov_tunables *sugov_tunables_alloc(struct sugov_policy *sg_policy)308308+{309309+ struct sugov_tunables *tunables;310310+311311+ tunables = kzalloc(sizeof(*tunables), GFP_KERNEL);312312+ if (tunables) {313313+ gov_attr_set_init(&tunables->attr_set, &sg_policy->tunables_hook);314314+ if (!have_governor_per_policy())315315+ global_tunables = tunables;316316+ }317317+ return tunables;318318+}319319+320320+static void sugov_tunables_free(struct sugov_tunables *tunables)321321+{322322+ if (!have_governor_per_policy())323323+ global_tunables = NULL;324324+325325+ kfree(tunables);326326+}327327+328328+static int sugov_init(struct cpufreq_policy *policy)329329+{330330+ struct sugov_policy *sg_policy;331331+ struct sugov_tunables *tunables;332332+ unsigned int lat;333333+ int ret = 0;334334+335335+ /* State should be equivalent to EXIT */336336+ if (policy->governor_data)337337+ return -EBUSY;338338+339339+ sg_policy = sugov_policy_alloc(policy);340340+ if (!sg_policy)341341+ return -ENOMEM;342342+343343+ mutex_lock(&global_tunables_lock);344344+345345+ if (global_tunables) {346346+ if (WARN_ON(have_governor_per_policy())) {347347+ ret = -EINVAL;348348+ goto free_sg_policy;349349+ }350350+ policy->governor_data = sg_policy;351351+ sg_policy->tunables = global_tunables;352352+353353+ gov_attr_set_get(&global_tunables->attr_set, &sg_policy->tunables_hook);354354+ goto out;355355+ }356356+357357+ tunables = sugov_tunables_alloc(sg_policy);358358+ if (!tunables) {359359+ ret = -ENOMEM;360360+ goto free_sg_policy;361361+ }362362+363363+ tunables->rate_limit_us = LATENCY_MULTIPLIER;364364+ lat = policy->cpuinfo.transition_latency / NSEC_PER_USEC;365365+ if (lat)366366+ tunables->rate_limit_us *= lat;367367+368368+ policy->governor_data = sg_policy;369369+ sg_policy->tunables = tunables;370370+371371+ ret = kobject_init_and_add(&tunables->attr_set.kobj, &sugov_tunables_ktype,372372+ get_governor_parent_kobj(policy), "%s",373373+ schedutil_gov.name);374374+ if (ret)375375+ goto fail;376376+377377+ out:378378+ mutex_unlock(&global_tunables_lock);379379+380380+ cpufreq_enable_fast_switch(policy);381381+ return 0;382382+383383+ fail:384384+ policy->governor_data = NULL;385385+ sugov_tunables_free(tunables);386386+387387+ free_sg_policy:388388+ mutex_unlock(&global_tunables_lock);389389+390390+ sugov_policy_free(sg_policy);391391+ pr_err("cpufreq: schedutil governor initialization failed (error %d)\n", ret);392392+ return ret;393393+}394394+395395+static int sugov_exit(struct cpufreq_policy *policy)396396+{397397+ struct sugov_policy *sg_policy = policy->governor_data;398398+ struct sugov_tunables *tunables = sg_policy->tunables;399399+ unsigned int count;400400+401401+ cpufreq_disable_fast_switch(policy);402402+403403+ mutex_lock(&global_tunables_lock);404404+405405+ count = gov_attr_set_put(&tunables->attr_set, &sg_policy->tunables_hook);406406+ policy->governor_data = NULL;407407+ if (!count)408408+ sugov_tunables_free(tunables);409409+410410+ mutex_unlock(&global_tunables_lock);411411+412412+ sugov_policy_free(sg_policy);413413+ return 0;414414+}415415+416416+static int sugov_start(struct cpufreq_policy *policy)417417+{418418+ struct sugov_policy *sg_policy = policy->governor_data;419419+ unsigned int cpu;420420+421421+ sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC;422422+ sg_policy->last_freq_update_time = 0;423423+ sg_policy->next_freq = UINT_MAX;424424+ sg_policy->work_in_progress = false;425425+ sg_policy->need_freq_update = false;426426+427427+ for_each_cpu(cpu, policy->cpus) {428428+ struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu);429429+430430+ sg_cpu->sg_policy = sg_policy;431431+ if (policy_is_shared(policy)) {432432+ sg_cpu->util = ULONG_MAX;433433+ sg_cpu->max = 0;434434+ sg_cpu->last_update = 0;435435+ cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,436436+ sugov_update_shared);437437+ } else {438438+ cpufreq_add_update_util_hook(cpu, &sg_cpu->update_util,439439+ sugov_update_single);440440+ }441441+ }442442+ return 0;443443+}444444+445445+static int sugov_stop(struct cpufreq_policy *policy)446446+{447447+ struct sugov_policy *sg_policy = policy->governor_data;448448+ unsigned int cpu;449449+450450+ for_each_cpu(cpu, policy->cpus)451451+ cpufreq_remove_update_util_hook(cpu);452452+453453+ synchronize_sched();454454+455455+ irq_work_sync(&sg_policy->irq_work);456456+ cancel_work_sync(&sg_policy->work);457457+ return 0;458458+}459459+460460+static int sugov_limits(struct cpufreq_policy *policy)461461+{462462+ struct sugov_policy *sg_policy = policy->governor_data;463463+464464+ if (!policy->fast_switch_enabled) {465465+ mutex_lock(&sg_policy->work_lock);466466+467467+ if (policy->max < policy->cur)468468+ __cpufreq_driver_target(policy, policy->max,469469+ CPUFREQ_RELATION_H);470470+ else if (policy->min > policy->cur)471471+ __cpufreq_driver_target(policy, policy->min,472472+ CPUFREQ_RELATION_L);473473+474474+ mutex_unlock(&sg_policy->work_lock);475475+ }476476+477477+ sg_policy->need_freq_update = true;478478+ return 0;479479+}480480+481481+int sugov_governor(struct cpufreq_policy *policy, unsigned int event)482482+{483483+ if (event == CPUFREQ_GOV_POLICY_INIT) {484484+ return sugov_init(policy);485485+ } else if (policy->governor_data) {486486+ switch (event) {487487+ case CPUFREQ_GOV_POLICY_EXIT:488488+ return sugov_exit(policy);489489+ case CPUFREQ_GOV_START:490490+ return sugov_start(policy);491491+ case CPUFREQ_GOV_STOP:492492+ return sugov_stop(policy);493493+ case CPUFREQ_GOV_LIMITS:494494+ return sugov_limits(policy);495495+ }496496+ }497497+ return -EINVAL;498498+}499499+500500+static struct cpufreq_governor schedutil_gov = {501501+ .name = "schedutil",502502+ .governor = sugov_governor,503503+ .owner = THIS_MODULE,504504+};505505+506506+static int __init sugov_module_init(void)507507+{508508+ return cpufreq_register_governor(&schedutil_gov);509509+}510510+511511+static void __exit sugov_module_exit(void)512512+{513513+ cpufreq_unregister_governor(&schedutil_gov);514514+}515515+516516+MODULE_AUTHOR("Rafael J. Wysocki <rafael.j.wysocki@intel.com>");517517+MODULE_DESCRIPTION("Utilization-based CPU frequency selection");518518+MODULE_LICENSE("GPL");519519+520520+#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL521521+struct cpufreq_governor *cpufreq_default_governor(void)522522+{523523+ return &schedutil_gov;524524+}525525+526526+fs_initcall(sugov_module_init);527527+#else528528+module_init(sugov_module_init);529529+#endif530530+module_exit(sugov_module_exit);