Skip to content

Commit 15882e2

Browse files
koushikbillakanti-amdadam360x
authored andcommitted
Update rocm_smi_kfd.cc
1 parent 11a7e06 commit 15882e2

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

projects/amdsmi/rocm_smi/src/rocm_smi_kfd.cc

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ int GetProcessInfo(rsmi_process_info_t *procs, uint32_t num_allocated,
358358
}
359359
}
360360
}
361+
else {
362+
// Skip unexpected entries that don't match known formats
363+
// (e.g., non-numeric, non-pid: format files/directories)
364+
dentry = readdir(proc_dir);
365+
continue;
366+
}
361367

362368
dentry = readdir(proc_dir);
363369
}
@@ -405,27 +411,11 @@ int GetKfdGpuIdsForPid(long pid, std::unordered_set<uint64_t>* out){
405411
perror(("Unable to open KFD process directory for process " + std::to_string(pid)).c_str());
406412
return errno ? errno : ESRCH;
407413
}
408-
409-
struct dirent* e;
410-
411-
while ((e = readdir(d))) {
412-
413-
if (e->d_name[0] == '.') continue; // skip "."/".." and hidden entries
414-
415-
// Grab KFD GPU id from one of these fields
416-
if (!strncmp(e->d_name, "stats_", 6)) {
417-
out->insert(strtoull(e->d_name + 6, nullptr, 10));
418-
} else if (!strncmp(e->d_name, "vram_", 5)) {
419-
out->insert(strtoull(e->d_name + 5, nullptr, 10));
420-
} else if (!strncmp(e->d_name, "counters_", 9)) {
421-
out->insert(strtoull(e->d_name + 9, nullptr, 10));
422-
} else if (!strncmp(e->d_name, "sdma_", 5)) {
423-
out->insert(strtoull(e->d_name + 5, nullptr, 10));
424-
}
425-
}
426-
427414
closedir(d);
428415

416+
// Use the lambda for the primary process directory (instead of duplicating code)
417+
extract_gpu_ids_from_dir(pdir);
418+
429419
// Also check secondary contexts (context_xxxx directories)
430420
// These are created by the KFD multiple contexts feature
431421
std::vector<std::string> context_paths = GetSecondaryContextPaths(pdir);

0 commit comments

Comments
 (0)