Skip to content

Commit d09f284

Browse files
committed
gpu_fdinfo: add gpu clock support for xe
1 parent a81d9e0 commit d09f284

File tree

2 files changed

+61
-9
lines changed

2 files changed

+61
-9
lines changed

src/gpu_fdinfo.cpp

+56-7
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,21 @@ int GPU_fdinfo::get_gpu_load()
244244
return result;
245245
}
246246

247-
void GPU_fdinfo::find_intel_gt_dir()
247+
void GPU_fdinfo::find_i915_gt_dir()
248248
{
249249
std::string device = "/sys/bus/pci/devices/" + pci_dev + "/drm";
250250

251-
auto dir_iterator = fs::directory_iterator(device);
252-
253251
// Find first dir which starts with name "card"
254252
for (const auto& entry : fs::directory_iterator(device)) {
255253
auto path = entry.path().string();
254+
256255
if (path.substr(device.size() + 1, 4) == "card") {
257256
device = path;
258257
break;
259258
}
260259
}
261260

262-
device += "/gt_cur_freq_mhz";
261+
device += "/gt_act_freq_mhz";
263262

264263
if (!fs::exists(device)) {
265264
SPDLOG_WARN(
@@ -272,13 +271,63 @@ void GPU_fdinfo::find_intel_gt_dir()
272271
gpu_clock_stream.open(device);
273272

274273
if (!gpu_clock_stream.good())
275-
SPDLOG_WARN("Intel gt dir: failed to open {}", device);
274+
SPDLOG_WARN("Intel i915 gt dir: failed to open {}", device);
275+
}
276+
277+
void GPU_fdinfo::find_xe_gt_dir()
278+
{
279+
std::string device = "/sys/bus/pci/devices/" + pci_dev + "/tile0";
280+
281+
if (!fs::exists(device)) {
282+
SPDLOG_WARN(
283+
"\"{}\" doesn't exist. GPU clock will be unavailable.",
284+
device
285+
);
286+
return;
287+
}
288+
289+
bool has_rcs = true;
290+
291+
// Check every "gt" dir if it has "engines/rcs" inside
292+
for (const auto& entry : fs::directory_iterator(device)) {
293+
auto path = entry.path().string();
294+
295+
if (path.substr(device.size() + 1, 2) != "gt")
296+
continue;
297+
298+
SPDLOG_DEBUG("Checking \"{}\" for rcs.", path);
299+
300+
if (!fs::exists(path + "/engines/rcs")) {
301+
SPDLOG_DEBUG("Skipping \"{}\" because rcs doesn't exist.", path);
302+
continue;
303+
}
304+
305+
SPDLOG_DEBUG("Found rcs in \"{}\"", path);
306+
has_rcs = true;
307+
device = path;
308+
break;
309+
310+
}
311+
312+
if (!has_rcs) {
313+
SPDLOG_WARN(
314+
"rcs not found inside \"{}\". GPU clock will not be available.",
315+
device
316+
);
317+
return;
318+
}
319+
320+
device += "/freq0/act_freq";
321+
322+
gpu_clock_stream.open(device);
323+
324+
if (!gpu_clock_stream.good())
325+
SPDLOG_WARN("Intel xe gt dir: failed to open {}", device);
276326
}
277327

278328
int GPU_fdinfo::get_gpu_clock()
279329
{
280-
// Only i915 currently supported
281-
if (module != "i915" || !gpu_clock_stream.is_open())
330+
if (!gpu_clock_stream.is_open())
282331
return 0;
283332

284333
std::string clock_str;

src/gpu_fdinfo.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class GPU_fdinfo {
6262
float last_power = 0;
6363

6464
std::ifstream gpu_clock_stream;
65-
void find_intel_gt_dir();
65+
void find_i915_gt_dir();
66+
void find_xe_gt_dir();
6667
int get_gpu_clock();
6768

6869
public:
@@ -109,7 +110,9 @@ class GPU_fdinfo {
109110
find_intel_hwmon();
110111

111112
if (module == "i915")
112-
find_intel_gt_dir();
113+
find_i915_gt_dir();
114+
else if (module == "xe")
115+
find_xe_gt_dir();
113116

114117
std::thread thread(&GPU_fdinfo::main_thread, this);
115118
thread.detach();

0 commit comments

Comments
 (0)