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 scaler and ai detailed info for %s as it has FW API "
443 (void)fprintf(stderr,
444 "ERROR: cannot print detailed info for %s as it has FW API "
466 (void)fprintf(stderr,
467 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
484 memcpy(p_session_context->
fw_rev,
497 if (!p_device_context)
503 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
507 (void)fprintf(stderr,
508 "ERROR: ni_device_open2() failed for %s: %s\n",
516 p_session_context->
hw_id =
518 memcpy(p_session_context->
fw_rev,
520 sizeof(p_session_context->
fw_rev));
523 return return_code ? false :
true;
540 void *p_log_buffer = NULL;
544 if (!
open_and_get_log(p_device_context, p_session_context, &p_log_buffer, gen_log_file)) {
545 printf(
"Error: failed to dump fw log of card:%d blk_name:%s\n", module_id, blk_name);
547 printf(
"Success: dumped fw log of card:%d blk_name:%s\n", module_id, blk_name);
555 printf(
"Info: artifacts not supported by card:%d fw_rev:%.8s, skipping\n",
564 printf(
"Info: fw log artifacts checked for card:%d blk_name:%s\n", module_id, blk_name);
568 printf(
"Error: fw log artifacts read failed for card:%d blk_name:%s\n", module_id, blk_name);
588 unsigned int module_count;
589 int32_t *module_id_arr = NULL;
594 module_count =
get_modules(module_type, coders, module_name, &module_id_arr);
596 printf(
"Error: module not found!\n");
600 bool gen_log_file =
true;
602 if (devid >= 0 && (uint32_t)devid < module_count)
606 if (!p_device_context)
610 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
618 for (i = 0; i < module_count; i++)
621 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
630#if defined(__linux__)
646static int run_bar4_operations(
const char *nor_cmd,
647 const char *t_domain,
const char *t_slot,
648 const char *t_blkdev)
652 (void)fprintf(stderr,
653 "This operation requires root (sudo). "
654 "Please rerun: sudo ni_rsrc_mon [options]\n");
658 bool is_device_selected = (t_slot != NULL || t_blkdev != NULL);
661 if (!is_device_selected)
664 rc = ni_rsrc_nor_log_command(nor_cmd,
".");
666 (void)fprintf(stderr,
"NOR flash command: all devices successful.\n");
668 (void)fprintf(stderr,
"NOR flash command: No Quadra devices found.\n");
670 (void)fprintf(stderr,
671 "NOR flash command: One or more devices failed.\n");
673 (
void)fprintf(stderr,
674 "NOR flash command: Unexpected error %d.\n", rc);
680 if (nor_cmd_decode(nor_cmd, &cmd) != 0)
683 QuadraDevice *dev = NULL;
685 ? quadra_device_find_by_bdf(t_domain ? t_domain :
"0000",
687 : quadra_device_find_by_block_dev(t_blkdev, &dev);
690 (void)fprintf(stderr,
"[ERROR] Target Quadra device not found.\n");
695 rc = ni_rsrc_nor_cmd_run(dev, 1, cmd,
".");
706 switch (*p_device_type)
719#define DYN_STR_BUF_CHUNK_SIZE 4096
741 int add_buf_size = 0;
742 char *tmp_char_ptr = NULL;
746 (void)fprintf(stderr,
"ERROR: invalid param *dyn_str_buf\n");
760 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
765 add_buf_size = (formatted_len + 1) > avail_buf ?
779 (void)fprintf(stderr,
"ERROR: strcat_dyn_buf() failed realloc()\n");
803#define NI_RSRC_MON_CARD_CACHE_MAX NI_MAX_DEVICE_CNT
816 for (i = 0; i < n; i++) {
819 cache[i].
valid =
false;
825 const char *blk_name)
828 if (!blk_name || !blk_name[0])
830 for (i = 0; i < n; i++) {
831 if (cache[i].valid &&
838static unsigned int build_card_and_qos_cache(
846 unsigned int index, card_count;
847 int32_t *card_module_ids = NULL;
851 char power_consumption[16];
857 card_count =
get_modules(card_type, p_device_queue, device_name,
863 for (index = 0; index < card_count; index++) {
868 uint16_t namespace_id = 0;
869 uint8_t qos_mode = 0;
871 cache[index].
valid =
false;
872 memset(cache[index].blk_name, 0,
sizeof(cache[index].blk_name));
875 card_module_ids[index]);
876 if (!p_device_context)
879 if (!
open_and_query(card_type, p_device_context, p_session_context,
880 device_name, detail, detail_data_v1)) {
888 cache[index].
valid =
true;
890 memset(&dev_extra, 0,
sizeof(dev_extra));
900 card_err = ni_rsrc_mon_get_card_error(p_session_context->
device_handle,
910 "\n\t\t\"DEVICE\": \"%s\",\n"
911 "\t\t\"L_FL2V\": \"%s\",\n"
912 "\t\t\"N_FL2V\": \"%s\",\n"
913 "\t\t\"FR\": \"%.8s\",\n"
914 "\t\t\"N_FR\": \"%.8s\",\n"
916 "\t\t\"NUMA_NODE\": %d,\n"
917 "\t\t\"PCIE_ADDR\": \"%s\",\n"
919 "\t\t\"TEMP\": %d,\n"
920 "\t\t\"POWER\": \"%s\",\n"
921 "\t\t\"SN\": \"%-8.*s\",\n"
922 "\t\t\"ERROR\": \"%s\",\n"
923 "\t\t\"FLAVOR\": \"%1c\"",
934 (int)sizeof(p_device_context->p_device_info->serial_number),
935 p_device_context->p_device_info->serial_number,
936 ni_rsrc_mon_card_error_str(card_err),
945 namespace_id = ns_vf_id.
ns_id;
957 ",\n\t\t\"QOS_MODE\": %u,\n"
958 "\t\t\"QOS_NS\": %u,\n"
959 "\t\t\"QOS_ALLOW\": %.1f,\n"
960 "\t\t\"QOS_OPMAX\": %.1f",
963 (qos_mode == 0 ? 0 : qos_ns_info.fAllowance),
964 (qos_mode == 0 ? 0 : opmax));
972 free(card_module_ids);
980 unsigned int index, device_count;
1003 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", device_name, device_count);
1005 switch (device_type)
1009 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
1010 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1015 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
1016 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1020 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
1021 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1025 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
1026 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1032 for (index = 0; index < device_count; index++)
1040 device_name, detail, detail_data_v1))
1057 switch (device_type)
1061 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1062 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1065 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
1081 "%-5d %-3u %-3u %-3u/%-3d %-3u "
1082 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1098 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1099 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1102 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
1118 "%-5d %-3u %-3u/%-3d %-3u "
1119 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1166 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1169 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
1172 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
1175 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
1181 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
1187 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
1200 "INDEX LOAD( FW ) PCIE_Card2Host_Gbps "
1201 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1206 "INDEX LOAD( FW ) MEM( SHARE ) "
1207 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1212 printf(
"%s", output_buf.
str_buf);
1221 for (index = 0; index < device_count; index++)
1225 if (!p_device_context)
1232 device_name, detail, detail_data_v1))
1240 (void)fprintf(stderr,
1241 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1264 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1281 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1305 printf(
"%s", output_buf.
str_buf);
1312 bool copied_block_name;
1316 unsigned int number_of_quadras;
1317 unsigned int number_of_device_types_present;
1318 unsigned int device_type_counter;
1319 unsigned int *maximum_firmware_loads;
1320 unsigned int *maximum_firmware_loads_per_quadra;
1334 maximum_firmware_loads = calloc(number_of_quadras,
sizeof(
unsigned int));
1335 if (!maximum_firmware_loads)
1337 (void)fprintf(stderr,
"calloc() returned NULL\n");
1341 maximum_firmware_loads_per_quadra = NULL;
1342 p_device_context = NULL;
1344 for (guid = 0; guid < number_of_quadras; guid++)
1347 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
1348 number_of_device_types_present = 0;
1349 device_type_counter = 0;
1350 copied_block_name =
false;
1353 device_type < maximum_device_type;
1356 if (p_device_queue->
xcoders[device_type][guid] != -1)
1358 number_of_device_types_present++;
1363 device_type < maximum_device_type;
1367 g_device_type_str[device_type],
1370 if (p_device_queue->
xcoders[device_type][guid] == -1)
1377 p_device_queue->
xcoders[device_type][guid]);
1381 device_name, detail, detail_data_v1))
1392 "%s: Simple output not supported. Try '-o full' "
1402 if (!copied_block_name)
1407 copied_block_name =
true;
1410 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.
fw_load)
1415 device_type_counter++;
1416 if (device_type_counter < number_of_device_types_present)
1437 if (*maximum_firmware_loads_per_quadra < load_query.
fw_load)
1439 *maximum_firmware_loads_per_quadra = load_query.
fw_load;
1441 if (*maximum_firmware_loads_per_quadra < load_query.
tp_fw_load)
1443 *maximum_firmware_loads_per_quadra = load_query.
tp_fw_load;
1446 *maximum_firmware_loads_per_quadra);
1451 stderr,
"ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1465 printf(
"%s", output_buf.
str_buf);
1467 free(maximum_firmware_loads);
1473 unsigned int i, index, device_count;
1475 int32_t *module_ids;
1483 int first_item_printed = 0;
1484 int first_device_type_printed = 0;
1489 device_type != max_device_type;
1502 if(first_device_type_printed)
1511 first_item_printed = 0;
1513 for (i = 0; i < device_count; i++)
1521 device_name, detail, detail_data_v1))
1530 if(first_item_printed)
1539 "\t\t\t\"NUMBER\": %u,\n"
1540 "\t\t\t\"INDEX\": %u,\n"
1541 "\t\t\t\"AvgCost\": %u,\n"
1542 "\t\t\t\"FrameRate\": %u,\n"
1543 "\t\t\t\"IDR\": %u,\n"
1544 "\t\t\t\"InFrame\": %u,\n"
1545 "\t\t\t\"OutFrame\": %u,\n"
1546 "\t\t\t\"Width\": %u,\n"
1547 "\t\t\t\"Height\": %u,\n"
1548 "\t\t\t\"SID\": \"%s\",\n"
1549 "\t\t\t\"DEVICE\": \"%s\"\n"
1567 "\t\t\t\"NUMBER\": %u,\n"
1568 "\t\t\t\"INDEX\": %u,\n"
1569 "\t\t\t\"AvgCost\": %u,\n"
1570 "\t\t\t\"FrameRate\": %u,\n"
1571 "\t\t\t\"IDR\": %u,\n"
1572 "\t\t\t\"UserIDR\": %u,\n"
1573 "\t\t\t\"InFrame\": %u,\n"
1574 "\t\t\t\"OutFrame\": %u,\n"
1575 "\t\t\t\"BR\": %u,\n"
1576 "\t\t\t\"AvgBR\": %u,\n"
1577 "\t\t\t\"Width\": %u,\n"
1578 "\t\t\t\"Height\": %u,\n"
1579 "\t\t\t\"Format\": \"%s\",\n"
1580 "\t\t\t\"SID\": \"%s\",\n"
1581 "\t\t\t\"DEVICE\": \"%s\"\n"
1604 "\t\t\t\"NUMBER\": %u,\n"
1605 "\t\t\t\"INDEX\": %u,\n"
1606 "\t\t\t\"VpuLoad\": %u,\n"
1607 "\t\t\t\"InFrame\": %u,\n"
1608 "\t\t\t\"OutFrame\": %u,\n"
1609 "\t\t\t\"Width\": %u,\n"
1610 "\t\t\t\"Height\": %u,\n"
1611 "\t\t\t\"SID\": \"%s\",\n"
1612 "\t\t\t\"DEVICE\": \"%s\"\n"
1624 first_item_printed = 1;
1633 first_device_type_printed = 1;
1641 printf(
"%s", output_buf.
str_buf);
1653 bool has_written_start =
false;
1655 unsigned int index, device_count, card_count = 0;
1656 int32_t *module_ids = NULL;
1657 uint32_t total_contexts, vpu_load, model_load;
1667 int32_t *extra_temp_per_index = NULL;
1668 uint32_t *extra_power_per_index = NULL;
1670 memset(card_cache, 0,
sizeof(card_cache));
1672 card_count = build_card_and_qos_cache(p_device_queue, p_session_context,
1673 detail, detail_data_v1,
1681 device_count =
get_modules(device_type, p_device_queue, device_name,
1687 if (!has_written_start)
1690 has_written_start =
true;
1697 for (index = 0; index < device_count; index++)
1701 if (!
open_and_query(device_type, p_device_context, p_session_context,
1702 device_name, detail, detail_data_v1))
1715 p_card = lookup_card_cache(card_cache, card_count,
1723 "\t\t\"NUMBER\": %u,\n"
1724 "\t\t\"INDEX\": %d,\n"
1725 "\t\t\"LOAD\": %u,\n"
1726 "\t\t\"LOAD-ALL\": %u,\n"
1727 "\t\t\"MODEL_LOAD\": %u,\n"
1728 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1729 "\t\t\"FW_LOAD\": %u,\n"
1730 "\t\t\"INST\": %u,\n"
1731 "\t\t\"INST-ALL\": %u,\n"
1732 "\t\t\"MAX_INST\": %d,\n"
1733 "\t\t\"MEM\": %u,\n"
1734 "\t\t\"CRITICAL_MEM\": %u,\n"
1735 "\t\t\"SHARE_MEM\": %u,\n"
1736 "\t\t\"P2P_MEM\": %u,\n"
1756 "\t\t\"NUMBER\": %u,\n"
1757 "\t\t\"INDEX\": %d,\n"
1758 "\t\t\"LOAD\": %u,\n"
1759 "\t\t\"MODEL_LOAD\": %u,\n"
1760 "\t\t\"FW_LOAD\": %u,\n"
1761 "\t\t\"INST\": %u,\n"
1762 "\t\t\"MAX_INST\": %d,\n"
1763 "\t\t\"MEM\": %u,\n"
1764 "\t\t\"CRITICAL_MEM\": %u,\n"
1765 "\t\t\"SHARE_MEM\": %u,\n"
1766 "\t\t\"P2P_MEM\": %u,\n"
1769 vpu_load, model_load,
1788 strcat_dyn_buf(&output_buf, (index < device_count - 1) ?
",\n" :
"\n");
1800 goto PRINT_OUTPUT_FINAL;
1807 device_count =
get_modules(device_type, p_device_queue, device_name,
1809 if (!device_count) {
1810 clear_card_cache(card_cache, card_count);
1812 printf(
"%s", output_buf.
str_buf);
1819 extra_temp_per_index = (int32_t *)calloc(device_count,
sizeof(int32_t));
1820 extra_power_per_index = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1822 g_temp_load = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1823 g_temp_pload = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
1830 (icore ==
TP_LOAD) ?
" \"tps\": [\n" :
" \"pcies\": [\n");
1833 for (index = 0; index < device_count; index++)
1837 if (!p_device_context)
1841 if (!
open_and_query(device_type, p_device_context, p_session_context,
1842 device_name, detail, detail_data_v1))
1859 p_card = lookup_card_cache(card_cache, card_count,
1867 "\t\t\"NUMBER\": %u,\n"
1868 "\t\t\"INDEX\": %d,\n"
1869 "\t\t\"LOAD\": 0,\n"
1870 "\t\t\"MODEL_LOAD\": 0,\n"
1871 "\t\t\"FW_LOAD\": %u,\n"
1872 "\t\t\"INST\": 0,\n"
1873 "\t\t\"MAX_INST\": 0,\n"
1875 "\t\t\"CRITICAL_MEM\": 0,\n"
1876 "\t\t\"SHARE_MEM\": 0,\n"
1877 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1878 "\t\t\"P2P_MEM\": 0,\n"
1892 "\t\t\"NUMBER\": %u,\n"
1893 "\t\t\"INDEX\": %d,\n"
1894 "\t\t\"LOAD\": 0,\n"
1895 "\t\t\"MODEL_LOAD\": 0,\n"
1896 "\t\t\"FW_LOAD\": %u,\n"
1897 "\t\t\"INST\": 0,\n"
1898 "\t\t\"MAX_INST\": 0,\n"
1900 "\t\t\"CRITICAL_MEM\": 0,\n"
1901 "\t\t\"SHARE_MEM\": %u,\n"
1902 "\t\t\"P2P_MEM\": 0,\n"
1914 strcat_dyn_buf(&output_buf, (index < device_count - 1) ?
",\n" :
"\n");
1915 if (index == device_count - 1 && icore !=
PCIE_LOAD)
1929 free(extra_temp_per_index);
1930 free(extra_power_per_index);
1935 clear_card_cache(card_cache, card_count);
1937 printf(
"%s", output_buf.
str_buf);
1944 bool has_written_start =
false;
1946 unsigned int index, device_count;
1947 int32_t *module_ids;
1948 uint32_t total_contexts;
1950 uint32_t model_load;
1952 char pcie[64] = {0};
1957 char power_consumption[16];
1959 uint16_t namespace_id = 0;
1967 int32_t *extra_temp_per_index = NULL;
1968 uint32_t *extra_power_per_index = NULL;
1984 if (!has_written_start)
1987 has_written_start =
true;
1994 for (index = 0; index < device_count; index++)
2002 device_name, detail, detail_data_v1))
2041 "\t\t\"NUMBER\": %u,\n"
2042 "\t\t\"INDEX\": %d,\n"
2043 "\t\t\"LOAD\": %u,\n"
2044 "\t\t\"LOAD-ALL\": %u,\n"
2045 "\t\t\"MODEL_LOAD\": %u,\n"
2046 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
2047 "\t\t\"FW_LOAD\": %u,\n"
2048 "\t\t\"INST\": %u,\n"
2049 "\t\t\"INST-ALL\": %u,\n"
2050 "\t\t\"MAX_INST\": %d,\n"
2051 "\t\t\"MEM\": %u,\n"
2052 "\t\t\"CRITICAL_MEM\": %u,\n"
2053 "\t\t\"SHARE_MEM\": %u,\n"
2054 "\t\t\"P2P_MEM\": %u,\n"
2055 "\t\t\"DEVICE\": \"%s\",\n"
2056 "\t\t\"L_FL2V\": \"%s\",\n"
2057 "\t\t\"N_FL2V\": \"%s\",\n"
2058 "\t\t\"FR\": \"%.8s\",\n"
2059 "\t\t\"N_FR\": \"%.8s\""
2061 ",\n\t\t\"NUMA_NODE\": %d,\n"
2062 "\t\t\"PCIE_ADDR\": \"%s\""
2089 "\t\t\"NUMBER\": %u,\n"
2090 "\t\t\"INDEX\": %d,\n"
2091 "\t\t\"LOAD\": %u,\n"
2092 "\t\t\"MODEL_LOAD\": %u,\n"
2093 "\t\t\"FW_LOAD\": %u,\n"
2094 "\t\t\"INST\": %u,\n"
2095 "\t\t\"MAX_INST\": %d,\n"
2096 "\t\t\"MEM\": %u,\n"
2097 "\t\t\"CRITICAL_MEM\": %u,\n"
2098 "\t\t\"SHARE_MEM\": %u,\n"
2099 "\t\t\"P2P_MEM\": %u,\n"
2100 "\t\t\"DEVICE\": \"%s\",\n"
2101 "\t\t\"L_FL2V\": \"%s\",\n"
2102 "\t\t\"N_FL2V\": \"%s\",\n"
2103 "\t\t\"FR\": \"%.8s\",\n"
2104 "\t\t\"N_FR\": \"%.8s\""
2106 ",\n\t\t\"NUMA_NODE\": %d,\n"
2107 "\t\t\"PCIE_ADDR\": \"%s\""
2132 ",\n\t\t\"TEMP\": %d,\n"
2133 "\t\t\"POWER\": \"%s\"",
2145 namespace_id = ns_vf_id.
ns_id;
2157 ",\n\t\t\"QOS MODE\": %u,\n"
2158 "\t\t\"QOS NS\": %u,\n"
2159 "\t\t\"QOS ALLOW\": %.1f,\n"
2160 "\t\t\"QOS OPMAX\": %.1f",
2163 (qos_mode == 0 ? 0 : qos_ns_info.
fAllowance),
2164 (qos_mode == 0 ? 0 :_opmax)
2175 if (index < device_count - 1)
2217 printf(
"%s", output_buf.
str_buf);
2223 extra_temp_per_index = (int32_t *)calloc(device_count,
sizeof(int32_t));
2224 extra_power_per_index = (uint32_t *)calloc(device_count,
sizeof(uint32_t));
2225 if (!extra_temp_per_index || !extra_power_per_index)
2227 (void)fprintf(stderr,
"ERROR: calloc() failed for extra info arrays\n");
2228 if (extra_temp_per_index) free(extra_temp_per_index);
2229 if (extra_power_per_index) free(extra_power_per_index);
2232 g_temp_load = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
2235 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_load\n");
2238 g_temp_pload = (uint32_t*)calloc(device_count,
sizeof(uint32_t));
2241 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pload\n");
2247 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_pthroughput\n");
2253 (void)fprintf(stderr,
"ERROR: calloc() failed for g_temp_sharemem\n");
2261 for (index = 0; index < device_count; index++)
2265 if (!p_device_context)
2272 device_name, detail, detail_data_v1))
2281 (void)fprintf(stderr,
2282 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2318 "\t\t\"NUMBER\": %u,\n"
2319 "\t\t\"INDEX\": %d,\n"
2320 "\t\t\"LOAD\": 0,\n"
2321 "\t\t\"MODEL_LOAD\": 0,\n"
2322 "\t\t\"FW_LOAD\": %u,\n"
2323 "\t\t\"INST\": 0,\n"
2324 "\t\t\"MAX_INST\": 0,\n"
2326 "\t\t\"CRITICAL_MEM\": 0,\n"
2327 "\t\t\"SHARE_MEM\": %u,\n"
2328 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2329 "\t\t\"P2P_MEM\": 0,\n"
2330 "\t\t\"DEVICE\": \"%s\",\n"
2331 "\t\t\"L_FL2V\": \"%s\",\n"
2332 "\t\t\"N_FL2V\": \"%s\",\n"
2333 "\t\t\"FR\": \"%.8s\",\n"
2334 "\t\t\"N_FR\": \"%.8s\""
2336 ",\n\t\t\"NUMA_NODE\": %d,\n"
2337 "\t\t\"PCIE_ADDR\": \"%s\""
2358 "\t\t\"NUMBER\": %u,\n"
2359 "\t\t\"INDEX\": %d,\n"
2360 "\t\t\"LOAD\": 0,\n"
2361 "\t\t\"MODEL_LOAD\": 0,\n"
2362 "\t\t\"FW_LOAD\": %u,\n"
2363 "\t\t\"INST\": 0,\n"
2364 "\t\t\"MAX_INST\": 0,\n"
2366 "\t\t\"CRITICAL_MEM\": 0,\n"
2367 "\t\t\"SHARE_MEM\": %u,\n"
2368 "\t\t\"P2P_MEM\": 0,\n"
2369 "\t\t\"DEVICE\": \"%s\",\n"
2370 "\t\t\"L_FL2V\": \"%s\",\n"
2371 "\t\t\"N_FL2V\": \"%s\",\n"
2372 "\t\t\"FR\": \"%.8s\",\n"
2373 "\t\t\"N_FR\": \"%.8s\""
2375 ",\n\t\t\"NUMA_NODE\": %d,\n"
2376 "\t\t\"PCIE_ADDR\": \"%s\""
2394 ni_sprintf(power_consumption, 16,
"%umW", extra_power_per_index[index]);
2397 ",\n\t\t\"TEMP\": %d,\n"
2398 "\t\t\"POWER\": \"%s\"\n"
2401 (extra_power_per_index[index] + 1) ? power_consumption :
"N/A");
2407 if (index < device_count - 1)
2434 printf(
"%s", output_buf.
str_buf);
2441 int index, instance_count;
2443 unsigned int module_count;
2445 int32_t *module_id_arr = NULL;
2453 module_type != max_device_type;
2467 strcat_dyn_buf(&output_buf,
"Num %ss: %u\n", module_name, module_count);
2475 "%-5s %-7s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2476 "AvgCost",
"VpuLoad",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2477 "SID",
"DEVICE",
"NAMESPACE");
2482 "%-5s %-7s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2483 "AvgCost",
"VpuLoad",
"FrameRate",
"IDR",
"InFrame",
"OutFrame",
"Width",
"Height",
2484 "SID",
"DEVICE",
"NAMESPACE");
2492 "%-5s %-7s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2493 "AvgCost",
"VpuLoad",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"fps",
"BR",
"AvgBR",
"Width",
"Height",
2494 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2499 "%-5s %-7s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n",
"INDEX",
2500 "AvgCost",
"VpuLoad",
"FrameRate",
"IDR",
"UserIDR",
"InFrame",
"OutFrame",
"BR",
"AvgBR",
"Width",
"Height",
2501 "Format",
"SID",
"DEVICE",
"NAMESPACE");
2509 "%-5s %-7s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2510 "VpuLoad",
"InFrame",
"OutFrame",
"fps",
"Width",
"Height",
2511 "SID",
"DEVICE",
"NAMESPACE");
2516 "%-5s %-7s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n",
"INDEX",
2517 "VpuLoad",
"InFrame",
"OutFrame",
"Width",
"Height",
2518 "SID",
"DEVICE",
"NAMESPACE");
2524 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n",
"INDEX",
2525 "LOAD",
"MODEL_LOAD",
"INST",
"MEM",
"SHARE_MEM",
"P2P_MEM",
2529 for (i = 0; i < module_count; i++)
2537 module_name, detail, detail_data_v1))
2545 if(previous_detail_data_p && checkInterval)
2547 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2552 "%-5d %-7d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2560 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2570 "%-5d %-7d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2579 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2592 "%-5d %-7d %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2597 (detail_data_v1->
sInstDetailStatus[index].
ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2611 "%-5d %-7d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2628 "%-5d %-7d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2649 "%-5d %-7d %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2663 if(previous_detail_data_p)
2685 "%-5d %-4u %-10s %-4u %-4u %-9u %-7u %-14s\n",
2692 (disp_model_load == 4294967295U) ?
"N/A" : ((void)snprintf(_ml,
sizeof(_ml),
"%u", disp_model_load), _ml),
2702 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2721 free(module_id_arr);
2725 printf(
"%s", output_buf.
str_buf);
2732 unsigned int index, device_count;
2733 int32_t *module_ids;
2738 char power_consumption[16];
2739 int instance_count = 0;
2742 unsigned int num_gen3_mismatch = 0;
2748 bool has_qos_data =
false;
2749 char qos_str[64] = {0};
2750 uint16_t namespace_id = 0;
2762 printf(
"%s", output_buf.
str_buf);
2767 for (index = 0; index < device_count; index++)
2770 if (!p_device_context)
2777 if (
device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2786 if (p_session_context->
device_handle != NI_INVALID_DEVICE_HANDLE)
2793 if (p_session_context->
device_handle == NI_INVALID_DEVICE_HANDLE)
2797 (void)fprintf(stderr,
2798 "ERROR: ni_device_open2() failed for %s: %s\n",
2823 namespace_id = ns_vf_id.
ns_id;
2829 has_qos_data =
true;
2835 if (show_qos_info && has_qos_data)
2837 char _allowance[16];
2838 uint8_t qos_mode = (uint8_t)(qos_header.
ui16QosState & 0xFF);
2840 (void)snprintf(qos_str,
sizeof(qos_str),
" %-9u %-7u %-10s %-8.1f",
2843 (qos_mode == 0) ?
"N/A" : ((void)snprintf(_allowance,
sizeof(_allowance),
"%.1f", qos_ns_info.
fAllowance), _allowance),
2844 (qos_mode == 0 ? 0 :_opmax));
2850 "%-4s %-8s %-8s %-14s %s\n",
"TEMP",
"POWER",
"FLAVOR",
"DEVICE",
2851 (show_qos_info && has_qos_data) ?
" QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" :
"");
2853 "%-4d %-8s %-8c %-14s %s\n",
2858 (show_qos_info && has_qos_data) ? qos_str:
"");
2862 if (instance_count == 0)
2865 "%-8s %-8s %-8s %-8s %-8.8s %-20.8s %s\n",
"INDEX",
"TEMP",
"POWER",
"FLAVOR",
"FR",
"SN",
2866 (show_qos_info && has_qos_data) ?
"QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" :
"");
2869 "%-8d %-8d %-8s %-8c %-8.8s %-8.*s %s\n",
2875 (show_qos_info && has_qos_data) ? qos_str:
"");
2886 (void)fprintf(stderr,
2887 "ERROR: ni_device_capability_query() failed for %s: %s\n",
2898 syslog(LOG_WARNING,
"ERROR: CRITICAL TEMP %ddegC HIT on SN %s!!!\n",temp_deg,device_capability_t.
serial_number);
2905 syslog(LOG_WARNING,
"ERROR: WARNING TEMP %ddegC HIT on SN %s!!!\n",temp_deg, device_capability_t.
serial_number);
2913 gen3_mismatch_index[num_gen3_mismatch++] = index;
2921 if (num_gen3_mismatch > 0)
2923 char index_list[128] = {0};
2925 for (
unsigned int i = 0; i < num_gen3_mismatch && len <
sizeof(index_list) - 4; i++)
2927 len += snprintf(index_list + len,
sizeof(index_list) - len,
2928 "%s%u", (i > 0) ?
", " :
"", gen3_mismatch_index[i]);
2931 "This system supports Gen4 PCIe speeds, but the following Quadra cards are "
2932 "currently running firmware that only supports PCIe Gen3 (Index: %s). "
2933 "All Quadra VPUs on this system can be firmware upgraded to support "
2934 "PCIe Gen 4 speeds, please update the firmware on each Quadra card to "
2935 "the default firmware flavor.\n",
2941 printf(
"%s", output_buf.
str_buf);
2948 (void)setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2950 int skip_init_rsrc = 0;
2951 int should_match_rev = 1;
2958 time_t startTime = {0}, now = {0};
2959 int timeout_seconds = 0;
2960 struct tm *ltime = NULL;
2962 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2967 bool fw_log_dump =
false;
2968 bool core_reset_log_dump =
false;
2970 int refresh_device_pool = 1;
2971 bool is_first_query =
true;
2973 int show_qos_info = 0;
2974 char *nor_command = NULL;
2975#if defined(__linux__)
2977 const char *target_slot = NULL;
2978 const char *target_domain = NULL;
2979 const char *target_blkdev = NULL;
2983 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2985 setup_signal_handler();
2993 static struct option long_opts[] = {
3002#
if defined(__linux__)
3003 "n:o:D:C:k:R:rt:Sl:hvdqs:b:N:",
3005 "n:o:D:C:k:R:rt:Sl:hvdqN:",
3007 long_opts, &long_idx)) != -1)
3012#if defined(__linux__)
3013 if (strcmp(long_opts[long_idx].
name,
"domain") == 0)
3022 if (!strcmp(
optarg,
"json"))
3026 else if (!strcmp(
optarg,
"simple"))
3030 else if (!strcmp(
optarg,
"text"))
3034 else if (!strcmp(
optarg,
"full"))
3038 else if (!strcmp(
optarg,
"json1"))
3042 else if (!strcmp(
optarg,
"json2"))
3046 else if (!strcmp(
optarg,
"extra"))
3052 (void)fprintf(stderr,
"Error: unknown selection for outputFormat: %s\n",
optarg);
3064 checkInterval = (int)tmp_val;
3075 fw_log_dump = tmp_val;
3086 core_reset_log_dump = tmp_val;
3087 if (core_reset_log_dump)
3099 devid = (int)tmp_val;
3110 refresh_device_pool = (int)tmp_val;
3113 should_match_rev = 0;
3123 timeout_seconds = (int)tmp_val;
3124 printf(
"Timeout will be set %d\n", timeout_seconds);
3136 (void)fprintf(stderr,
"FATAL: invalid log level selected: %s\n",
optarg);
3145 printf(
"-------- ni_rsrc_mon v%s --------\n"
3146 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
3147 "running on the system.\n"
3149 "Usage: ni_rsrc_mon [OPTIONS]\n"
3151 "Monitoring options:\n"
3152 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
3153 " report only once.\n"
3155 "-R Specify if refresh devices on host in each monitor interval.\n"
3156 " If 0, only refresh devices at the start.\n"
3158 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
3160 "-k Specify to dump which card's firmware logs.\n"
3161 " Default: -1(dump fw log of all cards).\n"
3162 "-r Initialize Quadra device regardless firmware release version to\n"
3163 " libxcoder version compatibility.\n"
3164 " Default: only initialize devices with compatible firmware version.\n"
3165 "-t Set timeout time in seconds for device polling. Program will exit with\n"
3166 " failure if timeout is reached without finding at least one device. If 0 or\n"
3167 " no selection, poll indefinitely until a Quadra device is found.\n"
3169 "-S Skip init_rsrc.\n"
3170 "-d Print detailed information for decoder/encoder in text and json formats.\n"
3171 "-l Set loglevel of libxcoder API.\n"
3172 " [none, fatal, error, info, debug, trace]\n"
3174 "-q Show QoS information - MODE,NS,ALLOW,OPMAX.\n"
3175 " MODE - QoS mode 0,1,2.[Default: 0\n"
3176 " NS - QoS NS set in mode 1/2. Default:1\n"
3177 " ALLOW - QoS allowance set in mode 1/2. Default:0\n"
3178 " OPMAX - QoS OverProvisioning max set in 2. Default:0\n"
3179 "-h Open this help message.\n"
3180 "-v Print version info.\n"
3181 "The Error information for critical/warning temperature and Pcie-gen mismatch is shown in all modes\n"
3183 "Firmware log dump options (Linux):\n"
3184 "-D Dump firmware logs (all devices) to current directory.\n"
3185 " Default: 0 (do not dump).\n"
3186 "-C Dump firmware core-reset logs (all devices) to current directory.\n"
3187 " Default: 0 (do not dump).\n"
3188 "-s Select a single device by PCIe slot \n"
3189 "-b Select a single device by NVMe block device name (Mutually exclusive with -s)\n"
3191 "NOR flash options (Linux, requires root):\n"
3192 "-N <cmd> NOR flash persistent log command. [w, r, e, ex], (long form: --nor)\n"
3193 " w - Write current DDR logs into NOR flash\n"
3194 " r - Read persistent logs from NOR flash into DDR, then dump\n"
3195 " e - Erase persistent logs from NOR flash\n"
3196 " ex - Simulate exception (DDR logs saved to NOR flash)\n"
3197 " -s / -b / --domain selector to choose specific card.\n"
3200 " ni_rsrc_mon -D 1 Dump firmware logs from all devices\n"
3201 " ni_rsrc_mon -C 1 Dump core-reset logs from all devices\n"
3202 " ni_rsrc_mon -N r Read NOR flash logs on all devices\n"
3203 " ni_rsrc_mon -N w -s 1 Write NOR flash logs on device slot 1, i.e. 0000:01:00.0\n"
3204 " ni_rsrc_mon --nor r -b nvme0n1 Read NOR flash and dump logs for block dev nvme0n1\n"
3206 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
3209 "Reporting columns for text output format\n"
3210 "INDEX index number used by resource manager to identify the resource\n"
3211 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
3212 "MODEL_LOAD estimated load based on framerate and resolution\n"
3213 "INST number of job instances\n"
3214 "MEM usage of memory by the subsystem\n"
3215 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
3216 "P2P_MEM usage of memory by P2P\n"
3217 "DEVICE path to NVMe device file handle\n"
3218 "NAMESPACE path to NVMe namespace file handle\n"
3219 "Additional information only in text(Default) mode \n"
3220 "TEMP current temperature (degrees Celsius)\n"
3221 "POWER current power(mW), N/A when query power not supported\n"
3222 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3223 "FR current firmware revision\n"
3224 "SN serial number of the Quadra device\n"
3226 "Additional reporting columns for full output format\n"
3227 "VPU same as LOAD in JSON outputs\n"
3229 "TOTAL same as MEM\n"
3230 "CRITICAL usage of memory considered critical\n"
3231 "L_FL2V last ran firmware loader 2 version\n"
3232 "N_FL2V nor flash firmware loader 2 version\n"
3233 "FR current firmware revision\n"
3234 "N_FR nor flash firmware revision\n"
3235 "TEMP current temperature (degrees Celsius)\n"
3236 "POWER current power(mW), N/A when query power not supported\n"
3237 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3238 "FR current firmware revision\n"
3239 "SN serial number of the Quadra device\n"
3240 "QOS Header shows QoS information when enabled\n"
3241 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
3243 "Additional reporting columns for full JSON formats\n"
3245 "FW_LOAD system load\n"
3246 "TEMP current temperature (degrees Celsius)\n"
3247 "POWER current power(mW), N/A when query power not supported\n"
3248 "FLAVOR current Flavor, N/A when query flavor not supported\n"
3249 "FR current firmware revision\n"
3250 "SN serial number of the Quadra device\n"
3251 "QOS decoder and encoder show QoS Information\n"
3252 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
3254 "Following detailed data is displayed per instance for decoder and encoder when -d flag is used"
3255 "INDEX index number used by resource manager to identify the instance\n"
3256 "AvgCost estimated load given in percentage based on framerate and resolution\n"
3257 "VpuLoad vpu load: per-channel consumption ratio in 1/10000 units. Always 0 on firmware < 6tD\n"
3258 "FrameRate framerate of current session\n"
3259 "IDR number of IDR frame it processes\n"
3260 "UserIDR number of force IDR frame set by user(encoder only)\n"
3261 "InFrame number of frames sent to the decoder or encoder\n"
3262 "OutFrame number of frames got from the decoder or encoder\n"
3263 "BR instantaneous bitrate of current encoder session\n"
3264 "AvgBR average bitrate of current encoder session\n"
3265 "Width width of decoder or encoder\n"
3266 "Height height of decoder or encoder\n"
3267 "Format input frame format send to encoder\n"
3269 "DEVICE path to NVMe device file handle\n"
3270 "NAMESPACE path to NVMe namespace file handle\n"
3272 "Extra output shows TEMP and POWER and FLAVOR of the Quadra device \n",
3276 printf(
"Release ver: %s\n"
3284#if defined(__linux__)
3296 (void)fprintf(stderr,
"FATAL: unknown option '-%c'\n", opt);
3299 (void)fprintf(stderr,
"FATAL: unknown option character '\\x%x'\n", opt);
3306 (void)fprintf(stderr,
"FATAL: option '-%c' lacks arg\n", opt);
3309 (void)fprintf(stderr,
"FATAL: unhandled option\n");
3314#if defined(__linux__)
3316 if (target_slot && target_blkdev)
3318 (void)fprintf(stderr,
"FATAL: -s and -b are mutually exclusive; "
3319 "specify a PCIe slot or a block device name, not both.\n");
3324 if ((argc <= 2) && (
optind == 1))
3339 (void)fprintf(stderr,
"FATAL: cannot allocate momory for ni_session_context_t\n");
3344 if (!skip_init_rsrc)
3348 if (!skip_init_rsrc && ret != 0)
3352 (void)fprintf(stderr,
"FATAL: NI resource unavailable\n");
3353#if defined(__linux__)
3356 (void)fprintf(stderr,
"Proceeding to dump firmware logs as root\n");
3359 (void)fprintf(stderr,
"This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3362 int rc = ni_rsrc_log_dump(
".", core_reset_log_dump);
3364 (void)fprintf(stderr,
"Firmware log dump: all devices successful.\n");
3366 (void)fprintf(stderr,
"Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3368 (void)fprintf(stderr,
"Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3370 (
void)fprintf(stderr,
"Firmware log dump: Unexpected error, return code %d\n", rc);
3374#if defined(__linux__)
3377 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3384 (void)fprintf(stderr,
"FATAL: cannot access NI resource\n");
3393 (void)fprintf(stderr,
"FATAL: cannot get devices info\n");
3400 printf(
"**************************************************\n");
3412 startTime = time(NULL);
3417 if(previous_detail_data == NULL)
3419 (void)fprintf(stderr,
"FATAL: Allocate buffer fail\n");
3423 memset((
void *)previous_detail_data, 0, allocate_size);
3428 struct tm temp_time;
3432 (void)strftime(buf,
sizeof(buf),
"%c", ltime);
3434 time_diff_seconds = (
long long)difftime(now, startTime);
3435 time_diff_minutes = time_diff_seconds / 60;
3436 time_diff_hours = time_diff_minutes / 60;
3439 if (is_first_query || refresh_device_pool)
3446 printf(
"%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
3453 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3455 (void)fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
3460 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
3462 perror(
"ERROR: cannot lock p_device_pool");
3469 ReleaseMutex((HANDLE)p_device_pool->
lock);
3471 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
3473 perror(
"ERROR: cannot unlock p_device_pool");
3477 switch (printFormat)
3481 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
3504 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
3514 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
3526 is_first_query =
false;
3530 printf(
"**************************************************\n");
3533 (void)fflush(stdout);
3535 if (checkInterval == 0)
3540 ni_usleep((int64_t)checkInterval * 1000 * 1000);
3547 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3549 (void)fprintf(stderr,
"ERROR: Failed to obtain mutex: %p\n", p_device_pool->
lock);
3554 if ( lockf(p_device_pool->
lock, F_LOCK, 0) )
3556 perror(
"ERROR: cannot lock p_device_pool");
3561 ReleaseMutex((HANDLE)p_device_pool->
lock);
3563 if ( lockf(p_device_pool->
lock, F_ULOCK, 0) )
3565 perror(
"ERROR: cannot unlock p_device_pool");
3568#if defined(__linux__)
3569 if (core_reset_log_dump)
3571 (void)fprintf(stderr,
"Proceeding to dump firmware logs as root\n");
3574 (void)fprintf(stderr,
"This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3577 int rc = ni_rsrc_log_dump(
".", core_reset_log_dump);
3579 (void)fprintf(stderr,
"Firmware log dump: all devices successful.\n");
3581 (void)fprintf(stderr,
"Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3583 (void)fprintf(stderr,
"Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3585 (
void)fprintf(stderr,
"Firmware log dump: Unexpected error, return code %d\n", rc);
3594#if defined(__linux__)
3598 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3615#ifdef __OPENHARMONY__
3616 (void)system(
"chmod -R 777 /dev/shm/");
3617#ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
3618 (void)system(
"chmod 777 /dev/block/vd* 2>/dev/null");
3620#elif defined(_ANDROID)
3621 (void)system(
"chmod -R 777 /dev/shm/");
3622 (void)system(
"chmod 777 /dev/block/nvme* 2>/dev/null");
3623 (void)system(
"chmod 777 /dev/nvme* 2>/dev/null");
3624 property_set(
"ni_rsrc_init_completed",
"yes");
3628 if(checkInterval && previous_detail_data)
3630 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 Extra Info 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
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_MAX_DEVICE_CNT], int checkInterval)
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
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