Skip to content

Commit 6c49103

Browse files
17314642flightlessmango
authored andcommitted
gpu_fdinfo: determine if i915 or xe driver is used
1 parent 22c7523 commit 6c49103

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/gpu.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ GPUS::GPUS(overlay_params* params) : params(params) {
7272
find_active_gpu();
7373
}
7474

75+
std::string GPU::is_i915_or_xe() {
76+
std::string path = "/sys/bus/pci/devices/";
77+
path += pci_dev + "/driver";
78+
79+
if (!fs::exists(path)) {
80+
SPDLOG_ERROR("{} doesn't exist", path);
81+
return "";
82+
}
83+
84+
if (!fs::is_symlink(path)) {
85+
SPDLOG_ERROR("{} is not a symlink (it should be)", path);
86+
return "";
87+
}
88+
89+
std::string driver = fs::read_symlink(path);
90+
driver = driver.substr(driver.rfind("/") + 1);
91+
92+
return driver;
93+
}
94+
7595
std::string GPUS::get_pci_device_address(const std::string& drm_card_path) {
7696
// Resolve the symbolic link to get the actual device path
7797
fs::path device_path = fs::canonical(fs::path(drm_card_path) / "device");

src/gpu.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "gpu_fdinfo.h"
1818

1919
class GPU {
20+
private:
21+
std::string is_i915_or_xe();
22+
2023
public:
2124
gpu_metrics metrics;
2225
std::string name;
@@ -38,7 +41,7 @@ class GPU {
3841
// For now we're only accepting one of these modules at once
3942
// Might be possible that multiple can exist on a system in the future?
4043
if (vendor_id == 0x8086)
41-
fdinfo = std::make_unique<GPU_fdinfo>("i915", pci_dev);
44+
fdinfo = std::make_unique<GPU_fdinfo>(is_i915_or_xe(), pci_dev);
4245

4346
if (vendor_id == 0x5143)
4447
fdinfo = std::make_unique<GPU_fdinfo>("msm", pci_dev);

0 commit comments

Comments
 (0)