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++)
875 device_name, detail, detail_data_v1))
884 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
907 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
924 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
948 printf(
"%s", output_buf.
str_buf);
955 bool copied_block_name;
959 unsigned int number_of_quadras;
960 unsigned int number_of_device_types_present;
961 unsigned int device_type_counter;
962 unsigned int *maximum_firmware_loads;
963 unsigned int *maximum_firmware_loads_per_quadra;
977 maximum_firmware_loads = calloc(number_of_quadras,
sizeof(
unsigned int));
978 if (!maximum_firmware_loads)
980 fprintf(stderr,
"calloc() returned NULL\n");
984 maximum_firmware_loads_per_quadra = NULL;
985 p_device_context = NULL;
987 for (guid = 0; guid < number_of_quadras; guid++)
990 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
991 number_of_device_types_present = 0;
992 device_type_counter = 0;
993 copied_block_name =
false;
996 device_type < maximum_device_type;
999 if (p_device_queue->
xcoders[device_type][guid] != -1)
1001 number_of_device_types_present++;
1006 device_type < maximum_device_type;
1010 g_device_type_str[device_type],
1013 if (p_device_queue->
xcoders[device_type][guid] == -1)
1020 p_device_queue->
xcoders[device_type][guid]);
1024 device_name, detail, detail_data_v1))
1035 "%s: Simple output not supported. Try '-o full' "
1045 if (!copied_block_name)
1050 copied_block_name =
true;
1053 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.
fw_load)
1058 device_type_counter++;
1059 if (device_type_counter < number_of_device_types_present)
1080 if (*maximum_firmware_loads_per_quadra < load_query.
fw_load)
1082 *maximum_firmware_loads_per_quadra = load_query.
fw_load;
1084 if (*maximum_firmware_loads_per_quadra < load_query.
tp_fw_load)
1086 *maximum_firmware_loads_per_quadra = load_query.
tp_fw_load;
1089 *maximum_firmware_loads_per_quadra);
1094 stderr,
"ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1108 printf(
"%s", output_buf.
str_buf);
1110 free(maximum_firmware_loads);
1117 unsigned int index, device_count;
1119 int32_t *module_ids;
1120 uint32_t total_contexts;
1122 uint32_t model_load;
1124 char pcie[64] = {0};
1138 device_type != max_device_type;
1152 for (index = 0; index < device_count; index++)
1160 device_name, detail, detail_data_v1))
1197 "\t\t\t\"NUMBER\": %u,\n"
1198 "\t\t\t\"INDEX\": %u,\n"
1199 "\t\t\t\"AvgCost\": %u,\n"
1200 "\t\t\t\"FrameRate\": %u,\n"
1201 "\t\t\t\"IDR\": %u,\n"
1202 "\t\t\t\"InFrame\": %u,\n"
1203 "\t\t\t\"OutFrame\": %u,\n"
1204 "\t\t\t\"Width\": %u,\n"
1205 "\t\t\t\"Height\": %u,\n"
1206 "\t\t\t\"SID\": %s,\n"
1207 "\t\t\t\"DEVICE\": \"%s\",\n"
1225 "\t\t\t\"NUMBER\": %u,\n"
1226 "\t\t\t\"INDEX\": %u,\n"
1227 "\t\t\t\"AvgCost\": %u,\n"
1228 "\t\t\t\"FrameRate\": %u,\n"
1229 "\t\t\t\"IDR\": %u,\n"
1230 "\t\t\t\"UserIDR\": %u,\n"
1231 "\t\t\t\"InFrame\": %u,\n"
1232 "\t\t\t\"OutFrame\": %u,\n"
1233 "\t\t\t\"BR\": %u,\n"
1234 "\t\t\t\"AvgBR\": %u,\n"
1235 "\t\t\t\"Width\": %u,\n"
1236 "\t\t\t\"Height\": %u,\n"
1237 "\t\t\t\"Format\": %s,\n"
1238 "\t\t\t\"SID\": %s,\n"
1239 "\t\t\t\"DEVICE\": \"%s\",\n"
1273 "\t\t\t\"NUMBER\": %u,\n"
1274 "\t\t\t\"INDEX\": %d,\n"
1275 "\t\t\t\"LOAD\": %u,\n"
1276 "\t\t\t\"LOAD-ALL\": %u,\n"
1277 "\t\t\t\"MODEL_LOAD\": %u,\n"
1278 "\t\t\t\"MODEL_LOAD-ALL\": %u,\n"
1279 "\t\t\t\"FW_LOAD\": %u,\n"
1280 "\t\t\t\"INST\": %u,\n"
1281 "\t\t\t\"INST-ALL\": %u,\n"
1282 "\t\t\t\"MAX_INST\": %d,\n"
1283 "\t\t\t\"MEM\": %u,\n"
1284 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1285 "\t\t\t\"SHARE_MEM\": %u,\n"
1286 "\t\t\t\"P2P_MEM\": %u,\n"
1287 "\t\t\t\"DEVICE\": \"%s\",\n"
1288 "\t\t\t\"L_FL2V\": \"%s\",\n"
1289 "\t\t\t\"N_FL2V\": \"%s\",\n"
1290 "\t\t\t\"FR\": \"%.8s\",\n"
1291 "\t\t\t\"N_FR\": \"%.8s\""
1293 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1294 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1301 device_name, device_count,
1331 "\t\t\t\"NUMBER\": %u,\n"
1332 "\t\t\t\"INDEX\": %d,\n"
1333 "\t\t\t\"LOAD\": %u,\n"
1334 "\t\t\t\"MODEL_LOAD\": %u,\n"
1335 "\t\t\t\"FW_LOAD\": %u,\n"
1336 "\t\t\t\"INST\": %u,\n"
1337 "\t\t\t\"MAX_INST\": %d,\n"
1338 "\t\t\t\"MEM\": %u,\n"
1339 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1340 "\t\t\t\"SHARE_MEM\": %u,\n"
1341 "\t\t\t\"P2P_MEM\": %u,\n"
1342 "\t\t\t\"DEVICE\": \"%s\",\n"
1343 "\t\t\t\"L_FL2V\": \"%s\",\n"
1344 "\t\t\t\"N_FL2V\": \"%s\",\n"
1345 "\t\t\t\"FR\": \"%.8s\",\n"
1346 "\t\t\t\"N_FR\": \"%.8s\""
1348 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1349 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1356 device_name, device_count,
1394 printf(
"%s", output_buf.
str_buf);
1417 printf(
"%s", output_buf.
str_buf);
1423 strcpy(device_name,
"nvme");
1424 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1427 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1430 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1433 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1439 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1445 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1451 (icore ==
TP_LOAD)?strcpy(device_name,
"tp"):strcpy(device_name,
"pcie");
1453 for (index = 0; index < device_count; index++)
1463 device_name, detail, detail_data_v1))
1473 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1501 "\t\t\t\"NUMBER\": %u,\n"
1502 "\t\t\t\"INDEX\": %d,\n"
1503 "\t\t\t\"LOAD\": 0,\n"
1504 "\t\t\t\"MODEL_LOAD\": 0,\n"
1505 "\t\t\t\"FW_LOAD\": %u,\n"
1506 "\t\t\t\"INST\": 0,\n"
1507 "\t\t\t\"MAX_INST\": 0,\n"
1508 "\t\t\t\"MEM\": 0,\n"
1509 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1510 "\t\t\t\"SHARE_MEM\": %u,\n"
1511 "\t\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1512 "\t\t\t\"P2P_MEM\": 0,\n"
1513 "\t\t\t\"DEVICE\": \"%s\",\n"
1514 "\t\t\t\"L_FL2V\": \"%s\",\n"
1515 "\t\t\t\"N_FL2V\": \"%s\",\n"
1516 "\t\t\t\"FR\": \"%.8s\",\n"
1517 "\t\t\t\"N_FR\": \"%.8s\""
1519 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1520 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1527 device_name, device_count,
1550 "\t\t\t\"NUMBER\": %u,\n"
1551 "\t\t\t\"INDEX\": %d,\n"
1552 "\t\t\t\"LOAD\": 0,\n"
1553 "\t\t\t\"MODEL_LOAD\": 0,\n"
1554 "\t\t\t\"FW_LOAD\": %u,\n"
1555 "\t\t\t\"INST\": 0,\n"
1556 "\t\t\t\"MAX_INST\": 0,\n"
1557 "\t\t\t\"MEM\": 0,\n"
1558 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1559 "\t\t\t\"SHARE_MEM\": %u,\n"
1560 "\t\t\t\"P2P_MEM\": 0,\n"
1561 "\t\t\t\"DEVICE\": \"%s\",\n"
1562 "\t\t\t\"L_FL2V\": \"%s\",\n"
1563 "\t\t\t\"N_FL2V\": \"%s\",\n"
1564 "\t\t\t\"FR\": \"%.8s\",\n"
1565 "\t\t\t\"N_FR\": \"%.8s\""
1567 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1568 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1575 device_name, device_count,
1602 printf(
"%s", output_buf.
str_buf);
1609 bool has_written_start =
false;
1611 unsigned int index, device_count;
1612 int32_t *module_ids;
1613 uint32_t total_contexts;
1615 uint32_t model_load;
1617 char pcie[64] = {0};
1622 char power_consumption[16];
1643 if (!has_written_start)
1646 has_written_start =
true;
1653 for (index = 0; index < device_count; index++)
1661 device_name, detail, detail_data_v1))
1700 "\t\t\"NUMBER\": %u,\n"
1701 "\t\t\"INDEX\": %d,\n"
1702 "\t\t\"LOAD\": %u,\n"
1703 "\t\t\"LOAD-ALL\": %u,\n"
1704 "\t\t\"MODEL_LOAD\": %u,\n"
1705 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1706 "\t\t\"FW_LOAD\": %u,\n"
1707 "\t\t\"INST\": %u,\n"
1708 "\t\t\"INST-ALL\": %u,\n"
1709 "\t\t\"MAX_INST\": %d,\n"
1710 "\t\t\"MEM\": %u,\n"
1711 "\t\t\"CRITICAL_MEM\": %u,\n"
1712 "\t\t\"SHARE_MEM\": %u,\n"
1713 "\t\t\"P2P_MEM\": %u,\n"
1714 "\t\t\"DEVICE\": \"%s\",\n"
1715 "\t\t\"L_FL2V\": \"%s\",\n"
1716 "\t\t\"N_FL2V\": \"%s\",\n"
1717 "\t\t\"FR\": \"%.8s\",\n"
1718 "\t\t\"N_FR\": \"%.8s\""
1720 ",\n\t\t\"NUMA_NODE\": %d,\n"
1721 "\t\t\"PCIE_ADDR\": \"%s\""
1749 "\t\t\"NUMBER\": %u,\n"
1750 "\t\t\"INDEX\": %d,\n"
1751 "\t\t\"LOAD\": %u,\n"
1752 "\t\t\"MODEL_LOAD\": %u,\n"
1753 "\t\t\"FW_LOAD\": %u,\n"
1754 "\t\t\"INST\": %u,\n"
1755 "\t\t\"MAX_INST\": %d,\n"
1756 "\t\t\"MEM\": %u,\n"
1757 "\t\t\"CRITICAL_MEM\": %u,\n"
1758 "\t\t\"SHARE_MEM\": %u,\n"
1759 "\t\t\"P2P_MEM\": %u,\n"
1760 "\t\t\"DEVICE\": \"%s\",\n"
1761 "\t\t\"L_FL2V\": \"%s\",\n"
1762 "\t\t\"N_FL2V\": \"%s\",\n"
1763 "\t\t\"FR\": \"%.8s\",\n"
1764 "\t\t\"N_FR\": \"%.8s\""
1766 ",\n\t\t\"NUMA_NODE\": %d,\n"
1767 "\t\t\"PCIE_ADDR\": \"%s\""
1792 ",\n\t\t\"TEMP\": %d,\n"
1793 "\t\t\"POWER\": \"%s\"\n"
1802 if (index < device_count - 1)
1844 printf(
"%s", output_buf.
str_buf);
1851 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1854 fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1857 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1860 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1866 fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1872 fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1880 for (index = 0; index < device_count; index++)
1890 device_name, detail, detail_data_v1))
1900 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1938 "\t\t\"NUMBER\": %u,\n"
1939 "\t\t\"INDEX\": %d,\n"
1940 "\t\t\"LOAD\": 0,\n"
1941 "\t\t\"MODEL_LOAD\": 0,\n"
1942 "\t\t\"FW_LOAD\": %u,\n"
1943 "\t\t\"INST\": 0,\n"
1944 "\t\t\"MAX_INST\": 0,\n"
1946 "\t\t\"CRITICAL_MEM\": 0,\n"
1947 "\t\t\"SHARE_MEM\": %u,\n"
1948 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1949 "\t\t\"P2P_MEM\": 0,\n"
1950 "\t\t\"DEVICE\": \"%s\",\n"
1951 "\t\t\"L_FL2V\": \"%s\",\n"
1952 "\t\t\"N_FL2V\": \"%s\",\n"
1953 "\t\t\"FR\": \"%.8s\",\n"
1954 "\t\t\"N_FR\": \"%.8s\""
1956 ",\n\t\t\"NUMA_NODE\": %d,\n"
1957 "\t\t\"PCIE_ADDR\": \"%s\""
1979 "\t\t\"NUMBER\": %u,\n"
1980 "\t\t\"INDEX\": %d,\n"
1981 "\t\t\"LOAD\": 0,\n"
1982 "\t\t\"MODEL_LOAD\": 0,\n"
1983 "\t\t\"FW_LOAD\": %u,\n"
1984 "\t\t\"INST\": 0,\n"
1985 "\t\t\"MAX_INST\": 0,\n"
1987 "\t\t\"CRITICAL_MEM\": 0,\n"
1988 "\t\t\"SHARE_MEM\": %u,\n"
1989 "\t\t\"P2P_MEM\": 0,\n"
1990 "\t\t\"DEVICE\": \"%s\",\n"
1991 "\t\t\"L_FL2V\": \"%s\",\n"
1992 "\t\t\"N_FL2V\": \"%s\",\n"
1993 "\t\t\"FR\": \"%.8s\",\n"
1994 "\t\t\"N_FR\": \"%.8s\""
1996 ",\n\t\t\"NUMA_NODE\": %d,\n"
1997 "\t\t\"PCIE_ADDR\": \"%s\""
2015 ",\n\t\t\"TEMP\": %d,\n"
2016 "\t\t\"POWER\": \"%s\"\n"
2025 if (index < device_count - 1)
2052 printf(
"%s", output_buf.
str_buf);
2059 int i, index, instance_count;
2060 unsigned int module_count;
2062 int32_t *module_id_arr = NULL;
2071 module_type != max_device_type;
2085 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", module_name, module_count);
2093 "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2094 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2095 "SID",
"DEVICE",
"NAMESPACE");
2100 "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2101 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"Width",
"Height",
2102 "SID",
"DEVICE",
"NAMESPACE");
2110 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2111 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"fps",
"BR",
"AvgBR",
"Width",
"Height",
2112 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2117 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2118 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"BR",
"AvgBR",
"Width",
"Height",
2119 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2125 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
2126 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
2130 for (i = 0; i < module_count; i++)
2138 module_name, detail, detail_data_v1))
2146 if(previous_detail_data_p && checkInterval)
2148 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2153 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2160 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2170 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2178 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2195 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2211 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2231 if(previous_detail_data_p)
2239 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2258 free(module_id_arr);
2262 printf(
"%s", output_buf.
str_buf);
2269 unsigned int index, device_count;
2270 int32_t *module_ids;
2275 char power_consumption[16];
2276 int instance_count = 0;
2288 printf(
"%s", output_buf.
str_buf);
2293 for (index = 0; index < device_count; index++)
2296 if (!p_device_context)
2303 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2312 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
2319 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
2322 "ERROR: ni_device_open() failed for %s: %s\n",
2343 "%-4s %-8s %-14s\n",
"TEMP",
"POWER",
"DEVICE");
2345 "%-4d %-8s %-14s\n",
2352 if (instance_count == 0)
2355 "%-8s %-8s %-8s %-8.8s %-8.8s \n",
"INDEX",
"TEMP",
"POWER",
"FR",
"SN");
2358 "%-8d %-8d %-8s %-8.8s %-8.*s \n",
2369 printf(
"%s", output_buf.
str_buf);
2376 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2378 int skip_init_rsrc = 0;
2379 int should_match_rev = 1;
2386 time_t startTime = {0}, now = {0};
2387 int timeout_seconds = 0;
2388 struct tm *ltime = NULL;
2390 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2395 bool fw_log_dump =
false;
2397 int refresh_device_pool = 1;
2398 bool is_first_query =
true;
2402 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2404 setup_signal_handler();
2408 while ((opt =
getopt(argc, argv,
"n:o:D:k:R:rt:Sl:hvd")) != -1)
2414 if (!strcmp(
optarg,
"json"))
2418 else if (!strcmp(
optarg,
"simple"))
2422 else if (!strcmp(
optarg,
"text"))
2426 else if (!strcmp(
optarg,
"full"))
2430 else if (!strcmp(
optarg,
"json1"))
2434 else if (!strcmp(
optarg,
"json2"))
2438 else if (!strcmp(
optarg,
"extra"))
2444 fprintf(stderr,
"Error: unknown selection for outputFormat: %s\n",
optarg);
2461 should_match_rev = 0;
2465 printf(
"Timeout will be set %d\n", timeout_seconds);
2476 fprintf(stderr,
"FATAL: invalid log level selected: %s\n",
optarg);
2482 printf(
"-------- ni_rsrc_mon v%s --------\n"
2483 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
2484 "running on the system.\n"
2486 "Usage: ni_rsrc_mon [OPTIONS]\n"
2487 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
2488 " report only once.\n"
2490 "-R Specify if refresh devices on host in each monitor interval.\n"
2491 " If 0, only refresh devices at the start.\n"
2493 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
2495 "-D Dump firmware logs to current directory. Default: 0(not dump fw log).\n"
2496 "-k Specify to dump which card's firmware logs.\n"
2497 " Default: -1(dump fw log of all cards).\n"
2498 "-r Initialize Quadra device regardless firmware release version to\n"
2499 " libxcoder version compatibility.\n"
2500 " Default: only initialize devices with compatible firmware version.\n"
2501 "-t Set timeout time in seconds for device polling. Program will exit with\n"
2502 " failure if timeout is reached without finding at least one device. If 0 or\n"
2503 " no selection, poll indefinitely until a Quadra device is found.\n"
2505 "-S Skip init_rsrc.\n"
2506 "-d Print detailed infomation for decoder/encoder in text and json formats.\n"
2507 "-l Set loglevel of libxcoder API.\n"
2508 " [none, fatal, error, info, debug, trace]\n"
2510 "-h Open this help message.\n"
2511 "-v Print version info.\n"
2513 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
2516 "Reporting columns for text output format\n"
2517 "INDEX index number used by resource manager to identify the resource\n"
2518 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
2519 "MODEL_LOAD estimated load based on framerate and resolution\n"
2520 "INST number of job instances\n"
2521 "MEM usage of memory by the subsystem\n"
2522 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
2523 "P2P_MEM usage of memory by P2P\n"
2524 "DEVICE path to NVMe device file handle\n"
2525 "NAMESPACE path to NVMe namespace file handle\n"
2527 "Additional reporting columns for full output format\n"
2528 "VPU same as LOAD in JSON outputs\n"
2530 "TOTAL same as MEM\n"
2531 "CRITICAL usage of memory considered critical\n"
2532 "L_FL2V last ran firmware loader 2 version\n"
2533 "N_FL2V nor flash firmware loader 2 version\n"
2534 "FR current firmware revision\n"
2535 "N_FR nor flash firmware revision\n"
2537 "Additional reporting columns for full JSON formats\n"
2539 "FW_LOAD system load\n",
2543 printf(
"Release ver: %s\n"
2553 fprintf(stderr,
"FATAL: unknown option '-%c'\n", opt);
2556 fprintf(stderr,
"FATAL: unknown option character '\\x%x'\n", opt);
2563 fprintf(stderr,
"FATAL: option '-%c' lacks arg\n", opt);
2566 fprintf(stderr,
"FATAL: unhandled option\n");
2571 if(checkInterval > 0 && printFormat ==
FMT_JSON)
2573 fprintf(stderr,
"EXIT: -o json cannot use with -n params\n");
2577 if ((argc <= 2) && (
optind == 1))
2592 fprintf(stderr,
"FATAL: cannot allocate momory for ni_session_context_t\n");
2597 if (!skip_init_rsrc && (ret =
ni_rsrc_init(should_match_rev,timeout_seconds)) != 0)
2601 fprintf(stderr,
"FATAL: NI resource unavailable\n");
2606 fprintf(stderr,
"FATAL: cannot access NI resource\n");
2615 fprintf(stderr,
"FATAL: cannot get devices info\n");
2622 printf(
"**************************************************\n");
2634 startTime = time(NULL);
2639 if(previous_detail_data == NULL)
2641 fprintf(stderr,
"FATAL: Allocate buffer fail\n");
2645 memset((
void *)previous_detail_data, 0, allocate_size);
2650 ltime = localtime(&now);
2653 strftime(buf,
sizeof(buf),
"%c", ltime);
2655 time_diff_seconds = (
long long)difftime(now, startTime);
2656 time_diff_minutes = time_diff_seconds / 60;
2657 time_diff_hours = time_diff_minutes / 60;
2660 if (is_first_query || refresh_device_pool)
2667 printf(
"%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
2674 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2676 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2681 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2683 perror(
"ERROR: cannot lock p_device_pool");
2690 ReleaseMutex((HANDLE)p_device_pool->
lock);
2692 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2694 perror(
"ERROR: cannot unlock p_device_pool");
2698 switch (printFormat)
2702 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
2711 print_json(coders, p_xCtxt, detail, &detail_data_v1);
2714 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
2717 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
2724 is_first_query =
false;
2728 printf(
"**************************************************\n");
2733 if (checkInterval == 0)
2745 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
2747 fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
2752 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
2754 perror(
"ERROR: cannot lock p_device_pool");
2759 ReleaseMutex((HANDLE)p_device_pool->
lock);
2761 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
2763 perror(
"ERROR: cannot unlock p_device_pool");
2781 #ifdef __OPENHARMONY__
2782 system(
"chmod -R 777 /dev/shm/");
2783 #ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
2784 system(
"chmod 777 /dev/block/vd* 2>/dev/null");
2786 #elif defined(_ANDROID)
2787 system(
"chmod -R 777 /dev/shm/");
2788 system(
"chmod 777 /dev/block/nvme* 2>/dev/null");
2789 system(
"chmod 777 /dev/nvme* 2>/dev/null");
2790 property_set(
"ni_rsrc_init_completed",
"yes");
2794 if(checkInterval && previous_detail_data)
2796 free(previous_detail_data);