Skip to content

Commit

Permalink
fix: 修复offset在新的cpu控制器未正常工作
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow3aaa committed Dec 1, 2024
1 parent 16a1475 commit b970c7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/cpu_common/cpu_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{
use anyhow::{Context, Result};
use sysinfo::{Cpu, CpuRefreshKind, RefreshKind, System};

use super::{IGNORE_MAP, OFFSET_MAP};
use super::IGNORE_MAP;
use crate::file_handler::FileHandler;

#[derive(Debug)]
Expand Down Expand Up @@ -80,17 +80,10 @@ impl Info {
}

pub fn write_freq(&mut self, freq: isize, file_handler: &mut FileHandler) -> Result<()> {
let offset = OFFSET_MAP
.get()
.context("OFFSET_MAP not initialized")?
.get(&self.policy)
.context("Policy offset not found")?
.load(Ordering::Acquire);

let min_freq = *self.freqs.first().context("No frequencies available")?;
let max_freq = *self.freqs.last().context("No frequencies available")?;

let adjusted_freq = freq.saturating_add(offset).clamp(min_freq, max_freq);
let adjusted_freq = freq.clamp(min_freq, max_freq);
self.cur_freq = adjusted_freq;
let adjusted_freq = adjusted_freq.to_string();

Expand Down
14 changes: 12 additions & 2 deletions src/cpu_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use std::{
fs,
path::Path,
sync::{
atomic::{AtomicBool, AtomicIsize},
atomic::{AtomicBool, AtomicIsize, Ordering},
OnceLock,
},
thread,
time::Duration,
};

use anyhow::Result;
use anyhow::{Context, Result};
use cpu_info::Info;
#[cfg(debug_assertions)]
use log::debug;
Expand Down Expand Up @@ -181,6 +181,16 @@ impl Controller {
let freq = fas_freqs.get(&cpu.policy).copied().unwrap();
let freq = freq.max(fas_freq_max * 80 / 100);

let offset = OFFSET_MAP
.get()
.context("OFFSET_MAP not initialized")
.unwrap()
.get(&cpu.policy)
.context("Policy offset not found")
.unwrap()
.load(Ordering::Acquire);
let freq = freq.min(fas_freq_max.saturating_add(offset));

#[cfg(debug_assertions)]
debug!("policy{} freq: {}", cpu.policy, freq);

Expand Down

0 comments on commit b970c7a

Please sign in to comment.