From 431fa8b190d874aa219bd9d210071700c708131f Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Fri, 20 Jan 2023 10:54:01 +0100 Subject: [PATCH 1/6] SWDEV-373295 - Added power_limit field in python api Change-Id: Ie81e78eb9930fb0d8132ee9f119e291afbcad84f Signed-off-by: Dalibor Stanisavljevic [ROCm/amdsmi commit: a926f4259972861875aeabe8544d0cc651036ee4] --- projects/amdsmi/py-interface/README.md | 2 ++ projects/amdsmi/py-interface/amdsmi_interface.py | 1 + 2 files changed, 3 insertions(+) diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index 1e7b1dbdab..bbc2e355e5 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -518,6 +518,7 @@ Field | Description `average_socket_power`| average socket power `voltage_gfx` | voltage gfx `energy_accumulator` | energy accumulator +`power_limit` | power limit Exceptions that can be thrown by `amdsmi_get_power_measure` function: * `AmdSmiLibraryException` @@ -536,6 +537,7 @@ try: print(power_measure['average_socket_power']) print(power_measure['voltage_gfx']) print(power_measure['energy_accumulator']) + print(power_measure['power_limit']) except AmdSmiException as e: print(e) ``` diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 14f26a7617..dc23c09a69 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -991,6 +991,7 @@ def amdsmi_get_power_measure( "average_socket_power": power_measure.average_socket_power, "voltage_gfx": power_measure.voltage_gfx, "energy_accumulator": power_measure.energy_accumulator, + "power_limit" : power_measure.power_limit, } From 90eec28e011260cb2540991f7429aa472fe45947 Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Thu, 19 Jan 2023 13:33:23 +0100 Subject: [PATCH 2/6] SWDEV-373282 - Fixed compiler warnings Signed-off-by: Dalibor Stanisavljevic Change-Id: Ieacf1057ad23f9a31d47a6d1199c90d8fa0d12db [ROCm/amdsmi commit: cf7a92f38301cc8081b0aba3e9c8275ffa30b475] --- .../amdsmi/example/amd_smi_drm_example.cc | 20 +++++++++---------- .../amdsmi/example/amd_smi_nodrm_example.cc | 12 +++++------ projects/amdsmi/src/amd_smi/amd_smi.cc | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 69d9ef12b0..ab36bf6604 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -271,7 +271,7 @@ int main() { ret = amdsmi_get_device_bdf(device_handles[j], &bdf); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_device_bdf:\n"); - printf("\tDevice[%d] BDF %04x:%02x:%02x.%d\n\n", i, + printf("\tDevice[%d] BDF %04lx:%02x:%02x.%d\n\n", i, bdf.domain_number, bdf.bus_number, bdf.device_number, bdf.function_number); @@ -313,7 +313,7 @@ int main() { power_measure.voltage_gfx); printf("\tAverage socket power: %d\n", power_measure.average_socket_power); - printf("\tEnergy accumulator: %d\n\n", + printf("\tEnergy accumulator: %ld\n\n", power_measure.energy_accumulator); printf("\tGPU Power limit: %d\n\n", power_measure.power_limit); @@ -354,7 +354,7 @@ int main() { printf("Number of Microcodes: %d\n", fw_information.num_fw_info); for (int j = 0; j < fw_information.num_fw_info; j++) { getFWNameFromId(fw_information.fw_info_list[j].fw_id, ucode_name); - printf(" %s: %d\n", ucode_name, fw_information.fw_info_list[j].fw_version); + printf(" %s: %ld\n", ucode_name, fw_information.fw_info_list[j].fw_version); } // Get GFX clock measurements @@ -399,14 +399,14 @@ int main() { AMDSMI_TEMP_CRITICAL, &temperature); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_dev_get_temp_metric:\n"); - printf("\tGPU VRAM temp limit: %d\n", temperature); + printf("\tGPU VRAM temp limit: %ld\n", temperature); // Get GFX temperature limit ret = amdsmi_dev_get_temp_metric( device_handles[j], TEMPERATURE_TYPE_EDGE, AMDSMI_TEMP_CRITICAL, &temperature); CHK_AMDSMI_RET(ret) - printf("\tGPU GFX temp limit: %d\n\n", temperature); + printf("\tGPU GFX temp limit: %ld\n\n", temperature); // Get temperature measurements // amdsmi_temperature_t edge_temp, junction_temp, vram_temp, @@ -423,13 +423,13 @@ int main() { CHK_AMDSMI_RET(ret) } printf(" Output of amdsmi_dev_get_temp_metric:\n"); - printf("\tGPU Edge temp measurement: %d\n", + printf("\tGPU Edge temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_EDGE]); - printf("\tGPU Junction temp measurement: %d\n", + printf("\tGPU Junction temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_JUNCTION]); - printf("\tGPU VRAM temp measurement: %d\n", + printf("\tGPU VRAM temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_VRAM]); - printf("\tGPU PLX temp measurement: %d\n\n", + printf("\tGPU PLX temp measurement: %ld\n\n", temp_measurements[TEMPERATURE_TYPE_PLX]); // Get RAS features enabled @@ -535,7 +535,7 @@ int main() { uint64_t mem = 0, gtt_mem = 0, cpu_mem = 0, vram_mem = 0; float gfx = 0, comp = 0, dma = 0, enc = 0, dec = 0; char bdf_str[20]; - sprintf(bdf_str, "%04x:%02x:%02x.%d", bdf.domain_number, + sprintf(bdf_str, "%04lx:%02x:%02x.%d", bdf.domain_number, bdf.bus_number, bdf.device_number, bdf.function_number); int num = 0; ret = amdsmi_get_process_list(device_handles[j], process_list, diff --git a/projects/amdsmi/example/amd_smi_nodrm_example.cc b/projects/amdsmi/example/amd_smi_nodrm_example.cc index 516dfa2e29..3f7cfadec0 100644 --- a/projects/amdsmi/example/amd_smi_nodrm_example.cc +++ b/projects/amdsmi/example/amd_smi_nodrm_example.cc @@ -122,7 +122,7 @@ int main() { ret = amdsmi_get_device_bdf(device_handles[j], &bdf); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_device_bdf:\n"); - printf("\tDevice[%d] BDF %04x:%02x:%02x.%d\n\n", i, + printf("\tDevice[%d] BDF %04lx:%02x:%02x.%d\n\n", i, bdf.domain_number, bdf.bus_number, bdf.device_number, bdf.function_number); @@ -132,7 +132,7 @@ int main() { printf(" Output of amdsmi_get_asic_info:\n"); printf("\tMarket Name: %s\n", asic_info.market_name); printf("\tFamilyID: 0x%x\n", asic_info.family); - printf("\tDeviceID: 0x%x\n", asic_info.device_id); + printf("\tDeviceID: 0x%lx\n", asic_info.device_id); printf("\tVendorID: 0x%x\n", asic_info.vendor_id); printf("\tRevisionID: 0x%x\n", asic_info.rev_id); printf("\tAsic serial: 0x%s\n\n", asic_info.asic_serial); @@ -233,13 +233,13 @@ int main() { CHK_AMDSMI_RET(ret) } printf(" Output of amdsmi_dev_get_temp_metric:\n"); - printf("\tGPU Edge temp measurement: %d\n", + printf("\tGPU Edge temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_EDGE]); - printf("\tGPU Junction temp measurement: %d\n", + printf("\tGPU Junction temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_JUNCTION]); - printf("\tGPU VRAM temp measurement: %d\n", + printf("\tGPU VRAM temp measurement: %ld\n", temp_measurements[TEMPERATURE_TYPE_VRAM]); - printf("\tGPU PLX temp measurement: %d\n\n", + printf("\tGPU PLX temp measurement: %ld\n\n", temp_measurements[TEMPERATURE_TYPE_PLX]); // Get bad pages diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 22e1681107..629ea5e988 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -588,7 +588,7 @@ amdsmi_get_asic_info(amdsmi_device_handle device_handle, amdsmi_asic_info_t *inf std::string path = "/sys/class/drm/" + gpu_device->get_gpu_path() + "/device/unique_id"; FILE *fp = fopen(path.c_str(), "r"); if (fp) { - fscanf(fp, "%s", &info->asic_serial); + fscanf(fp, "%s", info->asic_serial); fclose(fp); } @@ -1945,7 +1945,7 @@ amdsmi_status_t amdsmi_get_device_handle_from_bdf(amdsmi_bdf_t bdf, return status; } - for (auto idx = 0; idx < device_count; idx++) { + for (uint32_t idx = 0; idx < device_count; idx++) { amd::smi::AMDSmiGPUDevice* gpu_device = nullptr; status = get_gpu_device_from_handle(devs[idx], &gpu_device); if (status != AMDSMI_STATUS_SUCCESS) { From b23d1daf4988d9354c5274579ae2dbc471e901d0 Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Mon, 9 Jan 2023 15:50:00 +0100 Subject: [PATCH 3/6] SWDEV-375113 - Fixed process info The format of the fdinfo file has changed Change-Id: Iad2e26487e75f3e614e364456e929aa1f6f949a4 Signed-off-by: Dalibor Stanisavljevic [ROCm/amdsmi commit: 411ef540875f1f04dfbfae482e65777510eaca41] --- .../amdsmi/example/amd_smi_drm_example.cc | 55 +++++------ projects/amdsmi/include/amd_smi/amdsmi.h | 13 +-- projects/amdsmi/py-interface/README.md | 2 +- .../amdsmi/py-interface/amdsmi_interface.py | 10 +- .../amdsmi/py-interface/amdsmi_wrapper.py | 24 ++--- projects/amdsmi/src/amd_smi/fdinfo.cc | 97 ++++++++++--------- 6 files changed, 97 insertions(+), 104 deletions(-) diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index ab36bf6604..47857aa72a 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -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("+=======+==================+============+==============" diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index bed3b74360..3fb22f21e5 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -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 * diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index bbc2e355e5..e02eb3b1a1 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -846,7 +846,7 @@ Field | Description `name` | Name of process `pid` | Process ID `mem` | Process memory usage -`engine_usage`|
Subfield Description
`gfx`GFX engine usage
`compute`Compute engine usage
`sdma`DMA engine usage
`enc`Encode engine usage
`dec`Decode engine usage
+`engine_usage`|
Subfield Description
`gfx`GFX engine usage in ns
`compute`Compute engine usage in ns
`dma`DMA engine usage in ns
`enc`Encode engine usage in ns
`dec`Decode engine usage in ns
`memory_usage`|
Subfield Description
`gtt_mem`GTT memory usage
`cpu_mem`CPU memory usage
`vram_mem`VRAM memory usage
Exceptions that can be thrown by `amdsmi_get_process_info` function: diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index dc23c09a69..3f99be9fef 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -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, diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 6e88431c22..48027f84aa 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -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), diff --git a/projects/amdsmi/src/amd_smi/fdinfo.cc b/projects/amdsmi/src/amd_smi/fdinfo.cc index 03e00012ca..0876e7990a 100644 --- a/projects/amdsmi/src/amd_smi/fdinfo.cc +++ b/projects/amdsmi/src/amd_smi/fdinfo.cc @@ -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" From c121d6f631e618bd09284cdcf357cad3816a7ff2 Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Wed, 25 Jan 2023 14:21:17 +0100 Subject: [PATCH 4/6] SWDEV-373295 - Updated python interface Change-Id: I882179d97a4f522deb0e8b9cdbff85d9b23471ab Signed-off-by: Dalibor Stanisavljevic [ROCm/amdsmi commit: 08bcaee3e23158a52a43c114c018dca7bcbc754b] --- projects/amdsmi/py-interface/amdsmi_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 3f99be9fef..19eb3b72e5 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -839,7 +839,7 @@ def amdsmi_get_ras_block_features_enabled( ras_state = amdsmi_wrapper.amdsmi_ras_err_state_t() ras_states = [] - for key, gpu_block in amdsmi_wrapper.amdsmi_gpu_block__enumvalues.items(): + for key, gpu_block in amdsmi_wrapper.amdsmi_gpu_block_t__enumvalues.items(): if gpu_block == "AMDSMI_GPU_BLOCK_RESERVED": continue if gpu_block == "AMDSMI_GPU_BLOCK_LAST": From 1a7d00f665d85c0ea1d30922c56d96924ce2a3ee Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Wed, 28 Dec 2022 15:46:29 +0100 Subject: [PATCH 5/6] SWDEV-375213 - Separate smi from rocm part inside functions Change-Id: I81d2e9d02794ac017a74b3273c6f5a8c85b042a0 Signed-off-by: Dalibor Stanisavljevic [ROCm/amdsmi commit: ff553cdb567cdd675cd48e0c56d8a6e379bb42d9] --- projects/amdsmi/src/amd_smi/amd_smi.cc | 58 ++++++++++++++------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 629ea5e988..0604735011 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -300,17 +300,20 @@ amdsmi_status_t amdsmi_get_board_info(amdsmi_device_handle device_handle, amdsmi if (r != AMDSMI_STATUS_SUCCESS) return r; - // Get from sys file - status = smi_amdgpu_get_board_info(gpu_device, board_info); + if (gpu_device->check_if_drm_is_supported()) { + // Get from sys file + status = smi_amdgpu_get_board_info(gpu_device, board_info); + } + else { + // ignore the errors so that it can populate as many fields as possible. + // call rocm-smi which search multiple places for device name + status = rsmi_wrapper(rsmi_dev_name_get, device_handle, + board_info->product_name, AMDSMI_PRODUCT_NAME_LENGTH); - // ignore the errors so that it can populate as many fields as possible. - // call rocm-smi which search multiple places for device name - status = rsmi_wrapper(rsmi_dev_name_get, device_handle, - board_info->product_name, AMDSMI_PRODUCT_NAME_LENGTH); - - if (board_info->product_serial[0] == '\0') { - status = rsmi_wrapper(rsmi_dev_serial_number_get, device_handle, - board_info->product_serial, AMDSMI_NORMAL_STRING_LENGTH); + if (board_info->product_serial[0] == '\0') { + status = rsmi_wrapper(rsmi_dev_serial_number_get, device_handle, + board_info->product_serial, AMDSMI_NORMAL_STRING_LENGTH); + } } return AMDSMI_STATUS_SUCCESS; @@ -1079,23 +1082,26 @@ amdsmi_get_power_cap_info(amdsmi_device_handle device_handle, // Ignore errors to get as much as possible info. memset(info, 0, sizeof(amdsmi_power_cap_info_t)); - // Get power_cap and dpm - int power_cap = 0; - int dpm = 0; - status = smi_amdgpu_get_power_cap(gpudevice, &power_cap); + if (gpu_device->check_if_drm_is_supported()) { + // Get power_cap and dpm + int power_cap = 0; + int dpm = 0; + status = smi_amdgpu_get_power_cap(gpudevice, &power_cap); - info->power_cap = power_cap; - status = smi_amdgpu_get_ranges(gpudevice, CLK_TYPE_GFX, - NULL, NULL, &dpm); - info->dpm_cap = dpm; - - // Get other information from rocm-smi - auto rsmi_status = rsmi_dev_power_cap_default_get(gpudevice->get_gpu_id(), - &(info->default_power_cap)); - rsmi_status = rsmi_dev_power_cap_range_get(gpudevice->get_gpu_id(), - sensor_ind, &(info->max_power_cap), &(info->min_power_cap)); - rsmi_status = rsmi_dev_power_cap_get(gpudevice->get_gpu_id(), - sensor_ind, &(info->power_cap)); + info->power_cap = power_cap; + status = smi_amdgpu_get_ranges(gpudevice, CLK_TYPE_GFX, + NULL, NULL, &dpm); + info->dpm_cap = dpm; + } + else { + // Get other information from rocm-smi + auto rsmi_status = rsmi_dev_power_cap_default_get(gpudevice->get_gpu_id(), + &(info->default_power_cap)); + rsmi_status = rsmi_dev_power_cap_range_get(gpudevice->get_gpu_id(), + sensor_ind, &(info->max_power_cap), &(info->min_power_cap)); + rsmi_status = rsmi_dev_power_cap_get(gpudevice->get_gpu_id(), + sensor_ind, &(info->power_cap)); + } return AMDSMI_STATUS_SUCCESS; } From 56dec0a4d2aff4144c6750c62f86ea596c74b9d8 Mon Sep 17 00:00:00 2001 From: Dalibor Stanisavljevic Date: Thu, 26 Jan 2023 14:10:10 +0100 Subject: [PATCH 6/6] SWDEV-375213 - Renamed gpu_device to gpudevice for amdsmi_get_power_cap_info Change-Id: I8518587f35e4ce897317a09505435eee7a8f81f8 Signed-off-by: Dalibor Stanisavljevic [ROCm/amdsmi commit: c469c3d505483a78bc0dceaca6e8e4ea9a7ff1b5] --- projects/amdsmi/src/amd_smi/amd_smi.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 0604735011..be05374118 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -1082,7 +1082,7 @@ amdsmi_get_power_cap_info(amdsmi_device_handle device_handle, // Ignore errors to get as much as possible info. memset(info, 0, sizeof(amdsmi_power_cap_info_t)); - if (gpu_device->check_if_drm_is_supported()) { + if (gpudevice->check_if_drm_is_supported()) { // Get power_cap and dpm int power_cap = 0; int dpm = 0;