Skip to content

Commit

Permalink
feat: 缓解迁移问题
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow3aaa committed Dec 1, 2024
1 parent d9388c3 commit 1dc8437
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions src/cpu_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,50 @@ impl Controller {
#[cfg(debug_assertions)]
debug!("change freq: {}", control);

for cpu in &mut self.cpu_infos {
let cpu_usage = cpu
.cpu_usage()
.max_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal))
.unwrap_or_default();
let usage_tracking_sugg_freq = (cpu.cur_freq as f32 * cpu_usage / 100.0 / 0.5) as isize; // target_usage: 50%
let policy_freq = cpu
.cur_freq
.saturating_add(control)
.min(usage_tracking_sugg_freq)
.clamp(0, self.max_freq);
let fas_freqs: HashMap<_, _> = self
.cpu_infos
.iter_mut()
.map(|cpu| {
let cpu_usage = cpu
.cpu_usage()
.max_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal))
.unwrap_or_default();
let usage_tracking_sugg_freq =
(cpu.cur_freq as f32 * cpu_usage / 100.0 / 0.5) as isize; // target_usage: 50%
(
cpu.policy,
cpu.cur_freq
.saturating_add(control)
.min(usage_tracking_sugg_freq)
.clamp(0, self.max_freq),
)
})
.collect();

let fas_freq_max = fas_freqs.values().max().copied().unwrap();

#[cfg(debug_assertions)]
debug!(
"policy{} freq: {}",
self.cpu_infos.last().unwrap().policy,
fas_freq_max
);

let _ = self
.cpu_infos
.last_mut()
.unwrap()
.write_freq(fas_freq_max, &mut self.file_handler);

// skip P cores
for cpu in self.cpu_infos.iter_mut().rev().skip(1) {
let freq = fas_freqs.get(&cpu.policy).copied().unwrap();
let freq = freq.max(fas_freq_max * 80 / 100);

#[cfg(debug_assertions)]
debug!("policy{} freq: {}", cpu.policy, policy_freq);
let _ = cpu.write_freq(policy_freq, &mut self.file_handler);
debug!("policy{} freq: {}", cpu.policy, freq);

let _ = cpu.write_freq(freq, &mut self.file_handler);
}
}

Expand Down

0 comments on commit 1dc8437

Please sign in to comment.