29 #if __linux__ || __APPLE__
47 #define MAX_DEVICE_NAME_SIZE (9)
48 #define ABSOLUTE_TEMP_ZERO (-273)
63 #include <cutils/properties.h>
64 #define PROP_DECODER_TYPE "nidec_service_init"
65 #define LOG_TAG "ni_rsrc_mon"
82 static BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
116 void sig_handler(
int sig)
118 if (sig == SIGTERM || sig == SIGINT || sig == SIGHUP)
131 void setup_signal_handler(
void)
133 if (signal(SIGTERM, sig_handler) == SIG_ERR ||
134 signal(SIGHUP, sig_handler) == SIG_ERR ||
135 signal(SIGINT, sig_handler) == SIG_ERR)
137 perror(
"ERROR: signal handler setup");
148 void get_pcie_addr(
char *device_name,
char *pcie)
160 int get_numa_node(
char *device_name)
166 char cmd_ret[64] = {0};
172 ptr = device_name + 5;
173 snprintf(cmd,
sizeof(cmd) - 1,
"cat /sys/block/%s/device/*/numa_node",ptr);
174 cmd_fp = popen(cmd,
"r");
179 if (fgets(cmd_ret,
sizeof(cmd_ret)/
sizeof(cmd_ret[0]), cmd_fp) == 0)
181 goto get_numa_node_ret;
204 ni_device_handle_t device_handle)
208 fprintf(stderr,
"Error: device_type %d is not a valid device type\n",
213 if (
device_handles[xcoder_device_type][module_id] == device_handle)
216 NI_INVALID_DEVICE_HANDLE;
221 "Error: device_handle to remove %d"
222 "not match device_handles[%d][%d]=%d\n",
223 device_handle, device_type, module_id,
245 const size_t len = strlen(numArray);
247 for (i = 0; i < len; i++)
249 if (!isdigit(numArray[i]))
251 fprintf(stderr,
"invalid, ABORTING\n");
256 return len == i ?
atoi(numArray) : 0;
269 if ( *(int32_t*)a < *(int32_t*)b )
return -1;
270 if ( *(int32_t*)a > *(int32_t*)b )
return 1;
281 else if ((index >= 0 && index < 4) || (index >= 10 && index < 13))
285 else if (index >= 4 && index < 10)
289 else if (index >= 13 && index < 15)
298 static char sid[5] =
"0000";
304 snprintf(sid,
sizeof(sid),
"%04x", 0);
309 snprintf(sid,
sizeof(sid),
"%04x",
id);
317 int32_t **module_ids)
319 unsigned int device_count;
322 size_of_i32 =
sizeof(int32_t);
324 device_count = p_device_queue->
xcoder_cnt[device_type];
325 *module_ids = malloc(size_of_i32 * device_count);
328 fprintf(stderr,
"ERROR: malloc() failed for module_ids\n");
333 p_device_queue->
xcoders[device_type],
334 size_of_i32 * device_count);
342 g_device_type_str[device_type],
355 if (!p_device_context)
363 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
372 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
379 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
382 "ERROR: ni_device_open() failed for %s: %s\n",
391 p_session_context->
hw_id =
400 "ERROR: cannot print detailed info for %s as it has FW API "
423 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
440 memcpy(p_session_context->
fw_rev,
453 if (!p_device_context)
459 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
462 "ERROR: ni_device_open() failed for %s: %s\n",
470 p_session_context->
hw_id =
474 return return_code ? false :
true;
480 unsigned int module_count;
481 int32_t *module_id_arr = NULL;
486 module_count =
get_modules(module_type, coders, module_name, &module_id_arr);
488 printf(
"Error: module not found!\n");
492 bool gen_log_file =
true;
494 void* p_log_buffer = NULL;
495 if (devid >= 0 && devid < module_count)
501 if (!
open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
502 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n",
505 printf(
"Success: dumped fw log of card:%d blk_name:%s\n",
515 for (i = 0; i < module_count; i++)
518 if (!
open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
519 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n",
523 printf(
"Success: dumped fw log of card:%d blk_name:%s\n",
538 switch (*p_device_type)
542 strcpy(device_name,
"uploader");
551 #define DYN_STR_BUF_CHUNK_SIZE 4096
573 int add_buf_size = 0;
574 char *tmp_char_ptr = NULL;
578 fprintf(stderr,
"ERROR: invalid param *dyn_str_buf\n");
592 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
597 add_buf_size = (formatted_len + 1) > avail_buf ?
611 fprintf(stderr,
"ERROR: strcat_dyn_buf() failed realloc()\n");
637 unsigned int index, device_count;
659 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", device_name, device_count);
665 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
666 "DEVICE L_FL2V N_FL2V FR N_FR\n");
671 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
672 "DEVICE L_FL2V N_FL2V FR N_FR\n");
676 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
677 "DEVICE L_FL2V N_FL2V FR N_FR\n");
681 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
682 "DEVICE L_FL2V N_FL2V FR N_FR\n");
688 for (index = 0; index < device_count; index++)
696 device_name, detail, detail_data_v1))
705 "%-5d %-3u %-3u %-3u %-3u/%-3d %-3u %-3u "
706 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
725 "%-5d %-3u %-3u %-3u/%-3d %-3u "
726 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
742 "%-5d %-3u %-3u %-3u %-3u/%-3d %-3u %-3u "
743 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
762 "%-5d %-3u %-3u/%-3d %-3u "
763 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
810 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
813 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
816 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
819 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
825 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
831 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
844 "INDEX LOAD( FW ) PCIE_THROUGHPUT GBps "
845 "DEVICE L_FL2V N_FL2V FR N_FR\n");
850 "INDEX LOAD( FW ) MEM( SHARE ) "
851 "DEVICE L_FL2V N_FL2V FR N_FR\n");
856 printf(
"%s", output_buf.
str_buf);
865 for (index = 0; index < device_count; index++)
874 device_name, detail, detail_data_v1))
883 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
906 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
923 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
947 printf(
"%s", output_buf.
str_buf);
954 bool copied_block_name;
958 unsigned int number_of_quadras;
959 unsigned int number_of_device_types_present;
960 unsigned int device_type_counter;
961 unsigned int *maximum_firmware_loads;
962 unsigned int *maximum_firmware_loads_per_quadra;
976 maximum_firmware_loads = calloc(number_of_quadras,
sizeof(
unsigned int));
977 if (!maximum_firmware_loads)
979 fprintf(stderr,
"calloc() returned NULL\n");
983 maximum_firmware_loads_per_quadra = NULL;
984 p_device_context = NULL;
986 for (guid = 0; guid < number_of_quadras; guid++)
989 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
990 number_of_device_types_present = 0;
991 device_type_counter = 0;
992 copied_block_name =
false;
995 device_type < maximum_device_type;
998 if (p_device_queue->
xcoders[device_type][guid] != -1)
1000 number_of_device_types_present++;
1005 device_type < maximum_device_type;
1009 g_device_type_str[device_type],
1012 if (p_device_queue->
xcoders[device_type][guid] == -1)
1019 p_device_queue->
xcoders[device_type][guid]);
1023 device_name, detail, detail_data_v1))
1034 "%s: Simple output not supported. Try '-o full' "
1044 if (!copied_block_name)
1049 copied_block_name =
true;
1052 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.
fw_load)
1057 device_type_counter++;
1058 if (device_type_counter < number_of_device_types_present)
1079 if (*maximum_firmware_loads_per_quadra < load_query.
fw_load)
1081 *maximum_firmware_loads_per_quadra = load_query.
fw_load;
1083 if (*maximum_firmware_loads_per_quadra < load_query.
tp_fw_load)
1085 *maximum_firmware_loads_per_quadra = load_query.
tp_fw_load;
1088 *maximum_firmware_loads_per_quadra);
1093 stderr,
"ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1107 printf(
"%s", output_buf.
str_buf);
1109 free(maximum_firmware_loads);
1115 unsigned int index, device_count;
1117 int32_t *module_ids;
1125 int first_item_printed = 0;
1126 int first_device_type_printed = 0;
1131 device_type != max_device_type;
1144 for (index = 0; index < device_count; index++)
1152 device_name, detail, detail_data_v1))
1157 if(first_device_type_printed)
1167 first_item_printed = 0;
1172 if(first_item_printed)
1181 "\t\t\t\"NUMBER\": %u,\n"
1182 "\t\t\t\"INDEX\": %u,\n"
1183 "\t\t\t\"AvgCost\": %u,\n"
1184 "\t\t\t\"FrameRate\": %u,\n"
1185 "\t\t\t\"IDR\": %u,\n"
1186 "\t\t\t\"InFrame\": %u,\n"
1187 "\t\t\t\"OutFrame\": %u,\n"
1188 "\t\t\t\"Width\": %u,\n"
1189 "\t\t\t\"Height\": %u,\n"
1190 "\t\t\t\"SID\": \"%s\",\n"
1191 "\t\t\t\"DEVICE\": \"%s\"\n"
1209 "\t\t\t\"NUMBER\": %u,\n"
1210 "\t\t\t\"INDEX\": %u,\n"
1211 "\t\t\t\"AvgCost\": %u,\n"
1212 "\t\t\t\"FrameRate\": %u,\n"
1213 "\t\t\t\"IDR\": %u,\n"
1214 "\t\t\t\"UserIDR\": %u,\n"
1215 "\t\t\t\"InFrame\": %u,\n"
1216 "\t\t\t\"OutFrame\": %u,\n"
1217 "\t\t\t\"BR\": %u,\n"
1218 "\t\t\t\"AvgBR\": %u,\n"
1219 "\t\t\t\"Width\": %u,\n"
1220 "\t\t\t\"Height\": %u,\n"
1221 "\t\t\t\"Format\": \"%s\",\n"
1222 "\t\t\t\"SID\": \"%s\",\n"
1223 "\t\t\t\"DEVICE\": \"%s\"\n"
1241 first_item_printed = 1;
1248 first_device_type_printed = 1;
1257 printf(
"%s", output_buf.
str_buf);
1268 unsigned int index, device_count;
1270 int32_t *module_ids;
1271 uint32_t total_contexts;
1273 uint32_t model_load;
1275 char pcie[64] = {0};
1289 device_type != max_device_type;
1303 for (index = 0; index < device_count; index++)
1311 device_name, detail, detail_data_v1))
1348 "\t\t\t\"NUMBER\": %u,\n"
1349 "\t\t\t\"INDEX\": %u,\n"
1350 "\t\t\t\"AvgCost\": %u,\n"
1351 "\t\t\t\"FrameRate\": %u,\n"
1352 "\t\t\t\"IDR\": %u,\n"
1353 "\t\t\t\"InFrame\": %u,\n"
1354 "\t\t\t\"OutFrame\": %u,\n"
1355 "\t\t\t\"Width\": %u,\n"
1356 "\t\t\t\"Height\": %u,\n"
1357 "\t\t\t\"SID\": %s,\n"
1358 "\t\t\t\"DEVICE\": \"%s\",\n"
1376 "\t\t\t\"NUMBER\": %u,\n"
1377 "\t\t\t\"INDEX\": %u,\n"
1378 "\t\t\t\"AvgCost\": %u,\n"
1379 "\t\t\t\"FrameRate\": %u,\n"
1380 "\t\t\t\"IDR\": %u,\n"
1381 "\t\t\t\"UserIDR\": %u,\n"
1382 "\t\t\t\"InFrame\": %u,\n"
1383 "\t\t\t\"OutFrame\": %u,\n"
1384 "\t\t\t\"BR\": %u,\n"
1385 "\t\t\t\"AvgBR\": %u,\n"
1386 "\t\t\t\"Width\": %u,\n"
1387 "\t\t\t\"Height\": %u,\n"
1388 "\t\t\t\"Format\": %s,\n"
1389 "\t\t\t\"SID\": %s,\n"
1390 "\t\t\t\"DEVICE\": \"%s\",\n"
1424 "\t\t\t\"NUMBER\": %u,\n"
1425 "\t\t\t\"INDEX\": %d,\n"
1426 "\t\t\t\"LOAD\": %u,\n"
1427 "\t\t\t\"LOAD-ALL\": %u,\n"
1428 "\t\t\t\"MODEL_LOAD\": %u,\n"
1429 "\t\t\t\"MODEL_LOAD-ALL\": %u,\n"
1430 "\t\t\t\"FW_LOAD\": %u,\n"
1431 "\t\t\t\"INST\": %u,\n"
1432 "\t\t\t\"INST-ALL\": %u,\n"
1433 "\t\t\t\"MAX_INST\": %d,\n"
1434 "\t\t\t\"MEM\": %u,\n"
1435 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1436 "\t\t\t\"SHARE_MEM\": %u,\n"
1437 "\t\t\t\"P2P_MEM\": %u,\n"
1438 "\t\t\t\"DEVICE\": \"%s\",\n"
1439 "\t\t\t\"L_FL2V\": \"%s\",\n"
1440 "\t\t\t\"N_FL2V\": \"%s\",\n"
1441 "\t\t\t\"FR\": \"%.8s\",\n"
1442 "\t\t\t\"N_FR\": \"%.8s\""
1444 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1445 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1452 device_name, device_count,
1482 "\t\t\t\"NUMBER\": %u,\n"
1483 "\t\t\t\"INDEX\": %d,\n"
1484 "\t\t\t\"LOAD\": %u,\n"
1485 "\t\t\t\"MODEL_LOAD\": %u,\n"
1486 "\t\t\t\"FW_LOAD\": %u,\n"
1487 "\t\t\t\"INST\": %u,\n"
1488 "\t\t\t\"MAX_INST\": %d,\n"
1489 "\t\t\t\"MEM\": %u,\n"
1490 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1491 "\t\t\t\"SHARE_MEM\": %u,\n"
1492 "\t\t\t\"P2P_MEM\": %u,\n"
1493 "\t\t\t\"DEVICE\": \"%s\",\n"
1494 "\t\t\t\"L_FL2V\": \"%s\",\n"
1495 "\t\t\t\"N_FL2V\": \"%s\",\n"
1496 "\t\t\t\"FR\": \"%.8s\",\n"
1497 "\t\t\t\"N_FR\": \"%.8s\""
1499 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1500 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1507 device_name, device_count,
1544 printf(
"%s", output_buf.
str_buf);
1567 printf(
"%s", output_buf.
str_buf);
1573 strcpy(device_name,
"nvme");
1574 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1577 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1580 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1583 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1589 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1595 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1601 (icore ==
TP_LOAD)?strcpy(device_name,
"tp"):strcpy(device_name,
"pcie");
1603 for (index = 0; index < device_count; index++)
1611 device_name, detail, detail_data_v1))
1621 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1649 "\t\t\t\"NUMBER\": %u,\n"
1650 "\t\t\t\"INDEX\": %d,\n"
1651 "\t\t\t\"LOAD\": 0,\n"
1652 "\t\t\t\"MODEL_LOAD\": 0,\n"
1653 "\t\t\t\"FW_LOAD\": %u,\n"
1654 "\t\t\t\"INST\": 0,\n"
1655 "\t\t\t\"MAX_INST\": 0,\n"
1656 "\t\t\t\"MEM\": 0,\n"
1657 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1658 "\t\t\t\"SHARE_MEM\": %u,\n"
1659 "\t\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1660 "\t\t\t\"P2P_MEM\": 0,\n"
1661 "\t\t\t\"DEVICE\": \"%s\",\n"
1662 "\t\t\t\"L_FL2V\": \"%s\",\n"
1663 "\t\t\t\"N_FL2V\": \"%s\",\n"
1664 "\t\t\t\"FR\": \"%.8s\",\n"
1665 "\t\t\t\"N_FR\": \"%.8s\""
1667 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1668 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1675 device_name, device_count,
1697 "\t\t\t\"NUMBER\": %u,\n"
1698 "\t\t\t\"INDEX\": %d,\n"
1699 "\t\t\t\"LOAD\": 0,\n"
1700 "\t\t\t\"MODEL_LOAD\": 0,\n"
1701 "\t\t\t\"FW_LOAD\": %u,\n"
1702 "\t\t\t\"INST\": 0,\n"
1703 "\t\t\t\"MAX_INST\": 0,\n"
1704 "\t\t\t\"MEM\": 0,\n"
1705 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1706 "\t\t\t\"SHARE_MEM\": %u,\n"
1707 "\t\t\t\"P2P_MEM\": 0,\n"
1708 "\t\t\t\"DEVICE\": \"%s\",\n"
1709 "\t\t\t\"L_FL2V\": \"%s\",\n"
1710 "\t\t\t\"N_FL2V\": \"%s\",\n"
1711 "\t\t\t\"FR\": \"%.8s\",\n"
1712 "\t\t\t\"N_FR\": \"%.8s\""
1714 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1715 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1722 device_name, device_count,
1748 printf(
"%s", output_buf.
str_buf);
1755 bool has_written_start =
false;
1757 unsigned int index, device_count;
1758 int32_t *module_ids;
1759 uint32_t total_contexts;
1761 uint32_t model_load;
1763 char pcie[64] = {0};
1768 char power_consumption[16];
1789 if (!has_written_start)
1792 has_written_start =
true;
1799 for (index = 0; index < device_count; index++)
1807 device_name, detail, detail_data_v1))
1846 "\t\t\"NUMBER\": %u,\n"
1847 "\t\t\"INDEX\": %d,\n"
1848 "\t\t\"LOAD\": %u,\n"
1849 "\t\t\"LOAD-ALL\": %u,\n"
1850 "\t\t\"MODEL_LOAD\": %u,\n"
1851 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1852 "\t\t\"FW_LOAD\": %u,\n"
1853 "\t\t\"INST\": %u,\n"
1854 "\t\t\"INST-ALL\": %u,\n"
1855 "\t\t\"MAX_INST\": %d,\n"
1856 "\t\t\"MEM\": %u,\n"
1857 "\t\t\"CRITICAL_MEM\": %u,\n"
1858 "\t\t\"SHARE_MEM\": %u,\n"
1859 "\t\t\"P2P_MEM\": %u,\n"
1860 "\t\t\"DEVICE\": \"%s\",\n"
1861 "\t\t\"L_FL2V\": \"%s\",\n"
1862 "\t\t\"N_FL2V\": \"%s\",\n"
1863 "\t\t\"FR\": \"%.8s\",\n"
1864 "\t\t\"N_FR\": \"%.8s\""
1866 ",\n\t\t\"NUMA_NODE\": %d,\n"
1867 "\t\t\"PCIE_ADDR\": \"%s\""
1894 "\t\t\"NUMBER\": %u,\n"
1895 "\t\t\"INDEX\": %d,\n"
1896 "\t\t\"LOAD\": %u,\n"
1897 "\t\t\"MODEL_LOAD\": %u,\n"
1898 "\t\t\"FW_LOAD\": %u,\n"
1899 "\t\t\"INST\": %u,\n"
1900 "\t\t\"MAX_INST\": %d,\n"
1901 "\t\t\"MEM\": %u,\n"
1902 "\t\t\"CRITICAL_MEM\": %u,\n"
1903 "\t\t\"SHARE_MEM\": %u,\n"
1904 "\t\t\"P2P_MEM\": %u,\n"
1905 "\t\t\"DEVICE\": \"%s\",\n"
1906 "\t\t\"L_FL2V\": \"%s\",\n"
1907 "\t\t\"N_FL2V\": \"%s\",\n"
1908 "\t\t\"FR\": \"%.8s\",\n"
1909 "\t\t\"N_FR\": \"%.8s\""
1911 ",\n\t\t\"NUMA_NODE\": %d,\n"
1912 "\t\t\"PCIE_ADDR\": \"%s\""
1937 ",\n\t\t\"TEMP\": %d,\n"
1938 "\t\t\"POWER\": \"%s\"\n"
1947 if (index < device_count - 1)
1989 printf(
"%s", output_buf.
str_buf);
1996 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1999 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
2002 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
2005 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
2011 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
2017 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
2025 for (index = 0; index < device_count; index++)
2034 device_name, detail, detail_data_v1))
2044 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2082 "\t\t\"NUMBER\": %u,\n"
2083 "\t\t\"INDEX\": %d,\n"
2084 "\t\t\"LOAD\": 0,\n"
2085 "\t\t\"MODEL_LOAD\": 0,\n"
2086 "\t\t\"FW_LOAD\": %u,\n"
2087 "\t\t\"INST\": 0,\n"
2088 "\t\t\"MAX_INST\": 0,\n"
2090 "\t\t\"CRITICAL_MEM\": 0,\n"
2091 "\t\t\"SHARE_MEM\": %u,\n"
2092 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2093 "\t\t\"P2P_MEM\": 0,\n"
2094 "\t\t\"DEVICE\": \"%s\",\n"
2095 "\t\t\"L_FL2V\": \"%s\",\n"
2096 "\t\t\"N_FL2V\": \"%s\",\n"
2097 "\t\t\"FR\": \"%.8s\",\n"
2098 "\t\t\"N_FR\": \"%.8s\""
2100 ",\n\t\t\"NUMA_NODE\": %d,\n"
2101 "\t\t\"PCIE_ADDR\": \"%s\""
2122 "\t\t\"NUMBER\": %u,\n"
2123 "\t\t\"INDEX\": %d,\n"
2124 "\t\t\"LOAD\": 0,\n"
2125 "\t\t\"MODEL_LOAD\": 0,\n"
2126 "\t\t\"FW_LOAD\": %u,\n"
2127 "\t\t\"INST\": 0,\n"
2128 "\t\t\"MAX_INST\": 0,\n"
2130 "\t\t\"CRITICAL_MEM\": 0,\n"
2131 "\t\t\"SHARE_MEM\": %u,\n"
2132 "\t\t\"P2P_MEM\": 0,\n"
2133 "\t\t\"DEVICE\": \"%s\",\n"
2134 "\t\t\"L_FL2V\": \"%s\",\n"
2135 "\t\t\"N_FL2V\": \"%s\",\n"
2136 "\t\t\"FR\": \"%.8s\",\n"
2137 "\t\t\"N_FR\": \"%.8s\""
2139 ",\n\t\t\"NUMA_NODE\": %d,\n"
2140 "\t\t\"PCIE_ADDR\": \"%s\""
2157 ",\n\t\t\"TEMP\": %d,\n"
2158 "\t\t\"POWER\": \"%s\"\n"
2167 if (index < device_count - 1)
2194 printf(
"%s", output_buf.
str_buf);
2201 int i, index, instance_count;
2202 unsigned int module_count;
2204 int32_t *module_id_arr = NULL;
2213 module_type != max_device_type;
2227 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", module_name, module_count);
2235 "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2236 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2237 "SID",
"DEVICE",
"NAMESPACE");
2242 "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2243 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"Width",
"Height",
2244 "SID",
"DEVICE",
"NAMESPACE");
2252 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2253 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"fps",
"BR",
"AvgBR",
"Width",
"Height",
2254 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2259 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2260 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"BR",
"AvgBR",
"Width",
"Height",
2261 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2267 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
2268 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
2272 for (i = 0; i < module_count; i++)
2280 module_name, detail, detail_data_v1))
2288 if(previous_detail_data_p && checkInterval)
2290 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2295 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2302 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2312 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2320 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2337 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2353 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2373 if(previous_detail_data_p)
2381 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2400 free(module_id_arr);
2404 printf(
"%s", output_buf.
str_buf);
2411 unsigned int index, device_count;
2412 int32_t *module_ids;
2417 char power_consumption[16];
2418 int instance_count = 0;
2430 printf(
"%s", output_buf.
str_buf);
2435 for (index = 0; index < device_count; index++)
2438 if (!p_device_context)
2445 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2454 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
2461 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
2464 "ERROR: ni_device_open() failed for %s: %s\n",
2485 "%-4s %-8s %-14s\n",
"TEMP",
"POWER",
"DEVICE");
2487 "%-4d %-8s %-14s\n",
2494 if (instance_count == 0)
2497 "%-8s %-8s %-8s %-8.8s %-8.8s \n",
"INDEX",
"TEMP",
"POWER",
"FR",
"SN");
2500 "%-8d %-8d %-8s %-8.8s %-8.*s \n",
2511 printf(
"%s", output_buf.
str_buf);
2518 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2520 int skip_init_rsrc = 0;
2521 int should_match_rev = 1;
2528 time_t startTime = {0}, now = {0};
2529 int timeout_seconds = 0;
2530 struct tm *ltime = NULL;
2532 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2537 bool fw_log_dump =
false;
2539 int refresh_device_pool = 1;
2540 bool is_first_query =
true;
2544 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2546 setup_signal_handler();
2550 while ((opt =
getopt(argc, argv,
"n:o:D:k:R:rt:Sl:hvd")) != -1)
2556 if (!strcmp(
optarg,
"json"))
2560 else if (!strcmp(
optarg,
"simple"))
2564 else if (!strcmp(
optarg,
"text"))
2568 else if (!strcmp(
optarg,
"full"))
2572 else if (!strcmp(
optarg,
"json1"))
2576 else if (!strcmp(
optarg,
"json2"))
2580 else if (!strcmp(
optarg,
"extra"))
2586 fprintf(stderr,
"Error: unknown selection for outputFormat: %s\n",
optarg);
2603 should_match_rev = 0;
2607 printf(
"Timeout will be set %d\n", timeout_seconds);
2618 fprintf(stderr,
"FATAL: invalid log level selected: %s\n",
optarg);
2624 printf(
"-------- ni_rsrc_mon v%s --------\n"
2625 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
2626 "running on the system.\n"
2628 "Usage: ni_rsrc_mon [OPTIONS]\n"
2629 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
2630 " report only once.\n"
2632 "-R Specify if refresh devices on host in each monitor interval.\n"
2633 " If 0, only refresh devices at the start.\n"
2635 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
2637 "-D Dump firmware logs to current directory. Default: 0(not dump fw log).\n"
2638 "-k Specify to dump which card's firmware logs.\n"
2639 " Default: -1(dump fw log of all cards).\n"
2640 "-r Initialize Quadra device regardless firmware release version to\n"
2641 " libxcoder version compatibility.\n"
2642 " Default: only initialize devices with compatible firmware version.\n"
2643 "-t Set timeout time in seconds for device polling. Program will exit with\n"
2644 " failure if timeout is reached without finding at least one device. If 0 or\n"
2645 " no selection, poll indefinitely until a Quadra device is found.\n"
2647 "-S Skip init_rsrc.\n"
2648 "-d Print detailed information for decoder/encoder in text and json formats.\n"
2649 "-l Set loglevel of libxcoder API.\n"
2650 " [none, fatal, error, info, debug, trace]\n"
2652 "-h Open this help message.\n"
2653 "-v Print version info.\n"
2655 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
2658 "Reporting columns for text output format\n"
2659 "INDEX index number used by resource manager to identify the resource\n"
2660 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
2661 "MODEL_LOAD estimated load based on framerate and resolution\n"
2662 "INST number of job instances\n"
2663 "MEM usage of memory by the subsystem\n"
2664 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
2665 "P2P_MEM usage of memory by P2P\n"
2666 "DEVICE path to NVMe device file handle\n"
2667 "NAMESPACE path to NVMe namespace file handle\n"
2668 "Additional information only in text(Default) mode \n"
2669 "TEMP current temperature (degrees Celsius)\n"
2670 "POWER current power(mW), N/A when query power not supported\n"
2671 "FR current firmware revision\n"
2672 "SN serial number of the Quadra device\n"
2674 "Additional reporting columns for full output format\n"
2675 "VPU same as LOAD in JSON outputs\n"
2677 "TOTAL same as MEM\n"
2678 "CRITICAL usage of memory considered critical\n"
2679 "L_FL2V last ran firmware loader 2 version\n"
2680 "N_FL2V nor flash firmware loader 2 version\n"
2681 "FR current firmware revision\n"
2682 "N_FR nor flash firmware revision\n"
2684 "Additional reporting columns for full JSON formats\n"
2686 "FW_LOAD system load\n"
2688 "Extra output shows TEMP and POWER of the Quadra device \n",
2692 printf(
"Release ver: %s\n"
2702 fprintf(stderr,
"FATAL: unknown option '-%c'\n", opt);
2705 fprintf(stderr,
"FATAL: unknown option character '\\x%x'\n", opt);
2712 fprintf(stderr,
"FATAL: option '-%c' lacks arg\n", opt);
2715 fprintf(stderr,
"FATAL: unhandled option\n");
2720 if(checkInterval > 0 && printFormat ==
FMT_JSON)
2722 fprintf(stderr,
"EXIT: -o json cannot use with -n params\n");
2726 if ((argc <= 2) && (
optind == 1))
2741 fprintf(stderr,
"FATAL: cannot allocate momory for ni_session_context_t\n");
2746 if (!skip_init_rsrc && (ret =
ni_rsrc_init(should_match_rev,timeout_seconds)) != 0)
2750 fprintf(stderr,
"FATAL: NI resource unavailable\n");
2755 fprintf(stderr,
"FATAL: cannot access NI resource\n");
2764 fprintf(stderr,
"FATAL: cannot get devices info\n");
2771 printf(
"**************************************************\n");
2783 startTime = time(NULL);
2788 if(previous_detail_data == NULL)
2790 fprintf(stderr,
"FATAL: Allocate buffer fail\n");
2794 memset((
void *)previous_detail_data, 0, allocate_size);
2799 ltime = localtime(&now);
2802 strftime(buf,
sizeof(buf),
"%c", ltime);
2804 time_diff_seconds = (
long long)difftime(now, startTime);
2805 time_diff_minutes = time_diff_seconds / 60;
2806 time_diff_hours = time_diff_minutes / 60;
2809 if (is_first_query || refresh_device_pool)
2816 printf(
"%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
2823 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2825 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2830 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2832 perror(
"ERROR: cannot lock p_device_pool");
2839 ReleaseMutex((HANDLE)p_device_pool->
lock);
2841 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2843 perror(
"ERROR: cannot unlock p_device_pool");
2847 switch (printFormat)
2851 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
2860 print_json(coders, p_xCtxt, detail, &detail_data_v1);
2865 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
2875 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
2887 is_first_query =
false;
2891 printf(
"**************************************************\n");
2896 if (checkInterval == 0)
2908 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2910 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2915 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2917 perror(
"ERROR: cannot lock p_device_pool");
2922 ReleaseMutex((HANDLE)p_device_pool->
lock);
2924 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2926 perror(
"ERROR: cannot unlock p_device_pool");
2944 #ifdef __OPENHARMONY__
2945 system(
"chmod -R 777 /dev/shm/");
2946 #ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
2947 system(
"chmod 777 /dev/block/vd* 2>/dev/null");
2949 #elif defined(_ANDROID)
2950 system(
"chmod -R 777 /dev/shm/");
2951 system(
"chmod 777 /dev/block/nvme* 2>/dev/null");
2952 system(
"chmod 777 /dev/nvme* 2>/dev/null");
2953 property_set(
"ni_rsrc_init_completed",
"yes");
2957 if(checkInterval && previous_detail_data)
2959 free(previous_detail_data);