29#if __linux__ || __APPLE__
49#define MAX_DEVICE_NAME_SIZE (9)
50#define ABSOLUTE_TEMP_ZERO (-273)
55#define VIDEO_PROCESSING_SLICES 4
56#define THROTTLE_REF_WIN_US (1 << (10 + 7))
57#define VIDEO_SLICE_TIME (THROTTLE_REF_WIN_US * VIDEO_PROCESSING_SLICES)
81 default:
return "none";
86 ni_device_handle_t handle,
90 if (p_info && p_extra && handle != NI_INVALID_DEVICE_HANDLE &&
109#include <cutils/properties.h>
110#define PROP_DECODER_TYPE "nidec_service_init"
111#define LOG_TAG "ni_rsrc_mon"
132static BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
166void sig_handler(
int sig)
168 if (sig == SIGTERM || sig == SIGINT || sig == SIGHUP)
181void setup_signal_handler(
void)
183 if (signal(SIGTERM, sig_handler) == SIG_ERR ||
184 signal(SIGHUP, sig_handler) == SIG_ERR ||
185 signal(SIGINT, sig_handler) == SIG_ERR)
187 perror(
"ERROR: signal handler setup");
198void get_pcie_addr(
char *device_name,
char *pcie)
210int get_numa_node(
char *device_name)
229 ni_device_handle_t device_handle)
233 (void)fprintf(stderr,
"Error: device_type %d is not a valid device type\n",
238 if (
device_handles[xcoder_device_type][module_id] == device_handle)
241 NI_INVALID_DEVICE_HANDLE;
245 (void)fprintf(stderr,
246 "Error: device_handle to remove %" PRId64
247 "not match device_handles[%d][%d]=%" PRId64
"\n",
248 (int64_t)device_handle, device_type, module_id,
270 const size_t len = strlen(numArray);
272 for (i = 0; i < len; i++)
274 if (!isdigit(numArray[i]))
276 (void)fprintf(stderr,
"invalid, ABORTING\n");
302 if ( *(int32_t*)a < *(int32_t*)b )
return -1;
303 if ( *(int32_t*)a > *(int32_t*)b )
return 1;
314 else if ((index >= 0 && index < 4) || (index >= 10 && index < 13))
318 else if (index >= 4 && index < 10)
322 else if (index >= 13 && index < 15)
331static char sid[5] =
"0000";
337 (void)snprintf(sid,
sizeof(sid),
"%04x", 0);
342 (void)snprintf(sid,
sizeof(sid),
"%04x", id);
350 int32_t **module_ids)
352 unsigned int device_count;
355 size_of_i32 =
sizeof(int32_t);
357 device_count = p_device_queue->
xcoder_cnt[device_type];
358 *module_ids = malloc(size_of_i32 * device_count);
361 (void)fprintf(stderr,
"ERROR: malloc() failed for module_ids\n");
366 p_device_queue->
xcoders[device_type],
367 size_of_i32 * device_count);
375 g_device_type_str[device_type],
388 if (!p_device_context)
396 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
405 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
412 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
416 (void)fprintf(stderr,
417 "ERROR: ni_device_open2() failed for %s: %s\n",
426 p_session_context->
hw_id =
434 (void)fprintf(stderr,
435 "ERROR: cannot print detailed info for %s as it has FW API "
457 (void)fprintf(stderr,
458 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
475 memcpy(p_session_context->
fw_rev,
488 if (!p_device_context)
494 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
498 (void)fprintf(stderr,
499 "ERROR: ni_device_open2() failed for %s: %s\n",
507 p_session_context->
hw_id =
509 memcpy(p_session_context->
fw_rev,
511 sizeof(p_session_context->
fw_rev));
514 return return_code ? false :
true;
531 void *p_log_buffer = NULL;
535 if (!
open_and_get_log(p_device_context, p_session_context, &p_log_buffer, gen_log_file)) {
536 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n", module_id, blk_name);
538 printf(
"Success: dumped fw log of card:%d blk_name:%s\n", module_id, blk_name);
546 printf(
"Info: artifacts not supported by card:%d fw_rev:%.8s, skipping\n",
555 printf(
"Info: fw log artifacts checked for card:%d blk_name:%s\n", module_id, blk_name);
559 printf(
"Error: fw log artifacts read failed for card:%d blk_name:%s\n", module_id, blk_name);
579 unsigned int module_count;
580 int32_t *module_id_arr = NULL;
585 module_count =
get_modules(module_type, coders, module_name, &module_id_arr);
587 printf(
"Error: module not found!\n");
591 bool gen_log_file =
true;
593 if (devid >= 0 && (uint32_t)devid < module_count)
597 if (!p_device_context)
601 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
609 for (i = 0; i < module_count; i++)
612 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
621#if defined(__linux__)
637static int run_bar4_operations(
const char *nor_cmd,
638 const char *t_domain,
const char *t_slot,
639 const char *t_blkdev)
643 (void)fprintf(stderr,
644 "This operation requires root (sudo). "
645 "Please rerun: sudo ni_rsrc_mon [options]\n");
649 bool is_device_selected = (t_slot != NULL || t_blkdev != NULL);
652 if (!is_device_selected)
655 rc = ni_rsrc_nor_log_command(nor_cmd,
".");
657 (void)fprintf(stderr,
"NOR flash command: all devices successful.\n");
659 (void)fprintf(stderr,
"NOR flash command: No Quadra devices found.\n");
661 (void)fprintf(stderr,
662 "NOR flash command: One or more devices failed.\n");
664 (
void)fprintf(stderr,
665 "NOR flash command: Unexpected error %d.\n", rc);
671 if (nor_cmd_decode(nor_cmd, &cmd) != 0)
674 QuadraDevice *dev = NULL;
676 ? quadra_device_find_by_bdf(t_domain ? t_domain :
"0000",
678 : quadra_device_find_by_block_dev(t_blkdev, &dev);
681 (void)fprintf(stderr,
"[ERROR] Target Quadra device not found.\n");
686 rc = ni_rsrc_nor_cmd_run(dev, 1, cmd,
".");
697 switch (*p_device_type)
710#define DYN_STR_BUF_CHUNK_SIZE 4096
732 int add_buf_size = 0;
733 char *tmp_char_ptr = NULL;
737 (void)fprintf(stderr,
"ERROR: invalid param *dyn_str_buf\n");
751 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
756 add_buf_size = (formatted_len + 1) > avail_buf ?
770 (void)fprintf(stderr,
"ERROR: strcat_dyn_buf() failed realloc()\n");
794#define NI_RSRC_MON_CARD_CACHE_MAX NI_MAX_DEVICE_CNT
807 for (i = 0; i < n; i++) {
810 cache[i].
valid =
false;
816 const char *blk_name)
819 if (!blk_name || !blk_name[0])
821 for (i = 0; i < n; i++) {
822 if (cache[i].valid &&
829static unsigned int build_card_and_qos_cache(
837 unsigned int index, card_count;
838 int32_t *card_module_ids = NULL;
842 char power_consumption[16];
848 card_count =
get_modules(card_type, p_device_queue, device_name,
854 for (index = 0; index < card_count; index++) {
859 uint16_t namespace_id = 0;
860 uint8_t qos_mode = 0;
862 cache[index].
valid =
false;
863 memset(cache[index].blk_name, 0,
sizeof(cache[index].blk_name));
866 card_module_ids[index]);
867 if (!p_device_context)
870 if (!
open_and_query(card_type, p_device_context, p_session_context,
871 device_name, detail, detail_data_v1)) {
879 cache[index].
valid =
true;
881 memset(&dev_extra, 0,
sizeof(dev_extra));
891 card_err = ni_rsrc_mon_get_card_error(p_session_context->
device_handle,
901 "\n\t\t\"DEVICE\": \"%s\",\n"
902 "\t\t\"L_FL2V\": \"%s\",\n"
903 "\t\t\"N_FL2V\": \"%s\",\n"
904 "\t\t\"FR\": \"%.8s\",\n"
905 "\t\t\"N_FR\": \"%.8s\",\n"
907 "\t\t\"NUMA_NODE\": %d,\n"
908 "\t\t\"PCIE_ADDR\": \"%s\",\n"
910 "\t\t\"TEMP\": %d,\n"
911 "\t\t\"POWER\": \"%s\",\n"
912 "\t\t\"SN\": \"%-8.*s\",\n"
913 "\t\t\"ERROR\": \"%s\",\n"
914 "\t\t\"FLAVOR\": \"%1c\"",
925 (int)sizeof(p_device_context->p_device_info->serial_number),
926 p_device_context->p_device_info->serial_number,
927 ni_rsrc_mon_card_error_str(card_err),
936 namespace_id = ns_vf_id.
ns_id;
948 ",\n\t\t\"QOS_MODE\": %u,\n"
949 "\t\t\"QOS_NS\": %u,\n"
950 "\t\t\"QOS_ALLOW\": %.1f,\n"
951 "\t\t\"QOS_OPMAX\": %.1f",
954 (qos_mode == 0 ? 0 : qos_ns_info.fAllowance),
955 (qos_mode == 0 ? 0 : opmax));
963 free(card_module_ids);
971 unsigned int index, device_count;
994 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", device_name, device_count);
1000 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
1001 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1006 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
1007 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1011 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
1012 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1016 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
1017 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1023 for (index = 0; index < device_count; index++)
1031 device_name, detail, detail_data_v1))
1048 switch (device_type)
1052 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1053 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1056 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
1072 "%-5d %-3u %-3u %-3u/%-3d %-3u "
1073 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1089 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1090 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1093 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
1109 "%-5d %-3u %-3u/%-3d %-3u "
1110 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1157 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1160 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1163 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1166 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1172 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1178 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1191 "INDEX LOAD( FW ) PCIE_Card2Host_Gbps "
1192 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1197 "INDEX LOAD( FW ) MEM( SHARE ) "
1198 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1203 printf(
"%s", output_buf.
str_buf);
1212 for (index = 0; index < device_count; index++)
1216 if (!p_device_context)
1223 device_name, detail, detail_data_v1))
1231 (void)fprintf(stderr,
1232 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1255 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1272 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1296 printf(
"%s", output_buf.
str_buf);
1303 bool copied_block_name;
1307 unsigned int number_of_quadras;
1308 unsigned int number_of_device_types_present;
1309 unsigned int device_type_counter;
1310 unsigned int *maximum_firmware_loads;
1311 unsigned int *maximum_firmware_loads_per_quadra;
1325 maximum_firmware_loads = calloc(number_of_quadras,
sizeof(
unsigned int));
1326 if (!maximum_firmware_loads)
1328 (void)fprintf(stderr,
"calloc() returned NULL\n");
1332 maximum_firmware_loads_per_quadra = NULL;
1333 p_device_context = NULL;
1335 for (guid = 0; guid < number_of_quadras; guid++)
1338 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
1339 number_of_device_types_present = 0;
1340 device_type_counter = 0;
1341 copied_block_name =
false;
1344 device_type < maximum_device_type;
1347 if (p_device_queue->
xcoders[device_type][guid] != -1)
1349 number_of_device_types_present++;
1354 device_type < maximum_device_type;
1358 g_device_type_str[device_type],
1361 if (p_device_queue->
xcoders[device_type][guid] == -1)
1368 p_device_queue->
xcoders[device_type][guid]);
1372 device_name, detail, detail_data_v1))
1383 "%s: Simple output not supported. Try '-o full' "
1393 if (!copied_block_name)
1398 copied_block_name =
true;
1401 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.
fw_load)
1406 device_type_counter++;
1407 if (device_type_counter < number_of_device_types_present)
1428 if (*maximum_firmware_loads_per_quadra < load_query.
fw_load)
1430 *maximum_firmware_loads_per_quadra = load_query.
fw_load;
1432 if (*maximum_firmware_loads_per_quadra < load_query.
tp_fw_load)
1434 *maximum_firmware_loads_per_quadra = load_query.
tp_fw_load;
1437 *maximum_firmware_loads_per_quadra);
1442 stderr,
"ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1456 printf(
"%s", output_buf.
str_buf);
1458 free(maximum_firmware_loads);
1464 unsigned int i, index, device_count;
1466 int32_t *module_ids;
1474 int first_item_printed = 0;
1475 int first_device_type_printed = 0;
1480 device_type != max_device_type;
1493 if(first_device_type_printed)
1502 first_item_printed = 0;
1504 for (i = 0; i < device_count; i++)
1512 device_name, detail, detail_data_v1))
1521 if(first_item_printed)
1530 "\t\t\t\"NUMBER\": %u,\n"
1531 "\t\t\t\"INDEX\": %u,\n"
1532 "\t\t\t\"AvgCost\": %u,\n"
1533 "\t\t\t\"FrameRate\": %u,\n"
1534 "\t\t\t\"IDR\": %u,\n"
1535 "\t\t\t\"InFrame\": %u,\n"
1536 "\t\t\t\"OutFrame\": %u,\n"
1537 "\t\t\t\"Width\": %u,\n"
1538 "\t\t\t\"Height\": %u,\n"
1539 "\t\t\t\"SID\": \"%s\",\n"
1540 "\t\t\t\"DEVICE\": \"%s\"\n"
1558 "\t\t\t\"NUMBER\": %u,\n"
1559 "\t\t\t\"INDEX\": %u,\n"
1560 "\t\t\t\"AvgCost\": %u,\n"
1561 "\t\t\t\"FrameRate\": %u,\n"
1562 "\t\t\t\"IDR\": %u,\n"
1563 "\t\t\t\"UserIDR\": %u,\n"
1564 "\t\t\t\"InFrame\": %u,\n"
1565 "\t\t\t\"OutFrame\": %u,\n"
1566 "\t\t\t\"BR\": %u,\n"
1567 "\t\t\t\"AvgBR\": %u,\n"
1568 "\t\t\t\"Width\": %u,\n"
1569 "\t\t\t\"Height\": %u,\n"
1570 "\t\t\t\"Format\": \"%s\",\n"
1571 "\t\t\t\"SID\": \"%s\",\n"
1572 "\t\t\t\"DEVICE\": \"%s\"\n"
1590 first_item_printed = 1;
1599 first_device_type_printed = 1;
1607 printf(
"%s", output_buf.
str_buf);
1619 bool has_written_start =
false;
1621 unsigned int index, device_count, card_count = 0;
1622 int32_t *module_ids = NULL;
1623 uint32_t total_contexts, vpu_load, model_load;
1633 int32_t *extra_temp_per_index = NULL;
1634 uint32_t *extra_power_per_index = NULL;
1636 memset(card_cache, 0,
sizeof(card_cache));
1638 card_count = build_card_and_qos_cache(p_device_queue, p_session_context,
1639 detail, detail_data_v1,
1647 device_count =
get_modules(device_type, p_device_queue, device_name,
1653 if (!has_written_start)
1656 has_written_start =
true;
1663 for (index = 0; index < device_count; index++)
1667 if (!
open_and_query(device_type, p_device_context, p_session_context,
1668 device_name, detail, detail_data_v1))
1681 p_card = lookup_card_cache(card_cache, card_count,
1689 "\t\t\"NUMBER\": %u,\n"
1690 "\t\t\"INDEX\": %d,\n"
1691 "\t\t\"LOAD\": %u,\n"
1692 "\t\t\"LOAD-ALL\": %u,\n"
1693 "\t\t\"MODEL_LOAD\": %u,\n"
1694 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1695 "\t\t\"FW_LOAD\": %u,\n"
1696 "\t\t\"INST\": %u,\n"
1697 "\t\t\"INST-ALL\": %u,\n"
1698 "\t\t\"MAX_INST\": %d,\n"
1699 "\t\t\"MEM\": %u,\n"
1700 "\t\t\"CRITICAL_MEM\": %u,\n"
1701 "\t\t\"SHARE_MEM\": %u,\n"
1702 "\t\t\"P2P_MEM\": %u,\n"
1722 "\t\t\"NUMBER\": %u,\n"
1723 "\t\t\"INDEX\": %d,\n"
1724 "\t\t\"LOAD\": %u,\n"
1725 "\t\t\"MODEL_LOAD\": %u,\n"
1726 "\t\t\"FW_LOAD\": %u,\n"
1727 "\t\t\"INST\": %u,\n"
1728 "\t\t\"MAX_INST\": %d,\n"
1729 "\t\t\"MEM\": %u,\n"
1730 "\t\t\"CRITICAL_MEM\": %u,\n"
1731 "\t\t\"SHARE_MEM\": %u,\n"
1732 "\t\t\"P2P_MEM\": %u,\n"
1735 vpu_load, model_load,
1754 strcat_dyn_buf(&output_buf, (index < device_count - 1) ?
",\n" :
"\n");
1766 goto PRINT_OUTPUT_FINAL;
1773 device_count =
get_modules(device_type, p_device_queue, device_name,
1775 if (!device_count) {
1776 clear_card_cache(card_cache, card_count);
1778 printf(
"%s", output_buf.
str_buf);
1785 extra_temp_per_index = (int32_t *)calloc(device_count,
sizeof(int32_t));
1786 extra_power_per_index = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1788 g_temp_load = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1789 g_temp_pload = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1796 (icore ==
TP_LOAD) ?
" \"tps\": [\n" :
" \"pcies\": [\n");
1799 for (index = 0; index < device_count; index++)
1803 if (!p_device_context)
1807 if (!
open_and_query(device_type, p_device_context, p_session_context,
1808 device_name, detail, detail_data_v1))
1825 p_card = lookup_card_cache(card_cache, card_count,
1833 "\t\t\"NUMBER\": %u,\n"
1834 "\t\t\"INDEX\": %d,\n"
1835 "\t\t\"LOAD\": 0,\n"
1836 "\t\t\"MODEL_LOAD\": 0,\n"
1837 "\t\t\"FW_LOAD\": %u,\n"
1838 "\t\t\"INST\": 0,\n"
1839 "\t\t\"MAX_INST\": 0,\n"
1841 "\t\t\"CRITICAL_MEM\": 0,\n"
1842 "\t\t\"SHARE_MEM\": 0,\n"
1843 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1844 "\t\t\"P2P_MEM\": 0,\n"
1858 "\t\t\"NUMBER\": %u,\n"
1859 "\t\t\"INDEX\": %d,\n"
1860 "\t\t\"LOAD\": 0,\n"
1861 "\t\t\"MODEL_LOAD\": 0,\n"
1862 "\t\t\"FW_LOAD\": %u,\n"
1863 "\t\t\"INST\": 0,\n"
1864 "\t\t\"MAX_INST\": 0,\n"
1866 "\t\t\"CRITICAL_MEM\": 0,\n"
1867 "\t\t\"SHARE_MEM\": %u,\n"
1868 "\t\t\"P2P_MEM\": 0,\n"
1880 strcat_dyn_buf(&output_buf, (index < device_count - 1) ?
",\n" :
"\n");
1881 if (index == device_count - 1 && icore !=
PCIE_LOAD)
1895 free(extra_temp_per_index);
1896 free(extra_power_per_index);
1901 clear_card_cache(card_cache, card_count);
1903 printf(
"%s", output_buf.
str_buf);
1910 bool has_written_start =
false;
1912 unsigned int index, device_count;
1913 int32_t *module_ids;
1914 uint32_t total_contexts;
1916 uint32_t model_load;
1918 char pcie[64] = {0};
1923 char power_consumption[16];
1925 uint16_t namespace_id = 0;
1933 int32_t *extra_temp_per_index = NULL;
1934 uint32_t *extra_power_per_index = NULL;
1950 if (!has_written_start)
1953 has_written_start =
true;
1960 for (index = 0; index < device_count; index++)
1968 device_name, detail, detail_data_v1))
2007 "\t\t\"NUMBER\": %u,\n"
2008 "\t\t\"INDEX\": %d,\n"
2009 "\t\t\"LOAD\": %u,\n"
2010 "\t\t\"LOAD-ALL\": %u,\n"
2011 "\t\t\"MODEL_LOAD\": %u,\n"
2012 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
2013 "\t\t\"FW_LOAD\": %u,\n"
2014 "\t\t\"INST\": %u,\n"
2015 "\t\t\"INST-ALL\": %u,\n"
2016 "\t\t\"MAX_INST\": %d,\n"
2017 "\t\t\"MEM\": %u,\n"
2018 "\t\t\"CRITICAL_MEM\": %u,\n"
2019 "\t\t\"SHARE_MEM\": %u,\n"
2020 "\t\t\"P2P_MEM\": %u,\n"
2021 "\t\t\"DEVICE\": \"%s\",\n"
2022 "\t\t\"L_FL2V\": \"%s\",\n"
2023 "\t\t\"N_FL2V\": \"%s\",\n"
2024 "\t\t\"FR\": \"%.8s\",\n"
2025 "\t\t\"N_FR\": \"%.8s\""
2027 ",\n\t\t\"NUMA_NODE\": %d,\n"
2028 "\t\t\"PCIE_ADDR\": \"%s\""
2055 "\t\t\"NUMBER\": %u,\n"
2056 "\t\t\"INDEX\": %d,\n"
2057 "\t\t\"LOAD\": %u,\n"
2058 "\t\t\"MODEL_LOAD\": %u,\n"
2059 "\t\t\"FW_LOAD\": %u,\n"
2060 "\t\t\"INST\": %u,\n"
2061 "\t\t\"MAX_INST\": %d,\n"
2062 "\t\t\"MEM\": %u,\n"
2063 "\t\t\"CRITICAL_MEM\": %u,\n"
2064 "\t\t\"SHARE_MEM\": %u,\n"
2065 "\t\t\"P2P_MEM\": %u,\n"
2066 "\t\t\"DEVICE\": \"%s\",\n"
2067 "\t\t\"L_FL2V\": \"%s\",\n"
2068 "\t\t\"N_FL2V\": \"%s\",\n"
2069 "\t\t\"FR\": \"%.8s\",\n"
2070 "\t\t\"N_FR\": \"%.8s\""
2072 ",\n\t\t\"NUMA_NODE\": %d,\n"
2073 "\t\t\"PCIE_ADDR\": \"%s\""
2098 ",\n\t\t\"TEMP\": %d,\n"
2099 "\t\t\"POWER\": \"%s\"",
2111 namespace_id = ns_vf_id.
ns_id;
2123 ",\n\t\t\"QOS MODE\": %u,\n"
2124 "\t\t\"QOS NS\": %u,\n"
2125 "\t\t\"QOS ALLOW\": %.1f,\n"
2126 "\t\t\"QOS OPMAX\": %.1f",
2129 (qos_mode == 0 ? 0 : qos_ns_info.
fAllowance),
2130 (qos_mode == 0 ? 0 :_opmax)
2141 if (index < device_count - 1)
2183 printf(
"%s", output_buf.
str_buf);
2189 extra_temp_per_index = (int32_t *)calloc(device_count,
sizeof(int32_t));
2190 extra_power_per_index = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
2191 if (!extra_temp_per_index || !extra_power_per_index)
2193 (void)fprintf(stderr,
"ERROR: calloc() failed for extra info arrays\n");
2194 if (extra_temp_per_index) free(extra_temp_per_index);
2195 if (extra_power_per_index) free(extra_power_per_index);
2198 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
2201 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
2204 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
2207 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
2213 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
2219 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
2227 for (index = 0; index < device_count; index++)
2231 if (!p_device_context)
2238 device_name, detail, detail_data_v1))
2247 (void)fprintf(stderr,
2248 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2284 "\t\t\"NUMBER\": %u,\n"
2285 "\t\t\"INDEX\": %d,\n"
2286 "\t\t\"LOAD\": 0,\n"
2287 "\t\t\"MODEL_LOAD\": 0,\n"
2288 "\t\t\"FW_LOAD\": %u,\n"
2289 "\t\t\"INST\": 0,\n"
2290 "\t\t\"MAX_INST\": 0,\n"
2292 "\t\t\"CRITICAL_MEM\": 0,\n"
2293 "\t\t\"SHARE_MEM\": %u,\n"
2294 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2295 "\t\t\"P2P_MEM\": 0,\n"
2296 "\t\t\"DEVICE\": \"%s\",\n"
2297 "\t\t\"L_FL2V\": \"%s\",\n"
2298 "\t\t\"N_FL2V\": \"%s\",\n"
2299 "\t\t\"FR\": \"%.8s\",\n"
2300 "\t\t\"N_FR\": \"%.8s\""
2302 ",\n\t\t\"NUMA_NODE\": %d,\n"
2303 "\t\t\"PCIE_ADDR\": \"%s\""
2324 "\t\t\"NUMBER\": %u,\n"
2325 "\t\t\"INDEX\": %d,\n"
2326 "\t\t\"LOAD\": 0,\n"
2327 "\t\t\"MODEL_LOAD\": 0,\n"
2328 "\t\t\"FW_LOAD\": %u,\n"
2329 "\t\t\"INST\": 0,\n"
2330 "\t\t\"MAX_INST\": 0,\n"
2332 "\t\t\"CRITICAL_MEM\": 0,\n"
2333 "\t\t\"SHARE_MEM\": %u,\n"
2334 "\t\t\"P2P_MEM\": 0,\n"
2335 "\t\t\"DEVICE\": \"%s\",\n"
2336 "\t\t\"L_FL2V\": \"%s\",\n"
2337 "\t\t\"N_FL2V\": \"%s\",\n"
2338 "\t\t\"FR\": \"%.8s\",\n"
2339 "\t\t\"N_FR\": \"%.8s\""
2341 ",\n\t\t\"NUMA_NODE\": %d,\n"
2342 "\t\t\"PCIE_ADDR\": \"%s\""
2360 ni_sprintf(power_consumption, 16,
"%umW", extra_power_per_index[index]);
2363 ",\n\t\t\"TEMP\": %d,\n"
2364 "\t\t\"POWER\": \"%s\"\n"
2367 (extra_power_per_index[index] + 1) ? power_consumption :
"N/A");
2373 if (index < device_count - 1)
2400 printf(
"%s", output_buf.
str_buf);
2407 int index, instance_count;
2409 unsigned int module_count;
2411 int32_t *module_id_arr = NULL;
2421 module_type != max_device_type;
2435 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", module_name, module_count);
2443 "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2444 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2445 "SID",
"DEVICE",
"NAMESPACE");
2450 "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2451 "AvgCost",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"Width",
"Height",
2452 "SID",
"DEVICE",
"NAMESPACE");
2460 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2461 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"fps",
"BR",
"AvgBR",
"Width",
"Height",
2462 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2467 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2468 "AvgCost",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"BR",
"AvgBR",
"Width",
"Height",
2469 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2475 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
2476 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
2480 for (i = 0; i < module_count; i++)
2488 module_name, detail, detail_data_v1))
2496 if(previous_detail_data_p && checkInterval)
2498 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2503 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2510 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2520 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2528 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2545 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2561 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2581 if(previous_detail_data_p)
2603 "%-5d %-4u %-10s %-4u %-4u %-9u %-7u %-14s\n",
2610 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
2620 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2639 free(module_id_arr);
2643 printf(
"%s", output_buf.
str_buf);
2650 unsigned int index, device_count;
2651 int32_t *module_ids;
2656 char power_consumption[16];
2657 int instance_count = 0;
2660 unsigned int num_gen3_mismatch = 0;
2666 bool has_qos_data =
false;
2667 char qos_str[64] = {0};
2668 uint16_t namespace_id = 0;
2680 printf(
"%s", output_buf.
str_buf);
2685 for (index = 0; index < device_count; index++)
2688 if (!p_device_context)
2695 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2704 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
2711 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
2715 (void)fprintf(stderr,
2716 "ERROR: ni_device_open2() failed for %s: %s\n",
2741 namespace_id = ns_vf_id.
ns_id;
2747 has_qos_data =
true;
2753 if (show_qos_info && has_qos_data)
2755 char _allowance[16];
2756 uint8_t qos_mode = (uint8_t)(qos_header.
ui16QosState & 0xFF);
2758 (void)snprintf(qos_str,
sizeof(qos_str),
" %-9u %-7u %-10s %-8.1f",
2761 (qos_mode == 0) ?
"N/A" : ((void)snprintf(_allowance,
sizeof(_allowance),
"%.1f", qos_ns_info.
fAllowance), _allowance),
2762 (qos_mode == 0 ? 0 :_opmax));
2768 "%-4s %-8s %-8s %-14s %s\n",
"TEMP",
"POWER",
"FLAVOR",
"DEVICE",
2769 (show_qos_info && has_qos_data) ?
" QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" :
"");
2771 "%-4d %-8s %-8c %-14s %s\n",
2776 (show_qos_info && has_qos_data) ? qos_str:
"");
2780 if (instance_count == 0)
2783 "%-8s %-8s %-8s %-8s %-8.8s %-20.8s %s\n",
"INDEX",
"TEMP",
"POWER",
"FLAVOR",
"FR",
"SN",
2784 (show_qos_info && has_qos_data) ?
"QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" :
"");
2787 "%-8d %-8d %-8s %-8c %-8.8s %-8.*s %s\n",
2793 (show_qos_info && has_qos_data) ? qos_str:
"");
2804 (void)fprintf(stderr,
2805 "ERROR: ni_device_capability_query() failed for %s: %s\n",
2816 syslog(LOG_WARNING,
"ERROR: CRITICAL TEMP %ddegC HIT on SN %s!!!\n",temp_deg,device_capability_t.
serial_number);
2823 syslog(LOG_WARNING,
"ERROR: WARNING TEMP %ddegC HIT on SN %s!!!\n",temp_deg, device_capability_t.
serial_number);
2831 gen3_mismatch_index[num_gen3_mismatch++] = index;
2839 if (num_gen3_mismatch > 0)
2841 char index_list[128] = {0};
2843 for (
unsigned int i = 0; i < num_gen3_mismatch && len <
sizeof(index_list) - 4; i++)
2845 len += snprintf(index_list + len,
sizeof(index_list) - len,
2846 "%s%u", (i > 0) ?
", " :
"", gen3_mismatch_index[i]);
2849 "This system supports Gen4 PCIe speeds, but the following Quadra cards are "
2850 "currently running firmware that only supports PCIe Gen3 (Index: %s). "
2851 "All Quadra VPUs on this system can be firmware upgraded to support "
2852 "PCIe Gen 4 speeds, please update the firmware on each Quadra card to "
2853 "the default firmware flavor.\n",
2859 printf(
"%s", output_buf.
str_buf);
2866 (void)setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2868 int skip_init_rsrc = 0;
2869 int should_match_rev = 1;
2876 time_t startTime = {0}, now = {0};
2877 int timeout_seconds = 0;
2878 struct tm *ltime = NULL;
2880 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2885 bool fw_log_dump =
false;
2886 bool core_reset_log_dump =
false;
2888 int refresh_device_pool = 1;
2889 bool is_first_query =
true;
2891 int show_qos_info = 0;
2892 char *nor_command = NULL;
2893#if defined(__linux__)
2895 const char *target_slot = NULL;
2896 const char *target_domain = NULL;
2897 const char *target_blkdev = NULL;
2901 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2903 setup_signal_handler();
2911 static struct option long_opts[] = {
2920#
if defined(__linux__)
2921 "n:o:D:C:k:R:rt:Sl:hvdqs:b:N:",
2923 "n:o:D:C:k:R:rt:Sl:hvdqN:",
2925 long_opts, &long_idx)) != -1)
2930#if defined(__linux__)
2931 if (strcmp(long_opts[long_idx].
name,
"domain") == 0)
2940 if (!strcmp(
optarg,
"json"))
2944 else if (!strcmp(
optarg,
"simple"))
2948 else if (!strcmp(
optarg,
"text"))
2952 else if (!strcmp(
optarg,
"full"))
2956 else if (!strcmp(
optarg,
"json1"))
2960 else if (!strcmp(
optarg,
"json2"))
2964 else if (!strcmp(
optarg,
"extra"))
2970 (void)fprintf(stderr,
"Error: unknown selection for outputFormat: %s\n",
optarg);
2982 checkInterval = (int)tmp_val;
2993 fw_log_dump = tmp_val;
3004 core_reset_log_dump = tmp_val;
3005 if (core_reset_log_dump)
3017 devid = (int)tmp_val;
3028 refresh_device_pool = (int)tmp_val;
3031 should_match_rev = 0;
3041 timeout_seconds = (int)tmp_val;
3042 printf(
"Timeout will be set %d\n", timeout_seconds);
3054 (void)fprintf(stderr,
"FATAL: invalid log level selected: %s\n",
optarg);
3063 printf(
"-------- ni_rsrc_mon v%s --------\n"
3064 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
3065 "running on the system.\n"
3067 "Usage: ni_rsrc_mon [OPTIONS]\n"
3069 "Monitoring options:\n"
3070 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
3071 " report only once.\n"
3073 "-R Specify if refresh devices on host in each monitor interval.\n"
3074 " If 0, only refresh devices at the start.\n"
3076 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
3078 "-k Specify to dump which card's firmware logs.\n"
3079 " Default: -1(dump fw log of all cards).\n"
3080 "-r Initialize Quadra device regardless firmware release version to\n"
3081 " libxcoder version compatibility.\n"
3082 " Default: only initialize devices with compatible firmware version.\n"
3083 "-t Set timeout time in seconds for device polling. Program will exit with\n"
3084 " failure if timeout is reached without finding at least one device. If 0 or\n"
3085 " no selection, poll indefinitely until a Quadra device is found.\n"
3087 "-S Skip init_rsrc.\n"
3088 "-d Print detailed information for decoder/encoder in text and json formats.\n"
3089 "-l Set loglevel of libxcoder API.\n"
3090 " [none, fatal, error, info, debug, trace]\n"
3092 "-q Show QoS information - MODE,NS,ALLOW,OPMAX.\n"
3093 " MODE - QoS mode 0,1,2.[Default: 0\n"
3094 " NS - QoS NS set in mode 1/2. Default:1\n"
3095 " ALLOW - QoS allowance set in mode 1/2. Default:0\n"
3096 " OPMAX - QoS OverProvisioning max set in 2. Default:0\n"
3097 "-h Open this help message.\n"
3098 "-v Print version info.\n"
3099 "The Error information for critical/warning temperature and Pcie-gen mismatch is shown in all modes\n"
3101 "Firmware log dump options (Linux):\n"
3102 "-D Dump firmware logs (all devices) to current directory.\n"
3103 " Default: 0 (do not dump).\n"
3104 "-C Dump firmware core-reset logs (all devices) to current directory.\n"
3105 " Default: 0 (do not dump).\n"
3106 "-s Select a single device by PCIe slot \n"
3107 "-b Select a single device by NVMe block device name (Mutually exclusive with -s)\n"
3109 "NOR flash options (Linux, requires root):\n"
3110 "-N <cmd> NOR flash persistent log command. [w, r, e, ex], (long form: --nor)\n"
3111 " w - Write current DDR logs into NOR flash\n"
3112 " r - Read persistent logs from NOR flash into DDR, then dump\n"
3113 " e - Erase persistent logs from NOR flash\n"
3114 " ex - Simulate exception (DDR logs saved to NOR flash)\n"
3115 " -s / -b / --domain selector to choose specific card.\n"
3118 " ni_rsrc_mon -D 1 Dump firmware logs from all devices\n"
3119 " ni_rsrc_mon -C 1 Dump core-reset logs from all devices\n"
3120 " ni_rsrc_mon -N r Read NOR flash logs on all devices\n"
3121 " ni_rsrc_mon -N w -s 1 Write NOR flash logs on device slot 1, i.e. 0000:01:00.0\n"
3122 " ni_rsrc_mon --nor r -b nvme0n1 Read NOR flash and dump logs for block dev nvme0n1\n"
3124 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
3127 "Reporting columns for text output format\n"
3128 "INDEX index number used by resource manager to identify the resource\n"
3129 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
3130 "MODEL_LOAD estimated load based on framerate and resolution\n"
3131 "INST number of job instances\n"
3132 "MEM usage of memory by the subsystem\n"
3133 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
3134 "P2P_MEM usage of memory by P2P\n"
3135 "DEVICE path to NVMe device file handle\n"
3136 "NAMESPACE path to NVMe namespace file handle\n"
3137 "Additional information only in text(Default) mode \n"
3138 "TEMP current temperature (degrees Celsius)\n"
3139 "POWER current power(mW), N/A when query power not supported\n"
3140 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3141 "FR current firmware revision\n"
3142 "SN serial number of the Quadra device\n"
3144 "Additional reporting columns for full output format\n"
3145 "VPU same as LOAD in JSON outputs\n"
3147 "TOTAL same as MEM\n"
3148 "CRITICAL usage of memory considered critical\n"
3149 "L_FL2V last ran firmware loader 2 version\n"
3150 "N_FL2V nor flash firmware loader 2 version\n"
3151 "FR current firmware revision\n"
3152 "N_FR nor flash firmware revision\n"
3153 "TEMP current temperature (degrees Celsius)\n"
3154 "POWER current power(mW), N/A when query power not supported\n"
3155 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3156 "FR current firmware revision\n"
3157 "SN serial number of the Quadra device\n"
3158 "QOS Header shows QoS information when enabled\n"
3159 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
3161 "Additional reporting columns for full JSON formats\n"
3163 "FW_LOAD system load\n"
3164 "TEMP current temperature (degrees Celsius)\n"
3165 "POWER current power(mW), N/A when query power not supported\n"
3166 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3167 "FR current firmware revision\n"
3168 "SN serial number of the Quadra device\n"
3169 "QOS decoder and encoder show QoS Information\n"
3170 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
3172 "Following detailed data is displayed per instance for decoder and encoder when -d flag is used"
3173 "INDEX index number used by resource manager to identify the instance\n"
3174 "AvgCost estimated load given in percentage based on framerate and resolution\n"
3175 "FrameRate framerate of current session\n"
3176 "IDR number of IDR frame it processes\n"
3177 "UserIDR number of force IDR frame set by user(encoder only)\n"
3178 "InFrame number of frames sent to the decoder or encoder\n"
3179 "OutFrame number of frames got from the decoder or encoder\n"
3180 "BR instantaneous bitrate of current encoder session\n"
3181 "AvgBR average bitrate of current encoder session\n"
3182 "Width width of decoder or encoder\n"
3183 "Height height of decoder or encoder\n"
3184 "Format input frame format send to encoder\n"
3186 "DEVICE path to NVMe device file handle\n"
3187 "NAMESPACE path to NVMe namespace file handle\n"
3189 "Extra output shows TEMP and POWER and FLAVOR of the Quadra device \n",
3193 printf(
"Release ver: %s\n"
3201#if defined(__linux__)
3213 (void)fprintf(stderr,
"FATAL: unknown option '-%c'\n", opt);
3216 (void)fprintf(stderr,
"FATAL: unknown option character '\\x%x'\n", opt);
3223 (void)fprintf(stderr,
"FATAL: option '-%c' lacks arg\n", opt);
3226 (void)fprintf(stderr,
"FATAL: unhandled option\n");
3231#if defined(__linux__)
3233 if (target_slot && target_blkdev)
3235 (void)fprintf(stderr,
"FATAL: -s and -b are mutually exclusive; "
3236 "specify a PCIe slot or a block device name, not both.\n");
3241 if ((argc <= 2) && (
optind == 1))
3256 (void)fprintf(stderr,
"FATAL: cannot allocate momory for ni_session_context_t\n");
3261 if (!skip_init_rsrc)
3265 if (!skip_init_rsrc && ret != 0)
3269 (void)fprintf(stderr,
"FATAL: NI resource unavailable\n");
3270#if defined(__linux__)
3273 (void)fprintf(stderr,
"Proceeding to dump firmware logs as root\n");
3276 (void)fprintf(stderr,
"This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3279 int rc = ni_rsrc_log_dump(
".", core_reset_log_dump);
3281 (void)fprintf(stderr,
"Firmware log dump: all devices successful.\n");
3283 (void)fprintf(stderr,
"Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3285 (void)fprintf(stderr,
"Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3287 (
void)fprintf(stderr,
"Firmware log dump: Unexpected error, return code %d\n", rc);
3291#if defined(__linux__)
3294 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3301 (void)fprintf(stderr,
"FATAL: cannot access NI resource\n");
3310 (void)fprintf(stderr,
"FATAL: cannot get devices info\n");
3317 printf(
"**************************************************\n");
3329 startTime = time(NULL);
3334 if(previous_detail_data == NULL)
3336 (void)fprintf(stderr,
"FATAL: Allocate buffer fail\n");
3340 memset((
void *)previous_detail_data, 0, allocate_size);
3345 struct tm temp_time;
3349 (void)strftime(buf,
sizeof(buf),
"%c", ltime);
3351 time_diff_seconds = (
long long)difftime(now, startTime);
3352 time_diff_minutes = time_diff_seconds / 60;
3353 time_diff_hours = time_diff_minutes / 60;
3356 if (is_first_query || refresh_device_pool)
3363 printf(
"%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
3370 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3372 (void)fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
3377 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
3379 perror(
"ERROR: cannot lock p_device_pool");
3386 ReleaseMutex((HANDLE)p_device_pool->
lock);
3388 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
3390 perror(
"ERROR: cannot unlock p_device_pool");
3394 switch (printFormat)
3398 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
3421 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
3431 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
3443 is_first_query =
false;
3447 printf(
"**************************************************\n");
3450 (void)fflush(stdout);
3452 if (checkInterval == 0)
3457 ni_usleep((int64_t)checkInterval * 1000 * 1000);
3464 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3466 (void)fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
3471 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
3473 perror(
"ERROR: cannot lock p_device_pool");
3478 ReleaseMutex((HANDLE)p_device_pool->
lock);
3480 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
3482 perror(
"ERROR: cannot unlock p_device_pool");
3485#if defined(__linux__)
3486 if (core_reset_log_dump)
3488 (void)fprintf(stderr,
"Proceeding to dump firmware logs as root\n");
3491 (void)fprintf(stderr,
"This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3494 int rc = ni_rsrc_log_dump(
".", core_reset_log_dump);
3496 (void)fprintf(stderr,
"Firmware log dump: all devices successful.\n");
3498 (void)fprintf(stderr,
"Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3500 (void)fprintf(stderr,
"Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3502 (
void)fprintf(stderr,
"Firmware log dump: Unexpected error, return code %d\n", rc);
3511#if defined(__linux__)
3515 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3532#ifdef __OPENHARMONY__
3533 (void)system(
"chmod -R 777 /dev/shm/");
3534#ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
3535 (void)system(
"chmod 777 /dev/block/vd* 2>/dev/null");
3537#elif defined(_ANDROID)
3538 (void)system(
"chmod -R 777 /dev/shm/");
3539 (void)system(
"chmod 777 /dev/block/nvme* 2>/dev/null");
3540 (void)system(
"chmod 777 /dev/nvme* 2>/dev/null");
3541 property_set(
"ni_rsrc_init_completed",
"yes");
3545 if(checkInterval && previous_detail_data)
3547 free(previous_detail_data);
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_MAX_DEVICE_CNT
#define NI_XCODER_REVISION
#define LIBXCODER_API_VERSION
#define NI_MAX_DEVICE_NAME_LEN
#define NI_MAX_CONTEXTS_PER_HW_INSTANCE
@ NI_DEVICE_TYPE_XCODER_MAX
#define GET_XCODER_DEVICE_TYPE(t)
@ NI_RETCODE_ERROR_RESOURCE_UNAVAILABLE
#define IS_XCODER_DEVICE_TYPE(t)
ni_retcode_t ni_query_nvme_status(ni_session_context_t *p_ctx, ni_load_query_t *p_load_query)
Query NVMe load from the device.
ni_retcode_t ni_device_alloc_and_get_fw_log_artifacts(ni_session_context_t *p_ctx, bool gen_artifacts_file)
Read log artifacts from the device and save to disk.
ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle, ni_device_capability_t *p_cap, bool device_in_ctxt)
Query device and return device capability structure This function had replaced ni_device_capability_q...
ni_retcode_t ni_device_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query session data from the device - If device_type is valid, will query session data from specified ...
ni_session_context_t * ni_device_session_context_alloc_init(void)
Allocate and initialize a new ni_session_context_t struct.
ni_retcode_t ni_device_session_query_detail_v1(ni_session_context_t *p_ctx, ni_device_type_t device_type, ni_instance_mgr_detail_status_v1_t *detail_data)
Query detail session data from the device - If device_type is valid, will query session data from spe...
ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle, ni_device_vf_ns_id_t *p_dev_ns_vf, uint8_t fw_rev[])
Query VF and NS id from device.
ni_retcode_t ni_device_session_query_detail(ni_session_context_t *p_ctx, ni_device_type_t device_type, ni_instance_mgr_detail_status_t *detail_data)
Query detail session data from the device - If device_type is valid, will query session data from spe...
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
ni_retcode_t ni_query_qos_info(ni_device_handle_t device_handle, ni_qos_header_info_log_page_t *p_dev_qos_header, uint8_t fw_rev[])
Query QoS information for the device.
ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void **p_log_buffer, bool gen_log_file)
Allocate log buffer if needed and retrieve firmware logs from device.
ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle, ni_device_extra_info_t *p_dev_extra_info, uint8_t fw_rev[])
Query CompositeTemp from device.
ni_device_handle_t ni_device_open2(const char *p_dev, ni_device_mode_t mode)
Open device and return device device_handle if successful.
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
ni_retcode_t ni_query_qos_namespace_info(ni_device_handle_t device_handle, ni_qos_namespace_info_log_page_t *p_dev_qos_ns, uint8_t fw_rev[])
Query QoS information for a specific namespace.
Public definitions for operating NETINT video processing devices for video processing.
struct _ni_instance_mgr_detail_status_v1 ni_instance_mgr_detail_status_v1_t
int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
Implementation of getopt() and getopt_long() for Windows environment.
#define required_argument
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
#define NI_SW_RELEASE_TIME
int ni_rsrc_get_numa_node(char *device_name)
get linux numa_node
void ni_rsrc_free_device_context(ni_device_context_t *p_device_context)
Free previously allocated device context.
ni_retcode_t ni_rsrc_refresh(int should_match_rev)
Scan and refresh all resources on the host, taking into account hot-plugged and pulled out cards.
void ni_rsrc_free_device_pool(ni_device_pool_t *p_device_pool)
Free all resources taken by the device pool.
Public definitions for managing NETINT video processing devices.
LIB_API ni_device_context_t * ni_rsrc_get_device_context(ni_device_type_t type, int guid)
Allocates and returns a pointer to ni_device_context_t struct based on provided device_type and guid....
LIB_API ni_device_pool_t * ni_rsrc_get_device_pool(void)
Create and return the allocated ni_device_pool_t struct.
LIB_API int ni_rsrc_init(int should_match_rev, int timeout_seconds)
Initialize and create all resources required to work with NETINT NVMe transcoder devices....
void print_json_final(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
int compareInt32_t(const void *a, const void *b)
compare two int32_t for qsort
char * get_pixel_format(ni_device_context_t *p_device_context, int index)
uint32_t * g_temp_pthroughput
#define DYN_STR_BUF_CHUNK_SIZE
uint32_t * g_temp_sharemem
#define MAX_DEVICE_NAME_SIZE
bool open_and_get_log(ni_device_context_t *p_device_context, ni_session_context_t *p_session_context, void **p_log_buffer, bool gen_log_file)
int remove_device_from_saved(ni_device_type_t device_type, int32_t module_id, ni_device_handle_t device_handle)
remove one device from stored device_handles
void print_text(ni_device_queue_t *coders, ni_session_context_t *sessionCtxt, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1, ni_instance_mgr_detail_status_v1_t(*previous_detail_data_p)[NI_DEVICE_TYPE_XCODER_MAX], int checkInterval)
struct dyn_str_buf dyn_str_buf_t
int strcat_dyn_buf(dyn_str_buf_t *dyn_str_buf, const char *fmt,...)
Accumulate string data in a dynamically sized buffer. This is useful to separate error messages from ...
void print_full_text(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
bool open_and_query(ni_device_type_t device_type, ni_device_context_t *p_device_context, ni_session_context_t *p_session_context, char *device_name, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
int argToI(char *numArray)
convert number from argv input to integer if safe
void clear_dyn_str_buf(dyn_str_buf_t *dyn_str_buf)
void print_json_detail(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
void print_json1(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1, int format)
ni_device_handle_t device_handles[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
@ NI_RSRC_MON_ERR_CRITICAL_TEMP
@ NI_RSRC_MON_ERR_WARN_TEMP
@ NI_RSRC_MON_ERR_PCIE_MISMATCH
bool swap_encoder_and_uploader(ni_device_type_t *p_device_type, char *device_name)
#define NI_RSRC_MON_CARD_CACHE_MAX
void print_extra(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int internal_call, int show_qos_info)
char * get_session_id(ni_device_context_t *p_device_context, int id)
void dump_fw_log(ni_device_queue_t *coders, ni_session_context_t *sessionCtxt, int devid)
Dump firmware logs and artifacts for one or all Quadra cards.
unsigned int get_modules(ni_device_type_t device_type, ni_device_queue_t *p_device_queue, char *device_name, int32_t **module_ids)
#define ABSOLUTE_TEMP_ZERO
void print_simple_text(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
uint32_t g_xcoder_stop_process
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
void get_dev_pcie_addr(char *device_name, char *pcie, char *domain, char *slot, char *dev, char *func)
ni_retcode_t ni_strncpy(char *dest, size_t dmax, const char *src, size_t slen)
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
void ni_usleep(int64_t usec)
struct tm * ni_localtime(struct tm *dest, const time_t *src)
int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args)
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
ni_retcode_t ni_strtoi(const char *str, int32_t *out_val)
Safely convert a decimal string to a 32-bit integer with full validation. Trailing whitespace is tole...
int ni_cmp_fw_api_ver(const char ver1[], const char ver2[])
Compare two 3 character strings containing a FW API version. Handle comparision when FW API version f...
uint8_t serial_number[20]
ni_device_info_t * p_device_info
int pcie_gen3_on_gen4_host
uint8_t serial_number[20]
char dev_name[NI_MAX_DEVICE_NAME_LEN]
char blk_name[NI_MAX_DEVICE_NAME_LEN]
uint8_t fl_ver_last_ran[8]
uint8_t fw_rev_nor_flash[8]
uint8_t fl_ver_nor_flash[8]
ni_device_queue_t * p_device_queue
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
ni_instance_mgr_detail_status_append_t sInstDetailStatusAppend[NI_MAX_CONTEXTS_PER_HW_INSTANCE]
ni_instance_mgr_detail_status_t sInstDetailStatus[NI_MAX_CONTEXTS_PER_HW_INSTANCE]
uint32_t fw_share_mem_usage
uint32_t fw_p2p_mem_usage
uint32_t fw_video_shared_mem_usage
uint32_t active_hwuploaders
uint32_t fw_video_mem_usage
uint32_t overall_fw_model_load
uint32_t overall_current_load
uint32_t overall_instance_count
ni_device_handle_t device_handle
ni_load_query_t load_query
ni_device_handle_t blk_io_handle
ni_overall_load_query_t overall_load_query