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)
179 ni_device_handle_t device_handle)
183 fprintf(stderr,
"Error: device_type %d is not a valid device type\n",
188 if (
device_handles[xcoder_device_type][module_id] == device_handle)
191 NI_INVALID_DEVICE_HANDLE;
196 "Error: device_handle to remove %" PRId64
197 "not match device_handles[%d][%d]=%" PRId64
"\n",
198 (int64_t)device_handle, device_type, module_id,
220 const size_t len = strlen(numArray);
222 for (i = 0; i < len; i++)
224 if (!isdigit(numArray[i]))
226 fprintf(stderr,
"invalid, ABORTING\n");
231 return len == i ?
atoi(numArray) : 0;
244 if ( *(int32_t*)a < *(int32_t*)b )
return -1;
245 if ( *(int32_t*)a > *(int32_t*)b )
return 1;
256 else if ((index >= 0 && index < 4) || (index >= 10 && index < 13))
260 else if (index >= 4 && index < 10)
264 else if (index >= 13 && index < 15)
273 static char sid[5] =
"0000";
279 snprintf(sid,
sizeof(sid),
"%04x", 0);
284 snprintf(sid,
sizeof(sid),
"%04x",
id);
292 int32_t **module_ids)
294 unsigned int device_count;
297 size_of_i32 =
sizeof(int32_t);
299 device_count = p_device_queue->
xcoder_cnt[device_type];
300 *module_ids = malloc(size_of_i32 * device_count);
303 fprintf(stderr,
"ERROR: malloc() failed for module_ids\n");
308 p_device_queue->
xcoders[device_type],
309 size_of_i32 * device_count);
317 g_device_type_str[device_type],
330 if (!p_device_context)
338 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
347 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
354 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
359 "ERROR: ni_device_open() failed for %s: %s\n",
368 p_session_context->
hw_id =
377 "ERROR: cannot print detailed info for %s as it has FW API "
400 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
417 memcpy(p_session_context->
fw_rev,
430 if (!p_device_context)
436 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
441 "ERROR: ni_device_open() failed for %s: %s\n",
449 p_session_context->
hw_id =
453 return return_code ? false :
true;
459 unsigned int module_count;
460 int32_t *module_id_arr = NULL;
465 module_count =
get_modules(module_type, coders, module_name, &module_id_arr);
467 printf(
"Error: module not found!\n");
471 bool gen_log_file =
true;
473 void* p_log_buffer = NULL;
474 if (devid >= 0 && (uint32_t)devid < module_count)
480 if (!
open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
481 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n",
484 printf(
"Success: dumped fw log of card:%d blk_name:%s\n",
494 for (i = 0; i < module_count; i++)
497 if (!
open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
498 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n",
502 printf(
"Success: dumped fw log of card:%d blk_name:%s\n",
517 switch (*p_device_type)
530 #define DYN_STR_BUF_CHUNK_SIZE 4096
552 int add_buf_size = 0;
553 char *tmp_char_ptr = NULL;
557 fprintf(stderr,
"ERROR: invalid param *dyn_str_buf\n");
571 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
576 add_buf_size = (formatted_len + 1) > avail_buf ?
590 fprintf(stderr,
"ERROR: strcat_dyn_buf() failed realloc()\n");
617 unsigned int index, device_count;
639 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", device_name, device_count);
645 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
646 "DEVICE L_FL2V N_FL2V FR N_FR\n");
651 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
652 "DEVICE L_FL2V N_FL2V FR N_FR\n");
656 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
657 "DEVICE L_FL2V N_FL2V FR N_FR\n");
661 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
662 "DEVICE L_FL2V N_FL2V FR N_FR\n");
668 for (index = 0; index < device_count; index++)
676 device_name, detail, detail_data_v1))
685 "%-5d %-3u %-3u %-3u %-3u/%-3d %-3u %-3u "
686 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
705 "%-5d %-3u %-3u %-3u/%-3d %-3u "
706 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
722 "%-5d %-3u %-3u %-3u %-3u/%-3d %-3u %-3u "
723 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
742 "%-5d %-3u %-3u/%-3d %-3u "
743 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
790 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
793 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
796 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
799 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
805 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
811 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
824 "INDEX LOAD( FW ) PCIE_Card2Host_Gbps "
825 "DEVICE L_FL2V N_FL2V FR N_FR\n");
830 "INDEX LOAD( FW ) MEM( SHARE ) "
831 "DEVICE L_FL2V N_FL2V FR N_FR\n");
836 printf(
"%s", output_buf.
str_buf);
845 for (index = 0; index < device_count; index++)
854 device_name, detail, detail_data_v1))
863 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
886 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
903 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
927 printf(
"%s", output_buf.
str_buf);
934 bool copied_block_name;
938 unsigned int number_of_quadras;
939 unsigned int number_of_device_types_present;
940 unsigned int device_type_counter;
941 unsigned int *maximum_firmware_loads;
942 unsigned int *maximum_firmware_loads_per_quadra;
956 maximum_firmware_loads = calloc(number_of_quadras,
sizeof(
unsigned int));
957 if (!maximum_firmware_loads)
959 fprintf(stderr,
"calloc() returned NULL\n");
963 maximum_firmware_loads_per_quadra = NULL;
964 p_device_context = NULL;
966 for (guid = 0; guid < number_of_quadras; guid++)
969 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
970 number_of_device_types_present = 0;
971 device_type_counter = 0;
972 copied_block_name =
false;
975 device_type < maximum_device_type;
978 if (p_device_queue->
xcoders[device_type][guid] != -1)
980 number_of_device_types_present++;
985 device_type < maximum_device_type;
989 g_device_type_str[device_type],
992 if (p_device_queue->
xcoders[device_type][guid] == -1)
999 p_device_queue->
xcoders[device_type][guid]);
1003 device_name, detail, detail_data_v1))
1014 "%s: Simple output not supported. Try '-o full' "
1024 if (!copied_block_name)
1029 copied_block_name =
true;
1032 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.
fw_load)
1037 device_type_counter++;
1038 if (device_type_counter < number_of_device_types_present)
1059 if (*maximum_firmware_loads_per_quadra < load_query.
fw_load)
1061 *maximum_firmware_loads_per_quadra = load_query.
fw_load;
1063 if (*maximum_firmware_loads_per_quadra < load_query.
tp_fw_load)
1065 *maximum_firmware_loads_per_quadra = load_query.
tp_fw_load;
1068 *maximum_firmware_loads_per_quadra);
1073 stderr,
"ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1087 printf(
"%s", output_buf.
str_buf);
1089 free(maximum_firmware_loads);
1095 unsigned int i, index, device_count;
1097 int32_t *module_ids;
1105 int first_item_printed = 0;
1106 int first_device_type_printed = 0;
1111 device_type != max_device_type;
1124 for (i = 0; i < device_count; i++)
1132 device_name, detail, detail_data_v1))
1137 if(first_device_type_printed)
1147 first_item_printed = 0;
1152 if(first_item_printed)
1161 "\t\t\t\"NUMBER\": %u,\n"
1162 "\t\t\t\"INDEX\": %u,\n"
1163 "\t\t\t\"AvgCost\": %u,\n"
1164 "\t\t\t\"FrameRate\": %u,\n"
1165 "\t\t\t\"IDR\": %u,\n"
1166 "\t\t\t\"InFrame\": %u,\n"
1167 "\t\t\t\"OutFrame\": %u,\n"
1168 "\t\t\t\"Width\": %u,\n"
1169 "\t\t\t\"Height\": %u,\n"
1170 "\t\t\t\"SID\": \"%s\",\n"
1171 "\t\t\t\"DEVICE\": \"%s\"\n"
1189 "\t\t\t\"NUMBER\": %u,\n"
1190 "\t\t\t\"INDEX\": %u,\n"
1191 "\t\t\t\"AvgCost\": %u,\n"
1192 "\t\t\t\"FrameRate\": %u,\n"
1193 "\t\t\t\"IDR\": %u,\n"
1194 "\t\t\t\"UserIDR\": %u,\n"
1195 "\t\t\t\"InFrame\": %u,\n"
1196 "\t\t\t\"OutFrame\": %u,\n"
1197 "\t\t\t\"BR\": %u,\n"
1198 "\t\t\t\"AvgBR\": %u,\n"
1199 "\t\t\t\"Width\": %u,\n"
1200 "\t\t\t\"Height\": %u,\n"
1201 "\t\t\t\"Format\": \"%s\",\n"
1202 "\t\t\t\"SID\": \"%s\",\n"
1203 "\t\t\t\"DEVICE\": \"%s\"\n"
1221 first_item_printed = 1;
1228 first_device_type_printed = 1;
1237 printf(
"%s", output_buf.
str_buf);
1248 unsigned int i, index, device_count;
1250 int32_t *module_ids;
1251 uint32_t total_contexts;
1253 uint32_t model_load;
1255 char pcie[64] = {0};
1269 device_type != max_device_type;
1283 for (i = 0; i < device_count; i++)
1291 device_name, detail, detail_data_v1))
1328 "\t\t\t\"NUMBER\": %u,\n"
1329 "\t\t\t\"INDEX\": %u,\n"
1330 "\t\t\t\"AvgCost\": %u,\n"
1331 "\t\t\t\"FrameRate\": %u,\n"
1332 "\t\t\t\"IDR\": %u,\n"
1333 "\t\t\t\"InFrame\": %u,\n"
1334 "\t\t\t\"OutFrame\": %u,\n"
1335 "\t\t\t\"Width\": %u,\n"
1336 "\t\t\t\"Height\": %u,\n"
1337 "\t\t\t\"SID\": %s,\n"
1338 "\t\t\t\"DEVICE\": \"%s\",\n"
1356 "\t\t\t\"NUMBER\": %u,\n"
1357 "\t\t\t\"INDEX\": %u,\n"
1358 "\t\t\t\"AvgCost\": %u,\n"
1359 "\t\t\t\"FrameRate\": %u,\n"
1360 "\t\t\t\"IDR\": %u,\n"
1361 "\t\t\t\"UserIDR\": %u,\n"
1362 "\t\t\t\"InFrame\": %u,\n"
1363 "\t\t\t\"OutFrame\": %u,\n"
1364 "\t\t\t\"BR\": %u,\n"
1365 "\t\t\t\"AvgBR\": %u,\n"
1366 "\t\t\t\"Width\": %u,\n"
1367 "\t\t\t\"Height\": %u,\n"
1368 "\t\t\t\"Format\": %s,\n"
1369 "\t\t\t\"SID\": %s,\n"
1370 "\t\t\t\"DEVICE\": \"%s\",\n"
1404 "\t\t\t\"NUMBER\": %u,\n"
1405 "\t\t\t\"INDEX\": %d,\n"
1406 "\t\t\t\"LOAD\": %u,\n"
1407 "\t\t\t\"LOAD-ALL\": %u,\n"
1408 "\t\t\t\"MODEL_LOAD\": %u,\n"
1409 "\t\t\t\"MODEL_LOAD-ALL\": %u,\n"
1410 "\t\t\t\"FW_LOAD\": %u,\n"
1411 "\t\t\t\"INST\": %u,\n"
1412 "\t\t\t\"INST-ALL\": %u,\n"
1413 "\t\t\t\"MAX_INST\": %d,\n"
1414 "\t\t\t\"MEM\": %u,\n"
1415 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1416 "\t\t\t\"SHARE_MEM\": %u,\n"
1417 "\t\t\t\"P2P_MEM\": %u,\n"
1418 "\t\t\t\"DEVICE\": \"%s\",\n"
1419 "\t\t\t\"L_FL2V\": \"%s\",\n"
1420 "\t\t\t\"N_FL2V\": \"%s\",\n"
1421 "\t\t\t\"FR\": \"%.8s\",\n"
1422 "\t\t\t\"N_FR\": \"%.8s\""
1424 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1425 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1432 device_name, device_count,
1462 "\t\t\t\"NUMBER\": %u,\n"
1463 "\t\t\t\"INDEX\": %d,\n"
1464 "\t\t\t\"LOAD\": %u,\n"
1465 "\t\t\t\"MODEL_LOAD\": %u,\n"
1466 "\t\t\t\"FW_LOAD\": %u,\n"
1467 "\t\t\t\"INST\": %u,\n"
1468 "\t\t\t\"MAX_INST\": %d,\n"
1469 "\t\t\t\"MEM\": %u,\n"
1470 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1471 "\t\t\t\"SHARE_MEM\": %u,\n"
1472 "\t\t\t\"P2P_MEM\": %u,\n"
1473 "\t\t\t\"DEVICE\": \"%s\",\n"
1474 "\t\t\t\"L_FL2V\": \"%s\",\n"
1475 "\t\t\t\"N_FL2V\": \"%s\",\n"
1476 "\t\t\t\"FR\": \"%.8s\",\n"
1477 "\t\t\t\"N_FR\": \"%.8s\""
1479 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1480 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1487 device_name, device_count,
1524 printf(
"%s", output_buf.
str_buf);
1547 printf(
"%s", output_buf.
str_buf);
1554 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1557 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1560 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1563 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1569 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1575 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1584 for (i = 0; i < device_count; i++)
1592 device_name, detail, detail_data_v1))
1602 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1630 "\t\t\t\"NUMBER\": %u,\n"
1631 "\t\t\t\"INDEX\": %d,\n"
1632 "\t\t\t\"LOAD\": 0,\n"
1633 "\t\t\t\"MODEL_LOAD\": 0,\n"
1634 "\t\t\t\"FW_LOAD\": %u,\n"
1635 "\t\t\t\"INST\": 0,\n"
1636 "\t\t\t\"MAX_INST\": 0,\n"
1637 "\t\t\t\"MEM\": 0,\n"
1638 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1639 "\t\t\t\"SHARE_MEM\": %u,\n"
1640 "\t\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1641 "\t\t\t\"P2P_MEM\": 0,\n"
1642 "\t\t\t\"DEVICE\": \"%s\",\n"
1643 "\t\t\t\"L_FL2V\": \"%s\",\n"
1644 "\t\t\t\"N_FL2V\": \"%s\",\n"
1645 "\t\t\t\"FR\": \"%.8s\",\n"
1646 "\t\t\t\"N_FR\": \"%.8s\""
1648 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1649 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1656 device_name, device_count,
1678 "\t\t\t\"NUMBER\": %u,\n"
1679 "\t\t\t\"INDEX\": %d,\n"
1680 "\t\t\t\"LOAD\": 0,\n"
1681 "\t\t\t\"MODEL_LOAD\": 0,\n"
1682 "\t\t\t\"FW_LOAD\": %u,\n"
1683 "\t\t\t\"INST\": 0,\n"
1684 "\t\t\t\"MAX_INST\": 0,\n"
1685 "\t\t\t\"MEM\": 0,\n"
1686 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1687 "\t\t\t\"SHARE_MEM\": %u,\n"
1688 "\t\t\t\"P2P_MEM\": 0,\n"
1689 "\t\t\t\"DEVICE\": \"%s\",\n"
1690 "\t\t\t\"L_FL2V\": \"%s\",\n"
1691 "\t\t\t\"N_FL2V\": \"%s\",\n"
1692 "\t\t\t\"FR\": \"%.8s\",\n"
1693 "\t\t\t\"N_FR\": \"%.8s\""
1695 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1696 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1703 device_name, device_count,
1729 printf(
"%s", output_buf.
str_buf);
1736 bool has_written_start =
false;
1738 unsigned int index, device_count;
1739 int32_t *module_ids;
1740 uint32_t total_contexts;
1742 uint32_t model_load;
1744 char pcie[64] = {0};
1749 char power_consumption[16];
1770 if (!has_written_start)
1773 has_written_start =
true;
1780 for (index = 0; index < device_count; index++)
1788 device_name, detail, detail_data_v1))
1827 "\t\t\"NUMBER\": %u,\n"
1828 "\t\t\"INDEX\": %d,\n"
1829 "\t\t\"LOAD\": %u,\n"
1830 "\t\t\"LOAD-ALL\": %u,\n"
1831 "\t\t\"MODEL_LOAD\": %u,\n"
1832 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1833 "\t\t\"FW_LOAD\": %u,\n"
1834 "\t\t\"INST\": %u,\n"
1835 "\t\t\"INST-ALL\": %u,\n"
1836 "\t\t\"MAX_INST\": %d,\n"
1837 "\t\t\"MEM\": %u,\n"
1838 "\t\t\"CRITICAL_MEM\": %u,\n"
1839 "\t\t\"SHARE_MEM\": %u,\n"
1840 "\t\t\"P2P_MEM\": %u,\n"
1841 "\t\t\"DEVICE\": \"%s\",\n"
1842 "\t\t\"L_FL2V\": \"%s\",\n"
1843 "\t\t\"N_FL2V\": \"%s\",\n"
1844 "\t\t\"FR\": \"%.8s\",\n"
1845 "\t\t\"N_FR\": \"%.8s\""
1847 ",\n\t\t\"NUMA_NODE\": %d,\n"
1848 "\t\t\"PCIE_ADDR\": \"%s\""
1875 "\t\t\"NUMBER\": %u,\n"
1876 "\t\t\"INDEX\": %d,\n"
1877 "\t\t\"LOAD\": %u,\n"
1878 "\t\t\"MODEL_LOAD\": %u,\n"
1879 "\t\t\"FW_LOAD\": %u,\n"
1880 "\t\t\"INST\": %u,\n"
1881 "\t\t\"MAX_INST\": %d,\n"
1882 "\t\t\"MEM\": %u,\n"
1883 "\t\t\"CRITICAL_MEM\": %u,\n"
1884 "\t\t\"SHARE_MEM\": %u,\n"
1885 "\t\t\"P2P_MEM\": %u,\n"
1886 "\t\t\"DEVICE\": \"%s\",\n"
1887 "\t\t\"L_FL2V\": \"%s\",\n"
1888 "\t\t\"N_FL2V\": \"%s\",\n"
1889 "\t\t\"FR\": \"%.8s\",\n"
1890 "\t\t\"N_FR\": \"%.8s\""
1892 ",\n\t\t\"NUMA_NODE\": %d,\n"
1893 "\t\t\"PCIE_ADDR\": \"%s\""
1918 ",\n\t\t\"TEMP\": %d,\n"
1919 "\t\t\"POWER\": \"%s\"\n"
1928 if (index < device_count - 1)
1970 printf(
"%s", output_buf.
str_buf);
1977 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1980 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1983 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1986 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1992 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1998 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
2006 for (index = 0; index < device_count; index++)
2015 device_name, detail, detail_data_v1))
2025 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2063 "\t\t\"NUMBER\": %u,\n"
2064 "\t\t\"INDEX\": %d,\n"
2065 "\t\t\"LOAD\": 0,\n"
2066 "\t\t\"MODEL_LOAD\": 0,\n"
2067 "\t\t\"FW_LOAD\": %u,\n"
2068 "\t\t\"INST\": 0,\n"
2069 "\t\t\"MAX_INST\": 0,\n"
2071 "\t\t\"CRITICAL_MEM\": 0,\n"
2072 "\t\t\"SHARE_MEM\": %u,\n"
2073 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2074 "\t\t\"P2P_MEM\": 0,\n"
2075 "\t\t\"DEVICE\": \"%s\",\n"
2076 "\t\t\"L_FL2V\": \"%s\",\n"
2077 "\t\t\"N_FL2V\": \"%s\",\n"
2078 "\t\t\"FR\": \"%.8s\",\n"
2079 "\t\t\"N_FR\": \"%.8s\""
2081 ",\n\t\t\"NUMA_NODE\": %d,\n"
2082 "\t\t\"PCIE_ADDR\": \"%s\""
2103 "\t\t\"NUMBER\": %u,\n"
2104 "\t\t\"INDEX\": %d,\n"
2105 "\t\t\"LOAD\": 0,\n"
2106 "\t\t\"MODEL_LOAD\": 0,\n"
2107 "\t\t\"FW_LOAD\": %u,\n"
2108 "\t\t\"INST\": 0,\n"
2109 "\t\t\"MAX_INST\": 0,\n"
2111 "\t\t\"CRITICAL_MEM\": 0,\n"
2112 "\t\t\"SHARE_MEM\": %u,\n"
2113 "\t\t\"P2P_MEM\": 0,\n"
2114 "\t\t\"DEVICE\": \"%s\",\n"
2115 "\t\t\"L_FL2V\": \"%s\",\n"
2116 "\t\t\"N_FL2V\": \"%s\",\n"
2117 "\t\t\"FR\": \"%.8s\",\n"
2118 "\t\t\"N_FR\": \"%.8s\""
2120 ",\n\t\t\"NUMA_NODE\": %d,\n"
2121 "\t\t\"PCIE_ADDR\": \"%s\""
2138 ",\n\t\t\"TEMP\": %d,\n"
2139 "\t\t\"POWER\": \"%s\"\n"
2148 if (index < device_count - 1)
2175 printf(
"%s", output_buf.
str_buf);
2182 int index, instance_count;
2184 unsigned int module_count;
2186 int32_t *module_id_arr = NULL;
2195 module_type != max_device_type;
2209 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", module_name, module_count);
2217 "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2218 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2219 "SID",
"DEVICE",
"NAMESPACE");
2224 "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2225 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"Width",
"Height",
2226 "SID",
"DEVICE",
"NAMESPACE");
2234 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2235 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"fps",
"BR",
"AvgBR",
"Width",
"Height",
2236 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2241 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2242 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"BR",
"AvgBR",
"Width",
"Height",
2243 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2249 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
2250 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
2254 for (i = 0; i < module_count; i++)
2262 module_name, detail, detail_data_v1))
2270 if(previous_detail_data_p && checkInterval)
2272 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2277 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2284 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2294 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2302 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2319 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2335 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2355 if(previous_detail_data_p)
2363 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2382 free(module_id_arr);
2386 printf(
"%s", output_buf.
str_buf);
2393 unsigned int index, device_count;
2394 int32_t *module_ids;
2399 char power_consumption[16];
2400 int instance_count = 0;
2412 printf(
"%s", output_buf.
str_buf);
2417 for (index = 0; index < device_count; index++)
2420 if (!p_device_context)
2427 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2436 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
2443 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
2448 "ERROR: ni_device_open() failed for %s: %s\n",
2469 "%-4s %-8s %-14s\n",
"TEMP",
"POWER",
"DEVICE");
2471 "%-4d %-8s %-14s\n",
2478 if (instance_count == 0)
2481 "%-8s %-8s %-8s %-8.8s %-8.8s \n",
"INDEX",
"TEMP",
"POWER",
"FR",
"SN");
2484 "%-8d %-8d %-8s %-8.8s %-8.*s \n",
2495 printf(
"%s", output_buf.
str_buf);
2502 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2504 int skip_init_rsrc = 0;
2505 int should_match_rev = 1;
2512 time_t startTime = {0}, now = {0};
2513 int timeout_seconds = 0;
2514 struct tm *ltime = NULL;
2516 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2521 bool fw_log_dump =
false;
2523 int refresh_device_pool = 1;
2524 bool is_first_query =
true;
2528 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2530 setup_signal_handler();
2534 while ((opt =
getopt(argc, argv,
"n:o:D:k:R:rt:Sl:hvd")) != -1)
2540 if (!strcmp(
optarg,
"json"))
2544 else if (!strcmp(
optarg,
"simple"))
2548 else if (!strcmp(
optarg,
"text"))
2552 else if (!strcmp(
optarg,
"full"))
2556 else if (!strcmp(
optarg,
"json1"))
2560 else if (!strcmp(
optarg,
"json2"))
2564 else if (!strcmp(
optarg,
"extra"))
2570 fprintf(stderr,
"Error: unknown selection for outputFormat: %s\n",
optarg);
2587 should_match_rev = 0;
2591 printf(
"Timeout will be set %d\n", timeout_seconds);
2602 fprintf(stderr,
"FATAL: invalid log level selected: %s\n",
optarg);
2608 printf(
"-------- ni_rsrc_mon v%s --------\n"
2609 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
2610 "running on the system.\n"
2612 "Usage: ni_rsrc_mon [OPTIONS]\n"
2613 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
2614 " report only once.\n"
2616 "-R Specify if refresh devices on host in each monitor interval.\n"
2617 " If 0, only refresh devices at the start.\n"
2619 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
2621 "-D Dump firmware logs to current directory. Default: 0(not dump fw log).\n"
2622 "-k Specify to dump which card's firmware logs.\n"
2623 " Default: -1(dump fw log of all cards).\n"
2624 "-r Initialize Quadra device regardless firmware release version to\n"
2625 " libxcoder version compatibility.\n"
2626 " Default: only initialize devices with compatible firmware version.\n"
2627 "-t Set timeout time in seconds for device polling. Program will exit with\n"
2628 " failure if timeout is reached without finding at least one device. If 0 or\n"
2629 " no selection, poll indefinitely until a Quadra device is found.\n"
2631 "-S Skip init_rsrc.\n"
2632 "-d Print detailed information for decoder/encoder in text and json formats.\n"
2633 "-l Set loglevel of libxcoder API.\n"
2634 " [none, fatal, error, info, debug, trace]\n"
2636 "-h Open this help message.\n"
2637 "-v Print version info.\n"
2639 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
2642 "Reporting columns for text output format\n"
2643 "INDEX index number used by resource manager to identify the resource\n"
2644 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
2645 "MODEL_LOAD estimated load based on framerate and resolution\n"
2646 "INST number of job instances\n"
2647 "MEM usage of memory by the subsystem\n"
2648 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
2649 "P2P_MEM usage of memory by P2P\n"
2650 "DEVICE path to NVMe device file handle\n"
2651 "NAMESPACE path to NVMe namespace file handle\n"
2652 "Additional information only in text(Default) mode \n"
2653 "TEMP current temperature (degrees Celsius)\n"
2654 "POWER current power(mW), N/A when query power not supported\n"
2655 "FR current firmware revision\n"
2656 "SN serial number of the Quadra device\n"
2658 "Additional reporting columns for full output format\n"
2659 "VPU same as LOAD in JSON outputs\n"
2661 "TOTAL same as MEM\n"
2662 "CRITICAL usage of memory considered critical\n"
2663 "L_FL2V last ran firmware loader 2 version\n"
2664 "N_FL2V nor flash firmware loader 2 version\n"
2665 "FR current firmware revision\n"
2666 "N_FR nor flash firmware revision\n"
2667 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
2669 "Additional reporting columns for full JSON formats\n"
2671 "FW_LOAD system load\n"
2673 "Extra output shows TEMP and POWER of the Quadra device \n",
2677 printf(
"Release ver: %s\n"
2687 fprintf(stderr,
"FATAL: unknown option '-%c'\n", opt);
2690 fprintf(stderr,
"FATAL: unknown option character '\\x%x'\n", opt);
2697 fprintf(stderr,
"FATAL: option '-%c' lacks arg\n", opt);
2700 fprintf(stderr,
"FATAL: unhandled option\n");
2705 if(checkInterval > 0 && printFormat ==
FMT_JSON)
2707 fprintf(stderr,
"EXIT: -o json cannot use with -n params\n");
2711 if ((argc <= 2) && (
optind == 1))
2726 fprintf(stderr,
"FATAL: cannot allocate momory for ni_session_context_t\n");
2731 if (!skip_init_rsrc && (ret =
ni_rsrc_init(should_match_rev,timeout_seconds)) != 0)
2735 fprintf(stderr,
"FATAL: NI resource unavailable\n");
2740 fprintf(stderr,
"FATAL: cannot access NI resource\n");
2749 fprintf(stderr,
"FATAL: cannot get devices info\n");
2756 printf(
"**************************************************\n");
2768 startTime = time(NULL);
2773 if(previous_detail_data == NULL)
2775 fprintf(stderr,
"FATAL: Allocate buffer fail\n");
2779 memset((
void *)previous_detail_data, 0, allocate_size);
2784 struct tm temp_time;
2788 strftime(buf,
sizeof(buf),
"%c", ltime);
2790 time_diff_seconds = (
long long)difftime(now, startTime);
2791 time_diff_minutes = time_diff_seconds / 60;
2792 time_diff_hours = time_diff_minutes / 60;
2795 if (is_first_query || refresh_device_pool)
2802 printf(
"%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
2809 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2811 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2816 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2818 perror(
"ERROR: cannot lock p_device_pool");
2825 ReleaseMutex((HANDLE)p_device_pool->
lock);
2827 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2829 perror(
"ERROR: cannot unlock p_device_pool");
2833 switch (printFormat)
2837 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
2846 print_json(coders, p_xCtxt, detail, &detail_data_v1);
2851 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
2861 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
2873 is_first_query =
false;
2877 printf(
"**************************************************\n");
2882 if (checkInterval == 0)
2894 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2896 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2901 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2903 perror(
"ERROR: cannot lock p_device_pool");
2908 ReleaseMutex((HANDLE)p_device_pool->
lock);
2910 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2912 perror(
"ERROR: cannot unlock p_device_pool");
2930 #ifdef __OPENHARMONY__
2931 system(
"chmod -R 777 /dev/shm/");
2932 #ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
2933 system(
"chmod 777 /dev/block/vd* 2>/dev/null");
2935 #elif defined(_ANDROID)
2936 system(
"chmod -R 777 /dev/shm/");
2937 system(
"chmod 777 /dev/block/nvme* 2>/dev/null");
2938 system(
"chmod 777 /dev/nvme* 2>/dev/null");
2939 property_set(
"ni_rsrc_init_completed",
"yes");
2943 if(checkInterval && previous_detail_data)
2945 free(previous_detail_data);