mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
feat: generate drm bindings for xe
This commit is contained in:
parent
bf73acbdc2
commit
02e4e400e0
@ -17,7 +17,7 @@ serde = { workspace = true, features = ["rc"] }
|
|||||||
serde_with = { workspace = true }
|
serde_with = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
nix = { workspace = true, features = ["user", "fs"] }
|
nix = { workspace = true, features = ["user", "fs", "ioctl"] }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
tokio = { workspace = true, features = [
|
tokio = { workspace = true, features = [
|
||||||
"rt",
|
"rt",
|
||||||
|
@ -7,14 +7,21 @@ fn main() {
|
|||||||
|
|
||||||
println!("cargo::rerun-if-changed=wrapper/");
|
println!("cargo::rerun-if-changed=wrapper/");
|
||||||
|
|
||||||
let bindings = bindgen::builder()
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
.header("wrapper/intel.h")
|
|
||||||
|
bindgen::builder()
|
||||||
|
.header("wrapper/i915.h")
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate intel bindings");
|
.expect("Unable to generate intel bindings")
|
||||||
|
.write_to_file(out_path.join("i915_bindings.rs"))
|
||||||
|
.expect("Couldn't write bindings!");
|
||||||
|
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
bindgen::builder()
|
||||||
bindings
|
.header("wrapper/xe.h")
|
||||||
.write_to_file(out_path.join("intel_bindings.rs"))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||||
|
.generate()
|
||||||
|
.expect("Unable to generate intel bindings")
|
||||||
|
.write_to_file(out_path.join("xe_bindings.rs"))
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
mod drm;
|
||||||
|
|
||||||
use super::GpuController;
|
use super::GpuController;
|
||||||
use crate::{config, server::vulkan::get_vulkan_info};
|
use crate::{config, server::vulkan::get_vulkan_info};
|
||||||
use amdgpu_sysfs::gpu_handle::power_profile_mode::PowerProfileModesTable;
|
use amdgpu_sysfs::gpu_handle::power_profile_mode::PowerProfileModesTable;
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
use drm::bindings::i915;
|
||||||
use futures::future::LocalBoxFuture;
|
use futures::future::LocalBoxFuture;
|
||||||
use lact_schema::{
|
use lact_schema::{
|
||||||
ClocksInfo, ClocksTable, ClockspeedStats, DeviceInfo, DeviceStats, DrmInfo, GpuPciInfo,
|
ClocksInfo, ClocksTable, ClockspeedStats, DeviceInfo, DeviceStats, DrmInfo, GpuPciInfo,
|
||||||
@ -16,21 +19,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
#[allow(
|
|
||||||
non_upper_case_globals,
|
|
||||||
non_camel_case_types,
|
|
||||||
non_snake_case,
|
|
||||||
unused,
|
|
||||||
clippy::upper_case_acronyms,
|
|
||||||
clippy::unreadable_literal
|
|
||||||
)]
|
|
||||||
mod drm {
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/intel_bindings.rs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
enum DriverType {
|
enum DriverType {
|
||||||
Xe,
|
|
||||||
I915,
|
I915,
|
||||||
|
Xe,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IntelGpuController {
|
pub struct IntelGpuController {
|
||||||
@ -146,9 +137,9 @@ impl GpuController for IntelGpuController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let drm_info = DrmInfo {
|
let drm_info = DrmInfo {
|
||||||
intel: IntelDrmInfo {
|
intel: match self.driver_type {
|
||||||
execution_units: self.drm_try(drm::drm_intel_get_eu_total),
|
DriverType::I915 => self.get_drm_info_i915(),
|
||||||
subslices: self.drm_try(drm::drm_intel_get_subslice_total),
|
DriverType::Xe => self.get_drm_info_xe(),
|
||||||
},
|
},
|
||||||
vram_clock_ratio: 1.0,
|
vram_clock_ratio: 1.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -228,7 +219,7 @@ impl GpuController for IntelGpuController {
|
|||||||
clockspeed,
|
clockspeed,
|
||||||
vram: VramStats {
|
vram: VramStats {
|
||||||
total: self
|
total: self
|
||||||
.drm_try_2(drm::drm_intel_get_aperture_sizes)
|
.drm_try_2(i915::drm_intel_get_aperture_sizes)
|
||||||
.map(|(_, total)| total as u64),
|
.map(|(_, total)| total as u64),
|
||||||
used: None,
|
used: None,
|
||||||
},
|
},
|
||||||
@ -365,6 +356,20 @@ impl IntelGpuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_drm_info_i915(&self) -> IntelDrmInfo {
|
||||||
|
IntelDrmInfo {
|
||||||
|
execution_units: self.drm_try(i915::drm_intel_get_eu_total),
|
||||||
|
subslices: self.drm_try(i915::drm_intel_get_subslice_total),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_drm_info_xe(&self) -> IntelDrmInfo {
|
||||||
|
IntelDrmInfo {
|
||||||
|
execution_units: None,
|
||||||
|
subslices: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, allow(unreachable_code, unused_variables))]
|
#[cfg_attr(test, allow(unreachable_code, unused_variables))]
|
||||||
fn drm_try<T: Default>(&self, f: unsafe extern "C" fn(c_int, *mut T) -> c_int) -> Option<T> {
|
fn drm_try<T: Default>(&self, f: unsafe extern "C" fn(c_int, *mut T) -> c_int) -> Option<T> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
2
lact-daemon/src/server/gpu_controller/intel/drm.rs
Normal file
2
lact-daemon/src/server/gpu_controller/intel/drm.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod bindings;
|
||||||
|
pub mod xe;
|
16
lact-daemon/src/server/gpu_controller/intel/drm/bindings.rs
Normal file
16
lact-daemon/src/server/gpu_controller/intel/drm/bindings.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#![allow(
|
||||||
|
non_upper_case_globals,
|
||||||
|
non_camel_case_types,
|
||||||
|
non_snake_case,
|
||||||
|
unused,
|
||||||
|
clippy::upper_case_acronyms,
|
||||||
|
clippy::unreadable_literal
|
||||||
|
)]
|
||||||
|
|
||||||
|
pub mod i915 {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/i915_bindings.rs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod xe {
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/xe_bindings.rs"));
|
||||||
|
}
|
75
lact-daemon/src/server/gpu_controller/intel/drm/xe.rs
Normal file
75
lact-daemon/src/server/gpu_controller/intel/drm/xe.rs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*use super::bindings::xe::{drm_xe_device_query, DRM_XE_DEVICE_QUERY, DRM_XE_DEVICE_QUERY_ENGINES};
|
||||||
|
use crate::server::gpu_controller::intel::bindings::xe::{
|
||||||
|
drm_xe_query_engines, DRM_COMMAND_BASE, DRM_IOCTL_BASE, DRM_XE_DEVICE_QUERY_HWCONFIG,
|
||||||
|
};
|
||||||
|
use nix::{errno::Errno, ioctl_readwrite};
|
||||||
|
use std::{
|
||||||
|
alloc::{self, dealloc},
|
||||||
|
fs::File,
|
||||||
|
mem,
|
||||||
|
os::fd::AsRawFd,
|
||||||
|
};
|
||||||
|
|
||||||
|
ioctl_readwrite!(
|
||||||
|
xe_device_query,
|
||||||
|
DRM_IOCTL_BASE,
|
||||||
|
DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY,
|
||||||
|
drm_xe_device_query
|
||||||
|
);
|
||||||
|
|
||||||
|
pub fn query_engines(fd: &File) -> Result<(), Errno> {
|
||||||
|
unsafe {
|
||||||
|
let mut query = drm_xe_device_query {
|
||||||
|
extensions: 0,
|
||||||
|
query: DRM_XE_DEVICE_QUERY_ENGINES,
|
||||||
|
size: 0,
|
||||||
|
data: 0,
|
||||||
|
reserved: mem::zeroed(),
|
||||||
|
};
|
||||||
|
|
||||||
|
xe_device_query(fd.as_raw_fd(), &mut query)?;
|
||||||
|
|
||||||
|
let layout = alloc::Layout::from_size_align(
|
||||||
|
query.size as usize,
|
||||||
|
mem::align_of::<drm_xe_query_engines>(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
|
let query_engines = alloc::alloc(layout) as *const drm_xe_query_engines;
|
||||||
|
query.data = query_engines as u64;
|
||||||
|
|
||||||
|
xe_device_query(fd.as_raw_fd(), &mut query)?;
|
||||||
|
|
||||||
|
println!("query data: {query:?}");
|
||||||
|
|
||||||
|
for engine in (*query_engines)
|
||||||
|
.engines
|
||||||
|
.as_slice((*query_engines).num_engines as usize)
|
||||||
|
{
|
||||||
|
println!("Engine {engine:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
dealloc(query_engines as *mut u8, layout);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query_hwconfig(fd: &File) -> Result<(), Errno> {
|
||||||
|
unsafe {
|
||||||
|
let mut query = drm_xe_device_query {
|
||||||
|
extensions: 0,
|
||||||
|
query: DRM_XE_DEVICE_QUERY_HWCONFIG,
|
||||||
|
size: 0,
|
||||||
|
data: 0,
|
||||||
|
reserved: mem::zeroed(),
|
||||||
|
};
|
||||||
|
|
||||||
|
xe_device_query(fd.as_raw_fd(), &mut query)?;
|
||||||
|
|
||||||
|
println!("{query:?}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}*/
|
1
lact-daemon/wrapper/i915.h
Normal file
1
lact-daemon/wrapper/i915.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "libdrm/intel_bufmgr.h"
|
@ -1 +0,0 @@
|
|||||||
#include "libdrm/intel_bufmgr.h"
|
|
1
lact-daemon/wrapper/xe.h
Normal file
1
lact-daemon/wrapper/xe.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "drm/xe_drm.h"
|
Loading…
Reference in New Issue
Block a user