Lines Matching full:cpu
8 * Added handling for CPU hotplug
10 * Fix handling for CPU hotplug -- affected CPUs
28 #include <linux/cpu.h>
43 /* This one keeps track of the previously set governor of a removed CPU */
49 * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure
56 * the policy altogether (eg. CPU hotplug), will hold this lock in write
60 * - All holders of the lock should check to make sure that the CPU they
70 #define lock_policy_rwsem(mode, cpu) \ argument
72 (int cpu) \
74 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \
77 if (unlikely(!cpu_online(cpu))) { \
85 lock_policy_rwsem(read, cpu);
87 lock_policy_rwsem(write, cpu);
89 static void unlock_policy_rwsem_read(int cpu) in unlock_policy_rwsem_read() argument
91 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); in unlock_policy_rwsem_read()
96 static void unlock_policy_rwsem_write(int cpu) in unlock_policy_rwsem_write() argument
98 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); in unlock_policy_rwsem_write()
107 static unsigned int __cpufreq_get(unsigned int cpu);
112 * validation process for a new CPU frequency policy; the
114 * changes to devices when the CPU clock speed changes.
132 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) in cpufreq_cpu_get() argument
137 if (cpu >= nr_cpu_ids) in cpufreq_cpu_get()
150 /* get the CPU */ in cpufreq_cpu_get()
151 data = per_cpu(cpufreq_cpu_data, cpu); in cpufreq_cpu_get()
189 * systems as each CPU might be scaled differently. So, use the arch
190 * per-CPU loops_per_jiffy value wherever possible.
228 * function. It is called twice on all CPU frequency changes that have
241 policy = per_cpu(cpufreq_cpu_data, freqs->cpu); in cpufreq_notify_transition()
250 if ((policy) && (policy->cpu == freqs->cpu) && in cpufreq_notify_transition()
252 pr_debug("Warning: CPU frequency is" in cpufreq_notify_transition()
265 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, in cpufreq_notify_transition()
266 (unsigned long)freqs->cpu); in cpufreq_notify_transition()
267 trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu); in cpufreq_notify_transition()
268 trace_cpu_frequency(freqs->new, freqs->cpu); in cpufreq_notify_transition()
271 if (likely(policy) && likely(policy->cpu == freqs->cpu)) in cpufreq_notify_transition()
349 * Write out information from cpufreq_driver->policy[cpu]; object must be
380 ret = cpufreq_get_policy(&new_policy, policy->cpu); \
398 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
403 unsigned int cur_freq = __cpufreq_get(policy->cpu); in show_cpuinfo_cur_freq()
411 * show_scaling_governor - show the current policy for the specified CPU
427 * store_scaling_governor - store policy for the specified CPU
436 ret = cpufreq_get_policy(&new_policy, policy->cpu); in store_scaling_governor()
497 unsigned int cpu; in show_cpus() local
499 for_each_cpu(cpu, mask) { in show_cpus()
502 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); in show_cpus()
563 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
611 policy = cpufreq_cpu_get(policy->cpu); in show()
615 if (lock_policy_rwsem_read(policy->cpu) < 0) in show()
623 unlock_policy_rwsem_read(policy->cpu); in show()
636 policy = cpufreq_cpu_get(policy->cpu); in store()
640 if (lock_policy_rwsem_write(policy->cpu) < 0) in store()
648 unlock_policy_rwsem_write(policy->cpu); in store()
677 * Positive: When we have a managed CPU and the sysfs got symlinked
679 static int cpufreq_add_dev_policy(unsigned int cpu, in cpufreq_add_dev_policy() argument
690 gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); in cpufreq_add_dev_policy()
693 pr_debug("Restoring governor %s for cpu %d\n", in cpufreq_add_dev_policy()
694 policy->governor->name, cpu); in cpufreq_add_dev_policy()
701 if (cpu == j) in cpufreq_add_dev_policy()
705 * They may not be aware of it due to CPU Hotplug. in cpufreq_add_dev_policy()
713 unlock_policy_rwsem_write(cpu); in cpufreq_add_dev_policy()
714 per_cpu(cpufreq_policy_cpu, cpu) = managed_policy->cpu; in cpufreq_add_dev_policy()
716 if (lock_policy_rwsem_write(cpu) < 0) { in cpufreq_add_dev_policy()
726 per_cpu(cpufreq_cpu_data, cpu) = managed_policy; in cpufreq_add_dev_policy()
729 pr_debug("CPU already managed, adding link\n"); in cpufreq_add_dev_policy()
737 * Call driver->exit() because only the cpu parent of in cpufreq_add_dev_policy()
755 static int cpufreq_add_dev_symlink(unsigned int cpu, in cpufreq_add_dev_symlink() argument
765 if (j == cpu) in cpufreq_add_dev_symlink()
770 pr_debug("CPU %u already managed, adding link\n", j); in cpufreq_add_dev_symlink()
771 managed_policy = cpufreq_cpu_get(cpu); in cpufreq_add_dev_symlink()
783 static int cpufreq_add_dev_interface(unsigned int cpu, in cpufreq_add_dev_interface() argument
799 /* set up files for this cpu device */ in cpufreq_add_dev_interface()
828 per_cpu(cpufreq_policy_cpu, j) = policy->cpu; in cpufreq_add_dev_interface()
832 ret = cpufreq_add_dev_symlink(cpu, policy); in cpufreq_add_dev_interface()
860 * cpufreq_add_dev - add a CPU device
862 * Adds the cpufreq interface for a CPU device.
865 * with with cpu hotplugging and all hell will break loose. Tried to clean this
870 unsigned int cpu = dev->id; in cpufreq_add_dev() local
879 if (cpu_is_offline(cpu)) in cpufreq_add_dev()
882 pr_debug("adding CPU %u\n", cpu); in cpufreq_add_dev()
885 /* check whether a different CPU already registered this in cpufreq_add_dev()
886 * CPU because it is in the same boat. */ in cpufreq_add_dev()
887 policy = cpufreq_cpu_get(cpu); in cpufreq_add_dev()
910 policy->cpu = cpu; in cpufreq_add_dev()
911 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_add_dev()
913 /* Initially set CPU itself as the policy_cpu */ in cpufreq_add_dev()
914 per_cpu(cpufreq_policy_cpu, cpu) = cpu; in cpufreq_add_dev()
915 ret = (lock_policy_rwsem_write(cpu) < 0); in cpufreq_add_dev()
926 (cpumask_test_cpu(cpu, cp->related_cpus))) { in cpufreq_add_dev()
936 * to accept all calls to ->verify and ->setpolicy for this CPU in cpufreq_add_dev()
949 ret = cpufreq_add_dev_policy(cpu, policy, dev); in cpufreq_add_dev()
952 /* This is a managed cpu, symlink created, in cpufreq_add_dev()
958 ret = cpufreq_add_dev_interface(cpu, policy, dev); in cpufreq_add_dev()
962 unlock_policy_rwsem_write(cpu); in cpufreq_add_dev()
981 unlock_policy_rwsem_write(cpu); in cpufreq_add_dev()
995 * __cpufreq_remove_dev - remove a CPU device
997 * Removes the cpufreq interface for a CPU device.
998 * Caller should already have policy_rwsem in write mode for this CPU.
1003 unsigned int cpu = dev->id; in __cpufreq_remove_dev() local
1013 pr_debug("unregistering CPU %u\n", cpu); in __cpufreq_remove_dev()
1016 data = per_cpu(cpufreq_cpu_data, cpu); in __cpufreq_remove_dev()
1020 unlock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1023 per_cpu(cpufreq_cpu_data, cpu) = NULL; in __cpufreq_remove_dev()
1027 /* if this isn't the CPU which is the parent of the kobj, we in __cpufreq_remove_dev()
1030 if (unlikely(cpu != data->cpu)) { in __cpufreq_remove_dev()
1032 cpumask_clear_cpu(cpu, data->cpus); in __cpufreq_remove_dev()
1036 unlock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1045 strncpy(per_cpu(cpufreq_cpu_governor, cpu), data->governor->name, in __cpufreq_remove_dev()
1056 if (j == cpu) in __cpufreq_remove_dev()
1066 if (j == cpu) in __cpufreq_remove_dev()
1068 pr_debug("removing link for cpu %u\n", j); in __cpufreq_remove_dev()
1075 unlock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1077 lock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1090 unlock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1101 lock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1104 unlock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1107 /* when the CPU which is the parent of the kobj is hotplugged in __cpufreq_remove_dev()
1113 cpumask_clear_cpu(cpu, data->cpus); in __cpufreq_remove_dev()
1117 lock_policy_rwsem_write(cpu); in __cpufreq_remove_dev()
1132 unsigned int cpu = dev->id; in cpufreq_remove_dev() local
1135 if (cpu_is_offline(cpu)) in cpufreq_remove_dev()
1138 if (unlikely(lock_policy_rwsem_write(cpu))) in cpufreq_remove_dev()
1150 unsigned int cpu = policy->cpu; in handle_update() local
1151 pr_debug("handle_update for cpu %u called\n", cpu); in handle_update()
1152 cpufreq_update_policy(cpu); in handle_update()
1156 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble.
1157 * @cpu: cpu number
1158 * @old_freq: CPU frequency the kernel thinks the CPU runs at
1159 * @new_freq: CPU frequency the CPU actually runs at
1164 static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, in cpufreq_out_of_sync() argument
1169 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " in cpufreq_out_of_sync()
1172 freqs.cpu = cpu; in cpufreq_out_of_sync()
1181 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1182 * @cpu: CPU number
1187 unsigned int cpufreq_quick_get(unsigned int cpu) in cpufreq_quick_get() argument
1189 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_quick_get()
1202 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1203 * @cpu: CPU number
1205 * Just return the max possible frequency for a given CPU.
1207 unsigned int cpufreq_quick_get_max(unsigned int cpu) in cpufreq_quick_get_max() argument
1209 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_quick_get_max()
1222 static unsigned int __cpufreq_get(unsigned int cpu) in __cpufreq_get() argument
1224 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); in __cpufreq_get()
1230 ret_freq = cpufreq_driver->get(cpu); in __cpufreq_get()
1237 cpufreq_out_of_sync(cpu, policy->cur, ret_freq); in __cpufreq_get()
1246 * cpufreq_get - get the current CPU frequency (in kHz)
1247 * @cpu: CPU number
1249 * Get the CPU current (static) CPU frequency
1251 unsigned int cpufreq_get(unsigned int cpu) in cpufreq_get() argument
1254 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_get()
1259 if (unlikely(lock_policy_rwsem_read(cpu))) in cpufreq_get()
1262 ret_freq = __cpufreq_get(cpu); in cpufreq_get()
1264 unlock_policy_rwsem_read(cpu); in cpufreq_get()
1282 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend.
1285 * have been put offline by means of CPU hotplug.
1291 int cpu = smp_processor_id(); in cpufreq_bp_suspend() local
1294 pr_debug("suspending cpu %u\n", cpu); in cpufreq_bp_suspend()
1296 /* If there's no policy for the boot CPU, we have nothing to do. */ in cpufreq_bp_suspend()
1297 cpu_policy = cpufreq_cpu_get(cpu); in cpufreq_bp_suspend()
1305 "step on CPU %u\n", cpu_policy->cpu); in cpufreq_bp_suspend()
1313 * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU.
1322 * This function is only executed for the boot CPU. The other CPUs have not
1329 int cpu = smp_processor_id(); in cpufreq_bp_resume() local
1332 pr_debug("resuming cpu %u\n", cpu); in cpufreq_bp_resume()
1334 /* If there's no policy for the boot CPU, we have nothing to do. */ in cpufreq_bp_resume()
1335 cpu_policy = cpufreq_cpu_get(cpu); in cpufreq_bp_resume()
1343 "step on CPU %u\n", cpu_policy->cpu); in cpufreq_bp_resume()
1406 * Remove a driver from the CPU frequency notifier list.
1444 pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu, in __cpufreq_driver_target()
1446 if (cpu_online(policy->cpu) && cpufreq_driver->target) in __cpufreq_driver_target()
1459 policy = cpufreq_cpu_get(policy->cpu); in cpufreq_driver_target()
1463 if (unlikely(lock_policy_rwsem_write(policy->cpu))) in cpufreq_driver_target()
1468 unlock_policy_rwsem_write(policy->cpu); in cpufreq_driver_target()
1477 int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu) in __cpufreq_driver_getavg() argument
1481 policy = cpufreq_cpu_get(policy->cpu); in __cpufreq_driver_getavg()
1485 if (cpu_online(cpu) && cpufreq_driver->getavg) in __cpufreq_driver_getavg()
1486 ret = cpufreq_driver->getavg(policy, cpu); in __cpufreq_driver_getavg()
1530 pr_debug("__cpufreq_governor for CPU %u, event %u\n", in __cpufreq_governor()
1531 policy->cpu, event); in __cpufreq_governor()
1535 each CPU governed by this CPU */ in __cpufreq_governor()
1569 int cpu; in cpufreq_unregister_governor() local
1576 for_each_present_cpu(cpu) { in cpufreq_unregister_governor()
1577 if (cpu_online(cpu)) in cpufreq_unregister_governor()
1579 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) in cpufreq_unregister_governor()
1580 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); in cpufreq_unregister_governor()
1604 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) in cpufreq_get_policy() argument
1610 cpu_policy = cpufreq_cpu_get(cpu); in cpufreq_get_policy()
1631 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, in __cpufreq_set_policy()
1642 /* verify the cpu speed can be set within this limit */ in __cpufreq_set_policy()
1655 /* verify the cpu speed can be set within this limit, in __cpufreq_set_policy()
1712 * @cpu: CPU which shall be re-evaluated
1717 int cpufreq_update_policy(unsigned int cpu) in cpufreq_update_policy() argument
1719 struct cpufreq_policy *data = cpufreq_cpu_get(cpu); in cpufreq_update_policy()
1728 if (unlikely(lock_policy_rwsem_write(cpu))) { in cpufreq_update_policy()
1733 pr_debug("updating policy for CPU %u\n", cpu); in cpufreq_update_policy()
1743 policy.cur = cpufreq_driver->get(cpu); in cpufreq_update_policy()
1749 cpufreq_out_of_sync(cpu, data->cur, in cpufreq_update_policy()
1756 unlock_policy_rwsem_write(cpu); in cpufreq_update_policy()
1768 unsigned int cpu = (unsigned long)hcpu; in cpufreq_cpu_callback() local
1771 dev = get_cpu_device(cpu); in cpufreq_cpu_callback()
1780 if (unlikely(lock_policy_rwsem_write(cpu))) in cpufreq_cpu_callback()
1803 * cpufreq_register_driver - register a CPU Frequency driver
1805 * submitted by the CPU Frequency driver.
1807 * Registers a CPU Frequency driver to this core code. This code
1842 /* check for at least one working CPU */ in cpufreq_register_driver()
1851 pr_debug("no CPU initialized for driver %s\n", in cpufreq_register_driver()
1902 int cpu; in cpufreq_core_init() local
1904 for_each_possible_cpu(cpu) { in cpufreq_core_init()
1905 per_cpu(cpufreq_policy_cpu, cpu) = -1; in cpufreq_core_init()
1906 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); in cpufreq_core_init()