libxcoder 5.8.0
Loading...
Searching...
No Matches
ni_rsrc_mon.c
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file ni_rsrc_mon.c
24 *
25 * \brief Application to query and print live performance/load info of
26 * registered NETINT video processing devices on system
27 ******************************************************************************/
28
29#if __linux__ || __APPLE__
30#include <unistd.h>
31#include <signal.h>
32#include <syslog.h>
33#endif
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <stdarg.h>
38
39#include <errno.h>
40#include <time.h>
41#include <ctype.h>
42#include <string.h>
43#include "ni_device_api.h"
44#include "ni_rsrc_api.h"
45#include "ni_rsrc_priv.h"
46#include "ni_util.h"
47#include "ni_quadraprobe.h"
48
49#define MAX_DEVICE_NAME_SIZE (9)
50#define ABSOLUTE_TEMP_ZERO (-273)
51#define NP_LOAD (0)
52#define TP_LOAD (1)
53#define PCIE_LOAD (2)
54
55#define VIDEO_PROCESSING_SLICES 4
56#define THROTTLE_REF_WIN_US (1 << (10 + 7)) // 131072us or 0x20000 us, period between qos credit refresh
57#define VIDEO_SLICE_TIME (THROTTLE_REF_WIN_US * VIDEO_PROCESSING_SLICES)
58
59uint32_t* g_temp_load = NULL; //TP load storage
60uint32_t* g_temp_pload = NULL; //Pcie load storage
61uint32_t* g_temp_pthroughput = NULL; //Pcie throughput storage
62uint32_t* g_temp_sharemem = NULL; //TP sharedmem storage
63
66
73
74static const char *ni_rsrc_mon_card_error_str(ni_rsrc_mon_card_error_t err)
75{
76 switch (err) {
77 case NI_RSRC_MON_ERR_WARN_TEMP: return "warn_temp";
78 case NI_RSRC_MON_ERR_CRITICAL_TEMP: return "critical_temp";
79 case NI_RSRC_MON_ERR_PCIE_MISMATCH: return "pcie_mismatch";
81 default: return "none";
82 }
83}
84
85static ni_rsrc_mon_card_error_t ni_rsrc_mon_get_card_error(
86 ni_device_handle_t handle,
87 const ni_device_extra_info_t *p_extra,
88 const ni_device_info_t *p_info)
89{
90 if (p_info && p_extra && handle != NI_INVALID_DEVICE_HANDLE &&
91 p_extra->composite_temp > 0) {
92 ni_device_capability_t cap = {0};
93 if (ni_device_capability_query2(handle, &cap, false) == NI_RETCODE_SUCCESS) {
94 if ((int32_t)p_extra->composite_temp >= cap.critical_temp)
96 if ((int32_t)p_extra->composite_temp >= cap.warning_temp)
98 }
99 }
100#ifdef __linux__
101 if (p_info && p_info->pcie_gen3_on_gen4_host == 1)
103#endif
105}
106
107#ifdef _ANDROID
108
109#include <cutils/properties.h>
110#define PROP_DECODER_TYPE "nidec_service_init"
111#define LOG_TAG "ni_rsrc_mon"
112#endif
113
124
125#ifdef _WIN32
126#include "ni_getopt.h"
127#else
128#include <getopt.h>
129#endif
130
131#ifdef _WIN32
132static BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
133{
135 return TRUE;
156}
157
158#elif __linux__
159/*!******************************************************************************
160 * \brief
161 *
162 * \param
163 *
164 * \return
165 *******************************************************************************/
166void sig_handler(int sig)
167{
168 if (sig == SIGTERM || sig == SIGINT || sig == SIGHUP)
169 {
171 }
172}
173
174/*!******************************************************************************
175 * \brief
176 *
177 * \param
178 *
179 * \return
180 *******************************************************************************/
181void setup_signal_handler(void)
182{
183 if (signal(SIGTERM, sig_handler) == SIG_ERR ||
184 signal(SIGHUP, sig_handler) == SIG_ERR ||
185 signal(SIGINT, sig_handler) == SIG_ERR)
186 {
187 perror("ERROR: signal handler setup");
188 }
189}
190
191/*!******************************************************************************
192 * \brief get PCIe address
193 *
194 * \param[in] char *device_name e.g. /dev/nvme0n1
195 *
196 * \return void
197 * *******************************************************************************/
198void get_pcie_addr(char *device_name, char *pcie)
199{
200 get_dev_pcie_addr(device_name, pcie, NULL, NULL, NULL, NULL);
201}
202
203/*!******************************************************************************
204 * \brief get linux numa_node
205 *
206 * \param[in] char *device_name
207 *
208 * \return int atoi(cmd_ret)
209 *******************************************************************************/
210int get_numa_node(char *device_name)
211{
212 return ni_rsrc_get_numa_node(device_name);
213}
214
215#endif //__linux__
216
217/*!******************************************************************************
218 * \brief remove one device from stored device_handles
219 *
220 * \param ni_device_type_t device_type
221 *
222 * \param int32_t module_id
223 *
224 * \param ni_device_handle_t device_handle
225 *
226 * \return int 0 for success, -1 for failure
227 *******************************************************************************/
228int remove_device_from_saved(ni_device_type_t device_type, int32_t module_id,
229 ni_device_handle_t device_handle)
230{
231 if (!IS_XCODER_DEVICE_TYPE(device_type))
232 {
233 (void)fprintf(stderr, "Error: device_type %d is not a valid device type\n",
234 device_type);
235 return -1;
236 }
237 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
238 if (device_handles[xcoder_device_type][module_id] == device_handle)
239 {
240 device_handles[xcoder_device_type][module_id] =
241 NI_INVALID_DEVICE_HANDLE;
242 return 0;
243 } else
244 {
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,
249 (int64_t)device_handles[xcoder_device_type][module_id]);
250 return -1;
251 }
252}
253
254/*!******************************************************************************
255 * \brief convert number from argv input to integer if safe
256 *
257 * \param char *numArray
258 *
259 * \return int atoi(numArray)
260 *******************************************************************************/
261int argToI(char *numArray)
262{
263 int i;
264
265 if( !numArray )
266 {
267 return 0;
268 }
269
270 const size_t len = strlen(numArray);
271
272 for (i = 0; i < len; i++)
273 {
274 if (!isdigit(numArray[i]))
275 {
276 (void)fprintf(stderr, "invalid, ABORTING\n");
277 abort();
278 }
279 }
280
281 if (len != i)
282 return 0;
283 int32_t tmp_val;
284 if (ni_strtoi(numArray, &tmp_val) != NI_RETCODE_SUCCESS)
285 {
286 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value: %s\n", __func__, numArray);
287 return 0;
288 }
289 return (int)tmp_val;
290}
291
292/*!******************************************************************************
293 * \brief compare two int32_t for qsort
294 *
295 * \param[in] const void *a
296 * \param[in] const void *b
297 *
298 * \return int atoi(numArray)
299 *******************************************************************************/
300int compareInt32_t(const void *a, const void *b)
301{
302 if ( *(int32_t*)a < *(int32_t*)b ) return -1;
303 if ( *(int32_t*)a > *(int32_t*)b ) return 1;
304 return 0;
305}
306
307char *get_pixel_format(ni_device_context_t *p_device_context, int index)
308{
310 "6s3") < 0)
311 {
312 return "UNSUPPORT";
313 }
314 else if ((index >= 0 && index < 4) || (index >= 10 && index < 13))
315 {
316 return "YUV";
317 }
318 else if (index >= 4 && index < 10)
319 {
320 return "RGB";
321 }
322 else if (index >= 13 && index < 15)
323 {
324 return "TILE";
325 }
326 else{
327 return "INVALID";
328 }
329}
330
331static char sid[5] = "0000";
332char *get_session_id(ni_device_context_t *p_device_context, int id)
333{
335 "6s3") < 0)
336 {
337 (void)snprintf(sid, sizeof(sid), "%04x", 0);
338 return sid;
339 }
340 else
341 {
342 (void)snprintf(sid, sizeof(sid), "%04x", id);
343 return sid;
344 }
345}
346
347unsigned int get_modules(ni_device_type_t device_type,
348 ni_device_queue_t *p_device_queue,
349 char *device_name,
350 int32_t **module_ids)
351{
352 unsigned int device_count;
353 size_t size_of_i32;
354
355 size_of_i32 = sizeof(int32_t);
356
357 device_count = p_device_queue->xcoder_cnt[device_type];
358 *module_ids = malloc(size_of_i32 * device_count);
359 if (!(*module_ids))
360 {
361 (void)fprintf(stderr, "ERROR: malloc() failed for module_ids\n");
362 return 0;
363 }
364
365 memcpy(*module_ids,
366 p_device_queue->xcoders[device_type],
367 size_of_i32 * device_count);
368
369 qsort(*module_ids,
370 device_count,
371 size_of_i32,
373
374 ni_strncpy(device_name, MAX_DEVICE_NAME_SIZE,
375 g_device_type_str[device_type],
377
378 return device_count;
379}
380
382 ni_device_context_t *p_device_context,
383 ni_session_context_t *p_session_context,
384 char *device_name, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
385{
386 ni_retcode_t return_code;
387
388 if (!p_device_context)
389 {
390 return false;
391 }
392
393 // check if device has been opened already
394 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
395 int module_id = p_device_context->p_device_info->module_id;
396 if (device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
397 {
398 p_session_context->device_handle =
399 device_handles[xcoder_device_type][module_id];
400 } else
401 {
402 p_session_context->device_handle =
403 ni_device_open2(p_device_context->p_device_info->dev_name,
405 if (p_session_context->device_handle != NI_INVALID_DEVICE_HANDLE)
406 {
407 device_handles[xcoder_device_type][module_id] =
408 p_session_context->device_handle;
409 }
410 }
411
412 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
413 {
414 char errmsg[NI_ERRNO_LEN] = {0};
416 (void)fprintf(stderr,
417 "ERROR: ni_device_open2() failed for %s: %s\n",
418 p_device_context->p_device_info->dev_name,
419 errmsg);
420 ni_rsrc_free_device_context(p_device_context);
421 return false;
422 }
423
424 p_session_context->blk_io_handle =
425 p_session_context->device_handle;
426 p_session_context->hw_id =
427 p_device_context->p_device_info->hw_id;
428
429 if(detail)
430 {
432 "6i") < 0)
433 {
434 (void)fprintf(stderr,
435 "ERROR: cannot print detailed info for %s as it has FW API "
436 "version < 6.i\n", p_device_context->p_device_info->dev_name);
437 return false;
438 }
439 else if (ni_cmp_fw_api_ver((char*)&p_device_context->p_device_info->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6r6") < 0)
440 {
441 return_code = ni_device_session_query_detail(p_session_context,
442 GET_XCODER_DEVICE_TYPE(device_type), (ni_instance_mgr_detail_status_t *)detail_data_v1);
443 }
444 else
445 {
446 return_code = ni_device_session_query_detail_v1(p_session_context,
447 GET_XCODER_DEVICE_TYPE(device_type), detail_data_v1);
448 }
449 }
450 else
451 {
452 return_code = ni_device_session_query(p_session_context,
453 GET_XCODER_DEVICE_TYPE(device_type));
454 }
455 if (return_code != NI_RETCODE_SUCCESS)
456 {
457 (void)fprintf(stderr,
458 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
459 return_code,
460 device_name,
461 p_device_context->p_device_info->dev_name,
462 p_device_context->p_device_info->hw_id);
463 remove_device_from_saved(device_type, module_id,
464 p_session_context->device_handle);
465 ni_device_close(p_session_context->device_handle);
466 ni_rsrc_free_device_context(p_device_context);
467 return false;
468 }
469
470 if (!p_session_context->load_query.total_contexts)
471 {
472 p_session_context->load_query.current_load = 0;
473 }
474
475 memcpy(p_session_context->fw_rev,
476 p_device_context->p_device_info->fw_rev,
477 8);
478
479 return true;
480}
481
483 ni_session_context_t *p_session_context,
484 void** p_log_buffer,
485 bool gen_log_file)
486{
487 ni_retcode_t return_code;
488 if (!p_device_context)
489 return false;
490
491 p_session_context->device_handle =
492 ni_device_open2(p_device_context->p_device_info->blk_name,
494 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
495 {
496 char errmsg[NI_ERRNO_LEN] = {0};
498 (void)fprintf(stderr,
499 "ERROR: ni_device_open2() failed for %s: %s\n",
500 p_device_context->p_device_info->blk_name,
501 errmsg);
502 ni_rsrc_free_device_context(p_device_context);
503 return false;
504 }
505 p_session_context->blk_io_handle =
506 p_session_context->device_handle;
507 p_session_context->hw_id =
508 p_device_context->p_device_info->module_id;
509 memcpy(p_session_context->fw_rev,
510 p_device_context->p_device_info->fw_rev,
511 sizeof(p_session_context->fw_rev));
512
513 return_code = ni_device_alloc_and_get_firmware_logs(p_session_context, p_log_buffer, gen_log_file);
514 return return_code ? false : true;
515}
516
517/*!*****************************************************************************
518 * \brief Dump firmware logs and log artifacts (if present) for one Quadra card.
519 *
520 * Downloads the five per-core log buffers (NP/EP/DP/TP/FP) via NVMe,
521 * then attempts to read log_artifacts (artifacts.tar.gz).
522 *
523 * \param[in] p_device_context Device context
524 * \param[in] p_session_context Session context used for NVMe commands
525 * \param[in] gen_log_file true - write logs and artifacts to disk
526*******************************************************************************/
527static void dump_fw_log_and_artifacts(ni_device_context_t *p_device_context,
528 ni_session_context_t *p_session_context,
529 bool gen_log_file)
530{
531 void *p_log_buffer = NULL;
532 int module_id = p_device_context->p_device_info->module_id;
533 const char *blk_name = p_device_context->p_device_info->blk_name;
534
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);
537 } else {
538 printf("Success: dumped fw log of card:%d blk_name:%s\n", module_id, blk_name);
539 }
540
541 /* Artifacts supported in firmware >= 6tA, older firmware does not support */
543 (char *)&p_device_context->p_device_info->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
544 "6tA") < 0)
545 {
546 printf("Info: artifacts not supported by card:%d fw_rev:%.8s, skipping\n",
547 module_id, (char *)p_device_context->p_device_info->fw_rev);
548 }
549 else
550 {
551 ni_retcode_t artifacts_rc =
552 ni_device_alloc_and_get_fw_log_artifacts(p_session_context, gen_log_file);
553 if (artifacts_rc == NI_RETCODE_SUCCESS)
554 {
555 printf("Info: fw log artifacts checked for card:%d blk_name:%s\n", module_id, blk_name);
556 }
557 else
558 {
559 printf("Error: fw log artifacts read failed for card:%d blk_name:%s\n", module_id, blk_name);
560 }
561 }
562}
563
564/*!*****************************************************************************
565 * \brief Dump firmware logs and artifacts for one or all Quadra cards.
566 *
567 * If devid is a valid card index, dumps only for that card;
568 * otherwise dumps every card. For each card it downloads
569 * the five per-core log buffers and the log artifacts via NVMe and
570 * writes them to the current directory.
571 *
572 * \param[in] coders Device queue
573 * \param[in] sessionCtxt Session context for NVMe commands
574 * \param[in] devid Card index to dump, or -1 to dump all cards
575*******************************************************************************/
576void dump_fw_log(ni_device_queue_t *coders, ni_session_context_t *sessionCtxt, int devid)
577{
578 uint32_t i;
579 unsigned int module_count;
580 int32_t *module_id_arr = NULL;
581 char module_name[MAX_DEVICE_NAME_SIZE];
582 ni_device_context_t *p_device_context = NULL;
584
585 module_count = get_modules(module_type, coders, module_name, &module_id_arr);
586 if (!module_count) {
587 printf("Error: module not found!\n");
588 return;
589 }
590
591 bool gen_log_file = true; // dump and write fw logs to runtime dir
592
593 if (devid >= 0 && (uint32_t)devid < module_count)
594 {
595 // dump fw logs and artifacts of specified card
596 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[devid]);
597 if (!p_device_context)
598 return;
599 if (p_device_context->p_device_info->module_id == devid)
600 {
601 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
602 ni_device_close(sessionCtxt->device_handle);
603 ni_rsrc_free_device_context(p_device_context);
604 }
605 }
606 else
607 {
608 // dump fw logs and artifacts of all quadra cards
609 for (i = 0; i < module_count; i++)
610 {
611 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[i]);
612 dump_fw_log_and_artifacts(p_device_context, sessionCtxt, gen_log_file);
613 ni_device_close(sessionCtxt->device_handle);
614 ni_rsrc_free_device_context(p_device_context);
615 }
616 }
617
618 free(module_id_arr);
619}
620
621#if defined(__linux__)
622/*!*****************************************************************************
623 * \brief Run a NOR command on either one selected or all Quadra devices.
624 *
625 * A single device is selected using -s or -b, without a selector, the
626 * nor command will be excuted on all quadraprobe identified Quadra
627 * devices.
628 *
629 * \param[in] nor_cmd NOR command string ("w","r","e","ex").
630 * \param[in] t_domain --domain value, defaults to "0000".
631 * \param[in] t_slot -s slot value
632 * \param[in] t_blkdev -b block-device name
633 *
634 * \return 0 on success,
635 * non-zero on failure.
636 ******************************************************************************/
637static int run_bar4_operations(const char *nor_cmd,
638 const char *t_domain, const char *t_slot,
639 const char *t_blkdev)
640{
641 if (geteuid() != 0)
642 {
643 (void)fprintf(stderr,
644 "This operation requires root (sudo). "
645 "Please rerun: sudo ni_rsrc_mon [options]\n");
646 return 1;
647 }
648
649 bool is_device_selected = (t_slot != NULL || t_blkdev != NULL);
650 int rc;
651
652 if (!is_device_selected)
653 {
654 /* ---- All-device path ---- */
655 rc = ni_rsrc_nor_log_command(nor_cmd, ".");
656 if (rc == 0)
657 (void)fprintf(stderr, "NOR flash command: all devices successful.\n");
658 else if (rc == 1)
659 (void)fprintf(stderr, "NOR flash command: No Quadra devices found.\n");
660 else if (rc == 2)
661 (void)fprintf(stderr,
662 "NOR flash command: One or more devices failed.\n");
663 else
664 (void)fprintf(stderr,
665 "NOR flash command: Unexpected error %d.\n", rc);
666 }
667 else
668 {
669 /* ---- Single-device path (-s / -b) ---- */
670 uint32_t cmd;
671 if (nor_cmd_decode(nor_cmd, &cmd) != 0)
672 return 1;
673
674 QuadraDevice *dev = NULL;
675 rc = t_slot
676 ? quadra_device_find_by_bdf(t_domain ? t_domain : "0000",
677 t_slot, &dev)
678 : quadra_device_find_by_block_dev(t_blkdev, &dev);
679 if (rc != 0 || !dev)
680 {
681 (void)fprintf(stderr, "[ERROR] Target Quadra device not found.\n");
682 free(dev);
683 return 1;
684 }
685
686 rc = ni_rsrc_nor_cmd_run(dev, 1, cmd, ".");
687 free(dev); /* ni_rsrc_nor_cmd_run handles mmap cleanup internally */
688 }
689 return rc;
690}
691#endif /* __linux__ */
692
693
695 char *device_name)
696{
697 switch (*p_device_type)
698 {
700 *p_device_type = NI_DEVICE_TYPE_UPLOAD;
701 ni_strcpy(device_name, MAX_DEVICE_NAME_SIZE, "uploader");
702 return true;
704 *p_device_type = NI_DEVICE_TYPE_ENCODER;
705 default:
706 return false;
707 }
708}
709
710#define DYN_STR_BUF_CHUNK_SIZE 4096
711typedef struct dyn_str_buf
712{
713 int str_len; // Note: this does not include EOL char
714 int buf_size;
715 char *str_buf; // Pointer to string
717
718/*!*****************************************************************************
719 * \brief Accumulate string data in a dynamically sized buffer. This is
720 * useful to separate error messages from json and table output.
721 *
722 * \param[in] *dyn_str_buf pointer to structure holding dyn_str_buf info
723 * \param[in] *fmt printf format specifier
724 * \param[in] ... additional arguments
725 *
726 * \return 0 for success, -1 for error
727 ******************************************************************************/
728int strcat_dyn_buf(dyn_str_buf_t *dyn_str_buf, const char *fmt, ...)
729{
730 int avail_buf;
731 int formatted_len;
732 int add_buf_size = 0;
733 char *tmp_char_ptr = NULL;
734
735 if (!dyn_str_buf)
736 {
737 (void)fprintf(stderr, "ERROR: invalid param *dyn_str_buf\n");
738 return -1;
739 }
740
741 if (!fmt)
742 {
743 return 0;
744 }
745
746 va_list vl, tmp_vl;
747 va_start(vl, fmt);
748 va_copy(tmp_vl, vl);
749
750 // determine length of string to add
751 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
752 va_end(tmp_vl);
753
754 // check if str_buf needs to be expanded in increments of chunk size
755 avail_buf = dyn_str_buf->buf_size - dyn_str_buf->str_len;
756 add_buf_size = (formatted_len + 1) > avail_buf ?
757 ((formatted_len + 1 - avail_buf + DYN_STR_BUF_CHUNK_SIZE - 1) /
760 0;
761
762 // realloc() to expand str_buf if necessary
763 if (add_buf_size)
764 {
765 tmp_char_ptr = (char *)realloc(dyn_str_buf->str_buf,
766 sizeof(char) * dyn_str_buf->buf_size +
767 add_buf_size);
768 if (!tmp_char_ptr)
769 {
770 (void)fprintf(stderr, "ERROR: strcat_dyn_buf() failed realloc()\n");
771 va_end(vl);
772 return -1;
773 }
774 dyn_str_buf->str_buf = tmp_char_ptr;
775 dyn_str_buf->buf_size += add_buf_size;
776 avail_buf = dyn_str_buf->buf_size - dyn_str_buf->str_len;
777 }
778
779 // concatenate string to buffer
780 ni_vsprintf(dyn_str_buf->str_buf + dyn_str_buf->str_len, avail_buf, fmt, vl);
781 dyn_str_buf->str_len += formatted_len;
782
783 va_end(vl);
784 return 0;
785}
786
788{
789 free(dyn_str_buf->str_buf);
790 memset(dyn_str_buf, 0, sizeof(dyn_str_buf_t));
791}
792
793
794#define NI_RSRC_MON_CARD_CACHE_MAX NI_MAX_DEVICE_CNT
795
803
804static void clear_card_cache(ni_rsrc_mon_card_cache_t *cache, unsigned int n)
805{
806 unsigned int i;
807 for (i = 0; i < n; i++) {
808 clear_dyn_str_buf(&cache[i].card_obj);
809 clear_dyn_str_buf(&cache[i].qos_suffix);
810 cache[i].valid = false;
811 }
812}
813
814static const ni_rsrc_mon_card_cache_t *
815lookup_card_cache(const ni_rsrc_mon_card_cache_t *cache, unsigned int n,
816 const char *blk_name)
817{
818 unsigned int i;
819 if (!blk_name || !blk_name[0])
820 return NULL;
821 for (i = 0; i < n; i++) {
822 if (cache[i].valid &&
823 !strncmp(cache[i].blk_name, blk_name, NI_MAX_DEVICE_NAME_LEN))
824 return &cache[i];
825 }
826 return NULL;
827}
828
829static unsigned int build_card_and_qos_cache(
830 ni_device_queue_t *p_device_queue,
831 ni_session_context_t *p_session_context,
832 int detail,
835{
836 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
837 unsigned int index, card_count;
838 int32_t *card_module_ids = NULL;
840 ni_device_context_t *p_device_context;
841 ni_device_extra_info_t dev_extra = {0};
842 char power_consumption[16];
843#ifdef __linux__
844 char pcie[64] = {0};
845 int numa_node;
846#endif
847
848 card_count = get_modules(card_type, p_device_queue, device_name,
849 &card_module_ids);
850 if (!card_count)
851 return 0;
852
853
854 for (index = 0; index < card_count; index++) {
856 ni_qos_header_info_log_page_t qos_header = {0};
857 ni_qos_namespace_info_log_page_t qos_ns_info = {0};
858 ni_device_vf_ns_id_t ns_vf_id = {0};
859 uint16_t namespace_id = 0;
860 uint8_t qos_mode = 0;
861
862 cache[index].valid = false;
863 memset(cache[index].blk_name, 0, sizeof(cache[index].blk_name));
864
865 p_device_context = ni_rsrc_get_device_context(card_type,
866 card_module_ids[index]);
867 if (!p_device_context)
868 continue;
869
870 if (!open_and_query(card_type, p_device_context, p_session_context,
871 device_name, detail, detail_data_v1)) {
872 ni_rsrc_free_device_context(p_device_context);
873 continue;
874 }
875
876 ni_strncpy(cache[index].blk_name, NI_MAX_DEVICE_NAME_LEN, p_device_context->p_device_info->blk_name,
878 cache[index].module_id = p_device_context->p_device_info->module_id;
879 cache[index].valid = true;
880
881 memset(&dev_extra, 0, sizeof(dev_extra));
882 if (ni_query_extra_info(p_session_context->device_handle, &dev_extra,
883 p_device_context->p_device_info->fw_rev))
884 {
885 dev_extra.composite_temp = 0;
886 dev_extra.fw_flavour = '-';
887 }
888 if (dev_extra.power_consumption + 1)
889 ni_sprintf(power_consumption, 16, "%umW", dev_extra.power_consumption);
890
891 card_err = ni_rsrc_mon_get_card_error(p_session_context->device_handle,
892 &dev_extra,
893 p_device_context->p_device_info);
894
895#ifdef __linux__
896 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
897 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
898#endif
899
900 strcat_dyn_buf(&cache[index].card_obj,
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"
906#ifdef __linux__
907 "\t\t\"NUMA_NODE\": %d,\n"
908 "\t\t\"PCIE_ADDR\": \"%s\",\n"
909#endif
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\"",
915 p_device_context->p_device_info->dev_name,
916 p_device_context->p_device_info->fl_ver_last_ran,
917 p_device_context->p_device_info->fl_ver_nor_flash,
918 p_device_context->p_device_info->fw_rev,
919 p_device_context->p_device_info->fw_rev_nor_flash,
920#ifdef __linux__
921 numa_node, pcie,
922#endif
924 (dev_extra.power_consumption + 1) ? power_consumption : "N/A",
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),
928 dev_extra.fw_flavour
929 );
930
931
932 if (ni_query_vf_ns_id(p_session_context->device_handle, &ns_vf_id,
933 p_device_context->p_device_info->fw_rev) ==
935 {
936 namespace_id = ns_vf_id.ns_id;
937 if (ni_query_qos_info(p_session_context->device_handle, &qos_header,
938 p_device_context->p_device_info->fw_rev) ==
940 {
942 &qos_ns_info,
943 p_device_context->p_device_info->fw_rev);
944 qos_mode = (uint8_t)(qos_header.ui16QosState & 0xFF);
945 {
946 float opmax = (float)(qos_ns_info.ui32OPmaxUs * 100) / VIDEO_SLICE_TIME;
947 strcat_dyn_buf(&cache[index].qos_suffix,
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",
952 (uint8_t)(qos_header.ui16QosState & 0xFF),
953 namespace_id,
954 (qos_mode == 0 ? 0 : qos_ns_info.fAllowance),
955 (qos_mode == 0 ? 0 : opmax));
956 }
957 }
958 }
959
960 ni_rsrc_free_device_context(p_device_context);
961 }
962
963 free(card_module_ids);
964 return card_count;
965}
966
968 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
969{
970 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
971 unsigned int index, device_count;
972 int32_t *module_ids;
973 dyn_str_buf_t output_buf = {0};
974
975 ni_device_context_t *p_device_context;
976 ni_device_type_t device_type;
977 ni_load_query_t load_query;
978 ni_retcode_t return_code;
979 char _ml[16];
980
981 for (device_type = NI_DEVICE_TYPE_DECODER;
982 device_type != NI_DEVICE_TYPE_XCODER_MAX;
983 device_type++)
984 {
985 device_count = get_modules(device_type,
986 p_device_queue,
987 device_name,
988 &module_ids);
989 if (!device_count)
990 {
991 continue;
992 }
993UPLOADER:
994 strcat_dyn_buf(&output_buf, "Num %ss: %u\n", device_name, device_count);
995
996 switch (device_type)
997 {
999 strcat_dyn_buf(&output_buf,
1000 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
1001 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1002 break;
1004 case NI_DEVICE_TYPE_AI:
1005 strcat_dyn_buf(&output_buf,
1006 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
1007 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1008 break;
1010 strcat_dyn_buf(&output_buf,
1011 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
1012 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1013 break;
1015 strcat_dyn_buf(&output_buf,
1016 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
1017 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1018 break;
1019 default:
1020 break;
1021 }
1022
1023 for (index = 0; index < device_count; index++)
1024 {
1025 p_device_context =
1026 ni_rsrc_get_device_context(device_type,
1027 module_ids[index]);
1028 if (!open_and_query(device_type,
1029 p_device_context,
1030 p_session_context,
1031 device_name, detail, detail_data_v1))
1032 {
1033 continue;
1034 }
1035
1036 /* PF prints overall statistics; VFs print their own per-NS statistics. */
1037 uint32_t disp_load = p_session_context->load_query.current_load;
1038 uint32_t disp_total_ctx = p_session_context->load_query.total_contexts;
1039 uint32_t disp_model_load = p_session_context->load_query.fw_model_load;
1040 if (p_session_context->overall_load_query.admin_queried &&
1041 device_type != NI_DEVICE_TYPE_UPLOAD)
1042 {
1043 disp_load = p_session_context->overall_load_query.overall_current_load;
1044 disp_total_ctx = p_session_context->overall_load_query.overall_instance_count;
1045 disp_model_load = p_session_context->overall_load_query.overall_fw_model_load;
1046 }
1047
1048 switch (device_type)
1049 {
1051 strcat_dyn_buf(&output_buf,
1052 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1053 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1054 p_device_context->p_device_info->module_id,
1055 disp_load,
1056 (disp_model_load == 4294967295U) ? "N/A" : ((void)snprintf(_ml, sizeof(_ml), "%u", disp_model_load), _ml),
1057 p_session_context->load_query.fw_load,
1058 disp_total_ctx,
1059 p_device_context->p_device_info->max_instance_cnt,
1060 p_session_context->load_query.fw_video_mem_usage,
1061 p_session_context->load_query.fw_video_shared_mem_usage,
1062 p_session_context->load_query.fw_share_mem_usage,
1063 p_device_context->p_device_info->dev_name,
1064 p_device_context->p_device_info->fl_ver_last_ran,
1065 p_device_context->p_device_info->fl_ver_nor_flash,
1066 p_device_context->p_device_info->fw_rev,
1067 p_device_context->p_device_info->fw_rev_nor_flash);
1068 break;
1070 case NI_DEVICE_TYPE_AI:
1071 strcat_dyn_buf(&output_buf,
1072 "%-5d %-3u %-3u %-3u/%-3d %-3u "
1073 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1074 p_device_context->p_device_info->module_id,
1075 disp_load,
1076 p_session_context->load_query.fw_load,
1077 disp_total_ctx,
1078 p_device_context->p_device_info->max_instance_cnt,
1079 p_session_context->load_query.fw_video_mem_usage,
1080 p_session_context->load_query.fw_share_mem_usage,
1081 p_device_context->p_device_info->dev_name,
1082 p_device_context->p_device_info->fl_ver_last_ran,
1083 p_device_context->p_device_info->fl_ver_nor_flash,
1084 p_device_context->p_device_info->fw_rev,
1085 p_device_context->p_device_info->fw_rev_nor_flash);
1086 break;
1088 strcat_dyn_buf(&output_buf,
1089 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
1090 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1091 p_device_context->p_device_info->module_id,
1092 disp_load,
1093 (disp_model_load == 4294967295U) ? "N/A" : ((void)snprintf(_ml, sizeof(_ml), "%u", disp_model_load), _ml),
1094 p_session_context->load_query.fw_load,
1095 disp_total_ctx,
1096 p_device_context->p_device_info->max_instance_cnt,
1097 p_session_context->load_query.fw_video_mem_usage,
1098 p_session_context->load_query.fw_video_shared_mem_usage,
1099 p_session_context->load_query.fw_share_mem_usage,
1100 p_session_context->load_query.fw_p2p_mem_usage,
1101 p_device_context->p_device_info->dev_name,
1102 p_device_context->p_device_info->fl_ver_last_ran,
1103 p_device_context->p_device_info->fl_ver_nor_flash,
1104 p_device_context->p_device_info->fw_rev,
1105 p_device_context->p_device_info->fw_rev_nor_flash);
1106 break;
1108 strcat_dyn_buf(&output_buf,
1109 "%-5d %-3u %-3u/%-3d %-3u "
1110 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1111 p_device_context->p_device_info->module_id,
1112 p_session_context->load_query.fw_load,
1113 p_session_context->load_query.active_hwuploaders,
1114 p_device_context->p_device_info->max_instance_cnt,
1115 p_session_context->load_query.fw_video_mem_usage,
1116 p_session_context->load_query.fw_share_mem_usage,
1117 p_session_context->load_query.fw_p2p_mem_usage,
1118 p_device_context->p_device_info->dev_name,
1119 p_device_context->p_device_info->fl_ver_last_ran,
1120 p_device_context->p_device_info->fl_ver_nor_flash,
1121 p_device_context->p_device_info->fw_rev,
1122 p_device_context->p_device_info->fw_rev_nor_flash);
1123 break;
1124 default:
1125 break;
1126 }
1127
1128 ni_rsrc_free_device_context(p_device_context);
1129 }
1130
1131 if (swap_encoder_and_uploader(&device_type, device_name))
1132 {
1133 goto UPLOADER;
1134 }
1135
1136 free(module_ids);
1137 }
1138
1139 // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
1140 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
1141 goto PRINT_OUTPUT;
1142 }
1143
1144 //Nvme[0] and TP[1] and Pcie[2] load
1145 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
1146 {
1147 // ASSUMPTION: Each Quadra has at least and only one encoder.
1148 device_type = NI_DEVICE_TYPE_ENCODER;
1149 device_count = get_modules(device_type,
1150 p_device_queue,
1151 device_name,
1152 &module_ids);
1153
1154 if (icore == NP_LOAD)
1155 {
1156 strcat_dyn_buf(&output_buf, "Num Nvmes: ");
1157 g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1158 if (!g_temp_load)
1159 {
1160 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
1161 return;
1162 }
1163 g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1164 if (!g_temp_pload)
1165 {
1166 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
1167 return;
1168 }
1169 g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1170 if (!g_temp_pthroughput)
1171 {
1172 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
1173 return;
1174 }
1175 g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1176 if (!g_temp_sharemem)
1177 {
1178 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
1179 return;
1180 }
1181 }
1182 else
1183 {
1184 (icore == TP_LOAD)?strcat_dyn_buf(&output_buf, "Num TPs: "):strcat_dyn_buf(&output_buf, "Num PCIes: ");
1185 }
1186
1187 strcat_dyn_buf(&output_buf, "%u\n", device_count);
1188 if (icore == PCIE_LOAD)
1189 {
1190 strcat_dyn_buf(&output_buf,
1191 "INDEX LOAD( FW ) PCIE_Card2Host_Gbps "
1192 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1193 }
1194 else
1195 {
1196 strcat_dyn_buf(&output_buf,
1197 "INDEX LOAD( FW ) MEM( SHARE ) "
1198 "DEVICE L_FL2V N_FL2V FR N_FR\n");
1199 }
1200 if (!device_count)
1201 {
1202 if (output_buf.str_buf)
1203 printf("%s", output_buf.str_buf);
1204 clear_dyn_str_buf(&output_buf);
1205 free(g_temp_load);
1206 free(g_temp_pload);
1207 free(g_temp_pthroughput);
1208 free(g_temp_sharemem);
1209 return;
1210 }
1211
1212 for (index = 0; index < device_count; index++)
1213 {
1214 p_device_context = ni_rsrc_get_device_context(device_type,
1215 module_ids[index]);
1216 if (!p_device_context)
1217 continue;
1218 if (icore == NP_LOAD)
1219 {
1220 if (!open_and_query(device_type,
1221 p_device_context,
1222 p_session_context,
1223 device_name, detail, detail_data_v1))
1224 {
1225 continue;
1226 }
1227
1228 return_code = ni_query_nvme_status(p_session_context, &load_query);
1229 if (return_code != NI_RETCODE_SUCCESS)
1230 {
1231 (void)fprintf(stderr,
1232 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1233 return_code,
1234 device_name,
1235 p_device_context->p_device_info->dev_name,
1236 p_device_context->p_device_info->hw_id);
1237 remove_device_from_saved(device_type,
1238 p_device_context->p_device_info->module_id,
1239 p_session_context->device_handle);
1240 ni_device_close(p_session_context->device_handle);
1241 goto CLOSE;
1242 }
1243 g_temp_load[index] = load_query.tp_fw_load;
1244 g_temp_pload[index] = load_query.pcie_load;
1245 g_temp_pthroughput[index] = load_query.pcie_throughput;
1246 g_temp_sharemem[index] = load_query.fw_share_mem_usage;
1247 }
1248 if (icore==PCIE_LOAD)
1249 {
1250 load_query.fw_load = g_temp_pload[index];
1251 load_query.fw_share_mem_usage = g_temp_pthroughput[index];
1252
1253 strcat_dyn_buf(&output_buf,
1254 "%-5d %-3u %-3.1f "
1255 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1256 p_device_context->p_device_info->module_id,
1257 load_query.fw_load,
1258 (float)load_query.fw_share_mem_usage/10,
1259 p_device_context->p_device_info->dev_name,
1260 p_device_context->p_device_info->fl_ver_last_ran,
1261 p_device_context->p_device_info->fl_ver_nor_flash,
1262 p_device_context->p_device_info->fw_rev,
1263 p_device_context->p_device_info->fw_rev_nor_flash);
1264 }
1265 else
1266 {
1267 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
1268 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
1269
1270 strcat_dyn_buf(&output_buf,
1271 "%-5d %-3u %-3u "
1272 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
1273 p_device_context->p_device_info->module_id,
1274 load_query.fw_load,
1275 load_query.fw_share_mem_usage,
1276 p_device_context->p_device_info->dev_name,
1277 p_device_context->p_device_info->fl_ver_last_ran,
1278 p_device_context->p_device_info->fl_ver_nor_flash,
1279 p_device_context->p_device_info->fw_rev,
1280 p_device_context->p_device_info->fw_rev_nor_flash);
1281 }
1282
1283 CLOSE:
1284 ni_rsrc_free_device_context(p_device_context);
1285 }
1286 }
1287
1288 free(g_temp_load);
1289 free(g_temp_pload);
1290 free(g_temp_pthroughput);
1291 free(g_temp_sharemem);
1292 free(module_ids);
1293
1294PRINT_OUTPUT:
1295 if (output_buf.str_buf)
1296 printf("%s", output_buf.str_buf);
1297 clear_dyn_str_buf(&output_buf);
1298}
1299
1301 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
1302{
1303 bool copied_block_name;
1304 char block_name[NI_MAX_DEVICE_NAME_LEN] = {0};
1305 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1306 unsigned int guid;
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;
1312 dyn_str_buf_t output_buf = {0};
1313
1314 ni_device_context_t *p_device_context;
1315 ni_device_type_t device_type;
1316 ni_device_type_t maximum_device_type;
1317 ni_load_query_t load_query;
1318 ni_retcode_t return_code;
1319
1320 // Use NI_DEVICE_TYPE_ENCODER instead of NI_DEVICE_TYPE_NVME
1321 // so that Quadras running older firmware will show up.
1322 // Assumption: Each Quadra has at least one encoder.
1323 number_of_quadras = p_device_queue->xcoder_cnt[NI_DEVICE_TYPE_ENCODER];
1324
1325 maximum_firmware_loads = calloc(number_of_quadras, sizeof(unsigned int));
1326 if (!maximum_firmware_loads)
1327 {
1328 (void)fprintf(stderr, "calloc() returned NULL\n");
1329 return;
1330 }
1331
1332 maximum_firmware_loads_per_quadra = NULL;
1333 p_device_context = NULL;
1334
1335 for (guid = 0; guid < number_of_quadras; guid++)
1336 {
1337 maximum_device_type = NI_DEVICE_TYPE_XCODER_MAX;
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;
1342
1343 for (device_type = NI_DEVICE_TYPE_DECODER;
1344 device_type < maximum_device_type;
1345 device_type++)
1346 {
1347 if (p_device_queue->xcoders[device_type][guid] != -1)
1348 {
1349 number_of_device_types_present++;
1350 }
1351 }
1352
1353 for (device_type = NI_DEVICE_TYPE_DECODER;
1354 device_type < maximum_device_type;
1355 device_type++)
1356 {
1357 memcpy(device_name,
1358 g_device_type_str[device_type],
1360
1361 if (p_device_queue->xcoders[device_type][guid] == -1)
1362 {
1363 continue;
1364 }
1365
1366 p_device_context =
1367 ni_rsrc_get_device_context(device_type,
1368 p_device_queue->xcoders[device_type][guid]);
1369 if (!open_and_query(device_type,
1370 p_device_context,
1371 p_session_context,
1372 device_name, detail, detail_data_v1))
1373 {
1374 continue;
1375 }
1376
1377 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
1378 "6O") < 0)
1379 {
1380 if (maximum_device_type == NI_DEVICE_TYPE_XCODER_MAX)
1381 {
1382 strcat_dyn_buf(&output_buf,
1383 "%s: Simple output not supported. Try '-o full' "
1384 "instead.\n",
1385 p_device_context->p_device_info->dev_name);
1386 maximum_device_type = NI_DEVICE_TYPE_ENCODER;
1387 }
1388 ni_device_close(p_session_context->device_handle);
1389 ni_rsrc_free_device_context(p_device_context);
1390 continue;
1391 }
1392
1393 if (!copied_block_name)
1394 {
1396 p_device_context->p_device_info->dev_name,
1398 copied_block_name = true;
1399 }
1400
1401 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.fw_load)
1402 {
1403 *maximum_firmware_loads_per_quadra = p_session_context->load_query.fw_load;
1404 }
1405
1406 device_type_counter++;
1407 if (device_type_counter < number_of_device_types_present)
1408 {
1409 remove_device_from_saved(device_type,
1410 p_device_context->p_device_info->module_id,
1411 p_session_context->device_handle);
1412 ni_device_close(p_session_context->device_handle);
1413 ni_rsrc_free_device_context(p_device_context);
1414 }
1415 }
1416
1417 if (maximum_device_type == NI_DEVICE_TYPE_ENCODER)
1418 {
1419 continue;
1420 }
1421
1422 //Nvme and TP load
1423 {
1424 return_code =
1425 ni_query_nvme_status(p_session_context, &load_query);
1426 if (return_code == NI_RETCODE_SUCCESS)
1427 {
1428 if (*maximum_firmware_loads_per_quadra < load_query.fw_load)
1429 {
1430 *maximum_firmware_loads_per_quadra = load_query.fw_load;
1431 }
1432 if (*maximum_firmware_loads_per_quadra < load_query.tp_fw_load)
1433 {
1434 *maximum_firmware_loads_per_quadra = load_query.tp_fw_load;
1435 }
1436 strcat_dyn_buf(&output_buf, "%s: %u%%\n", block_name,
1437 *maximum_firmware_loads_per_quadra);
1438 }
1439 else
1440 {
1441 (void)fprintf(
1442 stderr, "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1443 return_code, device_name, p_device_context->p_device_info->dev_name,
1444 p_device_context->p_device_info->hw_id);
1445 remove_device_from_saved(device_type,
1446 p_device_context->p_device_info->module_id,
1447 p_session_context->device_handle);
1448 ni_device_close(p_session_context->device_handle);
1449 }
1450 }
1451
1452 ni_rsrc_free_device_context(p_device_context);
1453 }
1454
1455 if (output_buf.str_buf)
1456 printf("%s", output_buf.str_buf);
1457 clear_dyn_str_buf(&output_buf);
1458 free(maximum_firmware_loads);
1459}
1460
1461void 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)
1462{
1463 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1464 unsigned int i, index, device_count;
1465 int instance_count;
1466 int32_t *module_ids;
1467
1468 int detail = 1;
1469
1470 dyn_str_buf_t output_buf = {0};
1471 ni_device_context_t *p_device_context;
1472 ni_device_type_t device_type;
1473 int max_device_type = NI_DEVICE_TYPE_SCALER;
1474 int first_item_printed = 0;
1475 int first_device_type_printed = 0;
1476
1477 strcat_dyn_buf(&output_buf, "{\n");
1478
1479 for (device_type = NI_DEVICE_TYPE_DECODER;
1480 device_type != max_device_type;
1481 device_type++)
1482 {
1483 instance_count = 0;
1484 device_count = get_modules(device_type,
1485 p_device_queue,
1486 device_name,
1487 &module_ids);
1488 if (!device_count)
1489 {
1490 continue;
1491 }
1492
1493 if(first_device_type_printed)
1494 {
1495 strcat_dyn_buf(&output_buf, ",\n");
1496 }
1497 strcat_dyn_buf(&output_buf,
1498 "\t\"%s\" :"
1499 "[\n",
1500 device_name
1501 );
1502 first_item_printed = 0;
1503
1504 for (i = 0; i < device_count; i++)
1505 {
1506 p_device_context =
1507 ni_rsrc_get_device_context(device_type,
1508 module_ids[i]);
1509 if (!open_and_query(device_type,
1510 p_device_context,
1511 p_session_context,
1512 device_name, detail, detail_data_v1))
1513 {
1514 continue;
1515 }
1516
1517 for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
1518 {
1519 if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
1520 {
1521 if(first_item_printed)
1522 {
1523 strcat_dyn_buf(&output_buf, ",\n");
1524 }
1525
1526 if(device_type == NI_DEVICE_TYPE_DECODER)
1527 {
1528 strcat_dyn_buf(&output_buf,
1529 "\t\t{\n"
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"
1541 "\t\t}",
1542 device_count,
1543 instance_count++,
1544 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1545 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1546 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1547 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1548 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1549 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1550 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1551 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1552 p_device_context->p_device_info->dev_name);
1553 }
1554 else if (device_type == NI_DEVICE_TYPE_ENCODER)
1555 {
1556 strcat_dyn_buf(&output_buf,
1557 "\t\t{\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"
1573 "\t\t}",
1574 device_count,
1575 instance_count++,
1576 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1577 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1578 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1579 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
1580 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1581 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1582 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
1583 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
1584 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1585 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1586 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
1587 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1588 p_device_context->p_device_info->dev_name);
1589 }
1590 first_item_printed = 1;
1591 }
1592 }
1593 }
1594
1595 strcat_dyn_buf(&output_buf, "\n");
1596 strcat_dyn_buf(&output_buf,
1597 "\t]"
1598 );
1599 first_device_type_printed = 1;
1600 }
1601
1602 strcat_dyn_buf(&output_buf, "\n");
1603 strcat_dyn_buf(&output_buf, "}\n");
1604
1605 if(output_buf.str_buf)
1606 {
1607 printf("%s", output_buf.str_buf);
1608 }
1609
1610 clear_dyn_str_buf(&output_buf);
1611
1612}
1613
1615 ni_session_context_t *p_session_context,
1616 int detail,
1617 ni_instance_mgr_detail_status_v1_t *detail_data_v1)
1618{
1619 bool has_written_start = false;
1620 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1621 unsigned int index, device_count, card_count = 0;
1622 int32_t *module_ids = NULL;
1623 uint32_t total_contexts, vpu_load, model_load;
1624 dyn_str_buf_t output_buf = {0};
1626
1627 ni_device_context_t *p_device_context;
1628 ni_device_type_t device_type;
1629 ni_load_query_t load_query;
1630 ni_retcode_t return_code;
1631 const ni_rsrc_mon_card_cache_t *p_card = NULL;
1632
1633 int32_t *extra_temp_per_index = NULL;
1634 uint32_t *extra_power_per_index = NULL;
1635
1636 memset(card_cache, 0, sizeof(card_cache));
1637
1638 card_count = build_card_and_qos_cache(p_device_queue, p_session_context,
1639 detail, detail_data_v1,
1640 card_cache);
1641
1642
1643 for (device_type = NI_DEVICE_TYPE_DECODER;
1644 device_type != NI_DEVICE_TYPE_XCODER_MAX;
1645 device_type++)
1646 {
1647 device_count = get_modules(device_type, p_device_queue, device_name,
1648 &module_ids);
1649 if (!device_count)
1650 continue;
1651
1652UPLOADER:
1653 if (!has_written_start)
1654 {
1655 strcat_dyn_buf(&output_buf, "{\n \"%ss\": [\n", device_name);
1656 has_written_start = true;
1657 }
1658 else
1659 {
1660 strcat_dyn_buf(&output_buf, " ],\n \"%ss\": [\n", device_name);
1661 }
1662
1663 for (index = 0; index < device_count; index++)
1664 {
1665 p_device_context = ni_rsrc_get_device_context(device_type,
1666 module_ids[index]);
1667 if (!open_and_query(device_type, p_device_context, p_session_context,
1668 device_name, detail, detail_data_v1))
1669 continue;
1670
1671 if (device_type == NI_DEVICE_TYPE_UPLOAD) {
1672 total_contexts = p_session_context->load_query.active_hwuploaders;
1673 vpu_load = 0;
1674 model_load = 0;
1675 } else {
1676 total_contexts = p_session_context->load_query.total_contexts;
1677 vpu_load = p_session_context->load_query.current_load;
1678 model_load = p_session_context->load_query.fw_model_load;
1679 }
1680
1681 p_card = lookup_card_cache(card_cache, card_count,
1682 p_device_context->p_device_info->blk_name);
1683
1684 if (p_session_context->overall_load_query.admin_queried &&
1685 device_type != NI_DEVICE_TYPE_UPLOAD)
1686 {
1687 strcat_dyn_buf(&output_buf,
1688 "\t{\n"
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"
1703 ,
1704 device_count, p_device_context->p_device_info->module_id,
1705 vpu_load,
1706 p_session_context->overall_load_query.overall_current_load,
1707 model_load,
1708 p_session_context->overall_load_query.overall_fw_model_load,
1709 p_session_context->load_query.fw_load, total_contexts,
1710 p_session_context->overall_load_query.overall_instance_count,
1711 p_device_context->p_device_info->max_instance_cnt,
1712 p_session_context->load_query.fw_video_mem_usage,
1713 p_session_context->load_query.fw_video_shared_mem_usage,
1714 p_session_context->load_query.fw_share_mem_usage,
1715 p_session_context->load_query.fw_p2p_mem_usage
1716 );
1717 }
1718 else
1719 {
1720 strcat_dyn_buf(&output_buf,
1721 "\t{\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"
1733 ,
1734 device_count, p_device_context->p_device_info->module_id,
1735 vpu_load, model_load,
1736 p_session_context->load_query.fw_load, total_contexts,
1737 p_device_context->p_device_info->max_instance_cnt,
1738 p_session_context->load_query.fw_video_mem_usage,
1739 p_session_context->load_query.fw_video_shared_mem_usage,
1740 p_session_context->load_query.fw_share_mem_usage,
1741 p_session_context->load_query.fw_p2p_mem_usage
1742 );
1743 }
1744
1745 if (p_card && p_card->card_obj.str_buf)
1746 strcat_dyn_buf(&output_buf, "%s", p_card->card_obj.str_buf + 1);
1747
1748 if ((device_type == NI_DEVICE_TYPE_ENCODER ||
1749 device_type == NI_DEVICE_TYPE_DECODER) &&
1750 p_card && p_card->qos_suffix.str_buf)
1751 strcat_dyn_buf(&output_buf, "%s", p_card->qos_suffix.str_buf);
1752
1753 strcat_dyn_buf(&output_buf, "\n\t}");
1754 strcat_dyn_buf(&output_buf, (index < device_count - 1) ? ",\n" : "\n");
1755
1756 ni_rsrc_free_device_context(p_device_context);
1757 }
1758
1759 if (swap_encoder_and_uploader(&device_type, device_name))
1760 goto UPLOADER;
1761 free(module_ids);
1762 module_ids = NULL;
1763 }
1764
1765 if (ni_cmp_fw_api_ver((char *)&p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0)
1766 goto PRINT_OUTPUT_FINAL;
1767
1768 strcat_dyn_buf(&output_buf, " ],\n");
1769
1770 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
1771 {
1772 device_type = NI_DEVICE_TYPE_ENCODER;
1773 device_count = get_modules(device_type, p_device_queue, device_name,
1774 &module_ids);
1775 if (!device_count) {
1776 clear_card_cache(card_cache, card_count);
1777 if (output_buf.str_buf)
1778 printf("%s", output_buf.str_buf);
1779 clear_dyn_str_buf(&output_buf);
1780 return;
1781 }
1782
1783 if (icore == NP_LOAD)
1784 {
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));
1787 strcat_dyn_buf(&output_buf, " \"nvmes\": [\n");
1788 g_temp_load = (uint32_t *)calloc(device_count, sizeof(uint32_t));
1789 g_temp_pload = (uint32_t *)calloc(device_count, sizeof(uint32_t));
1790 g_temp_pthroughput = (uint32_t *)calloc(device_count, sizeof(uint32_t));
1791 g_temp_sharemem = (uint32_t *)calloc(device_count, sizeof(uint32_t));
1792 }
1793 else
1794 {
1795 strcat_dyn_buf(&output_buf,
1796 (icore == TP_LOAD) ? " \"tps\": [\n" : " \"pcies\": [\n");
1797 }
1798
1799 for (index = 0; index < device_count; index++)
1800 {
1801 p_device_context = ni_rsrc_get_device_context(device_type,
1802 module_ids[index]);
1803 if (!p_device_context)
1804 continue;
1805 if (icore == NP_LOAD)
1806 {
1807 if (!open_and_query(device_type, p_device_context, p_session_context,
1808 device_name, detail, detail_data_v1))
1809 continue;
1810 return_code = ni_query_nvme_status(p_session_context, &load_query);
1811 if (return_code != NI_RETCODE_SUCCESS)
1812 {
1813 remove_device_from_saved(device_type,
1814 p_device_context->p_device_info->module_id,
1815 p_session_context->device_handle);
1816 ni_device_close(p_session_context->device_handle);
1817 goto CLOSE_FINAL;
1818 }
1819 g_temp_load[index] = load_query.tp_fw_load;
1820 g_temp_pload[index] = load_query.pcie_load;
1821 g_temp_pthroughput[index] = load_query.pcie_throughput;
1822 g_temp_sharemem[index] = load_query.fw_share_mem_usage;
1823 }
1824
1825 p_card = lookup_card_cache(card_cache, card_count,
1826 p_device_context->p_device_info->blk_name);
1827
1828
1829 if (icore==PCIE_LOAD)
1830 {
1831 strcat_dyn_buf(&output_buf,
1832 "\t{\n"
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"
1840 "\t\t\"MEM\": 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"
1845 , device_count,
1846 p_device_context->p_device_info->module_id,
1847 g_temp_pload[index],
1848 (float)g_temp_pthroughput[index]/10
1849 );
1850 }
1851 else
1852 {
1853 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
1854 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
1855
1856 strcat_dyn_buf(&output_buf,
1857 "\t{\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"
1865 "\t\t\"MEM\": 0,\n"
1866 "\t\t\"CRITICAL_MEM\": 0,\n"
1867 "\t\t\"SHARE_MEM\": %u,\n"
1868 "\t\t\"P2P_MEM\": 0,\n"
1869 , device_count,
1870 p_device_context->p_device_info->module_id,
1871 load_query.fw_load,
1872 load_query.fw_share_mem_usage
1873 );
1874 }
1875
1876 if (p_card && p_card->card_obj.str_buf)
1877 strcat_dyn_buf(&output_buf, "%s", p_card->card_obj.str_buf + 1);
1878
1879 strcat_dyn_buf(&output_buf, "\n\t}");
1880 strcat_dyn_buf(&output_buf, (index < device_count - 1) ? ",\n" : "\n");
1881 if (index == device_count - 1 && icore != PCIE_LOAD)
1882 strcat_dyn_buf(&output_buf, " ],\n");
1883
1884CLOSE_FINAL:
1885 ni_rsrc_free_device_context(p_device_context);
1886 }
1887 free(module_ids);
1888 module_ids = NULL;
1889 }
1890
1891 free(g_temp_load);
1892 free(g_temp_pload);
1893 free(g_temp_pthroughput);
1894 free(g_temp_sharemem);
1895 free(extra_temp_per_index);
1896 free(extra_power_per_index);
1898
1899PRINT_OUTPUT_FINAL:
1900 strcat_dyn_buf(&output_buf, " ]\n}\n");
1901 clear_card_cache(card_cache, card_count);
1902 if (output_buf.str_buf)
1903 printf("%s", output_buf.str_buf);
1904 clear_dyn_str_buf(&output_buf);
1905}
1906
1907void print_json1(ni_device_queue_t *p_device_queue,
1908 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1, int format)
1909{
1910 bool has_written_start = false;
1911 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1912 unsigned int index, device_count;
1913 int32_t *module_ids;
1914 uint32_t total_contexts;
1915 uint32_t vpu_load;
1916 uint32_t model_load;
1917#ifdef __linux__
1918 char pcie[64] = {0};
1919 int numa_node;
1920#endif
1921 dyn_str_buf_t output_buf = {0};
1922 ni_device_extra_info_t p_dev_extra_info = {0};
1923 char power_consumption[16];
1924
1925 uint16_t namespace_id = 0;
1926 uint8_t qos_mode;
1927
1928 ni_device_context_t *p_device_context;
1929 ni_device_type_t device_type;
1930 ni_load_query_t load_query;
1931 ni_retcode_t return_code;
1932
1933 int32_t *extra_temp_per_index = NULL;
1934 uint32_t *extra_power_per_index = NULL;
1935
1936 for (device_type = NI_DEVICE_TYPE_DECODER;
1937 device_type != NI_DEVICE_TYPE_XCODER_MAX;
1938 device_type++)
1939 {
1940 device_count = get_modules(device_type,
1941 p_device_queue,
1942 device_name,
1943 &module_ids);
1944 if (!device_count)
1945 {
1946 continue;
1947 }
1948
1949UPLOADER:
1950 if (!has_written_start)
1951 {
1952 strcat_dyn_buf(&output_buf, "{\n \"%ss\": [\n", device_name);
1953 has_written_start = true;
1954 }
1955 else
1956 {
1957 strcat_dyn_buf(&output_buf, " ],\n \"%ss\": [\n", device_name);
1958 }
1959
1960 for (index = 0; index < device_count; index++)
1961 {
1962 p_device_context =
1963 ni_rsrc_get_device_context(device_type,
1964 module_ids[index]);
1965 if (!open_and_query(device_type,
1966 p_device_context,
1967 p_session_context,
1968 device_name, detail, detail_data_v1))
1969 {
1970 continue;
1971 }
1972
1973 if (device_type == NI_DEVICE_TYPE_UPLOAD)
1974 {
1975 total_contexts = p_session_context->load_query.active_hwuploaders;
1976 vpu_load = 0;
1977 model_load = 0;
1978 }
1979 else
1980 {
1981 total_contexts = p_session_context->load_query.total_contexts;
1982 vpu_load = p_session_context->load_query.current_load;
1983 model_load = p_session_context->load_query.fw_model_load;
1984 }
1985#ifdef __linux__
1986 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1987 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1988#endif
1989 if (format == 2)
1990 {
1991 if (ni_query_extra_info(p_session_context->device_handle,
1992 &p_dev_extra_info,
1993 p_device_context->p_device_info->fw_rev))
1994 {
1995 p_dev_extra_info.composite_temp = 0;
1996 }
1997 if (p_dev_extra_info.power_consumption + 1)
1998 {
1999 ni_sprintf(power_consumption, 16, "%umW", p_dev_extra_info.power_consumption);
2000 }
2001 }
2002 if (p_session_context->overall_load_query.admin_queried &&
2003 device_type != NI_DEVICE_TYPE_UPLOAD)
2004 {
2005 strcat_dyn_buf(&output_buf,
2006 "\t{\n"
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\""
2026#ifdef __linux__
2027 ",\n\t\t\"NUMA_NODE\": %d,\n"
2028 "\t\t\"PCIE_ADDR\": \"%s\""
2029#endif
2030 , device_count, p_device_context->p_device_info->module_id,
2031 vpu_load,
2032 p_session_context->overall_load_query.overall_current_load,
2033 model_load,
2034 p_session_context->overall_load_query.overall_fw_model_load,
2035 p_session_context->load_query.fw_load, total_contexts,
2036 p_session_context->overall_load_query.overall_instance_count,
2037 p_device_context->p_device_info->max_instance_cnt,
2038 p_session_context->load_query.fw_video_mem_usage,
2039 p_session_context->load_query.fw_video_shared_mem_usage,
2040 p_session_context->load_query.fw_share_mem_usage,
2041 p_session_context->load_query.fw_p2p_mem_usage,
2042 p_device_context->p_device_info->dev_name,
2043 p_device_context->p_device_info->fl_ver_last_ran,
2044 p_device_context->p_device_info->fl_ver_nor_flash,
2045 p_device_context->p_device_info->fw_rev,
2046 p_device_context->p_device_info->fw_rev_nor_flash
2047#ifdef __linux__
2048 , numa_node, pcie
2049#endif
2050 );
2051 } else
2052 {
2053 strcat_dyn_buf(&output_buf,
2054 "\t{\n"
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\""
2071#ifdef __linux__
2072 ",\n\t\t\"NUMA_NODE\": %d,\n"
2073 "\t\t\"PCIE_ADDR\": \"%s\""
2074#endif
2075 ,device_count, p_device_context->p_device_info->module_id,
2076 vpu_load,
2077 model_load,
2078 p_session_context->load_query.fw_load, total_contexts,
2079 p_device_context->p_device_info->max_instance_cnt,
2080 p_session_context->load_query.fw_video_mem_usage,
2081 p_session_context->load_query.fw_video_shared_mem_usage,
2082 p_session_context->load_query.fw_share_mem_usage,
2083 p_session_context->load_query.fw_p2p_mem_usage,
2084 p_device_context->p_device_info->dev_name,
2085 p_device_context->p_device_info->fl_ver_last_ran,
2086 p_device_context->p_device_info->fl_ver_nor_flash,
2087 p_device_context->p_device_info->fw_rev,
2088 p_device_context->p_device_info->fw_rev_nor_flash
2089#ifdef __linux__
2090 ,
2091 numa_node, pcie
2092#endif
2093 );
2094 }
2095 if (format == 2)
2096 {
2097 strcat_dyn_buf(&output_buf,
2098 ",\n\t\t\"TEMP\": %d,\n"
2099 "\t\t\"POWER\": \"%s\"",
2100 p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2101 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A");
2102 if ((device_type == NI_DEVICE_TYPE_ENCODER) || (device_type == NI_DEVICE_TYPE_DECODER))
2103 {
2104 ni_qos_header_info_log_page_t qos_header = {0};
2105 ni_qos_namespace_info_log_page_t qos_ns_info = {0};
2106 ni_device_vf_ns_id_t ns_vf_id = {0};
2107
2108 if (ni_query_vf_ns_id(p_session_context->device_handle, &ns_vf_id,
2109 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2110 {
2111 namespace_id = ns_vf_id.ns_id;
2112
2113 if (ni_query_qos_info(p_session_context->device_handle, &qos_header,
2114 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2115 {
2116 ni_query_qos_namespace_info(p_session_context->device_handle, &qos_ns_info,
2117 p_device_context->p_device_info->fw_rev);
2118
2119 qos_mode = (uint8_t)(qos_header.ui16QosState & 0xFF);
2120 float _opmax = (float)(qos_ns_info.ui32OPmaxUs * 100) / VIDEO_SLICE_TIME;
2121
2122 strcat_dyn_buf(&output_buf,
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",
2127 (uint8_t)(qos_header.ui16QosState & 0xFF),
2128 namespace_id,
2129 (qos_mode == 0 ? 0 : qos_ns_info.fAllowance),
2130 (qos_mode == 0 ? 0 :_opmax)
2131 );
2132 }
2133 }
2134 }
2135 strcat_dyn_buf(&output_buf, "\n\t}");
2136 }
2137 else
2138 {
2139 strcat_dyn_buf(&output_buf, "\n\t}");
2140 }
2141 if (index < device_count - 1)
2142 {
2143 strcat_dyn_buf(&output_buf, ",\n");
2144 }
2145 else
2146 {
2147 strcat_dyn_buf(&output_buf, "\n");
2148 }
2149
2150 ni_rsrc_free_device_context(p_device_context);
2151 }
2152
2153 if (swap_encoder_and_uploader(&device_type, device_name))
2154 {
2155 goto UPLOADER;
2156 }
2157
2158 free(module_ids);
2159 }
2160
2161 // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
2162 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
2163 goto PRINT_OUTPUT;
2164 }
2165 else
2166 {
2167 strcat_dyn_buf(&output_buf, " ],\n");
2168 }
2169
2170 //Nvme[0] and TP[1] load
2171 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
2172 {
2173 // ASSUMPTION: Each Quadra has at least and only one encoder.
2174 device_type = NI_DEVICE_TYPE_ENCODER;
2175 device_count = get_modules(device_type,
2176 p_device_queue,
2177 device_name,
2178 &module_ids);
2179
2180 if (!device_count)
2181 {
2182 if (output_buf.str_buf)
2183 printf("%s", output_buf.str_buf);
2184 clear_dyn_str_buf(&output_buf);
2185 return;
2186 }
2187 if (icore == NP_LOAD)
2188 {
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)
2192 {
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);
2196 }
2197 strcat_dyn_buf(&output_buf, " \"nvmes\": [\n");
2198 g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2199 if (!g_temp_load)
2200 {
2201 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
2202 return;
2203 }
2204 g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2205 if (!g_temp_pload)
2206 {
2207 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
2208 return;
2209 }
2210 g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2211 if (!g_temp_pthroughput)
2212 {
2213 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
2214 return;
2215 }
2216 g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2217 if (!g_temp_sharemem)
2218 {
2219 (void)fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
2220 return;
2221 }
2222 }
2223 else
2224 {
2225 (icore == TP_LOAD)?strcat_dyn_buf(&output_buf, " \"tps\": [\n"):strcat_dyn_buf(&output_buf, " \"pcies\": [\n");
2226 }
2227 for (index = 0; index < device_count; index++)
2228 {
2229 p_device_context = ni_rsrc_get_device_context(device_type,
2230 module_ids[index]);
2231 if (!p_device_context)
2232 continue;
2233 if (icore == NP_LOAD)
2234 {
2235 if (!open_and_query(device_type,
2236 p_device_context,
2237 p_session_context,
2238 device_name, detail, detail_data_v1))
2239 {
2240 continue;
2241 }
2242
2243 return_code =
2244 ni_query_nvme_status(p_session_context, &load_query);
2245 if (return_code != NI_RETCODE_SUCCESS)
2246 {
2247 (void)fprintf(stderr,
2248 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2249 return_code,
2250 device_name,
2251 p_device_context->p_device_info->dev_name,
2252 p_device_context->p_device_info->hw_id);
2253 remove_device_from_saved(device_type,
2254 p_device_context->p_device_info->module_id,
2255 p_session_context->device_handle);
2256 ni_device_close(p_session_context->device_handle);
2257 goto CLOSE;
2258 }
2259 g_temp_load[index] = load_query.tp_fw_load;
2260 g_temp_pload[index] = load_query.pcie_load;
2261 g_temp_pthroughput[index] = load_query.pcie_throughput;
2262 g_temp_sharemem[index] = load_query.fw_share_mem_usage;
2263 if (format == 2)
2264 {
2265 if (ni_query_extra_info(p_session_context->device_handle,
2266 &p_dev_extra_info,
2267 p_device_context->p_device_info->fw_rev))
2268 {
2269 p_dev_extra_info.composite_temp = 0;
2270 }
2271 extra_temp_per_index[index] = p_dev_extra_info.composite_temp;
2272 extra_power_per_index[index] = p_dev_extra_info.power_consumption;
2273 }
2274 }
2275#ifdef __linux__
2276 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
2277 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
2278#endif
2279
2280 if (icore==PCIE_LOAD)
2281 {
2282 strcat_dyn_buf(&output_buf,
2283 "\t{\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"
2291 "\t\t\"MEM\": 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\""
2301#ifdef __linux__
2302 ",\n\t\t\"NUMA_NODE\": %d,\n"
2303 "\t\t\"PCIE_ADDR\": \"%s\""
2304#endif
2305 , device_count, p_device_context->p_device_info->module_id,
2306 g_temp_pload[index], 0, (float)g_temp_pthroughput[index]/10,
2307 p_device_context->p_device_info->dev_name,
2308 p_device_context->p_device_info->fl_ver_last_ran,
2309 p_device_context->p_device_info->fl_ver_nor_flash,
2310 p_device_context->p_device_info->fw_rev,
2311 p_device_context->p_device_info->fw_rev_nor_flash
2312#ifdef __linux__
2313 , numa_node, pcie
2314#endif
2315 );
2316 }
2317 else
2318 {
2319 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
2320 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
2321
2322 strcat_dyn_buf(&output_buf,
2323 "\t{\n"
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"
2331 "\t\t\"MEM\": 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\""
2340#ifdef __linux__
2341 ",\n\t\t\"NUMA_NODE\": %d,\n"
2342 "\t\t\"PCIE_ADDR\": \"%s\""
2343#endif
2344 , device_count, p_device_context->p_device_info->module_id,
2345 load_query.fw_load, load_query.fw_share_mem_usage,
2346 p_device_context->p_device_info->dev_name,
2347 p_device_context->p_device_info->fl_ver_last_ran,
2348 p_device_context->p_device_info->fl_ver_nor_flash,
2349 p_device_context->p_device_info->fw_rev,
2350 p_device_context->p_device_info->fw_rev_nor_flash
2351#ifdef __linux__
2352 , numa_node, pcie
2353#endif
2354 );
2355 }
2356 if (format == 2)
2357 {
2358 if (p_dev_extra_info.power_consumption + 1)
2359 {
2360 ni_sprintf(power_consumption, 16, "%umW", extra_power_per_index[index]);
2361 }
2362 strcat_dyn_buf(&output_buf,
2363 ",\n\t\t\"TEMP\": %d,\n"
2364 "\t\t\"POWER\": \"%s\"\n"
2365 "\t}",
2366 extra_temp_per_index[index] + ABSOLUTE_TEMP_ZERO,
2367 (extra_power_per_index[index] + 1) ? power_consumption : "N/A");
2368 }
2369 else
2370 {
2371 strcat_dyn_buf(&output_buf, "\n\t}");
2372 }
2373 if (index < device_count - 1)
2374 {
2375 strcat_dyn_buf(&output_buf, ",\n");
2376 }
2377 else
2378 {
2379 strcat_dyn_buf(&output_buf, "\n");
2380 if (icore != PCIE_LOAD)
2381 {
2382 strcat_dyn_buf(&output_buf, " ],\n");
2383 }
2384 }
2385
2386CLOSE:
2387 ni_rsrc_free_device_context(p_device_context);
2388 }
2389 }
2390
2391 free(g_temp_load);
2392 free(g_temp_pload);
2393 free(g_temp_pthroughput);
2394 free(g_temp_sharemem);
2395 free(module_ids);
2396
2397PRINT_OUTPUT:
2398 strcat_dyn_buf(&output_buf, " ]\n}\n");
2399 if (output_buf.str_buf)
2400 printf("%s", output_buf.str_buf);
2401 clear_dyn_str_buf(&output_buf);
2402}
2403
2405 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)
2406{
2407 int index, instance_count; // used in later FOR-loop when compiled without c99
2408 unsigned int i;
2409 unsigned int module_count;
2410 char module_name[MAX_DEVICE_NAME_SIZE] = {0};
2411 int32_t *module_id_arr = NULL;
2412 dyn_str_buf_t output_buf = {0};
2413 ni_device_context_t *p_device_context = NULL;
2414 ni_device_type_t module_type;
2415 int max_device_type = NI_DEVICE_TYPE_XCODER_MAX;
2416 char _ml[16];
2417
2418 if(detail)
2419 max_device_type = NI_DEVICE_TYPE_SCALER;
2420 for (module_type = NI_DEVICE_TYPE_DECODER;
2421 module_type != max_device_type;
2422 module_type++)
2423 {
2424 instance_count = 0;
2425 module_count = get_modules(module_type,
2426 coders,
2427 module_name,
2428 &module_id_arr);
2429
2430 if (!module_count)
2431 {
2432 continue;
2433 }
2434
2435 strcat_dyn_buf(&output_buf, "Num %ss: %u\n", module_name, module_count);
2436 if(detail)
2437 {
2438 if(module_type == NI_DEVICE_TYPE_DECODER)
2439 {
2440 if(checkInterval)
2441 {
2442 strcat_dyn_buf(&output_buf,
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");
2446 }
2447 else
2448 {
2449 strcat_dyn_buf(&output_buf,
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");
2453 }
2454 }
2455 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2456 {
2457 if(checkInterval)
2458 {
2459 strcat_dyn_buf(&output_buf,
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");
2463 }
2464 else
2465 {
2466 strcat_dyn_buf(&output_buf,
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");
2470 }
2471 }
2472 }
2473 else
2474 strcat_dyn_buf(&output_buf,
2475 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n", "INDEX",
2476 "LOAD", "MODEL_LOAD", "INST", "MEM", "SHARE_MEM", "P2P_MEM",
2477 "DEVICE");
2478
2480 for (i = 0; i < module_count; i++)
2481 {
2482 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[i]);
2483
2485 if (open_and_query(module_type,
2486 p_device_context,
2487 sessionCtxt,
2488 module_name, detail, detail_data_v1))
2489 {
2490 if(detail)
2491 {
2492 for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
2493 {
2494 if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
2495 {
2496 if(previous_detail_data_p && checkInterval)
2497 {
2498 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2499 {
2500 if(module_type == NI_DEVICE_TYPE_DECODER)
2501 {
2502 strcat_dyn_buf(&output_buf,
2503 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2504 instance_count++,
2505 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2506 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2507 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2508 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2509 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2510 (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2511 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2512 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2513 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2514 p_device_context->p_device_info->dev_name,
2515 p_device_context->p_device_info->blk_name);
2516 }
2517 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2518 {
2519 strcat_dyn_buf(&output_buf,
2520 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2521 instance_count++,
2522 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2523 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2524 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2525 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2526 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2527 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2528 (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2529 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2530 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2531 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2532 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2533 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2534 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2535 p_device_context->p_device_info->dev_name,
2536 p_device_context->p_device_info->blk_name);
2537 }
2538 }
2539 }
2540 else
2541 {
2542 if(module_type == NI_DEVICE_TYPE_DECODER)
2543 {
2544 strcat_dyn_buf(&output_buf,
2545 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2546 instance_count++,
2547 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2548 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2549 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2550 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2551 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2552 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2553 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2554 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2555 p_device_context->p_device_info->dev_name,
2556 p_device_context->p_device_info->blk_name);
2557 }
2558 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2559 {
2560 strcat_dyn_buf(&output_buf,
2561 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2562 instance_count++,
2563 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2564 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2565 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2566 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2567 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2568 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2569 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2570 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2571 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2572 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2573 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2574 get_session_id(p_device_context, (int)detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2575 p_device_context->p_device_info->dev_name,
2576 p_device_context->p_device_info->blk_name);
2577 }
2578 }
2579 }
2580 }
2581 if(previous_detail_data_p)
2582 {
2583 memcpy(&previous_detail_data_p[module_type][i], detail_data_v1, sizeof(ni_instance_mgr_detail_status_v1_t));
2584 }
2585 }
2586 else
2587 {
2588 /* PF prints overall statistics; VFs print their own per-NS statistics. */
2589 uint32_t disp_load = sessionCtxt->load_query.current_load;
2590 uint32_t disp_total_ctx = sessionCtxt->load_query.total_contexts;
2591 uint32_t disp_model_load = sessionCtxt->load_query.fw_model_load;
2592 if (sessionCtxt->overall_load_query.admin_queried &&
2593 module_type != NI_DEVICE_TYPE_UPLOAD)
2594 {
2595 disp_load = sessionCtxt->overall_load_query.overall_current_load;
2596 disp_total_ctx = sessionCtxt->overall_load_query.overall_instance_count;
2597 disp_model_load = sessionCtxt->overall_load_query.overall_fw_model_load;
2598 }
2599
2600 if((module_type == NI_DEVICE_TYPE_DECODER) || (module_type == NI_DEVICE_TYPE_ENCODER))
2601 {
2602 strcat_dyn_buf(&output_buf,
2603 "%-5d %-4u %-10s %-4u %-4u %-9u %-7u %-14s\n",
2604 p_device_context->p_device_info->module_id,
2605#ifdef XCODER_311
2606 disp_load,
2607#else
2608 (disp_total_ctx == 0 || disp_load > sessionCtxt->load_query.fw_load) ? disp_load : sessionCtxt->load_query.fw_load,
2609#endif
2610 (disp_model_load == 4294967295U) ? "N/A" : ((void)snprintf(_ml, sizeof(_ml), "%u", disp_model_load), _ml),
2611 disp_total_ctx,
2612 sessionCtxt->load_query.fw_video_mem_usage,
2613 sessionCtxt->load_query.fw_share_mem_usage,
2614 sessionCtxt->load_query.fw_p2p_mem_usage,
2615 p_device_context->p_device_info->dev_name);
2616 }
2617 else
2618 {
2619 strcat_dyn_buf(&output_buf,
2620 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2621 p_device_context->p_device_info->module_id,
2622#ifdef XCODER_311
2623 disp_load,
2624#else
2625 (disp_total_ctx == 0 || disp_load > sessionCtxt->load_query.fw_load) ? disp_load : sessionCtxt->load_query.fw_load,
2626#endif
2627 disp_model_load,
2628 disp_total_ctx,
2629 sessionCtxt->load_query.fw_video_mem_usage,
2630 sessionCtxt->load_query.fw_share_mem_usage,
2631 sessionCtxt->load_query.fw_p2p_mem_usage,
2632 p_device_context->p_device_info->dev_name);
2633 }
2634 }
2635
2636 ni_rsrc_free_device_context(p_device_context);
2637 }
2638 }
2639 free(module_id_arr);
2640 }
2641
2642 if (output_buf.str_buf)
2643 printf("%s", output_buf.str_buf);
2644 clear_dyn_str_buf(&output_buf);
2645}
2646
2647void print_extra(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int internal_call, int show_qos_info)
2648{
2649 char device_name[MAX_DEVICE_NAME_SIZE];
2650 unsigned int index, device_count;
2651 int32_t *module_ids;
2652 dyn_str_buf_t output_buf = {0};
2653 ni_device_context_t *p_device_context;
2654 ni_device_type_t device_type;
2655 ni_device_extra_info_t p_dev_extra_info = {0};
2656 char power_consumption[16];
2657 int instance_count = 0;
2658#ifdef __linux__
2659 unsigned int gen3_mismatch_index[NI_MAX_DEVICE_CNT];
2660 unsigned int num_gen3_mismatch = 0;
2661#endif
2662
2663 ni_qos_header_info_log_page_t qos_header = {0};
2664 ni_qos_namespace_info_log_page_t qos_ns_info = {0};
2665 ni_device_vf_ns_id_t ns_vf_id = {0};
2666 bool has_qos_data = false;
2667 char qos_str[64] = {0};
2668 uint16_t namespace_id = 0;
2669
2670 // ASSUMPTION: Each Quadra has at least and only one encoder.
2671 device_type = NI_DEVICE_TYPE_ENCODER;
2672 device_count = get_modules(device_type,
2673 p_device_queue,
2674 device_name,
2675 &module_ids);
2676
2677 if (!device_count)
2678 {
2679 if (output_buf.str_buf)
2680 printf("%s", output_buf.str_buf);
2681 clear_dyn_str_buf(&output_buf);
2682 return;
2683 }
2684
2685 for (index = 0; index < device_count; index++)
2686 {
2687 p_device_context = ni_rsrc_get_device_context(device_type, module_ids[index]);
2688 if (!p_device_context)
2689 {
2690 continue;
2691 }
2692 // check if device has been opened already
2693 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
2694 int module_id = p_device_context->p_device_info->module_id;
2695 if (device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2696 {
2697 p_session_context->device_handle =
2698 device_handles[xcoder_device_type][module_id];
2699 } else
2700 {
2701 p_session_context->device_handle =
2702 ni_device_open2(p_device_context->p_device_info->dev_name,
2704 if (p_session_context->device_handle != NI_INVALID_DEVICE_HANDLE)
2705 {
2706 device_handles[xcoder_device_type][module_id] =
2707 p_session_context->device_handle;
2708 }
2709 }
2710
2711 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
2712 {
2713 char errmsg[NI_ERRNO_LEN] = {0};
2715 (void)fprintf(stderr,
2716 "ERROR: ni_device_open2() failed for %s: %s\n",
2717 p_device_context->p_device_info->dev_name,
2718 errmsg);
2719 ni_rsrc_free_device_context(p_device_context);
2720 continue;
2721 }
2722
2723 if (ni_query_extra_info(p_session_context->device_handle,
2724 &p_dev_extra_info,
2725 p_device_context->p_device_info->fw_rev))
2726 {
2727 p_dev_extra_info.composite_temp = 0;
2728 p_dev_extra_info.fw_flavour = '-';
2729 }
2730
2731 if (p_dev_extra_info.power_consumption + 1)
2732 {
2733 ni_sprintf(power_consumption, 16, "%umW", p_dev_extra_info.power_consumption);
2734 }
2735
2736 if (show_qos_info)
2737 {
2738 if (ni_query_vf_ns_id(p_session_context->device_handle, &ns_vf_id,
2739 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2740 {
2741 namespace_id = ns_vf_id.ns_id;
2742 }
2743
2744 if (ni_query_qos_info(p_session_context->device_handle, &qos_header,
2745 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2746 {
2747 has_qos_data = true;
2748 ni_query_qos_namespace_info(p_session_context->device_handle, &qos_ns_info,
2749 p_device_context->p_device_info->fw_rev);
2750 }
2751 }
2752
2753 if (show_qos_info && has_qos_data)
2754 {
2755 char _allowance[16];
2756 uint8_t qos_mode = (uint8_t)(qos_header.ui16QosState & 0xFF);
2757 float _opmax = (float) (qos_ns_info.ui32OPmaxUs * 100) / VIDEO_SLICE_TIME;
2758 (void)snprintf(qos_str, sizeof(qos_str), " %-9u %-7u %-10s %-8.1f",
2759 (uint8_t)(qos_header.ui16QosState & 0xFF),
2760 namespace_id,
2761 (qos_mode == 0) ? "N/A" : ((void)snprintf(_allowance, sizeof(_allowance), "%.1f", qos_ns_info.fAllowance), _allowance),
2762 (qos_mode == 0 ? 0 :_opmax));
2763 }
2764
2765 if (!internal_call)
2766 {
2767 strcat_dyn_buf(&output_buf,
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" : "");
2770 strcat_dyn_buf(&output_buf,
2771 "%-4d %-8s %-8c %-14s %s\n",
2772 p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2773 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2774 p_dev_extra_info.fw_flavour,
2775 p_device_context->p_device_info->dev_name,
2776 (show_qos_info && has_qos_data) ? qos_str:"");
2777 }
2778 else
2779 {
2780 if (instance_count == 0)
2781 {
2782 strcat_dyn_buf(&output_buf,
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" : "");
2785 }
2786 strcat_dyn_buf(&output_buf,
2787 "%-8d %-8d %-8s %-8c %-8.8s %-8.*s %s\n",
2788 instance_count++ , p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2789 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2790 p_dev_extra_info.fw_flavour,
2791 p_device_context->p_device_info->fw_rev,
2792 (int)sizeof(p_device_context->p_device_info->serial_number), p_device_context->p_device_info->serial_number,
2793 (show_qos_info && has_qos_data) ? qos_str:"");
2794
2795 }
2796
2797 //Temperature overshoot detection
2798 ni_device_capability_t device_capability_t = {0};
2799 int32_t temp_deg = p_dev_extra_info.composite_temp - 273;
2800 if (ni_device_capability_query2(p_session_context->device_handle, &device_capability_t, false) != NI_RETCODE_SUCCESS)
2801 {
2802 char errmsg[NI_ERRNO_LEN] = {0};
2804 (void)fprintf(stderr,
2805 "ERROR: ni_device_capability_query() failed for %s: %s\n",
2806 p_device_context->p_device_info->dev_name,
2807 errmsg);
2808 ni_rsrc_free_device_context(p_device_context);
2809 continue;
2810
2811 }
2812 if (p_dev_extra_info.composite_temp >= device_capability_t.critical_temp)
2813 {
2814 ni_log(NI_LOG_ERROR, "ERROR: CRITICAL TEMP HIT %ddegC on SN %s\n",temp_deg, device_capability_t.serial_number);
2815#if __linux__
2816 syslog(LOG_WARNING, "ERROR: CRITICAL TEMP %ddegC HIT on SN %s!!!\n",temp_deg,device_capability_t.serial_number);
2817#endif
2818 }
2819 else if (p_dev_extra_info.composite_temp >= device_capability_t.warning_temp)
2820 {
2821 ni_log(NI_LOG_ERROR, "ERROR: WARNING TEMP HIT %ddegC on SN %s\n",temp_deg, device_capability_t.serial_number);
2822#if __linux__
2823 syslog(LOG_WARNING, "ERROR: WARNING TEMP %ddegC HIT on SN %s!!!\n",temp_deg, device_capability_t.serial_number);
2824#endif
2825 }
2826
2827 //Pcie gen mismatch detection
2828#ifdef __linux__
2829 if (p_device_context->p_device_info->pcie_gen3_on_gen4_host == 1)
2830 {
2831 gen3_mismatch_index[num_gen3_mismatch++] = index;
2832 }
2833#endif
2834
2835 ni_rsrc_free_device_context(p_device_context);
2836 }
2837
2838#ifdef __linux__
2839 if (num_gen3_mismatch > 0)
2840 {
2841 char index_list[128] = {0};
2842 size_t len = 0;
2843 for (unsigned int i = 0; i < num_gen3_mismatch && len < sizeof(index_list) - 4; i++)
2844 {
2845 len += snprintf(index_list + len, sizeof(index_list) - len,
2846 "%s%u", (i > 0) ? ", " : "", gen3_mismatch_index[i]);
2847 }
2848 strcat_dyn_buf(&output_buf,
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",
2854 index_list);
2855 }
2856#endif
2857
2858 if (output_buf.str_buf)
2859 printf("%s", output_buf.str_buf);
2860 clear_dyn_str_buf(&output_buf);
2861 free(module_ids);
2862}
2863
2864int main(int argc, char *argv[])
2865{
2866 (void)setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2867 int checkInterval;
2868 int skip_init_rsrc = 0;
2869 int should_match_rev = 1;
2870 int detail = 0;
2871 ni_instance_mgr_detail_status_v1_t detail_data_v1 = {0};
2872 ni_instance_mgr_detail_status_v1_t (*previous_detail_data)[NI_DEVICE_TYPE_XCODER_MAX] = NULL;
2873 ni_device_pool_t *p_device_pool = NULL;
2874 ni_device_queue_t *coders = NULL;
2875 ni_session_context_t *p_xCtxt = NULL;
2876 time_t startTime = {0}, now = {0};
2877 int timeout_seconds = 0;
2878 struct tm *ltime = NULL;
2879 char buf[64] = {0};
2880 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2881 int opt;
2882 ni_log_level_t log_level = NI_LOG_INFO;
2883 enum outFormat printFormat = FMT_TEXT;
2884 checkInterval = 0;
2885 bool fw_log_dump = false;
2886 bool core_reset_log_dump = false;
2887 int devid = -1;
2888 int refresh_device_pool = 1;
2889 bool is_first_query = true;
2890 int ret = 0;
2891 int show_qos_info = 0;
2892 char *nor_command = NULL;
2893#if defined(__linux__)
2894 /* Per-device selection (-s / -b / --domain) — apply to --nor */
2895 const char *target_slot = NULL; /* -s <bus_hex> */
2896 const char *target_domain = NULL; /* --domain <hex> */
2897 const char *target_blkdev = NULL; /* -b <nvme_dev> */
2898#endif
2899
2900#ifdef _WIN32
2901 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2902#elif __linux__
2903 setup_signal_handler();
2904#endif
2905
2906 /* Long-option table - mirrors quadraprobe.py flags where possible.
2907 * Short flags -s, -b are free in ni_rsrc_mon and match quadraprobe.
2908 * --domain maps quadraprobe's -d (conflicts with our detail flag).
2909 * -N / --nor: short -N is preferred; --nor kept as an alias because
2910 * quadraprobe's short form -n collides with our interval flag. */
2911 static struct option long_opts[] = {
2912 {"domain", required_argument, NULL, 0},
2913 {"nor", required_argument, NULL, 'N'},
2914 {NULL, 0, NULL, 0}
2915 };
2916 int long_idx = 0;
2917 // arg handling
2918 // NOLINTNEXTLINE(concurrency-mt-unsafe) - single-threaded CLI tool
2919 while ((opt = getopt_long(argc, argv,
2920#if defined(__linux__)
2921 "n:o:D:C:k:R:rt:Sl:hvdqs:b:N:",
2922#else
2923 "n:o:D:C:k:R:rt:Sl:hvdqN:",
2924#endif
2925 long_opts, &long_idx)) != -1)
2926 {
2927 switch (opt)
2928 {
2929 case 0: /* long option without a short equivalent */
2930#if defined(__linux__)
2931 if (strcmp(long_opts[long_idx].name, "domain") == 0)
2932 target_domain = optarg;
2933#endif
2934 break;
2935 case 'N':
2936 nor_command = optarg;
2937 break;
2938 case 'o':
2939 // Output print format
2940 if (!strcmp(optarg, "json"))
2941 {
2942 printFormat = FMT_JSON;
2943 }
2944 else if (!strcmp(optarg, "simple"))
2945 {
2946 printFormat = FMT_SIMPLE_TEXT;
2947 }
2948 else if (!strcmp(optarg, "text"))
2949 {
2950 printFormat = FMT_TEXT;
2951 }
2952 else if (!strcmp(optarg, "full"))
2953 {
2954 printFormat = FMT_FULL_TEXT;
2955 }
2956 else if (!strcmp(optarg, "json1"))
2957 {
2958 printFormat = FMT_JSON1;
2959 }
2960 else if (!strcmp(optarg, "json2"))
2961 {
2962 printFormat = FMT_JSON2;
2963 }
2964 else if (!strcmp(optarg, "extra"))
2965 {
2966 printFormat = FMT_EXTRA;
2967 }
2968 else
2969 {
2970 (void)fprintf(stderr, "Error: unknown selection for outputFormat: %s\n", optarg);
2971 return 1;
2972 }
2973 break;
2974 case 'n':
2975 {
2976 int32_t tmp_val;
2977 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
2978 {
2979 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
2980 return 1;
2981 }
2982 checkInterval = (int)tmp_val;
2983 break;
2984 }
2985 case 'D':
2986 {
2987 int32_t tmp_val;
2988 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
2989 {
2990 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
2991 return 1;
2992 }
2993 fw_log_dump = tmp_val;
2994 break;
2995 }
2996 case 'C':
2997 {
2998 int32_t tmp_val;
2999 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
3000 {
3001 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
3002 return 1;
3003 }
3004 core_reset_log_dump = tmp_val;
3005 if (core_reset_log_dump)
3006 fw_log_dump = true;
3007 break;
3008 }
3009 case 'k':
3010 {
3011 int32_t tmp_val;
3012 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
3013 {
3014 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
3015 return 1;
3016 }
3017 devid = (int)tmp_val;
3018 break;
3019 }
3020 case 'R':
3021 {
3022 int32_t tmp_val;
3023 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
3024 {
3025 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
3026 return 1;
3027 }
3028 refresh_device_pool = (int)tmp_val;
3029 }
3030 case 'r':
3031 should_match_rev = 0;
3032 break;
3033 case 't':
3034 {
3035 int32_t tmp_val;
3036 if (ni_strtoi(optarg, &tmp_val) != NI_RETCODE_SUCCESS)
3037 {
3038 ni_log(NI_LOG_ERROR, "ERROR: %s invalid value for -%c: %s\n", __func__, opt, optarg);
3039 return 1;
3040 }
3041 timeout_seconds = (int)tmp_val;
3042 printf("Timeout will be set %d\n", timeout_seconds);
3043 break;
3044 }
3045 case 'S':
3046 skip_init_rsrc = 1;
3047 break;
3048 case 'l':
3049 log_level = arg_to_ni_log_level(optarg);
3050 if (log_level != NI_LOG_INVALID)
3051 {
3052 ni_log_set_level(log_level);
3053 } else {
3054 (void)fprintf(stderr, "FATAL: invalid log level selected: %s\n", optarg);
3055 return 1;
3056 }
3057 break;
3058 case 'q':
3059 show_qos_info = 1;
3060 break;
3061 case 'h':
3062 // help message (limit to 80 characters wide)
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"
3066 "\n"
3067 "Usage: ni_rsrc_mon [OPTIONS]\n"
3068 "\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"
3072 " Default: 0\n"
3073 "-R Specify if refresh devices on host in each monitor interval.\n"
3074 " If 0, only refresh devices at the start.\n"
3075 " Default: 1\n"
3076 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
3077 " Default: text\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"
3086 " Default: 0\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"
3091 " Default: info\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"
3100 "\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"
3108 "\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"
3116 "\n"
3117 "Examples:\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"
3123 "\n"
3124 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
3125 "Quadra device.\n"
3126 "\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"
3143 "\n"
3144 "Additional reporting columns for full output format\n"
3145 "VPU same as LOAD in JSON outputs\n"
3146 "FW system load\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"
3160 "\n"
3161 "Additional reporting columns for full JSON formats\n"
3162 "LOAD VPU load\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"
3171 "\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"
3185 "SID session id\n"
3186 "DEVICE path to NVMe device file handle\n"
3187 "NAMESPACE path to NVMe namespace file handle\n"
3188 "\n"
3189 "Extra output shows TEMP and POWER and FLAVOR of the Quadra device \n",
3191 return 0;
3192 case 'v':
3193 printf("Release ver: %s\n"
3194 "API ver: %s\n"
3195 "Date: %s\n"
3196 "ID: %s\n",
3199 return 0;
3200 /* ---- New flags (mirrors quadraprobe.py) ---- */
3201#if defined(__linux__)
3202 case 's':
3203 target_slot = optarg;
3204 break;
3205 case 'b':
3206 target_blkdev = optarg;
3207 break;
3208#endif
3209 /* ---- Existing flags ---- */
3210 case '?':
3211 if (isprint(opt))
3212 {
3213 (void)fprintf(stderr, "FATAL: unknown option '-%c'\n", opt);
3214 } else
3215 {
3216 (void)fprintf(stderr, "FATAL: unknown option character '\\x%x'\n", opt);
3217 }
3218 return 1;
3219 case 'd':
3220 detail = 1;
3221 break;
3222 case ':':
3223 (void)fprintf(stderr, "FATAL: option '-%c' lacks arg\n", opt);
3224 return 1;
3225 default:
3226 (void)fprintf(stderr, "FATAL: unhandled option\n");
3227 return 1;
3228 }
3229 }
3230
3231#if defined(__linux__)
3232 /* -s and -b are mutually exclusive */
3233 if (target_slot && target_blkdev)
3234 {
3235 (void)fprintf(stderr, "FATAL: -s and -b are mutually exclusive; "
3236 "specify a PCIe slot or a block device name, not both.\n");
3237 return 1;
3238 }
3239#endif
3240
3241 if ((argc <= 2) && (optind == 1))
3242 {
3243 for (; optind < argc; optind++)
3244 {
3245 checkInterval = argToI(argv[optind]);
3246 }
3247 }
3248
3249#ifdef _ANDROID
3250 ni_log_set_log_tag(LOG_TAG);
3251#endif
3252
3254 if(!p_xCtxt)
3255 {
3256 (void)fprintf(stderr, "FATAL: cannot allocate momory for ni_session_context_t\n");
3257 return 1;
3258 }
3259
3260 ni_log_set_level(NI_LOG_ERROR); // silence informational prints
3261 if (!skip_init_rsrc)
3262 {
3263 ret = ni_rsrc_init(should_match_rev, timeout_seconds);
3264 }
3265 if (!skip_init_rsrc && ret != 0)
3266 {
3268 ni_rsrc_refresh(should_match_rev);
3269 (void)fprintf(stderr, "FATAL: NI resource unavailable\n");
3270#if defined(__linux__)
3271 if (fw_log_dump)
3272 {
3273 (void)fprintf(stderr, "Proceeding to dump firmware logs as root\n");
3274 if (geteuid() != 0)
3275 {
3276 (void)fprintf(stderr, "This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3277 exit(1); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
3278 }
3279 int rc = ni_rsrc_log_dump(".", core_reset_log_dump);
3280 if (rc == 0)
3281 (void)fprintf(stderr, "Firmware log dump: all devices successful.\n");
3282 else if (rc == 1)
3283 (void)fprintf(stderr, "Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3284 else if (rc == 2)
3285 (void)fprintf(stderr, "Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3286 else
3287 (void)fprintf(stderr, "Firmware log dump: Unexpected error, return code %d\n", rc);
3288 }
3289#endif
3290 ret = 0;
3291#if defined(__linux__)
3292 if (nor_command)
3293 {
3294 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3295 target_blkdev);
3296 }
3297#endif
3298 } else
3299 {
3300 ret = 1;
3301 (void)fprintf(stderr, "FATAL: cannot access NI resource\n");
3302 }
3303 LRETURN;
3304 }
3305 ni_log_set_level(log_level);
3306
3307 p_device_pool = ni_rsrc_get_device_pool();
3308 if (!p_device_pool)
3309 {
3310 (void)fprintf(stderr, "FATAL: cannot get devices info\n");
3311 ret = 1;
3312 LRETURN;
3313 }
3314
3315 if (log_level >= NI_LOG_INFO)
3316 {
3317 printf("**************************************************\n");
3318 }
3319
3320 // initialise device handles
3321 for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
3322 {
3323 for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
3324 {
3325 device_handles[i][j] = NI_INVALID_DEVICE_HANDLE;
3326 }
3327 }
3328
3329 startTime = time(NULL);
3330 if(checkInterval)
3331 {
3332 int allocate_size = (int)((size_t)NI_MAX_DEVICE_CNT * NI_DEVICE_TYPE_XCODER_MAX * sizeof(ni_instance_mgr_detail_status_v1_t));
3333 previous_detail_data = (ni_instance_mgr_detail_status_v1_t (*)[NI_DEVICE_TYPE_XCODER_MAX])malloc(allocate_size);
3334 if(previous_detail_data == NULL)
3335 {
3336 (void)fprintf(stderr, "FATAL: Allocate buffer fail\n");
3337 ret = 1;
3338 LRETURN;
3339 }
3340 memset((void *)previous_detail_data, 0, allocate_size);
3341 }
3342 while (!g_xcoder_stop_process)
3343 {
3344 now = time(NULL);
3345 struct tm temp_time;
3346 ltime = ni_localtime(&temp_time, &now);
3347 if (ltime)
3348 {
3349 (void)strftime(buf, sizeof(buf), "%c", ltime);
3350 }
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;
3354
3355
3356 if (is_first_query || refresh_device_pool)
3357 {
3358 ni_rsrc_refresh(should_match_rev);
3359 }
3360
3361 if (log_level >= NI_LOG_INFO)
3362 {
3363 printf("%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
3365 }
3366
3369#ifdef _WIN32
3370 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
3371 {
3372 (void)fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
3373 ret = 1;
3374 LRETURN;
3375 }
3376#elif __linux__
3377 if ( lockf(p_device_pool->lock, F_LOCK, 0) )
3378 {
3379 perror("ERROR: cannot lock p_device_pool");
3380 }
3381#endif
3382
3383 coders = p_device_pool->p_device_queue;
3384
3385#ifdef _WIN32
3386 ReleaseMutex((HANDLE)p_device_pool->lock);
3387#elif __linux__
3388 if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
3389 {
3390 perror("ERROR: cannot unlock p_device_pool");
3391 }
3392#endif
3393
3394 switch (printFormat)
3395 {
3396 case FMT_TEXT:
3397 print_extra(coders, p_xCtxt, 1, show_qos_info);
3398 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
3399 break;
3400 case FMT_FULL_TEXT:
3401 show_qos_info=1;
3402 print_extra(coders, p_xCtxt, 1, show_qos_info);
3403 print_full_text(coders, p_xCtxt, 0, &detail_data_v1);
3404 break;
3405 case FMT_SIMPLE_TEXT:
3406 print_simple_text(coders, p_xCtxt, 0, &detail_data_v1);
3407 break;
3408 case FMT_JSON:
3409 if(!detail)
3410 {
3411 print_json_final(coders, p_xCtxt, 0, &detail_data_v1);
3412 }
3413 else
3414 {
3415 print_json_detail(coders, p_xCtxt, &detail_data_v1);
3416 }
3417 break;
3418 case FMT_JSON1:
3419 if(!detail)
3420 {
3421 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
3422 }
3423 else
3424 {
3425 print_json_detail(coders, p_xCtxt, &detail_data_v1);
3426 }
3427 break;
3428 case FMT_JSON2:
3429 if(!detail)
3430 {
3431 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
3432 }
3433 else
3434 {
3435 print_json_detail(coders, p_xCtxt, &detail_data_v1);
3436 }
3437 break;
3438 case FMT_EXTRA:
3439 print_extra(coders, p_xCtxt, 0, show_qos_info);
3440 break;
3441 }
3442
3443 is_first_query = false;
3444
3445 if (log_level >= NI_LOG_INFO)
3446 {
3447 printf("**************************************************\n");
3448 }
3449
3450 (void)fflush(stdout);
3451
3452 if (checkInterval == 0)
3453 {
3454 // run once
3455 break;
3456 }
3457 ni_usleep((int64_t)checkInterval * 1000 * 1000);
3458 }
3459
3460 if (fw_log_dump)
3461 {
3462 // dump fw log
3463#ifdef _WIN32
3464 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
3465 {
3466 (void)fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
3467 ret = 1;
3468 LRETURN;
3469 }
3470#elif __linux__
3471 if ( lockf(p_device_pool->lock, F_LOCK, 0) )
3472 {
3473 perror("ERROR: cannot lock p_device_pool");
3474 }
3475#endif
3476 coders = p_device_pool->p_device_queue;
3477#ifdef _WIN32
3478 ReleaseMutex((HANDLE)p_device_pool->lock);
3479#elif __linux__
3480 if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
3481 {
3482 perror("ERROR: cannot unlock p_device_pool");
3483 }
3484#endif
3485#if defined(__linux__)
3486 if (core_reset_log_dump)
3487 {
3488 (void)fprintf(stderr, "Proceeding to dump firmware logs as root\n");
3489 if (geteuid() != 0)
3490 {
3491 (void)fprintf(stderr, "This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3492 exit(1); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
3493 }
3494 int rc = ni_rsrc_log_dump(".", core_reset_log_dump);
3495 if (rc == 0)
3496 (void)fprintf(stderr, "Firmware log dump: all devices successful.\n");
3497 else if (rc == 1)
3498 (void)fprintf(stderr, "Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3499 else if (rc == 2)
3500 (void)fprintf(stderr, "Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3501 else
3502 (void)fprintf(stderr, "Firmware log dump: Unexpected error, return code %d\n", rc);
3503 }
3504 else
3505#endif
3506 {
3507 dump_fw_log(coders, p_xCtxt, devid);
3508 }
3509 }
3510
3511#if defined(__linux__)
3512 if (nor_command)
3513 {
3514 /* NOR flash commands; -s / -b / --domain target a single device. */
3515 ret = run_bar4_operations(nor_command, target_domain, target_slot,
3516 target_blkdev);
3517 }
3518#endif
3519
3520 // close all opened devices
3521 for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
3522 {
3523 for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
3524 {
3525 if (device_handles[i][j] != NI_INVALID_DEVICE_HANDLE)
3526 {
3528 }
3529 }
3530 }
3531
3532#ifdef __OPENHARMONY__
3533 (void)system("chmod -R 777 /dev/shm/"); // NOLINT(cert-env33-c,concurrency-mt-unsafe) - init-time only, no user input
3534#ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
3535 (void)system("chmod 777 /dev/block/vd* 2>/dev/null"); // NOLINT(cert-env33-c,concurrency-mt-unsafe) - init-time only, no user input
3536#endif
3537#elif defined(_ANDROID)
3538 (void)system("chmod -R 777 /dev/shm/"); // NOLINT(cert-env33-c,concurrency-mt-unsafe) - init-time only, no user input
3539 (void)system("chmod 777 /dev/block/nvme* 2>/dev/null"); // NOLINT(cert-env33-c,concurrency-mt-unsafe) - init-time only, no user input
3540 (void)system("chmod 777 /dev/nvme* 2>/dev/null"); // NOLINT(cert-env33-c,concurrency-mt-unsafe) - init-time only, no user input
3541 property_set("ni_rsrc_init_completed", "yes");
3542#endif
3543
3544END:
3545 if(checkInterval && previous_detail_data)
3546 {
3547 free(previous_detail_data);
3548 }
3550 ni_rsrc_free_device_pool(p_device_pool);
3551 free(p_xCtxt);
3552 return ret;
3553}
#define LOG_TAG
int main()
Definition client.cpp:51
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition ni_defs.h:99
#define NI_MAX_DEVICE_CNT
Definition ni_defs.h:235
#define END
Definition ni_defs.h:338
#define NI_XCODER_REVISION
Definition ni_defs.h:98
#define LIBXCODER_API_VERSION
Definition ni_defs.h:115
#define NI_MAX_DEVICE_NAME_LEN
Definition ni_defs.h:236
#define NI_MAX_CONTEXTS_PER_HW_INSTANCE
Definition ni_defs.h:248
ni_device_type_t
Definition ni_defs.h:356
@ NI_DEVICE_TYPE_SCALER
Definition ni_defs.h:362
@ NI_DEVICE_TYPE_AI
Definition ni_defs.h:363
@ NI_DEVICE_TYPE_DECODER
Definition ni_defs.h:360
@ NI_DEVICE_TYPE_UPLOAD
Definition ni_defs.h:367
@ NI_DEVICE_TYPE_ENCODER
Definition ni_defs.h:361
@ NI_DEVICE_TYPE_XCODER_MAX
Definition ni_defs.h:364
#define NI_ERRNO
Definition ni_defs.h:229
#define GET_XCODER_DEVICE_TYPE(t)
Definition ni_defs.h:434
#define LRETURN
Definition ni_defs.h:337
ni_retcode_t
Definition ni_defs.h:447
@ NI_RETCODE_SUCCESS
Definition ni_defs.h:448
@ NI_RETCODE_ERROR_RESOURCE_UNAVAILABLE
Definition ni_defs.h:455
#define IS_XCODER_DEVICE_TYPE(t)
Definition ni_defs.h:431
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.
@ NI_DEVICE_READ_ONLY
struct _ni_instance_mgr_detail_status_v1 ni_instance_mgr_detail_status_v1_t
int optind
Definition ni_getopt.c:34
char * optarg
Definition ni_getopt.c:33
int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
Definition ni_getopt.c:99
Implementation of getopt() and getopt_long() for Windows environment.
#define required_argument
Definition ni_getopt.h:86
ni_log_level_t arg_to_ni_log_level(const char *arg_str)
Convert terminal arg string to ni_log_level_t.
Definition ni_log.c:262
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition ni_log.c:202
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Definition ni_log.c:183
#define NI_ERRNO_LEN
Definition ni_log.h:51
ni_log_level_t
Definition ni_log.h:58
@ NI_LOG_ERROR
Definition ni_log.h:62
@ NI_LOG_INFO
Definition ni_log.h:63
@ NI_LOG_INVALID
Definition ni_log.h:59
Quadraprobe definitions.
#define NI_SW_RELEASE_ID
#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....
outFormat
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
uint32_t * g_temp_load
Definition ni_rsrc_mon.c:59
char * get_pixel_format(ni_device_context_t *p_device_context, int index)
uint32_t * g_temp_pthroughput
Definition ni_rsrc_mon.c:61
#define DYN_STR_BUF_CHUNK_SIZE
#define NP_LOAD
Definition ni_rsrc_mon.c:51
uint32_t * g_temp_sharemem
Definition ni_rsrc_mon.c:62
#define MAX_DEVICE_NAME_SIZE
Definition ni_rsrc_mon.c:49
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
uint32_t * g_temp_pload
Definition ni_rsrc_mon.c:60
#define TP_LOAD
Definition ni_rsrc_mon.c:52
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)
#define VIDEO_SLICE_TIME
Definition ni_rsrc_mon.c:57
@ FMT_JSON2
@ FMT_JSON
@ FMT_SIMPLE_TEXT
@ FMT_FULL_TEXT
@ FMT_EXTRA
@ FMT_JSON1
@ FMT_TEXT
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]
Definition ni_rsrc_mon.c:65
ni_rsrc_mon_card_error_t
Definition ni_rsrc_mon.c:67
@ NI_RSRC_MON_ERR_CRITICAL_TEMP
Definition ni_rsrc_mon.c:70
@ NI_RSRC_MON_ERR_WARN_TEMP
Definition ni_rsrc_mon.c:69
@ NI_RSRC_MON_ERR_PCIE_MISMATCH
Definition ni_rsrc_mon.c:71
@ NI_RSRC_MON_ERR_NONE
Definition ni_rsrc_mon.c:68
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)
#define PCIE_LOAD
Definition ni_rsrc_mon.c:53
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
Definition ni_rsrc_mon.c:50
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)
Definition ni_util.c:525
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition ni_util.c:663
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition ni_util.c:460
void ni_usleep(int64_t usec)
Definition ni_util.c:366
struct tm * ni_localtime(struct tm *dest, const time_t *src)
Definition ni_util.c:1018
int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args)
Definition ni_util.c:1054
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
Definition ni_util.c:1077
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...
Definition ni_util.c:2577
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...
Definition ni_util.c:4383
Utility definitions.
device capability type
ni_device_info_t * p_device_info
uint8_t serial_number[20]
char dev_name[NI_MAX_DEVICE_NAME_LEN]
uint8_t fw_rev[8]
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
Definition ni_rsrc_api.h:99
ni_lock_handle_t lock
Definition ni_rsrc_api.h:98
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
Definition ni_rsrc_api.h:70
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
Definition ni_rsrc_api.h:69
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_model_load
uint32_t fw_p2p_mem_usage
uint32_t fw_video_shared_mem_usage
uint32_t pcie_throughput
uint32_t current_load
uint32_t total_contexts
uint32_t active_hwuploaders
uint32_t fw_video_mem_usage
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
char * str_buf
const char * name
Definition ni_getopt.h:75