Skip to content

Use fdinfo's engine count when refreshing utilisation rate #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions include/nvtop/extract_gpuinfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum gpuinfo_static_info_valid {
gpuinfo_n_shared_cores_valid,
gpuinfo_l2cache_size_valid,
gpuinfo_n_exec_engines_valid,
gpuinfo_engine_count_valid,
gpuinfo_static_info_count,
};

Expand All @@ -74,6 +75,7 @@ struct gpuinfo_static_info {
unsigned n_shared_cores;
unsigned l2cache_size;
unsigned n_exec_engines;
unsigned engine_count;
bool integrated_graphics;
bool encode_decode_shared;
unsigned char valid[(gpuinfo_static_info_count + CHAR_BIT - 1) / CHAR_BIT];
Expand Down
8 changes: 7 additions & 1 deletion src/extract_gpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ void gpuinfo_refresh_utilisation_rate(struct gpu_info *gpu_info) {
unsigned int utilisation_rate;
uint64_t max_freq_hz;
double avg_delta_secs;
unsigned int ec;

for (unsigned processIdx = 0; processIdx < gpu_info->processes_count; ++processIdx) {
struct gpu_process *process_info = &gpu_info->processes[processIdx];
Expand All @@ -351,9 +352,14 @@ void gpuinfo_refresh_utilisation_rate(struct gpu_info *gpu_info) {
if (!gfx_total_process_cycles)
return;

if (IS_VALID(gpuinfo_engine_count_valid, gpu_info->static_info.valid))
ec = gpu_info->static_info.engine_count;
else
ec = 1;

avg_delta_secs = ((double)total_delta / gpu_info->processes_count) / 1000000000.0;
max_freq_hz = gpu_info->dynamic_info.gpu_clock_speed_max * 1000000;
utilisation_rate = (unsigned int)((((double)gfx_total_process_cycles) / (((double)max_freq_hz) * avg_delta_secs * 2)) * 100);
utilisation_rate = (unsigned int)((((double)gfx_total_process_cycles) / (((double)max_freq_hz) * avg_delta_secs * ec)) * 100);
utilisation_rate = utilisation_rate > 100 ? 100 : utilisation_rate;

SET_GPUINFO_DYNAMIC(&gpu_info->dynamic_info, gpu_util_rate, utilisation_rate);
Expand Down
7 changes: 5 additions & 2 deletions src/extract_gpuinfo_mali_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ bool mali_common_parse_drm_fdinfo(struct gpu_info *info, FILE *fdinfo_file,
check_fdinfo_keys match_keys,
struct fdinfo_data *fid)
{
struct gpuinfo_static_info *static_info = &info->static_info;
static char *line = NULL;
static size_t line_buf_size = 0;
uint64_t total_time = 0;
Expand Down Expand Up @@ -529,8 +530,10 @@ bool mali_common_parse_drm_fdinfo(struct gpu_info *info, FILE *fdinfo_file,
}
}

if (fid->engine_count)
SET_GPUINFO_PROCESS(process_info, gfx_engine_used, total_time);
if (fid->engine_count) {
SET_GPUINFO_PROCESS(process_info, gfx_engine_used, total_time);
SET_GPUINFO_STATIC(static_info, engine_count, fid->engine_count);
}

if (!client_id_set)
return false;
Expand Down