Skip to content

Commit a280e5f

Browse files
committed
Fix division by zero on intel xe
Fixes: #354
1 parent 72312d8 commit a280e5f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/extract_gpuinfo_intel_xe.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,22 @@ bool parse_drm_fdinfo_intel_xe(struct gpu_info *info, FILE *fdinfo_file, struct
227227
{
228228
uint64_t cycles_delta = gpu_cycles.rcs - cache_entry->gpu_cycles.rcs;
229229
uint64_t total_cycles_delta = total_cycles.rcs - cache_entry->total_cycles.rcs;
230-
SET_GPUINFO_PROCESS(process_info, gpu_usage, cycles_delta * 100 / total_cycles_delta);
230+
if (total_cycles_delta > 0)
231+
SET_GPUINFO_PROCESS(process_info, gpu_usage, cycles_delta * 100 / total_cycles_delta);
232+
else
233+
SET_GPUINFO_PROCESS(process_info, gpu_usage, 0);
231234
}
232235
{
233236
uint64_t cycles_delta = gpu_cycles.ccs - cache_entry->gpu_cycles.ccs;
234237
uint64_t total_cycles_delta = total_cycles.ccs - cache_entry->total_cycles.ccs;
235-
SET_GPUINFO_PROCESS(process_info, gpu_usage, process_info->gpu_usage + cycles_delta * 100 / total_cycles_delta);
238+
if (total_cycles_delta > 0)
239+
SET_GPUINFO_PROCESS(process_info, gpu_usage, process_info->gpu_usage + cycles_delta * 100 / total_cycles_delta);
236240
}
237241
{
238242
uint64_t cycles_delta = gpu_cycles.vcs - cache_entry->gpu_cycles.vcs;
239243
uint64_t total_cycles_delta = total_cycles.vcs - cache_entry->total_cycles.vcs;
240-
SET_GPUINFO_PROCESS(process_info, decode_usage, cycles_delta * 100 / total_cycles_delta);
244+
if (total_cycles_delta > 0)
245+
SET_GPUINFO_PROCESS(process_info, decode_usage, cycles_delta * 100 / total_cycles_delta);
241246
}
242247

243248
} else {

0 commit comments

Comments
 (0)