kernel/sched/cpufreq_schedutil.c
Source file repositories/reference/linux-study-clean/kernel/sched/cpufreq_schedutil.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/cpufreq_schedutil.c- Extension
.c- Size
- 26229 bytes
- Lines
- 939
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
uapi/linux/sched/types.hsched.h
Detected Declarations
struct sugov_tunablesstruct sugov_policystruct sugov_cpufunction sugov_should_update_freqfunction sugov_update_next_freqfunction sugov_deferred_updatefunction arch_scale_freq_reffunction next_freqfunction sugov_effective_cpu_perffunction sugov_get_utilfunction sugov_iowait_resetfunction sugov_iowait_boostfunction sugov_iowait_applyfunction sugov_hold_freqfunction sugov_hold_freqfunction sugov_should_update_freqfunction sugov_update_single_commonfunction sugov_update_single_freqfunction sugov_update_single_perffunction sugov_next_freq_sharedfunction for_each_cpufunction sugov_update_sharedfunction sugov_workfunction sugov_irq_workfunction rate_limit_us_showfunction rate_limit_us_storefunction sugov_tunables_freefunction sugov_policy_freefunction sugov_kthread_createfunction sugov_kthread_stopfunction sugov_clear_global_tunablesfunction sugov_initfunction sugov_exitfunction sugov_startfunction for_each_cpufunction sugov_stopfunction sugov_limitsfunction sugov_is_governor
Annotated Snippet
struct sugov_tunables {
struct gov_attr_set attr_set;
unsigned int rate_limit_us;
};
struct sugov_policy {
struct cpufreq_policy *policy;
struct sugov_tunables *tunables;
struct list_head tunables_hook;
raw_spinlock_t update_lock;
u64 last_freq_update_time;
s64 freq_update_delay_ns;
unsigned int next_freq;
unsigned int cached_raw_freq;
/* The next fields are only needed if fast switch cannot be used: */
struct irq_work irq_work;
struct kthread_work work;
struct mutex work_lock;
struct kthread_worker worker;
struct task_struct *thread;
bool work_in_progress;
bool limits_changed;
bool need_freq_update;
};
struct sugov_cpu {
struct update_util_data update_util;
struct sugov_policy *sg_policy;
unsigned int cpu;
bool iowait_boost_pending;
unsigned int iowait_boost;
u64 last_update;
unsigned long util;
unsigned long bw_min;
/* The field below is for single-CPU policies only: */
#ifdef CONFIG_NO_HZ_COMMON
unsigned long saved_idle_calls;
#endif
};
static DEFINE_PER_CPU(struct sugov_cpu, sugov_cpu);
/************************ Governor internals ***********************/
static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
{
s64 delta_ns;
/*
* Since cpufreq_update_util() is called with rq->lock held for
* the @target_cpu, our per-CPU data is fully serialized.
*
* However, drivers cannot in general deal with cross-CPU
* requests, so while get_next_freq() will work, our
* sugov_update_commit() call may not for the fast switching platforms.
*
* Hence stop here for remote requests if they aren't supported
* by the hardware, as calculating the frequency is pointless if
* we cannot in fact act on it.
*
* This is needed on the slow switching platforms too to prevent CPUs
* going offline from leaving stale IRQ work items behind.
*/
if (!cpufreq_this_cpu_can_update(sg_policy->policy))
return false;
if (unlikely(READ_ONCE(sg_policy->limits_changed))) {
WRITE_ONCE(sg_policy->limits_changed, false);
sg_policy->need_freq_update = true;
/*
* The above limits_changed update must occur before the reads
* of policy limits in cpufreq_driver_resolve_freq() or a policy
* limits update might be missed, so use a memory barrier to
* ensure it.
*
* This pairs with the write memory barrier in sugov_limits().
*/
smp_mb();
return true;
} else if (sg_policy->need_freq_update) {
/* ignore_dl_rate_limit() wants a new frequency to be found. */
Annotation
- Immediate include surface: `uapi/linux/sched/types.h`, `sched.h`.
- Detected declarations: `struct sugov_tunables`, `struct sugov_policy`, `struct sugov_cpu`, `function sugov_should_update_freq`, `function sugov_update_next_freq`, `function sugov_deferred_update`, `function arch_scale_freq_ref`, `function next_freq`, `function sugov_effective_cpu_perf`, `function sugov_get_util`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.