mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
wip i915 freq controls
This commit is contained in:
parent
29f04bd687
commit
b832087dfd
@ -13,17 +13,17 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
use tracing::{error, info, warn};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
// enum DriverType {
|
||||
// Xe,
|
||||
// I915,
|
||||
// }
|
||||
enum DriverType {
|
||||
Xe,
|
||||
I915,
|
||||
}
|
||||
|
||||
pub struct IntelGpuController {
|
||||
sysfs_path: PathBuf,
|
||||
driver: String,
|
||||
// driver_type: DriverType,
|
||||
driver_type: DriverType,
|
||||
pci_slot_id: Option<String>,
|
||||
pci_info: GpuPciInfo,
|
||||
tile_gts: Vec<PathBuf>,
|
||||
@ -36,11 +36,11 @@ impl IntelGpuController {
|
||||
pci_slot_id: Option<String>,
|
||||
pci_info: GpuPciInfo,
|
||||
) -> Self {
|
||||
// let driver_type = match driver.as_str() {
|
||||
// "xe" => DriverType::Xe,
|
||||
// "i915" => DriverType::I915,
|
||||
// _ => unreachable!(),
|
||||
// };
|
||||
let driver_type = match driver.as_str() {
|
||||
"xe" => DriverType::Xe,
|
||||
"i915" => DriverType::I915,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let mut tile_gts = vec![];
|
||||
|
||||
@ -50,7 +50,13 @@ impl IntelGpuController {
|
||||
for gt_entry in fs::read_dir(entry.path()).into_iter().flatten().flatten() {
|
||||
if let Some(gt_name) = gt_entry.file_name().to_str() {
|
||||
if gt_name.starts_with("gt") {
|
||||
tile_gts.push(gt_entry.path());
|
||||
let gt_path = gt_entry
|
||||
.path()
|
||||
.strip_prefix(&sysfs_path)
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
debug!("initialized GT at '{}'", gt_path.display());
|
||||
tile_gts.push(gt_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,15 +64,18 @@ impl IntelGpuController {
|
||||
}
|
||||
}
|
||||
|
||||
info!(
|
||||
"initialized {} gt at '{}'",
|
||||
tile_gts.len(),
|
||||
sysfs_path.display()
|
||||
);
|
||||
if !tile_gts.is_empty() {
|
||||
info!(
|
||||
"initialized {} gt at '{}'",
|
||||
tile_gts.len(),
|
||||
sysfs_path.display()
|
||||
);
|
||||
}
|
||||
|
||||
Self {
|
||||
sysfs_path,
|
||||
driver,
|
||||
driver_type,
|
||||
pci_slot_id,
|
||||
pci_info,
|
||||
tile_gts,
|
||||
@ -134,13 +143,27 @@ impl GpuController for IntelGpuController {
|
||||
config: &'a config::Gpu,
|
||||
) -> LocalBoxFuture<'a, anyhow::Result<()>> {
|
||||
Box::pin(async {
|
||||
if let Some(max_clock) = config.clocks_configuration.max_core_clock {
|
||||
self.write_gt_file("freq0/max_freq", &max_clock.to_string())
|
||||
.context("Could not set max clock")?;
|
||||
}
|
||||
if let Some(min_clock) = config.clocks_configuration.min_core_clock {
|
||||
self.write_gt_file("freq0/min_freq", &min_clock.to_string())
|
||||
.context("Could not set min clock")?;
|
||||
match self.driver_type {
|
||||
DriverType::Xe => {
|
||||
if let Some(max_clock) = config.clocks_configuration.max_core_clock {
|
||||
self.write_gt_file("freq0/max_freq", &max_clock.to_string())
|
||||
.context("Could not set max clock")?;
|
||||
}
|
||||
if let Some(min_clock) = config.clocks_configuration.min_core_clock {
|
||||
self.write_gt_file("freq0/min_freq", &min_clock.to_string())
|
||||
.context("Could not set min clock")?;
|
||||
}
|
||||
}
|
||||
DriverType::I915 => {
|
||||
if let Some(max_clock) = config.clocks_configuration.max_core_clock {
|
||||
self.write_file("../gt_max_freq_mhz", &max_clock.to_string())
|
||||
.context("Could not set max clock")?;
|
||||
}
|
||||
if let Some(min_clock) = config.clocks_configuration.min_core_clock {
|
||||
self.write_file("../gt_min_freq_mhz", &min_clock.to_string())
|
||||
.context("Could not set min clock")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -166,13 +189,23 @@ impl GpuController for IntelGpuController {
|
||||
}
|
||||
|
||||
fn get_clocks_info(&self) -> anyhow::Result<ClocksInfo> {
|
||||
let clocks_table = IntelClocksTable {
|
||||
gt_freq: self
|
||||
.read_gt_file("freq0/min_freq")
|
||||
.zip(self.read_gt_file("freq0/max_freq")),
|
||||
rp0_freq: self.read_gt_file("freq0/rp0_freq"),
|
||||
rpe_freq: self.read_gt_file("freq0/rpe_freq"),
|
||||
rpn_freq: self.read_gt_file("freq0/rpn_freq"),
|
||||
let clocks_table = match self.driver_type {
|
||||
DriverType::Xe => IntelClocksTable {
|
||||
gt_freq: self
|
||||
.read_gt_file("freq0/min_freq")
|
||||
.zip(self.read_gt_file("freq0/max_freq")),
|
||||
rp0_freq: self.read_gt_file("freq0/rp0_freq"),
|
||||
rpe_freq: self.read_gt_file("freq0/rpe_freq"),
|
||||
rpn_freq: self.read_gt_file("freq0/rpn_freq"),
|
||||
},
|
||||
DriverType::I915 => IntelClocksTable {
|
||||
gt_freq: self
|
||||
.read_file("../gt_min_freq_mhz")
|
||||
.zip(self.read_file("../gt_max_freq_mhz")),
|
||||
rpn_freq: self.read_file("../gt_RPn_freq_mhz"),
|
||||
rpe_freq: self.read_file("../gt_RP1_freq_mhz"),
|
||||
rp0_freq: self.read_file("../gt_RP0_freq_mhz"),
|
||||
},
|
||||
};
|
||||
|
||||
let table = if clocks_table == IntelClocksTable::default() {
|
||||
@ -211,46 +244,59 @@ impl IntelGpuController {
|
||||
self.tile_gts.first().map(PathBuf::as_ref)
|
||||
}
|
||||
|
||||
fn read_file<T>(&self, path: impl AsRef<Path>) -> Option<T>
|
||||
where
|
||||
T: FromStr,
|
||||
T::Err: Display,
|
||||
{
|
||||
let file_path = self.get_path().join(path);
|
||||
|
||||
if file_path.exists() {
|
||||
match fs::read_to_string(&file_path) {
|
||||
Ok(contents) => match contents.trim().parse() {
|
||||
Ok(value) => return Some(value),
|
||||
Err(err) => {
|
||||
error!(
|
||||
"could not parse value from '{}': {err}",
|
||||
file_path.display()
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
error!("could not read file at '{}': {err}", file_path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn write_file(&self, path: impl AsRef<Path>, contents: &str) -> anyhow::Result<()> {
|
||||
let file_path = self.get_path().join(path);
|
||||
|
||||
if file_path.exists() {
|
||||
fs::write(&file_path, contents)
|
||||
.with_context(|| format!("Could not write to '{}'", file_path.display()))?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("File '{}' does not exist", file_path.display()))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_gt_file<T>(&self, file_name: &str) -> Option<T>
|
||||
where
|
||||
T: FromStr,
|
||||
T::Err: Display,
|
||||
{
|
||||
if let Some(gt_path) = self.first_tile_gt() {
|
||||
self.first_tile_gt().and_then(|gt_path| {
|
||||
let file_path = gt_path.join(file_name);
|
||||
|
||||
if file_path.exists() {
|
||||
match fs::read_to_string(&file_path) {
|
||||
Ok(contents) => match contents.trim().parse() {
|
||||
Ok(value) => return Some(value),
|
||||
Err(err) => {
|
||||
error!(
|
||||
"could not parse value from '{}': {err}",
|
||||
file_path.display()
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
error!("could not read file at '{}': {err}", file_path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
self.read_file(file_path)
|
||||
})
|
||||
}
|
||||
|
||||
fn write_gt_file(&self, file_name: &str, contents: &str) -> anyhow::Result<()> {
|
||||
if let Some(gt_path) = self.first_tile_gt() {
|
||||
let file_path = gt_path.join(file_name);
|
||||
|
||||
if file_path.exists() {
|
||||
fs::write(&file_path, contents)
|
||||
.with_context(|| format!("Could not write to '{}'", file_path.display()))?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("File '{}' does not exist", file_path.display()))
|
||||
}
|
||||
self.write_file(file_path, contents)
|
||||
} else {
|
||||
Err(anyhow!("No GTs available"))
|
||||
}
|
||||
|
@ -3,7 +3,20 @@ source: lact-daemon/src/tests/mod.rs
|
||||
expression: device_info
|
||||
---
|
||||
{
|
||||
"clocks_info": {},
|
||||
"clocks_info": {
|
||||
"table": {
|
||||
"type": "intel",
|
||||
"value": {
|
||||
"gt_freq": [
|
||||
300,
|
||||
1150
|
||||
],
|
||||
"rp0_freq": 1150,
|
||||
"rpe_freq": 300,
|
||||
"rpn_freq": 300
|
||||
}
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"driver": "i915",
|
||||
"link_info": {},
|
||||
|
Loading…
Reference in New Issue
Block a user