时方程的解就是解方程gx=3就是f123÷233=12.2312=1223...12

Linux/drivers/cpufreq/cpufreq.c - Linux Cross Reference - Free Electrons
Version: &&&&&&&&&&&&&&&&&&&&&4.9
linux/drivers/cpufreq/cpufreq.c
Copyright (C) 2001 Russell King
(C) 2002 - 2003 Dominik Brodowski &linux@brodo.de&
(C) 2013 Viresh Kumar &viresh.kumar@linaro.org&
Oct 2005 - Ashok Raj &ashok.&
Added handling for CPU hotplug
Feb 2006 - Jacob Shin &jacob.&
Fix handling for CPU hotplug -- affected CPUs
* This prog you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
#define ()
#include &linux/cpu.h&
#include &linux/cpufreq.h&
#include &linux/delay.h&
#include &linux/device.h&
#include &linux/init.h&
#include &linux/kernel_stat.h&
#include &linux/module.h&
#include &linux/mutex.h&
#include &linux/slab.h&
#include &linux/suspend.h&
#include &linux/syscore_ops.h&
#include &linux/tick.h&
#include &trace/events/power.h&
static (cpufreq_policy_list);
static inline
return (-&);
/* Macros to iterate over CPU policies */
#define (__policy, __active)
(__policy, &cpufreq_policy_list, policy_list) \
if ((__active) == !(__policy))
#define (__policy)
(__policy, )
#define (__policy)
(__policy, )
#define (__policy)
(__policy, &cpufreq_policy_list, policy_list)
/* Iterate over governors */
static (cpufreq_governor_list);
#define (__governor)
(__governor, &cpufreq_governor_list, governor_list)
* The "cpufreq driver" - the arch- or hardware-dependent low
* level driver of CPUFreq support, and its spinlock. This lock
* also protects the cpufreq_cpu_data array.
static struct
static (struct
*, cpufreq_cpu_data);
static (cpufreq_driver_lock);
/* Flag to suspend/resume CPUFreq governors */
static inline
return -&target_index || -&;
/* internal prototypes */
static unsigned int (struct
static int (struct
static void (struct
static int (struct
static void (struct
static void (struct
* Two notifier lists: the "policy" list is involved in the
* validation process for a new CPU the
* "transition" list for kernel code that needs to handle
* changes to devices when the CPU clock speed changes.
* The mutex locks both lists.
static (cpufreq_policy_notifier_list);
static int
static int (void)
void (void)
static (cpufreq_governor_mutex);
return !!(-& & );
return &-&;
static inline
(unsigned int ,
cur_wall_time = (());
busy_time = ().cpustat[CPUTIME_USER];
busy_time += ().cpustat[CPUTIME_SYSTEM];
busy_time += ().cpustat[CPUTIME_IRQ];
busy_time += ().cpustat[CPUTIME_SOFTIRQ];
busy_time += ().cpustat[CPUTIME_STEAL];
busy_time += ().cpustat[CPUTIME_NICE];
idle_time = cur_wall_time - busy_
*wall = (cur_wall_time);
return (idle_time);
(unsigned int ,
*wall, int io_busy)
idle_time = (, io_busy ? wall : );
if (idle_time == -1ULL)
return (, wall);
else if (!io_busy)
idle_time += (, wall);
return idle_
* This is a generic cpufreq init() routine which can be used by cpufreq
* drivers of SMP systems. It will do following:
* - validate & show freq table passed
* - set policies transition latency
* - policy-&cpus with all possible CPUs
int (struct
unsigned int )
("%s: invalid frequency table: %d\n", , );
* The driver only supports the SMP configuration where all processors
* share the clock and voltage and clock.
*(unsigned int )
* = (cpufreq_cpu_data, );
&& (, -&) ?
unsigned int (unsigned int )
if (! || (-&)) {
("%s: No %s associated to cpu: %d\n",
? "clk" : "policy", );
return (-&) / 1000;
* cpufreq_cpu_get: returns policy for a cpu and marks it busy.
* @cpu: cpu to find policy for.
* This returns policy for 'cpu', returns NULL if it doesn't exist.
* It also increments the kobject reference count to mark it busy and so would
* require a corresponding call to cpufreq_cpu_put() to decrement it back.
* If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be
* freed as that depends on the kobj count.
* Return: A valid policy on success, otherwise NULL on failure.
*(unsigned int )
if (( &= ))
/* get the cpufreq driver */
(&cpufreq_driver_lock, );
/* get the CPU */
(&cpufreq_driver_lock, );
* cpufreq_cpu_put: Decrements the usage count of a policy
* @policy: policy earlier returned by cpufreq_cpu_get().
* This decrements the kobject reference count incremented earlier by calling
* cpufreq_cpu_get().
void (struct
/*********************************************************************
EXTERNALLY AFFECTING FREQUENCY CHANGES
*********************************************************************/
* adjust_jiffies - adjust the system "loops_per_jiffy"
* This function alters the system "loops_per_jiffy" for the clock
* speed change. Note that loops_per_jiffy cannot be updated on SMP
* systems as each CPU might be scaled differently. So, use the arch
* per-CPU loops_per_jiffy value wherever possible.
static void (unsigned long , struct
static unsigned long l_p_j_
static unsigned int l_p_j_ref_
if (ci-& & )
if (!l_p_j_ref_freq) {
l_p_j_ref = ;
l_p_j_ref_freq = ci-&;
("saving %lu as reference value for loops_per_ freq is %u kHz\n",
l_p_j_ref, l_p_j_ref_freq);
&& ci-& != ci-&) {
= (l_p_j_ref, l_p_j_ref_freq,
("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
static void (struct
*, unsigned int )
("notification %u of frequency transition to %u kHz\n",
switch () {
/* detect if the driver reported a value as "old frequency"
* which is not equal to what the cpufreq core thinks is
* "old frequency".
if (!(-& & )) {
if (() && (-& == -&) &&
(-&cur) && (-&cur != -&)) {
("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
-&, -&cur);
("FREQ: %lu - CPU: %lu\n",
(unsigned long)-&, (unsigned long)-&);
trace_cpu_frequency(-&, -&);
if (() && (-& == -&))
-&cur = -&;
* cpufreq_notify_transition - call notifier chain and adjust_jiffies
* on frequency transition.
* This function calls the transition notifiers and the "adjust_jiffies"
* function. It is called twice on all CPU frequency changes that have
* external effects.
static void (struct
*, unsigned int )
/* Do post notifications when there are chances that transition has failed */
static void (struct
*, int transition_failed)
if (!transition_failed)
void (struct
* Catch double invocations of _begin() which lead to self-deadlock.
* ASYNC_NOTIFICATION drivers are left out because the cpufreq core
* doesn't invoke _begin() on their behalf, and hence the chances of
* double invocations are very low. Moreover, there are scenarios
* where these checks can emit false-positive warnings in these
* so we avoid that by skipping them altogether.
== -&transition_task);
(-&transition_wait, !-&transition_ongoing);
(&-&transition_lock);
if ((-&transition_ongoing)) {
(&-&transition_lock);
-&transition_ongoing = ;
-&transition_task = ;
(&-&transition_lock);
void (struct
*, int transition_failed)
if (((!-&transition_ongoing)))
(, , transition_failed);
-&transition_ongoing = ;
-&transition_task = ;
(&-&transition_wait);
* Fast frequency switching status count.
Positive means "enabled", negative
* means "disabled" and 0 means "not decided yet".
static (cpufreq_fast_switch_lock);
static void (void)
("Registered transition notifiers:\n");
for ( = .; ;
("%pF\n", -&notifier_call);
* cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
* @policy: cpufreq policy to enable fast frequency switching for.
* Try to enable fast frequency switching for @policy.
* The attempt will fail if there is at least one transition notifier registered
* at this point, as fast frequency switching is quite fundamentally at odds
* with transition notifiers.
Thus if successful, it will make registration of
* transition notifiers fail going forward.
void (struct
(&-&rwsem);
if (!-&fast_switch_possible)
(&cpufreq_fast_switch_lock);
if ( &= 0) {
-&fast_switch_enabled = ;
("CPU%u: Fast frequency switching not enabled\n",
(&cpufreq_fast_switch_lock);
* cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
* @policy: cpufreq policy to disable fast frequency switching for.
void (struct
(&cpufreq_fast_switch_lock);
if (-&fast_switch_enabled) {
-&fast_switch_enabled = ;
if (!( &= 0))
(&cpufreq_fast_switch_lock);
* cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
* @target_freq: target frequency to resolve.
* The target to driver frequency mapping is cached in the policy.
* Return: Lowest driver-supported frequency greater than or equal to the
* given target_freq, subject to policy (min/max) and driver limitations.
unsigned int (struct
unsigned int target_freq)
target_freq = (target_freq, -&, -&);
-&cached_target_freq = target_
if (-&target_index) {
= (, target_freq,
-&cached_resolved_idx = ;
return -&[].;
if (-&resolve_freq)
return -&resolve_freq(, target_freq);
return target_
/*********************************************************************
SYSFS INTERFACE
*********************************************************************/
*, char *)
return (, "%d\n", -&boost_enabled);
const char *,
= (, "%d", &);
if ( != 1 ||
("%s: Cannot %s BOOST!\n",
? "enable" : "disable");
("%s: cpufreq BOOST %s\n",
? "enabled" : "disabled");
static struct
*(const char *str_governor)
if (!(str_governor, -&, ))
* cpufreq_parse_governor - parse a governor string
static int (char *str_governor, unsigned int *,
**governor)
if (-&setpolicy) {
if (!(str_governor, "performance", )) {
} else if (!(str_governor, "powersave",
(&cpufreq_governor_mutex);
= (str_governor);
if ( == ) {
(&cpufreq_governor_mutex);
= ("cpufreq_%s", str_governor);
(&cpufreq_governor_mutex);
if ( == 0)
= (str_governor);
if ( != ) {
*governor = ;
(&cpufreq_governor_mutex);
* cpufreq_per_cpu_attr_read() / show_##file_name() -
* print out cpufreq information
* Write out information from cpufreq_driver-&policy[cpu]; object must be
* "unsigned int".
#define (, object)
show_##file_name
*, char *)
return (, "%u\n", -&object);
(cpuinfo_min_freq, .min_freq);
(cpuinfo_max_freq, .);
(cpuinfo_transition_latency, .);
(scaling_min_freq, );
(scaling_max_freq, );
*, char *)
if ( && -&setpolicy && -&)
= (, "%u\n", -&(-&));
= (, "%u\n", -&cur);
static int (struct
*new_policy);
* cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
#define (, object)
store_##file_name
*, const char *,
(&new_policy, , sizeof(*));
= (, "%u", &new_policy.object);
if ( != 1)
= new_policy.
= (, &new_policy);
-&user_policy.object = ;
(scaling_min_freq, );
(scaling_max_freq, );
* show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
unsigned int
return (, "&unknown&");
return (, "%u\n", );
* show_scaling_governor - show the current policy for the specified CPU
*, char *)
if (-& == )
return (, "powersave\n");
else if (-& == )
return (, "performance\n");
else if (-&governor)
return (, , "%s\n",
-&governor-&);
* store_scaling_governor - store policy for the specified CPU
const char *,
str_governor[16];
(&new_policy, , sizeof(*));
= (, "%15s", str_governor);
if ( != 1)
if ((str_governor, &new_policy.,
&new_policy.governor))
= (, &new_policy);
* show_scaling_driver - show the cpufreq driver currently loaded
*, char *)
return (, , "%s\n", -&);
* show_scaling_available_governors - show the available CPUfreq governors
if (!()) {
+= (, "performance powersave");
if ( &= () (( / sizeof(char))
- ( + 2)))
+= (&[], , "%s ", -&);
+= (&[], "\n");
(const struct
*, char *)
+= (&[], ( -
- 2), " ");
+= (&[], ( -
- 2), "%u", );
if ( &= ( - 5))
+= (&[], "\n");
* show_related_cpus - show the CPUs affected by each transition even if
* hw coordination is in use
*, char *)
return (-&related_cpus, );
* show_affected_cpus - show the CPUs affected by each transition
*, char *)
return (-&, );
const char *,
unsigned int
if (!-&governor || !-&governor-&store_setspeed)
= (, "%u", &);
if ( != 1)
-&governor-&store_setspeed(, );
*, char *)
if (!-&governor || !-&governor-&show_setspeed)
return (, "&unsupported&\n");
return -&governor-&show_setspeed(, );
* show_bios_limit - show the current cpufreq HW/BIOS limitation
*, char *)
if (-&bios_limit) {
= -&bios_limit(-&, &);
return (, "%u\n", );
return (, "%u\n", -&.);
(cpuinfo_cur_freq, 0400);
(cpuinfo_min_freq);
(cpuinfo_max_freq);
(cpuinfo_transition_latency);
(scaling_available_governors);
(scaling_driver);
(scaling_cur_freq);
(bios_limit);
(related_cpus);
(affected_cpus);
(scaling_min_freq);
(scaling_max_freq);
(scaling_governor);
(scaling_setspeed);
static struct
&cpuinfo_min_freq.,
&cpuinfo_max_freq.,
&cpuinfo_transition_latency.,
&scaling_min_freq.,
&scaling_max_freq.,
&affected_cpus.,
&related_cpus.,
&scaling_governor.,
&scaling_driver.,
&scaling_available_governors.,
&scaling_setspeed.,
#define (k) (k, struct , )
#define () (, struct , )
*, char *)
*fattr = ();
(&-&rwsem);
= fattr-&(, );
(&-&rwsem);
const char *,
*fattr = ();
if ((-&)) {
(&-&rwsem);
= fattr-&(, , );
(&-&rwsem);
static void (struct
("last reference is dropped\n");
(&-&kobj_unregister);
static const struct
static struct
static int (struct
(, "%s: Adding symlink\n", );
return (&-&, &-&, "cpufreq");
static void (struct
(, "%s: Removing symlink\n", );
(&-&, "cpufreq");
static int (struct
/* set up files for this cpu device */
drv_attr = -&;
while (drv_attr && *drv_attr) {
= (&-&, &((*drv_attr)-&));
drv_attr++;
= (&-&, &cpuinfo_cur_freq.);
= (&-&, &scaling_cur_freq.);
if (-&bios_limit) {
= (&-&, &bios_limit.);
static int (struct
(&new_policy, , sizeof(*));
/* Update governor of new_policy to the governor used before hotplug */
gov = (-&last_governor);
if (gov) {
("Restoring governor %s for cpu %d\n",
-&governor-&, -&);
new_policy.governor =
/* Use the default policy if there is no last_policy. */
if (-&setpolicy) {
if (-&last_policy)
new_policy. = -&last_
(gov-&, &new_policy.,
/* set default policy */
return (, &new_policy);
static int (struct
*, unsigned int )
/* Has this CPU been taken care of already? */
if ((, -&))
(&-&rwsem);
("%s: Failed to start governor\n", );
(&-&rwsem);
static void (struct
(, struct , );
unsigned int
("handle_update for cpu %u called\n", );
static struct
*(unsigned int )
= (sizeof(*), );
if (!(&-&, ))
goto err_free_
if (!(&-&related_cpus, ))
goto err_free_
if (!(&-&real_cpus, ))
goto err_free_
= (&-&, &,
, "policy%u", );
("%s: failed to init policy-&kobj: %d\n", , );
goto err_free_real_
(&-&policy_list);
(&-&rwsem);
(&-&transition_lock);
(&-&transition_wait);
(&-&kobj_unregister);
err_free_real_cpus:
(-&real_cpus);
err_free_rcpumask:
(-&related_cpus);
err_free_cpumask:
err_free_policy:
static void (struct
(&cpufreq_policy_notifier_list,
(&-&rwsem);
= &-&kobj_
(&-&rwsem);
* We need to make sure that the underlying kobj is
* actually not referenced anymore by anybody before we
* proceed with unloading.
("waiting for dropping of refcount\n");
("wait complete\n");
static void (struct
/* Remove policy from list */
(&cpufreq_driver_lock, );
(&-&policy_list);
(, -&related_cpus)
(cpufreq_cpu_data, ) = ;
(&cpufreq_driver_lock, );
(-&real_cpus);
(-&related_cpus);
static int (unsigned int )
("%s: bringing CPU%u online\n", , );
/* Check if this CPU already has a policy to manage it */
= (cpufreq_cpu_data, );
(!(, -&related_cpus));
return (, );
/* This is the only online CPU for the policy.
Start over. */
new_policy = ;
(&-&rwsem);
-&governor = ;
(&-&rwsem);
new_policy = ;
/* call driver. From then on the cpufreq must be able
* to accept all calls to -&verify and -&setpolicy for this CPU
("initialization failed\n");
goto out_free_
(&-&rwsem);
if (new_policy) {
/* related_cpus should at least include policy-&cpus. */
(-&related_cpus, -&);
/* Clear mask of registered CPUs */
(-&real_cpus);
* affected cpus must always be the one, which are online. We aren't
* managing offline cpus here.
(-&, -&, );
if (new_policy) {
-&user_policy. = -&;
-&user_policy. = -&;
(&cpufreq_driver_lock, );
(, -&related_cpus)
(cpufreq_cpu_data, ) = ;
(&cpufreq_driver_lock, );
if (-& && !-&setpolicy) {
-&cur = -&(-&);
if (!-&cur) {
("%s: -&get() failed\n", );
goto out_exit_
* Sometimes boot loaders set CPU frequency to a value outside of
* frequency table present with cpufreq core. In such cases CPU might be
* unstable if it has to run on that frequency for long duration of time
* and so its better to set it to a frequency which is specified in
* freq-table. This also makes cpufreq stats inconsistent as
* cpufreq-stats would fail to register because current frequency of CPU
* isn't found in freq-table.
* Because we don't want this change to effect boot process badly, we go
* for the next freq which is &= policy-&cur ('cur' must be set by now,
* otherwise we will end up setting freq to lowest of the table as 'cur'
* is initialized to zero).
* We are passing target-freq as "policy-&cur - 1" otherwise
* __cpufreq_driver_target() would simply fail, as policy-&cur will be
* equal to target-freq.
if ((-& & )
/* Are we running at unknown frequency ? */
= (, -&cur);
if ( == -) {
/* Warn user and fix it */
("%s: CPU%d: Running at unlisted freq: %u KHz\n",
, -&, -&cur);
= (, -&cur - 1,
* Reaching here after boot in a few seconds may not
* mean that system will remain stable at "unknown"
* frequency for longer duration. Hence, a BUG_ON().
("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n",
, -&, -&cur);
if (new_policy) {
goto out_exit_
(&cpufreq_policy_notifier_list,
(&cpufreq_driver_lock, );
(&-&policy_list, &cpufreq_policy_list);
(&cpufreq_driver_lock, );
(&cpufreq_policy_notifier_list,
("%s: Failed to initialize policy for cpu: %d (%d)\n",
/* cpufreq_policy_free() will notify based on this */
new_policy = ;
goto out_exit_
(&-&rwsem);
(&-&, KOBJ_ADD);
/* Callback for handling stuff after policy is ready */
("initialization complete\n");
out_exit_policy:
(&-&rwsem);
out_free_policy:
(, !new_policy);
static int (unsigned int );
* cpufreq_add_dev - the cpufreq interface for a CPU device.
* @dev: CPU device.
* @sif: Subsystem interface structure pointer (not used)
static int (struct
(, "%s: adding CPU%u\n", , );
/* Create sysfs link on CPU registration */
= (cpufreq_cpu_data, );
if (! || (, -&real_cpus))
(, -&real_cpus);
static int (unsigned int )
("%s: unregistering CPU %u\n", , );
("%s: No cpu_data found\n", );
(&-&rwsem);
(-&last_governor, -&governor-&,
-&last_policy = -&;
} else if ( == -&) {
/* Nominate new CPU */
-& = (-&);
/* Start governor again for active policy */
if (!()) {
("%s: Failed to start governor\n", );
if (-&stop_cpu)
-&stop_cpu();
* Perform the -&exit() even during light-weight tear-down,
* since this is a core component, and is essential for the
* subsequent light-weight -&init() to succeed.
(&-&rwsem);
* cpufreq_remove_dev - remove a CPU device
* Removes the cpufreq interface for a CPU device.
static void (struct
unsigned int
* = (cpufreq_cpu_data, );
(, -&real_cpus);
if ((-&real_cpus))
cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
in deep trouble.
@policy: policy managing CPUs
@new_freq: CPU frequency the CPU actually runs at
We adjust to current frequency first, and need to clean up later.
So either call to cpufreq_update_policy() or schedule handle_update()).
static void (struct
unsigned int new_freq)
("Warning: CPU frequency out of sync: cpufreq and timing core thinks of %u, is %u kHz\n",
-&cur, new_freq);
* cpufreq_quick_get - get the CPU frequency (in kHz) from policy-&cur
* @cpu: CPU number
* This is the last known freq, without actually getting it from the driver.
* Return value will be same as what is shown in scaling_cur_freq in sysfs.
unsigned int (unsigned int )
unsigned int ret_freq = 0;
(&cpufreq_driver_lock, );
if ( && -&setpolicy && -&) {
ret_freq = -&();
(&cpufreq_driver_lock, );
return ret_
(&cpufreq_driver_lock, );
ret_freq = -&
return ret_
* cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
* @cpu: CPU number
* Just return the max possible frequency for a given CPU.
unsigned int (unsigned int )
unsigned int ret_freq = 0;
ret_freq = -&;
return ret_
static unsigned int (struct
unsigned int ret_freq = 0;
return ret_
ret_freq = -&(-&);
* Updating inactive policies is invalid, so avoid doing that.
* if fast frequency switching is used with the given policy, the check
* against policy-&cur is pointless, so skip it in that case too.
if ((()) || -&fast_switch_enabled)
return ret_
if (ret_freq && -&cur &&
!(-& & )) {
/* verify no discrepancy between actual and
saved value exists */
if ((ret_freq != -&cur)) {
(, ret_freq);
return ret_
* cpufreq_get - get the current CPU frequency (in kHz)
* @cpu: CPU number
* Get the CPU current (static) CPU frequency
unsigned int (unsigned int )
unsigned int ret_freq = 0;
(&-&rwsem);
ret_freq = ();
(&-&rwsem);
return ret_
static unsigned int (struct
unsigned int new_
new_freq = -&(-&);
if (!new_freq)
if (!-&cur) {
("cpufreq: Driver did not initialize current freq\n");
-&cur = new_
} else if (-&cur != new_freq && ()) {
(, new_freq);
return new_
static struct
= "cpufreq",
* In case platform wants some specific frequency to be configured
* during suspend..
int (struct
if (!-&) {
("%s: suspend_freq not defined\n", );
("%s: Setting suspend-freq: %u\n", ,
("%s: unable to set suspend-freq: %u. err: %d\n",
* cpufreq_suspend() - Suspend CPUFreq governors
* Called during system wide Suspend/Hibernate cycles for suspending governors
* as some platforms can't change frequency after this point in suspend cycle.
* Because some of the devices (like: i2c, regulators, etc) they use for
* changing frequency are suspended quickly after this point.
void (void)
if (!() && !-&)
("%s: Suspending Governors\n", );
(&-&rwsem);
(&-&rwsem);
if (-& && -&())
("%s: Failed to suspend driver: %p\n", ,
* cpufreq_resume() - Resume CPUFreq governors
* Called during system wide Suspend/Hibernate cycle for resuming governors that
* are suspended with cpufreq_suspend().
void (void)
if (!() && !-&)
("%s: Resuming Governors\n", );
if (-& && -&()) {
("%s: Failed to resume driver: %p\n", ,
} else if (()) {
(&-&rwsem);
(&-&rwsem);
("%s: Failed to start governor for policy: %p\n",
cpufreq_get_current_driver - return current driver's name
Return the name string of the currently loaded cpufreq driver
or NULL, if none.
const char *(void)
return -&;
cpufreq_get_driver_data - return current driver data
Return the private data of the currently loaded cpufreq
driver, or NULL if no cpufreq driver is loaded.
void *(void)
return -&;
/*********************************************************************
NOTIFIER LISTS INTERFACE
*********************************************************************/
cpufreq_register_notifier - register a driver with cpufreq
@nb: notifier function to register
@list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
Add a driver to one of two lists: either a list of drivers that
are notified about clock rate changes (once before and once after
the transition), or a list of drivers that are notified about
changes in cpufreq policy.
This function may sleep, and has the same return conditions as
blocking_notifier_chain_register.
int (struct
*, unsigned int )
switch () {
(&cpufreq_fast_switch_lock);
if ( & 0) {
(&cpufreq_fast_switch_lock);
(&cpufreq_fast_switch_lock);
&cpufreq_policy_notifier_list, );
cpufreq_unregister_notifier - unregister a driver with cpufreq
@nb: notifier block to be unregistered
@list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
Remove a driver from the CPU frequency notifier list.
This function may sleep, and has the same return conditions as
blocking_notifier_chain_unregister.
int (struct
*, unsigned int )
switch () {
(&cpufreq_fast_switch_lock);
if (! && !( &= 0))
(&cpufreq_fast_switch_lock);
&cpufreq_policy_notifier_list, );
/*********************************************************************
*********************************************************************/
* cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
* @policy: cpufreq policy to switch the frequency for.
* @target_freq: New frequency to set (may be approximate).
* Carry out a fast frequency switch without sleeping.
* The driver's -&fast_switch() callback invoked by this function must be
* suitable for being called from within RCU-sched read-side critical sections
* and it is expected to select the minimum available frequency greater than or
* equal to @target_freq (CPUFREQ_RELATION_L).
* This function must not be called if policy-&fast_switch_enabled is unset.
* Governors calling this function must guarantee that it will never be invoked
* twice in parallel for the same policy and that it will never be called in
* parallel with either -&target() or -&target_index() for the same policy.
* If CPUFREQ_ENTRY_INVALID is returned by the driver's -&fast_switch()
* callback to indicate an error condition, the hardware configuration must be
* preserved.
unsigned int (struct
unsigned int target_freq)
target_freq = (target_freq, -&, -&);
return -&fast_switch(, target_freq);
/* Must set freqs-&new to intermediate frequency */
static int (struct
-& = -&get_intermediate(, );
/* We don't need to switch to intermediate freq */
("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n",
, -&, -&, -&);
= -&target_intermediate(, );
("%s: Failed to change to intermediate frequency: %d\n",
static int (struct
= {. = -&cur, . = 0};
unsigned int intermediate_freq = 0;
unsigned int newfreq = -&[].;
int retval = -;
if (newfreq == -&cur)
= !(-& & );
/* Handle switching to intermediate frequency */
if (-&get_intermediate) {
retval = (, &, );
if (retval)
intermediate_freq = .;
/* Set old freq to intermediate */
if (intermediate_freq)
("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
, -&, ., .);
retval = -&target_index(, );
if (retval)
("%s: Failed to change cpu frequency: %d\n", ,
(, &, retval);
* Failed after setting to intermediate freq? Driver should have
* reverted back to initial frequency and so should we. Check
* here for intermediate_freq instead of get_intermediate, in
* case we haven't switched to intermediate freq at all.
if ((retval && intermediate_freq)) {
. = intermediate_
. = -&restore_
int (struct
unsigned int target_freq,
unsigned int relation)
unsigned int old_target_freq = target_
/* Make sure that target_freq is within supported range */
target_freq = (target_freq, -&, -&);
("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
-&, target_freq, relation, old_target_freq);
* This might look like a redundant call as we are checking it again
* after finding index. But it is left intentionally for cases where
* exactly same freq is called again and so we can save on few function
if (target_freq == -&cur)
/* Save last value to restore later on errors */
-&restore_freq = -&
return -&(, target_freq, relation);
if (!-&target_index)
= (, target_freq, relation);
return (, );
int (struct
unsigned int target_freq,
unsigned int relation)
(&-&rwsem);
= (, target_freq, relation);
(&-&rwsem);
static int (struct
/* Don't start any governor operations if we are entering suspend */
* Governor might not be initiated here if ACPI _PPC changed
* notification happened, so check it.
if (!-&governor)
if (-&governor-&max_transition_latency &&
-&governor-&max_transition_latency) {
*gov = ();
if (gov) {
("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
-&governor-&, gov-&);
-&governor =
if (!(-&governor-&))
("%s: for CPU %u\n", , -&);
if (-&governor-&) {
= -&governor-&();
(-&governor-&);
static void (struct
if ( || !-&governor)
("%s: for CPU %u\n", , -&);
if (-&governor-&)
-&governor-&();
(-&governor-&);
static int (struct
if (!-&governor)
("%s: for CPU %u\n", , -&);
if (-& && !-&setpolicy)
if (-&governor-&) {
= -&governor-&();
if (-&governor-&)
-&governor-&();
static void (struct
if ( || !-&governor)
("%s: for CPU %u\n", , -&);
if (-&governor-&)
-&governor-&();
static void (struct
if ( || !-&governor)
("%s: for CPU %u\n", , -&);
if (-&governor-&)
-&governor-&();
int (struct
*governor)
if (!governor)
(&cpufreq_governor_mutex);
if (!(governor-&)) {
(&governor-&governor_list, &cpufreq_governor_list);
(&cpufreq_governor_mutex);
void (struct
*governor)
if (!governor)
/* clear last_governor for all inactive policies */
(&cpufreq_driver_lock, );
if (!(-&last_governor, governor-&)) {
-&governor = ;
(-&last_governor, "\0");
(&cpufreq_driver_lock, );
(&cpufreq_governor_mutex);
(&governor-&governor_list);
(&cpufreq_governor_mutex);
/*********************************************************************
POLICY INTERFACE
*********************************************************************/
* cpufreq_get_policy - get the current cpufreq_policy
* @policy: struct cpufreq_policy into which the current cpufreq_policy
is written
* Reads the current cpufreq policy.
int (struct
*, unsigned int )
cpu_policy = ();
if (!cpu_policy)
(, cpu_policy, sizeof(*));
(cpu_policy);
* policy : current policy.
* new_policy: policy to be set.
static int (struct
*new_policy)
("setting new policy for CPU %u: %u - %u kHz\n",
new_policy-&, new_policy-&, new_policy-&);
(&new_policy-&, &-&, sizeof(-&));
* This check works well when we store new min/max freq attributes,
* because new_policy is a copy of policy with one field updated.
if (new_policy-& & new_policy-&)
/* verify the cpu speed can be set within this limit */
= -&(new_policy);
/* adjust if necessary - all reasons */
(&cpufreq_policy_notifier_list,
, new_policy);
* verify the cpu speed can be set within this limit, which might be
* different to the first one
= -&(new_policy);
/* notification of the new policy */
(&cpufreq_policy_notifier_list,
, new_policy);
-& = new_policy-&;
-& = new_policy-&;
-&cached_target_freq = ;
("new min and max freqs are %u - %u kHz\n",
if (-&setpolicy) {
-& = new_policy-&;
("setting range\n");
return -&setpolicy(new_policy);
if (new_policy-&governor == -&governor) {
("cpufreq: governor limits update\n");
("governor switch\n");
/* save old, working values */
old_gov = -&
/* end old governor */
if (old_gov) {
/* start new governor */
-&governor = new_policy-&
("cpufreq: governor change\n");
/* new governor failed, so re-start old one */
("starting governor %s failed\n", -&governor-&);
if (old_gov) {
-&governor = old_
-&governor = ;
cpufreq_update_policy - re-evaluate an existing cpufreq policy
@cpu: CPU which shall be re-evaluated
Useful for policy notifiers which have different necessities
at different times.
int (unsigned int )
(&-&rwsem);
("updating policy for CPU %u\n", );
(&new_policy, , sizeof(*));
new_policy. = -&user_policy.;
new_policy. = -&user_policy.;
* BIOS might change freq behind our back
* -& ask driver for current freq and notify governors about a change
if (-& && !-&setpolicy) {
new_policy.cur = ();
if ((!new_policy.cur)) {
= (, &new_policy);
(&-&rwsem);
/*********************************************************************
*********************************************************************/
static int (int )
("%s: Policy frequency update failed\n",
(&-&rwsem);
-&user_policy. = -&;
(&-&rwsem);
int (int )
if (-&boost_enabled == )
(&cpufreq_driver_lock, );
-&boost_enabled = ;
(&cpufreq_driver_lock, );
(&cpufreq_driver_lock, );
-&boost_enabled = !;
(&cpufreq_driver_lock, );
("%s: Cannot %s BOOST\n",
? "enable" : "disable");
return () && -&;
static int (void)
("%s: cannot register global BOOST sysfs file\n",
static void (void)
int (void)
/* This will get removed on driver unregister */
return ();
int (void)
return -&boost_
/*********************************************************************
REGISTER / UNREGISTER CPUFREQ DRIVER
*********************************************************************/
* cpufreq_register_driver - register a CPU Frequency driver
* @driver_data: A struct cpufreq_driver containing the values#
* submitted by the CPU Frequency driver.
* Registers a CPU Frequency driver to this core code. This code
* returns zero on success, -EEXIST when another driver got here first
* (and isn't unregistered in the meantime).
int (struct
if (! || !-& || !-& ||
!(-&setpolicy || -&target_index ||
(-&setpolicy && (-&target_index ||
(!!-&get_intermediate != !!-&target_intermediate))
("trying to register driver %s\n", -&);
/* Protect against concurrent CPU online/offline. */
(&cpufreq_driver_lock, );
(&cpufreq_driver_lock, );
(&cpufreq_driver_lock, );
if (-&setpolicy)
goto err_null_
goto err_boost_
if (!(-& & ) &&
(&cpufreq_policy_list)) {
/* if all -&init() calls failed, unregister */
("%s: No CPU initialized for driver %s\n", ,
goto err_if_
= (CPUHP_AP_ONLINE_DYN, "cpufreq:online",
goto err_if_
("driver %s up and running\n", -&);
err_if_unreg:
err_boost_unreg:
err_null_driver:
(&cpufreq_driver_lock, );
(&cpufreq_driver_lock, );
* cpufreq_unregister_driver - unregister the current CPUFreq driver
* Unregister the current CPUFreq driver. Only call this if you have
* the right to do so, i.e. if you have succeeded in initialising before!
* Returns zero if successful, and -EINVAL if the cpufreq_driver is
* currently not initialised.
int (struct
if (! || ( != ))
("unregistering driver %s\n", -&);
/* Protect against concurrent cpu hotplug */
(&cpufreq_driver_lock, );
(&cpufreq_driver_lock, );
* Stop cpufreq at shutdown to make sure it isn't holding any locks
* or mutexes when secondary CPUs are halted.
static struct
static int
= ("cpufreq", &.-&);
This page was automatically generated by
Linux is a registered trademark of Linus Torvalds

我要回帖

更多关于 方程的解就是解方程 的文章

 

随机推荐