Skip to content

Commit

Permalink
Merge branch 'fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
Syllo committed Nov 3, 2022
2 parents 65a9fc1 + 1030078 commit 02219c9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
6 changes: 4 additions & 2 deletions include/nvtop/extract_gpuinfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ struct gpuinfo_dynamic_info {
};

enum gpu_process_type {
gpu_process_graphical,
gpu_process_compute,
gpu_process_unknown = 0,
gpu_process_graphical = 1,
gpu_process_compute = 2,
gpu_process_graphical_compute = 3,
gpu_process_type_count,
};

Expand Down
12 changes: 8 additions & 4 deletions src/extract_gpuinfo_amdgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ static bool parse_drm_fdinfo_amd(struct gpu_info *info, FILE *fdinfo_file, struc
continue;

if (is_gfx_old) {
process_info->type |= gpu_process_graphical;
SET_GPUINFO_PROCESS(process_info, gpu_usage, process_info->gpu_usage + usage_percent_int);
} else if (is_compute_old) {
process_info->type = gpu_process_compute;
process_info->type |= gpu_process_compute;
SET_GPUINFO_PROCESS(process_info, gpu_usage, process_info->gpu_usage + usage_percent_int);
} else if (is_dec_old) {
SET_GPUINFO_PROCESS(process_info, decode_usage, process_info->decode_usage + usage_percent_int);
Expand All @@ -869,9 +870,10 @@ static bool parse_drm_fdinfo_amd(struct gpu_info *info, FILE *fdinfo_file, struc
continue;

if (is_gfx_new) {
process_info->type |= gpu_process_graphical;
SET_GPUINFO_PROCESS(process_info, gfx_engine_used, time_spent);
} else if (is_compute_new) {
process_info->type = gpu_process_compute;
process_info->type |= gpu_process_compute;
SET_GPUINFO_PROCESS(process_info, compute_engine_used, time_spent);
} else if (is_enc_new) {
SET_GPUINFO_PROCESS(process_info, enc_engine_used, time_spent);
Expand Down Expand Up @@ -907,9 +909,11 @@ static bool parse_drm_fdinfo_amd(struct gpu_info *info, FILE *fdinfo_file, struc
AMDGPU_CACHE_FIELD_VALID(cache_entry, compute_engine_used) &&
process_info->compute_engine_used >= cache_entry->compute_engine_used &&
process_info->compute_engine_used - cache_entry->compute_engine_used <= time_elapsed) {
unsigned gfx_usage = GPUINFO_PROCESS_FIELD_VALID(process_info, gpu_usage) ? process_info->gpu_usage : 0;
SET_GPUINFO_PROCESS(process_info, gpu_usage,
busy_usage_from_time_usage_round(process_info->compute_engine_used,
cache_entry->compute_engine_used, time_elapsed));
gfx_usage + busy_usage_from_time_usage_round(process_info->compute_engine_used,
cache_entry->compute_engine_used,
time_elapsed));
}
if (GPUINFO_PROCESS_FIELD_VALID(process_info, dec_engine_used) &&
AMDGPU_CACHE_FIELD_VALID(cache_entry, dec_engine_used) &&
Expand Down
2 changes: 2 additions & 0 deletions src/extract_gpuinfo_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ static bool parse_drm_fdinfo_intel(struct gpu_info *info, FILE *fdinfo_file, str
}
if (!client_id_set)
return false;
// The intel driver does not expose compute engine metrics as of yet
process_info->type |= gpu_process_graphical;

struct intel_process_info_cache *cache_entry;
struct unique_cache_id ucid = {.client_id = cid, .pid = process_info->pid};
Expand Down
7 changes: 5 additions & 2 deletions src/extract_processinfo_fdinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,20 @@ void processinfo_sweep_fdinfos(void) {
bool callback_success = false;
struct callback_entry *current_callback = NULL;
processes_info_local.pid = client_pid;
processes_info_local.type = gpu_process_graphical;
for (unsigned callback_idx = 0; !callback_success && callback_idx < registered_callback_entries; ++callback_idx) {
rewind(fdinfo_file);
fflush(fdinfo_file);
RESET_ALL(processes_info_local.valid);
processes_info_local.type = gpu_process_unknown;
current_callback = &callback_entries[callback_idx];
callback_success = current_callback->callback(current_callback->gpu_info, fdinfo_file, &processes_info_local);
}
fclose(fdinfo_file);
if (!callback_success)
continue;
// Default to graphical type
if (processes_info_local.type == gpu_process_unknown)
processes_info_local.type = gpu_process_graphical;

unsigned process_index =
current_callback->gpu_info->processes_count ? current_callback->gpu_info->processes_count - 1 : 0;
Expand Down Expand Up @@ -208,7 +211,7 @@ void processinfo_sweep_fdinfos(void) {
}
struct gpu_process *process_info = &current_callback->gpu_info->processes[process_index];

process_info->type = processes_info_local.type;
process_info->type |= processes_info_local.type;

if (GPUINFO_PROCESS_FIELD_VALID(&processes_info_local, gpu_memory_usage)) {
SET_GPUINFO_PROCESS(process_info, gpu_memory_usage,
Expand Down
18 changes: 14 additions & 4 deletions src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static unsigned int sizeof_device_field[device_field_count] = {
};

static unsigned int sizeof_process_field[process_field_count] = {
[process_pid] = 7, [process_user] = 4, [process_gpu_id] = 3, [process_type] = 7,
[process_pid] = 7, [process_user] = 4, [process_gpu_id] = 3, [process_type] = 8,
[process_gpu_rate] = 4, [process_enc_rate] = 4, [process_dec_rate] = 4,
[process_memory] = 14, // 9 for mem 5 for %
[process_cpu_usage] = 6, [process_cpu_mem_usage] = 9, [process_command] = 0,
Expand Down Expand Up @@ -1052,7 +1052,7 @@ static void filter_out_nvtop_pid(all_processes *all_procs, struct nvtop_interfac
for (unsigned procId = 0; procId < all_procs->processes_count; ++procId) {
if (all_procs->processes[procId].process->pid == nvtop_pid) {
memmove(&all_procs->processes[procId], &all_procs->processes[procId + 1],
all_procs->processes_count - procId - 1);
(all_procs->processes_count - procId - 1) * sizeof(*all_procs->processes));
all_procs->processes_count = all_procs->processes_count - 1;
break;
}
Expand Down Expand Up @@ -1174,7 +1174,10 @@ static void print_processes_on_screen(all_processes all_procs, struct process_wi
}

if (process_is_field_displayed(process_type, fields_to_display)) {
if (processes[i].process->type == gpu_process_graphical) {
if (processes[i].process->type == gpu_process_graphical_compute) {
printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ",
sizeof_process_field[process_type], "Both G+C");
} else if (processes[i].process->type == gpu_process_graphical) {
printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ",
sizeof_process_field[process_type], "Graphic");
} else {
Expand Down Expand Up @@ -1261,7 +1264,14 @@ static void print_processes_on_screen(all_processes all_procs, struct process_wi
mvwchgat(win, write_at, 0, -1, A_STANDOUT, cyan_color, NULL);
} else {
if (process_is_field_displayed(process_type, fields_to_display)) {
if (processes[i].process->type == gpu_process_graphical) {
if (processes[i].process->type == gpu_process_graphical_compute) {
set_attribute_between(win, write_at, start_col_process_type - (int)process->offset_column,
start_col_process_type - (int)process->offset_column + 4, 0, cyan_color);
set_attribute_between(win, write_at, end_col_process_type - (int)process->offset_column - 3,
end_col_process_type - (int)process->offset_column - 2, 0, yellow_color);
set_attribute_between(win, write_at, end_col_process_type - (int)process->offset_column - 1,
end_col_process_type - (int)process->offset_column, 0, magenta_color);
} else if (processes[i].process->type == gpu_process_graphical) {
set_attribute_between(win, write_at, start_col_process_type - (int)process->offset_column,
end_col_process_type - (int)process->offset_column, 0, yellow_color);
} else {
Expand Down

0 comments on commit 02219c9

Please sign in to comment.