SWDEV-375113 - Fixed process info
The format of the fdinfo file has changed Change-Id: Iad2e26487e75f3e614e364456e929aa1f6f949a4 Signed-off-by: Dalibor Stanisavljevic <Dalibor.Stanisavljevic@amd.com>
Этот коммит содержится в:
@@ -498,15 +498,6 @@ int main() {
|
||||
: -1;
|
||||
};
|
||||
|
||||
auto sum_item = [](uint16_t *a) -> float {
|
||||
float b = 0;
|
||||
for (int iterator = 0; iterator < AMDSMI_MAX_MM_IP_COUNT;
|
||||
iterator += 1) {
|
||||
b += (float)a[iterator] / 100.0;
|
||||
}
|
||||
return b;
|
||||
};
|
||||
|
||||
// Get frequency ranges
|
||||
amdsmi_frequency_range_t freq_ranges = {};
|
||||
ret = amdsmi_get_target_frequency_range(
|
||||
@@ -533,7 +524,7 @@ int main() {
|
||||
amdsmi_proc_info_t info_list[num_process];
|
||||
amdsmi_proc_info_t process = {};
|
||||
uint64_t mem = 0, gtt_mem = 0, cpu_mem = 0, vram_mem = 0;
|
||||
float gfx = 0, comp = 0, dma = 0, enc = 0, dec = 0;
|
||||
uint64_t gfx = 0, comp = 0, dma = 0, enc = 0, dec = 0;
|
||||
char bdf_str[20];
|
||||
sprintf(bdf_str, "%04lx:%02x:%02x.%d", bdf.domain_number,
|
||||
bdf.bus_number, bdf.device_number, bdf.function_number);
|
||||
@@ -562,7 +553,7 @@ int main() {
|
||||
printf(
|
||||
"| pid | name | user | gpu bdf | "
|
||||
"fb usage | gtt memory | cpu memory | vram memory | "
|
||||
"ring usage (%%) |\n");
|
||||
"engine usage (ns) |\n");
|
||||
printf("| | | | "
|
||||
"| | | | "
|
||||
" | gfx comp dma enc dec |\n");
|
||||
@@ -580,49 +571,49 @@ int main() {
|
||||
pwd = getpwuid(st.st_uid);
|
||||
if (!pwd)
|
||||
printf("| %5d | %16s | %10d | %s | %7ld KiB | %7ld KiB "
|
||||
"| %7ld KiB | %7ld KiB | %6.2f %6.2f %6.2f "
|
||||
"%6.2f %6.2f |\n",
|
||||
"| %7ld KiB | %7ld KiB | %lu %lu %lu "
|
||||
"%lu %lu |\n",
|
||||
info_list[it].pid, info_list[it].name, st.st_uid,
|
||||
bdf_str, info_list[it].mem / 1024,
|
||||
info_list[it].memory_usage.gtt_mem / 1024,
|
||||
info_list[it].memory_usage.cpu_mem / 1024,
|
||||
info_list[it].memory_usage.vram_mem / 1024,
|
||||
sum_item(info_list[it].engine_usage.gfx),
|
||||
sum_item(info_list[it].engine_usage.compute),
|
||||
sum_item(info_list[it].engine_usage.sdma),
|
||||
sum_item(info_list[it].engine_usage.enc),
|
||||
sum_item(info_list[it].engine_usage.dec));
|
||||
info_list[it].engine_usage.gfx,
|
||||
info_list[it].engine_usage.compute,
|
||||
info_list[it].engine_usage.dma,
|
||||
info_list[it].engine_usage.enc,
|
||||
info_list[it].engine_usage.dec);
|
||||
else
|
||||
printf("| %5d | %16s | %10s | %s | %7ld KiB | %7ld KiB "
|
||||
"| %7ld KiB | %7ld KiB | %6.2f %6.2f %6.2f "
|
||||
"%6.2f %6.2f |\n",
|
||||
"| %7ld KiB | %7ld KiB | %lu %lu %lu "
|
||||
"%lu %lu |\n",
|
||||
info_list[it].pid, info_list[it].name,
|
||||
pwd->pw_name, bdf_str, info_list[it].mem / 1024,
|
||||
info_list[it].memory_usage.gtt_mem / 1024,
|
||||
info_list[it].memory_usage.cpu_mem / 1024,
|
||||
info_list[it].memory_usage.vram_mem / 1024,
|
||||
sum_item(info_list[it].engine_usage.gfx),
|
||||
sum_item(info_list[it].engine_usage.compute),
|
||||
sum_item(info_list[it].engine_usage.sdma),
|
||||
sum_item(info_list[it].engine_usage.enc),
|
||||
sum_item(info_list[it].engine_usage.dec));
|
||||
info_list[it].engine_usage.gfx,
|
||||
info_list[it].engine_usage.compute,
|
||||
info_list[it].engine_usage.dma,
|
||||
info_list[it].engine_usage.enc,
|
||||
info_list[it].engine_usage.dec);
|
||||
mem += info_list[it].mem / 1024;
|
||||
gtt_mem += info_list[it].memory_usage.gtt_mem / 1024;
|
||||
cpu_mem += info_list[it].memory_usage.cpu_mem / 1024;
|
||||
vram_mem += info_list[it].memory_usage.vram_mem / 1024;
|
||||
gfx += sum_item(info_list[it].engine_usage.gfx);
|
||||
comp += sum_item(info_list[it].engine_usage.compute);
|
||||
dma += sum_item(info_list[it].engine_usage.sdma);
|
||||
enc += sum_item(info_list[it].engine_usage.enc);
|
||||
dec += sum_item(info_list[it].engine_usage.dec);
|
||||
gfx = info_list[it].engine_usage.gfx;
|
||||
comp = info_list[it].engine_usage.compute;
|
||||
dma = info_list[it].engine_usage.dma;
|
||||
enc = info_list[it].engine_usage.enc;
|
||||
dec = info_list[it].engine_usage.dec;
|
||||
printf(
|
||||
"+-------+------------------+------------+-------------"
|
||||
"-+-------------+-------------+-------------+----------"
|
||||
"----+-----------------------------------------+\n");
|
||||
}
|
||||
printf("| TOTAL:| %s | %7ld "
|
||||
"KiB | %7ld KiB | %7ld KiB | %7ld KiB | %6.2f %6.2f "
|
||||
"%6.2f %6.2f %6.2f |\n",
|
||||
"KiB | %7ld KiB | %7ld KiB | %7ld KiB | %lu %lu "
|
||||
"%lu %lu %lu |\n",
|
||||
bdf_str, mem, gtt_mem, cpu_mem, vram_mem, gfx, comp, dma,
|
||||
enc, dec);
|
||||
printf("+=======+==================+============+=============="
|
||||
|
||||
@@ -388,12 +388,12 @@ typedef struct {
|
||||
amdsmi_process_handle pid;
|
||||
uint64_t mem; /** in bytes */
|
||||
struct {
|
||||
uint16_t gfx[AMDSMI_MAX_MM_IP_COUNT];
|
||||
uint16_t compute[AMDSMI_MAX_MM_IP_COUNT];
|
||||
uint16_t sdma[AMDSMI_MAX_MM_IP_COUNT];
|
||||
uint16_t enc[AMDSMI_MAX_MM_IP_COUNT];
|
||||
uint16_t dec[AMDSMI_MAX_MM_IP_COUNT];
|
||||
} engine_usage; /** percentage 0-100% times 100 */
|
||||
uint64_t gfx;
|
||||
uint64_t compute;
|
||||
uint64_t dma;
|
||||
uint64_t enc;
|
||||
uint64_t dec;
|
||||
} engine_usage; /** How much time the process spend using these engines in ns */
|
||||
struct {
|
||||
uint64_t gtt_mem;
|
||||
uint64_t cpu_mem;
|
||||
@@ -3825,6 +3825,7 @@ amdsmi_get_process_list(amdsmi_device_handle device_handle, amdsmi_process_handl
|
||||
|
||||
/**
|
||||
* @brief Returns the process information of a given process.
|
||||
* Engine usage show how much time the process spend using these engines in ns.
|
||||
*
|
||||
* @param[in] device_handle Device which to query
|
||||
*
|
||||
|
||||
@@ -846,7 +846,7 @@ Field | Description
|
||||
`name` | Name of process
|
||||
`pid` | Process ID
|
||||
`mem` | Process memory usage
|
||||
`engine_usage`| <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gfx`</td><td>GFX engine usage</td></tr><tr><td>`compute`</td><td>Compute engine usage</td></tr><tr><td>`sdma`</td><td>DMA engine usage</td></tr><tr><td>`enc`</td><td>Encode engine usage</td></tr><tr><td>`dec`</td><td>Decode engine usage</td></tr></tbody></table>
|
||||
`engine_usage`| <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gfx`</td><td>GFX engine usage in ns</td></tr><tr><td>`compute`</td><td>Compute engine usage in ns</td></tr><tr><td>`dma`</td><td>DMA engine usage in ns </td></tr><tr><td>`enc`</td><td>Encode engine usage in ns</td></tr><tr><td>`dec`</td><td>Decode engine usage in ns</td></tr></tbody></table>
|
||||
`memory_usage`| <table><thead><tr> <th> Subfield </th> <th> Description</th> </tr></thead><tbody><tr><td>`gtt_mem`</td><td>GTT memory usage</td></tr><tr><td>`cpu_mem`</td><td>CPU memory usage</td></tr><tr><td>`vram_mem`</td><td>VRAM memory usage</td></tr> </tbody></table>
|
||||
|
||||
Exceptions that can be thrown by `amdsmi_get_process_info` function:
|
||||
|
||||
@@ -916,11 +916,11 @@ def amdsmi_get_process_info(
|
||||
"pid": info.pid,
|
||||
"mem": info.mem,
|
||||
"engine_usage": {
|
||||
"gfx": list(info.engine_usage.gfx),
|
||||
"compute": list(info.engine_usage.compute),
|
||||
"sdma": list(info.engine_usage.sdma),
|
||||
"enc": list(info.engine_usage.enc),
|
||||
"dec": list(info.engine_usage.dec),
|
||||
"gfx": info.engine_usage.gfx,
|
||||
"compute": info.engine_usage.compute,
|
||||
"dma": info.engine_usage.dma,
|
||||
"enc": info.engine_usage.enc,
|
||||
"dec": info.engine_usage.dec,
|
||||
},
|
||||
"memory_usage": {
|
||||
"gtt_mem": info.memory_usage.gtt_mem,
|
||||
|
||||
@@ -697,6 +697,18 @@ amdsmi_process_handle = ctypes.c_uint32
|
||||
class struct_c__SA_amdsmi_proc_info_t(Structure):
|
||||
pass
|
||||
|
||||
class struct_c__SA_amdsmi_proc_info_t_0(Structure):
|
||||
pass
|
||||
|
||||
struct_c__SA_amdsmi_proc_info_t_0._pack_ = 1 # source:False
|
||||
struct_c__SA_amdsmi_proc_info_t_0._fields_ = [
|
||||
('gfx', ctypes.c_uint64),
|
||||
('compute', ctypes.c_uint64),
|
||||
('dma', ctypes.c_uint64),
|
||||
('enc', ctypes.c_uint64),
|
||||
('dec', ctypes.c_uint64),
|
||||
]
|
||||
|
||||
class struct_c__SA_amdsmi_proc_info_t_1(Structure):
|
||||
pass
|
||||
|
||||
@@ -707,18 +719,6 @@ struct_c__SA_amdsmi_proc_info_t_1._fields_ = [
|
||||
('vram_mem', ctypes.c_uint64),
|
||||
]
|
||||
|
||||
class struct_c__SA_amdsmi_proc_info_t_0(Structure):
|
||||
pass
|
||||
|
||||
struct_c__SA_amdsmi_proc_info_t_0._pack_ = 1 # source:False
|
||||
struct_c__SA_amdsmi_proc_info_t_0._fields_ = [
|
||||
('gfx', ctypes.c_uint16 * 8),
|
||||
('compute', ctypes.c_uint16 * 8),
|
||||
('sdma', ctypes.c_uint16 * 8),
|
||||
('enc', ctypes.c_uint16 * 8),
|
||||
('dec', ctypes.c_uint16 * 8),
|
||||
]
|
||||
|
||||
struct_c__SA_amdsmi_proc_info_t._pack_ = 1 # source:False
|
||||
struct_c__SA_amdsmi_proc_info_t._fields_ = [
|
||||
('name', ctypes.c_char * 32),
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
static const char *container_type_name[AMDSMI_MAX_CONTAINER_TYPE] = {
|
||||
[CONTAINER_LXC] = "lxc",
|
||||
[CONTAINER_DOCKER] = "docker",
|
||||
};
|
||||
|
||||
amdsmi_status_t gpuvsmi_pid_is_gpu(const std::string &path, const char *bdf)
|
||||
{
|
||||
DIR *d;
|
||||
@@ -155,85 +160,65 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid,
|
||||
|
||||
if (it == pasids.end())
|
||||
pasids.push_back(pasid);
|
||||
} else if (line.find("gtt mem:") != std::string::npos) {
|
||||
} else if (line.find("drm-memory-gtt:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
|
||||
if (sscanf(line.c_str(), "gtt mem: %lu", &mem) != 1)
|
||||
if (sscanf(line.c_str(), "drm-memory-gtt: %lu", &mem) != 1)
|
||||
continue;
|
||||
|
||||
info.mem += mem * 1024;
|
||||
info.memory_usage.gtt_mem += mem * 1024;
|
||||
} else if (line.find("cpu mem:") != std::string::npos) {
|
||||
} else if (line.find("drm-memory-cpu:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
|
||||
if (sscanf(line.c_str(), "cpu mem: %lu", &mem) != 1)
|
||||
if (sscanf(line.c_str(), "drm-memory-cpu: %lu", &mem) != 1)
|
||||
continue;
|
||||
|
||||
info.mem += mem * 1024;
|
||||
info.memory_usage.cpu_mem += mem * 1024;
|
||||
} else if (line.find("vram mem:") != std::string::npos) {
|
||||
} else if (line.find("drm-memory-vram:") != std::string::npos) {
|
||||
unsigned long mem;
|
||||
|
||||
if (sscanf(line.c_str(), "vram mem: %lu", &mem) != 1)
|
||||
if (sscanf(line.c_str(), "drm-memory-vram: %lu", &mem) != 1)
|
||||
continue;
|
||||
|
||||
info.mem += mem * 1024;
|
||||
info.memory_usage.vram_mem += mem * 1024;
|
||||
} else if (line.find("gfx") != std::string::npos) {
|
||||
float usage;
|
||||
int ring;
|
||||
} else if (line.find("drm-engine-gfx") != std::string::npos) {
|
||||
uint64_t engine_gfx;
|
||||
|
||||
if (sscanf(line.c_str(), "gfx%d: %f%%", &ring, &usage) != 2)
|
||||
if (sscanf(line.c_str(), "drm-engine-gfx: %lu", &engine_gfx) != 1)
|
||||
continue;
|
||||
|
||||
if (ring >= AMDSMI_MAX_MM_IP_COUNT)
|
||||
info.engine_usage.gfx = engine_gfx;
|
||||
} else if (line.find("drm-engine-compute") != std::string::npos) {
|
||||
uint64_t engine_compute;
|
||||
|
||||
if (sscanf(line.c_str(), "drm-engine-compute: %lu", &engine_compute) != 1)
|
||||
continue;
|
||||
|
||||
info.engine_usage.gfx[ring] += (uint16_t)(usage * 100);
|
||||
} else if (line.find("compute") != std::string::npos) {
|
||||
float usage;
|
||||
int ring;
|
||||
info.engine_usage.compute = engine_compute;
|
||||
} else if (line.find("drm-engine-dma") != std::string::npos) {
|
||||
uint64_t engine_dma;
|
||||
|
||||
if (sscanf(line.c_str(), "compute%d: %f%%", &ring, &usage) != 2)
|
||||
if (sscanf(line.c_str(), "drm-engine-dma: %lu", &engine_dma) != 1)
|
||||
continue;
|
||||
|
||||
if (ring >= AMDSMI_MAX_MM_IP_COUNT)
|
||||
info.engine_usage.dma = engine_dma;
|
||||
} else if (line.find("drm-engine-enc") != std::string::npos) {
|
||||
uint64_t engine_enc;
|
||||
|
||||
if (sscanf(line.c_str(), "drm-engine-enc: %lu", &engine_enc) != 1)
|
||||
continue;
|
||||
|
||||
info.engine_usage.compute[ring] += (uint16_t)(usage * 100);
|
||||
} else if (line.find("dma") != std::string::npos) {
|
||||
float usage;
|
||||
int ring;
|
||||
info.engine_usage.enc = engine_enc;
|
||||
} else if (line.find("drm-engine-dec") != std::string::npos) {
|
||||
uint64_t engine_dec;
|
||||
|
||||
if (sscanf(line.c_str(), "dma%d: %f%%", &ring, &usage) != 2)
|
||||
if (sscanf(line.c_str(), "drm-engine-dec: %lu", &engine_dec) != 1)
|
||||
continue;
|
||||
|
||||
if (ring >= AMDSMI_MAX_MM_IP_COUNT)
|
||||
continue;
|
||||
|
||||
info.engine_usage.sdma[ring] += (uint16_t)(usage * 100);
|
||||
} else if (line.find("enc") != std::string::npos) {
|
||||
float usage;
|
||||
int ring;
|
||||
|
||||
if (sscanf(line.c_str(), "enc%d: %f%%", &ring, &usage) != 2)
|
||||
continue;
|
||||
|
||||
if (ring >= AMDSMI_MAX_MM_IP_COUNT)
|
||||
continue;
|
||||
|
||||
info.engine_usage.enc[ring] += (uint16_t)(usage * 100);
|
||||
} else if (line.find("dec") != std::string::npos) {
|
||||
float usage;
|
||||
int ring;
|
||||
|
||||
if (sscanf(line.c_str(), "dec%d: %f%%", &ring, &usage) != 2)
|
||||
continue;
|
||||
|
||||
if (ring >= AMDSMI_MAX_MM_IP_COUNT)
|
||||
continue;
|
||||
|
||||
info.engine_usage.dec[ring] += (uint16_t)(usage * 100);
|
||||
info.engine_usage.dec = engine_dec;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,9 +241,25 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid,
|
||||
(unsigned long) AMDSMI_NORMAL_STRING_LENGTH,
|
||||
name.length()));
|
||||
|
||||
for (int i = 0; i < AMDSMI_MAX_CONTAINER_TYPE; i++) {
|
||||
std::ifstream cgroup_info(cgroup_path.c_str());
|
||||
std::string container_id;
|
||||
for (std::string line; getline(cgroup_info, line);) {
|
||||
if (line.find(container_type_name[i]) != std::string::npos) {
|
||||
container_id = line.substr(line.find(container_type_name[i]) +
|
||||
strlen(container_type_name[i]) + 1, 16);
|
||||
strcpy(info.container_name, container_id.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (strlen(info.container_name) > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
info.pid = (uint32_t)pid;
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Ссылка в новой задаче
Block a user