Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ Example output:
<th>AMD</th>
<th colspan="2">Intel Discrete</th>
<th>Intel Integrated</th>
<th>Panfrost driver</th>
<th>Panfrost/Panthor driver</th>
</tr>
<tr>
<th></th>
Expand Down Expand Up @@ -689,5 +689,6 @@ Example output:
- GPU usage and memory usage shows usage of current process, not total system usage (it's an issue on intel's side)
- Integrated Intel GPUs are **limited** due to lack of hwmon interface (it's an issue on intel's side, [i915 source](https://github.com/torvalds/linux/blob/5fc31936081919a8572a3d644f3fbb258038f337/drivers/gpu/drm/i915/i915_hwmon.c#L914-L916), [xe source](https://github.com/torvalds/linux/blob/5fc31936081919a8572a3d644f3fbb258038f337/drivers/gpu/drm/xe/xe_hwmon.c#L824-L826))

#### Panfrost notes
- GPU usage requires `echo 1 | sudo tee /sys/class/drm/renderD*/device/profiling`
#### Panfrost and Panthor notes
- GPU usage requires `echo N | sudo tee /sys/class/drm/renderD*/device/profiling`
- Where N is a number, 1 for panfrost and 3 for panthor.
7 changes: 4 additions & 3 deletions src/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class GPU {
amdgpu = std::make_unique<AMDGPU>(pci_dev, device_id, vendor_id);

if (
driver == "i915" || driver == "xe" || driver == "panfrost" ||
driver == "i915" || driver == "xe" ||
driver == "panfrost" || driver == "panthor" ||
driver == "msm_dpu" || driver == "msm_drm"
)
fdinfo = std::make_unique<GPU_fdinfo>(driver, pci_dev, drm_node);
Expand Down Expand Up @@ -199,8 +200,8 @@ class GPUS {
std::string get_pci_device_address(const std::string& drm_card_path);
std::string get_driver(const std::string& node);

const std::array<std::string, 7> supported_drivers = {
"amdgpu", "nvidia", "i915", "xe", "panfrost", "msm_dpu", "msm_drm"
const std::array<std::string, 8> supported_drivers = {
"amdgpu", "nvidia", "i915", "xe", "panfrost", "panthor", "msm_dpu", "msm_drm"
};
};

Expand Down
32 changes: 24 additions & 8 deletions src/gpu_fdinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,20 @@ float GPU_fdinfo::get_memory_used()
if (mem.empty())
continue;

total += std::stoull(mem);
std::string unit = mem.substr(mem.rfind(" ") + 1);
uint64_t val = std::stoull(mem);

if (unit == "KiB")
val *= 1024;
else if (unit == "MiB")
val *= 1024 * 1024;
else if (unit == "GiB")
val *= 1024 * 1024 * 1024;

total += val;
}

// TODO: sometimes it's not KB, so add a check for that.
return static_cast<float>(total) / 1024 / 1024;
return static_cast<float>(total) / 1024 / 1024 / 1024;
}

void GPU_fdinfo::find_hwmon_sensors()
Expand All @@ -168,7 +177,7 @@ void GPU_fdinfo::find_hwmon_sensors()

if (module == "msm")
hwmon = find_hwmon_sensor_dir("gpu");
else if (module == "panfrost")
else if (module == "panfrost" || module == "panthor")
hwmon = find_hwmon_sensor_dir("gpu_thermal");
else
hwmon = find_hwmon_dir();
Expand Down Expand Up @@ -527,8 +536,8 @@ void GPU_fdinfo::load_xe_i915_throttle_reasons(

int GPU_fdinfo::get_gpu_clock()
{
if (module == "panfrost")
return get_gpu_clock_panfrost();
if (module == "panfrost" || module == "panthor")
return get_gpu_clock_mali();

if (!gpu_clock_stream.is_open())
return 0;
Expand All @@ -545,11 +554,18 @@ int GPU_fdinfo::get_gpu_clock()
return std::stoi(clock_str);
}

int GPU_fdinfo::get_gpu_clock_panfrost() {
int GPU_fdinfo::get_gpu_clock_mali() {
if (fdinfo_data.empty())
return 0;

auto freq_str = fdinfo_data[0]["drm-curfreq-fragment"];
std::string key;

if (module == "panfrost")
key = "drm-curfreq-fragment";
else if (module == "panthor")
key = "drm-curfreq-panthor";

std::string freq_str = fdinfo_data[0][key];

if (freq_str.empty())
return 0;
Expand Down
5 changes: 4 additions & 1 deletion src/gpu_fdinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class GPU_fdinfo {
int get_gpu_clock();

uint64_t get_gpu_time_panfrost();
int get_gpu_clock_panfrost();
int get_gpu_clock_mali();

std::ifstream throttle_status_stream;
std::vector<std::ifstream> throttle_power_streams;
Expand Down Expand Up @@ -150,6 +150,9 @@ class GPU_fdinfo {
} else if (module == "panfrost") {
drm_engine_type = "drm-engine-fragment";
drm_memory_type = "drm-resident-memory";
} else if (module == "panthor") {
drm_engine_type = "drm-engine-panthor";
drm_memory_type = "drm-resident-memory";
}

if (fdinfo_data.size() > 0 &&
Expand Down