libxcoder 5.7.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#endif
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37
38#include <errno.h>
39#include <time.h>
40#include <ctype.h>
41#include <string.h>
42#include "ni_device_api.h"
43#include "ni_rsrc_api.h"
44#include "ni_rsrc_priv.h"
45#include "ni_util.h"
46#include "ni_quadraprobe.h"
47
48#define MAX_DEVICE_NAME_SIZE (9)
49#define ABSOLUTE_TEMP_ZERO (-273)
50#define NP_LOAD (0)
51#define TP_LOAD (1)
52#define PCIE_LOAD (2)
53
54#define VIDEO_PROCESSING_SLICES 4
55#define THROTTLE_REF_WIN_US (1 << (10 + 7)) // 131072us or 0x20000 us, period between qos credit refresh
56#define VIDEO_SLICE_TIME (THROTTLE_REF_WIN_US * VIDEO_PROCESSING_SLICES)
57
58uint32_t* g_temp_load = NULL; //TP load storage
59uint32_t* g_temp_pload = NULL; //Pcie load storage
60uint32_t* g_temp_pthroughput = NULL; //Pcie throughput storage
61uint32_t* g_temp_sharemem = NULL; //TP sharedmem storage
62
65
66#ifdef _ANDROID
67
68#include <cutils/properties.h>
69#define PROP_DECODER_TYPE "nidec_service_init"
70#define LOG_TAG "ni_rsrc_mon"
71#endif
72
83
84#ifdef _WIN32
85#include "ni_getopt.h"
86
87static BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
88{
90 return TRUE;
111}
112
113#elif __linux__
114/*!******************************************************************************
115 * \brief
116 *
117 * \param
118 *
119 * \return
120 *******************************************************************************/
121void sig_handler(int sig)
122{
123 if (sig == SIGTERM || sig == SIGINT || sig == SIGHUP)
124 {
126 }
127}
128
129/*!******************************************************************************
130 * \brief
131 *
132 * \param
133 *
134 * \return
135 *******************************************************************************/
136void setup_signal_handler(void)
137{
138 if (signal(SIGTERM, sig_handler) == SIG_ERR ||
139 signal(SIGHUP, sig_handler) == SIG_ERR ||
140 signal(SIGINT, sig_handler) == SIG_ERR)
141 {
142 perror("ERROR: signal handler setup");
143 }
144}
145
146/*!******************************************************************************
147 * \brief get PCIe address
148 *
149 * \param[in] char *device_name e.g. /dev/nvme0n1
150 *
151 * \return void
152 * *******************************************************************************/
153void get_pcie_addr(char *device_name, char *pcie)
154{
155 get_dev_pcie_addr(device_name, pcie, NULL, NULL, NULL, NULL);
156}
157
158/*!******************************************************************************
159 * \brief get linux numa_node
160 *
161 * \param[in] char *device_name
162 *
163 * \return int atoi(cmd_ret)
164 *******************************************************************************/
165int get_numa_node(char *device_name)
166{
167 return ni_rsrc_get_numa_node(device_name);
168}
169
170#endif //__linux__
171
172/*!******************************************************************************
173 * \brief remove one device from stored device_handles
174 *
175 * \param ni_device_type_t device_type
176 *
177 * \param int32_t module_id
178 *
179 * \param ni_device_handle_t device_handle
180 *
181 * \return int 0 for success, -1 for failure
182 *******************************************************************************/
183int remove_device_from_saved(ni_device_type_t device_type, int32_t module_id,
184 ni_device_handle_t device_handle)
185{
186 if (!IS_XCODER_DEVICE_TYPE(device_type))
187 {
188 fprintf(stderr, "Error: device_type %d is not a valid device type\n",
189 device_type);
190 return -1;
191 }
192 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
193 if (device_handles[xcoder_device_type][module_id] == device_handle)
194 {
195 device_handles[xcoder_device_type][module_id] =
196 NI_INVALID_DEVICE_HANDLE;
197 return 0;
198 } else
199 {
200 fprintf(stderr,
201 "Error: device_handle to remove %" PRId64
202 "not match device_handles[%d][%d]=%" PRId64 "\n",
203 (int64_t)device_handle, device_type, module_id,
204 (int64_t)device_handles[xcoder_device_type][module_id]);
205 return -1;
206 }
207}
208
209/*!******************************************************************************
210 * \brief convert number from argv input to integer if safe
211 *
212 * \param char *numArray
213 *
214 * \return int atoi(numArray)
215 *******************************************************************************/
216int argToI(char *numArray)
217{
218 int i;
219
220 if( !numArray )
221 {
222 return 0;
223 }
224
225 const size_t len = strlen(numArray);
226
227 for (i = 0; i < len; i++)
228 {
229 if (!isdigit(numArray[i]))
230 {
231 fprintf(stderr, "invalid, ABORTING\n");
232 abort();
233 }
234 }
235
236 return len == i ? atoi(numArray) : 0;
237}
238
239/*!******************************************************************************
240 * \brief compare two int32_t for qsort
241 *
242 * \param[in] const void *a
243 * \param[in] const void *b
244 *
245 * \return int atoi(numArray)
246 *******************************************************************************/
247int compareInt32_t(const void *a, const void *b)
248{
249 if ( *(int32_t*)a < *(int32_t*)b ) return -1;
250 if ( *(int32_t*)a > *(int32_t*)b ) return 1;
251 return 0;
252}
253
254char *get_pixel_format(ni_device_context_t *p_device_context, int index)
255{
257 "6s3") < 0)
258 {
259 return "UNSUPPORT";
260 }
261 else if ((index >= 0 && index < 4) || (index >= 10 && index < 13))
262 {
263 return "YUV";
264 }
265 else if (index >= 4 && index < 10)
266 {
267 return "RGB";
268 }
269 else if (index >= 13 && index < 15)
270 {
271 return "TILE";
272 }
273 else{
274 return "INVALID";
275 }
276}
277
278static char sid[5] = "0000";
279char *get_session_id(ni_device_context_t *p_device_context, int id)
280{
282 "6s3") < 0)
283 {
284 snprintf(sid, sizeof(sid), "%04x", 0);
285 return sid;
286 }
287 else
288 {
289 snprintf(sid, sizeof(sid), "%04x", id);
290 return sid;
291 }
292}
293
294unsigned int get_modules(ni_device_type_t device_type,
295 ni_device_queue_t *p_device_queue,
296 char *device_name,
297 int32_t **module_ids)
298{
299 unsigned int device_count;
300 size_t size_of_i32;
301
302 size_of_i32 = sizeof(int32_t);
303
304 device_count = p_device_queue->xcoder_cnt[device_type];
305 *module_ids = malloc(size_of_i32 * device_count);
306 if (!(*module_ids))
307 {
308 fprintf(stderr, "ERROR: malloc() failed for module_ids\n");
309 return 0;
310 }
311
312 memcpy(*module_ids,
313 p_device_queue->xcoders[device_type],
314 size_of_i32 * device_count);
315
316 qsort(*module_ids,
317 device_count,
318 size_of_i32,
320
321 ni_strncpy(device_name, MAX_DEVICE_NAME_SIZE,
322 g_device_type_str[device_type],
324
325 return device_count;
326}
327
329 ni_device_context_t *p_device_context,
330 ni_session_context_t *p_session_context,
331 char *device_name, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
332{
333 ni_retcode_t return_code;
334
335 if (!p_device_context)
336 {
337 return false;
338 }
339
340 // check if device has been opened already
341 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
342 int module_id = p_device_context->p_device_info->module_id;
343 if (device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
344 {
345 p_session_context->device_handle =
346 device_handles[xcoder_device_type][module_id];
347 } else
348 {
349 p_session_context->device_handle =
350 ni_device_open2(p_device_context->p_device_info->dev_name,
352 if (p_session_context->device_handle != NI_INVALID_DEVICE_HANDLE)
353 {
354 device_handles[xcoder_device_type][module_id] =
355 p_session_context->device_handle;
356 }
357 }
358
359 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
360 {
361 char errmsg[NI_ERRNO_LEN] = {0};
363 fprintf(stderr,
364 "ERROR: ni_device_open2() failed for %s: %s\n",
365 p_device_context->p_device_info->dev_name,
366 errmsg);
367 ni_rsrc_free_device_context(p_device_context);
368 return false;
369 }
370
371 p_session_context->blk_io_handle =
372 p_session_context->device_handle;
373 p_session_context->hw_id =
374 p_device_context->p_device_info->hw_id;
375
376 if(detail)
377 {
379 "6i") < 0)
380 {
381 fprintf(stderr,
382 "ERROR: cannot print detailed info for %s as it has FW API "
383 "version < 6.i\n", p_device_context->p_device_info->dev_name);
384 return false;
385 }
386 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)
387 {
388 return_code = ni_device_session_query_detail(p_session_context,
389 GET_XCODER_DEVICE_TYPE(device_type), (ni_instance_mgr_detail_status_t *)detail_data_v1);
390 }
391 else
392 {
393 return_code = ni_device_session_query_detail_v1(p_session_context,
394 GET_XCODER_DEVICE_TYPE(device_type), detail_data_v1);
395 }
396 }
397 else
398 {
399 return_code = ni_device_session_query(p_session_context,
400 GET_XCODER_DEVICE_TYPE(device_type));
401 }
402 if (return_code != NI_RETCODE_SUCCESS)
403 {
404 fprintf(stderr,
405 "ERROR: ni_device_session_query() returned %d for %s:%s:%d\n",
406 return_code,
407 device_name,
408 p_device_context->p_device_info->dev_name,
409 p_device_context->p_device_info->hw_id);
410 remove_device_from_saved(device_type, module_id,
411 p_session_context->device_handle);
412 ni_device_close(p_session_context->device_handle);
413 ni_rsrc_free_device_context(p_device_context);
414 return false;
415 }
416
417 if (!p_session_context->load_query.total_contexts)
418 {
419 p_session_context->load_query.current_load = 0;
420 }
421
422 memcpy(p_session_context->fw_rev,
423 p_device_context->p_device_info->fw_rev,
424 8);
425
426 return true;
427}
428
430 ni_session_context_t *p_session_context,
431 void** p_log_buffer,
432 bool gen_log_file)
433{
434 ni_retcode_t return_code;
435 if (!p_device_context)
436 return false;
437
438 p_session_context->device_handle =
439 ni_device_open2(p_device_context->p_device_info->blk_name,
441 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
442 {
443 char errmsg[NI_ERRNO_LEN] = {0};
445 fprintf(stderr,
446 "ERROR: ni_device_open2() failed for %s: %s\n",
447 p_device_context->p_device_info->blk_name,
448 errmsg);
449 ni_rsrc_free_device_context(p_device_context);
450 return false;
451 }
452 p_session_context->blk_io_handle =
453 p_session_context->device_handle;
454 p_session_context->hw_id =
455 p_device_context->p_device_info->module_id;
456
457 return_code = ni_device_alloc_and_get_firmware_logs(p_session_context, p_log_buffer, gen_log_file);
458 return return_code ? false : true;
459}
460
461void dump_fw_log(ni_device_queue_t *coders, ni_session_context_t *sessionCtxt, int devid)
462{
463 uint32_t i;
464 unsigned int module_count;
465 int32_t *module_id_arr = NULL;
466 char module_name[MAX_DEVICE_NAME_SIZE];
467 ni_device_context_t *p_device_context = NULL;
469
470 module_count = get_modules(module_type, coders, module_name, &module_id_arr);
471 if (!module_count) {
472 printf("Error: module not found!\n");
473 return;
474 }
475
476 bool gen_log_file = true; // dump and write fw logs to runtime dir
477
478 void* p_log_buffer = NULL;
479 if (devid >= 0 && (uint32_t)devid < module_count)
480 {
481 // dump fw logs of specified card
482 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[devid]);
483 if (p_device_context->p_device_info->module_id == devid)
484 {
485 if (!open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
486 printf("Error: failed to dump fw log of card:%d blk_name:%s\n",
487 devid, p_device_context->p_device_info->blk_name);
488 } else {
489 printf("Success: dumped fw log of card:%d blk_name:%s\n",
490 devid, p_device_context->p_device_info->blk_name);
491 }
492 ni_device_close(sessionCtxt->device_handle);
493 ni_rsrc_free_device_context(p_device_context);
494 }
495 }
496 else
497 {
498 // dump fw logs of all quadra cards
499 for (i = 0; i < module_count; i++)
500 {
501 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[i]);
502 if (!open_and_get_log(p_device_context, sessionCtxt, &p_log_buffer, gen_log_file)) {
503 printf("Error: failed to dump fw log of card:%d blk_name:%s\n",
504 p_device_context->p_device_info->module_id,
505 p_device_context->p_device_info->blk_name);
506 } else {
507 printf("Success: dumped fw log of card:%d blk_name:%s\n",
508 p_device_context->p_device_info->module_id,
509 p_device_context->p_device_info->blk_name);
510 }
511 ni_device_close(sessionCtxt->device_handle);
512 ni_rsrc_free_device_context(p_device_context);
513 }
514 }
515
516 free(module_id_arr);
517}
518
520 char *device_name)
521{
522 switch (*p_device_type)
523 {
525 *p_device_type = NI_DEVICE_TYPE_UPLOAD;
526 ni_strcpy(device_name, MAX_DEVICE_NAME_SIZE, "uploader");
527 return true;
529 *p_device_type = NI_DEVICE_TYPE_ENCODER;
530 default:
531 return false;
532 }
533}
534
535#define DYN_STR_BUF_CHUNK_SIZE 4096
536typedef struct dyn_str_buf
537{
538 int str_len; // Note: this does not include EOL char
539 int buf_size;
540 char *str_buf; // Pointer to string
542
543/*!*****************************************************************************
544 * \brief Accumulate string data in a dynamically sized buffer. This is
545 * useful to separate error messages from json and table output.
546 *
547 * \param[in] *dyn_str_buf pointer to structure holding dyn_str_buf info
548 * \param[in] *fmt printf format specifier
549 * \param[in] ... additional arguments
550 *
551 * \return 0 for success, -1 for error
552 ******************************************************************************/
553int strcat_dyn_buf(dyn_str_buf_t *dyn_str_buf, const char *fmt, ...)
554{
555 int avail_buf;
556 int formatted_len;
557 int add_buf_size = 0;
558 char *tmp_char_ptr = NULL;
559
560 if (!dyn_str_buf)
561 {
562 fprintf(stderr, "ERROR: invalid param *dyn_str_buf\n");
563 return -1;
564 }
565
566 if (!fmt)
567 {
568 return 0;
569 }
570
571 va_list vl, tmp_vl;
572 va_start(vl, fmt);
573 va_copy(tmp_vl, vl);
574
575 // determine length of string to add
576 formatted_len = vsnprintf(NULL, 0, fmt, tmp_vl);
577 va_end(tmp_vl);
578
579 // check if str_buf needs to be expanded in increments of chunk size
580 avail_buf = dyn_str_buf->buf_size - dyn_str_buf->str_len;
581 add_buf_size = (formatted_len + 1) > avail_buf ?
582 ((formatted_len + 1 - avail_buf + DYN_STR_BUF_CHUNK_SIZE - 1) /
585 0;
586
587 // realloc() to expand str_buf if necessary
588 if (add_buf_size)
589 {
590 tmp_char_ptr = (char *)realloc(dyn_str_buf->str_buf,
591 sizeof(char) * dyn_str_buf->buf_size +
592 add_buf_size);
593 if (!tmp_char_ptr)
594 {
595 fprintf(stderr, "ERROR: strcat_dyn_buf() failed realloc()\n");
596 va_end(vl);
597 return -1;
598 }
599 dyn_str_buf->str_buf = tmp_char_ptr;
600 dyn_str_buf->buf_size += add_buf_size;
601 avail_buf = dyn_str_buf->buf_size - dyn_str_buf->str_len;
602 }
603
604 // concatenate string to buffer
605 ni_vsprintf(dyn_str_buf->str_buf + dyn_str_buf->str_len, avail_buf, fmt, vl);
606 dyn_str_buf->str_len += formatted_len;
607
608 va_end(vl);
609 return 0;
610}
611
613{
614 free(dyn_str_buf->str_buf);
615 memset(dyn_str_buf, 0, sizeof(dyn_str_buf_t));
616}
617
619 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
620{
621 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
622 unsigned int index, device_count;
623 int32_t *module_ids;
624 dyn_str_buf_t output_buf = {0};
625
626 ni_device_context_t *p_device_context;
627 ni_device_type_t device_type;
628 ni_load_query_t load_query;
629 ni_retcode_t return_code;
630 char _ml[16];
631
632 for (device_type = NI_DEVICE_TYPE_DECODER;
633 device_type != NI_DEVICE_TYPE_XCODER_MAX;
634 device_type++)
635 {
636 device_count = get_modules(device_type,
637 p_device_queue,
638 device_name,
639 &module_ids);
640 if (!device_count)
641 {
642 continue;
643 }
644UPLOADER:
645 strcat_dyn_buf(&output_buf, "Num %ss: %u\n", device_name, device_count);
646
647 switch (device_type)
648 {
650 strcat_dyn_buf(&output_buf,
651 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE ) "
652 "DEVICE L_FL2V N_FL2V FR N_FR\n");
653 break;
656 strcat_dyn_buf(&output_buf,
657 "INDEX LOAD(VPU FW ) INST MEM(TOTAL SHARE ) "
658 "DEVICE L_FL2V N_FL2V FR N_FR\n");
659 break;
661 strcat_dyn_buf(&output_buf,
662 "INDEX LOAD(VPU MODEL FW ) INST MEM(TOTAL CRITICAL SHARE P2P) "
663 "DEVICE L_FL2V N_FL2V FR N_FR\n");
664 break;
666 strcat_dyn_buf(&output_buf,
667 "INDEX LOAD( FW ) INST MEM(TOTAL SHARE P2P) "
668 "DEVICE L_FL2V N_FL2V FR N_FR\n");
669 break;
670 default:
671 break;
672 }
673
674 for (index = 0; index < device_count; index++)
675 {
676 p_device_context =
677 ni_rsrc_get_device_context(device_type,
678 module_ids[index]);
679 if (!open_and_query(device_type,
680 p_device_context,
681 p_session_context,
682 device_name, detail, detail_data_v1))
683 {
684 continue;
685 }
686
687 switch (device_type)
688 {
690 strcat_dyn_buf(&output_buf,
691 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
692 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
693 p_device_context->p_device_info->module_id,
694 p_session_context->load_query.current_load,
695 (p_session_context->load_query.fw_model_load == 4294967295U) ? "N/A" : (snprintf(_ml, sizeof(_ml), "%u", p_session_context->load_query.fw_model_load), _ml),
696 p_session_context->load_query.fw_load,
697 p_session_context->load_query.total_contexts,
698 p_device_context->p_device_info->max_instance_cnt,
699 p_session_context->load_query.fw_video_mem_usage,
700 p_session_context->load_query.fw_video_shared_mem_usage,
701 p_session_context->load_query.fw_share_mem_usage,
702 p_device_context->p_device_info->dev_name,
703 p_device_context->p_device_info->fl_ver_last_ran,
704 p_device_context->p_device_info->fl_ver_nor_flash,
705 p_device_context->p_device_info->fw_rev,
706 p_device_context->p_device_info->fw_rev_nor_flash);
707 break;
710 strcat_dyn_buf(&output_buf,
711 "%-5d %-3u %-3u %-3u/%-3d %-3u "
712 "%-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
713 p_device_context->p_device_info->module_id,
714 p_session_context->load_query.current_load,
715 p_session_context->load_query.fw_load,
716 p_session_context->load_query.total_contexts,
717 p_device_context->p_device_info->max_instance_cnt,
718 p_session_context->load_query.fw_video_mem_usage,
719 p_session_context->load_query.fw_share_mem_usage,
720 p_device_context->p_device_info->dev_name,
721 p_device_context->p_device_info->fl_ver_last_ran,
722 p_device_context->p_device_info->fl_ver_nor_flash,
723 p_device_context->p_device_info->fw_rev,
724 p_device_context->p_device_info->fw_rev_nor_flash);
725 break;
727 strcat_dyn_buf(&output_buf,
728 "%-5d %-3u %-3s %-3u %-3u/%-3d %-3u %-3u "
729 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
730 p_device_context->p_device_info->module_id,
731 p_session_context->load_query.current_load,
732 (p_session_context->load_query.fw_model_load == 4294967295U) ? "N/A" : (snprintf(_ml, sizeof(_ml), "%u", p_session_context->load_query.fw_model_load), _ml),
733 p_session_context->load_query.fw_load,
734 p_session_context->load_query.total_contexts,
735 p_device_context->p_device_info->max_instance_cnt,
736 p_session_context->load_query.fw_video_mem_usage,
737 p_session_context->load_query.fw_video_shared_mem_usage,
738 p_session_context->load_query.fw_share_mem_usage,
739 p_session_context->load_query.fw_p2p_mem_usage,
740 p_device_context->p_device_info->dev_name,
741 p_device_context->p_device_info->fl_ver_last_ran,
742 p_device_context->p_device_info->fl_ver_nor_flash,
743 p_device_context->p_device_info->fw_rev,
744 p_device_context->p_device_info->fw_rev_nor_flash);
745 break;
747 strcat_dyn_buf(&output_buf,
748 "%-5d %-3u %-3u/%-3d %-3u "
749 "%-3u %-3u %-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
750 p_device_context->p_device_info->module_id,
751 p_session_context->load_query.fw_load,
752 p_session_context->load_query.active_hwuploaders,
753 p_device_context->p_device_info->max_instance_cnt,
754 p_session_context->load_query.fw_video_mem_usage,
755 p_session_context->load_query.fw_share_mem_usage,
756 p_session_context->load_query.fw_p2p_mem_usage,
757 p_device_context->p_device_info->dev_name,
758 p_device_context->p_device_info->fl_ver_last_ran,
759 p_device_context->p_device_info->fl_ver_nor_flash,
760 p_device_context->p_device_info->fw_rev,
761 p_device_context->p_device_info->fw_rev_nor_flash);
762 break;
763 default:
764 break;
765 }
766
767 ni_rsrc_free_device_context(p_device_context);
768 }
769
770 if (swap_encoder_and_uploader(&device_type, device_name))
771 {
772 goto UPLOADER;
773 }
774
775 free(module_ids);
776 }
777
778 // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
779 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
780 goto PRINT_OUTPUT;
781 }
782
783 //Nvme[0] and TP[1] and Pcie[2] load
784 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
785 {
786 // ASSUMPTION: Each Quadra has at least and only one encoder.
787 device_type = NI_DEVICE_TYPE_ENCODER;
788 device_count = get_modules(device_type,
789 p_device_queue,
790 device_name,
791 &module_ids);
792
793 if (icore == NP_LOAD)
794 {
795 strcat_dyn_buf(&output_buf, "Num Nvmes: ");
796 g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
797 if (!g_temp_load)
798 {
799 fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
800 return;
801 }
802 g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
803 if (!g_temp_pload)
804 {
805 fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
806 return;
807 }
808 g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
810 {
811 fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
812 return;
813 }
814 g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
815 if (!g_temp_sharemem)
816 {
817 fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
818 return;
819 }
820 }
821 else
822 {
823 (icore == TP_LOAD)?strcat_dyn_buf(&output_buf, "Num TPs: "):strcat_dyn_buf(&output_buf, "Num PCIes: ");
824 }
825
826 strcat_dyn_buf(&output_buf, "%u\n", device_count);
827 if (icore == PCIE_LOAD)
828 {
829 strcat_dyn_buf(&output_buf,
830 "INDEX LOAD( FW ) PCIE_Card2Host_Gbps "
831 "DEVICE L_FL2V N_FL2V FR N_FR\n");
832 }
833 else
834 {
835 strcat_dyn_buf(&output_buf,
836 "INDEX LOAD( FW ) MEM( SHARE ) "
837 "DEVICE L_FL2V N_FL2V FR N_FR\n");
838 }
839 if (!device_count)
840 {
841 if (output_buf.str_buf)
842 printf("%s", output_buf.str_buf);
843 clear_dyn_str_buf(&output_buf);
844 free(g_temp_load);
845 free(g_temp_pload);
846 free(g_temp_pthroughput);
847 free(g_temp_sharemem);
848 return;
849 }
850
851 for (index = 0; index < device_count; index++)
852 {
853 p_device_context = ni_rsrc_get_device_context(device_type,
854 module_ids[index]);
855 if (icore == NP_LOAD)
856 {
857 if (!open_and_query(device_type,
858 p_device_context,
859 p_session_context,
860 device_name, detail, detail_data_v1))
861 {
862 continue;
863 }
864
865 return_code = ni_query_nvme_status(p_session_context, &load_query);
866 if (return_code != NI_RETCODE_SUCCESS)
867 {
868 fprintf(stderr,
869 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
870 return_code,
871 device_name,
872 p_device_context->p_device_info->dev_name,
873 p_device_context->p_device_info->hw_id);
874 remove_device_from_saved(device_type,
875 p_device_context->p_device_info->module_id,
876 p_session_context->device_handle);
877 ni_device_close(p_session_context->device_handle);
878 goto CLOSE;
879 }
880 g_temp_load[index] = load_query.tp_fw_load;
881 g_temp_pload[index] = load_query.pcie_load;
882 g_temp_pthroughput[index] = load_query.pcie_throughput;
883 g_temp_sharemem[index] = load_query.fw_share_mem_usage;
884 }
885 if (icore==PCIE_LOAD)
886 {
887 load_query.fw_load = g_temp_pload[index];
888 load_query.fw_share_mem_usage = g_temp_pthroughput[index];
889
890 strcat_dyn_buf(&output_buf,
891 "%-5d %-3u %-3.1f "
892 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
893 p_device_context->p_device_info->module_id,
894 load_query.fw_load,
895 (float)load_query.fw_share_mem_usage/10,
896 p_device_context->p_device_info->dev_name,
897 p_device_context->p_device_info->fl_ver_last_ran,
898 p_device_context->p_device_info->fl_ver_nor_flash,
899 p_device_context->p_device_info->fw_rev,
900 p_device_context->p_device_info->fw_rev_nor_flash);
901 }
902 else
903 {
904 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
905 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
906
907 strcat_dyn_buf(&output_buf,
908 "%-5d %-3u %-3u "
909 "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
910 p_device_context->p_device_info->module_id,
911 load_query.fw_load,
912 load_query.fw_share_mem_usage,
913 p_device_context->p_device_info->dev_name,
914 p_device_context->p_device_info->fl_ver_last_ran,
915 p_device_context->p_device_info->fl_ver_nor_flash,
916 p_device_context->p_device_info->fw_rev,
917 p_device_context->p_device_info->fw_rev_nor_flash);
918 }
919
920 CLOSE:
921 ni_rsrc_free_device_context(p_device_context);
922 }
923 }
924
925 free(g_temp_load);
926 free(g_temp_pload);
927 free(g_temp_pthroughput);
928 free(g_temp_sharemem);
929 free(module_ids);
930
931PRINT_OUTPUT:
932 if (output_buf.str_buf)
933 printf("%s", output_buf.str_buf);
934 clear_dyn_str_buf(&output_buf);
935}
936
938 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
939{
940 bool copied_block_name;
941 char block_name[NI_MAX_DEVICE_NAME_LEN] = {0};
942 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
943 unsigned int guid;
944 unsigned int number_of_quadras;
945 unsigned int number_of_device_types_present;
946 unsigned int device_type_counter;
947 unsigned int *maximum_firmware_loads;
948 unsigned int *maximum_firmware_loads_per_quadra;
949 dyn_str_buf_t output_buf = {0};
950
951 ni_device_context_t *p_device_context;
952 ni_device_type_t device_type;
953 ni_device_type_t maximum_device_type;
954 ni_load_query_t load_query;
955 ni_retcode_t return_code;
956
957 // Use NI_DEVICE_TYPE_ENCODER instead of NI_DEVICE_TYPE_NVME
958 // so that Quadras running older firmware will show up.
959 // Assumption: Each Quadra has at least one encoder.
960 number_of_quadras = p_device_queue->xcoder_cnt[NI_DEVICE_TYPE_ENCODER];
961
962 maximum_firmware_loads = calloc(number_of_quadras, sizeof(unsigned int));
963 if (!maximum_firmware_loads)
964 {
965 fprintf(stderr, "calloc() returned NULL\n");
966 return;
967 }
968
969 maximum_firmware_loads_per_quadra = NULL;
970 p_device_context = NULL;
971
972 for (guid = 0; guid < number_of_quadras; guid++)
973 {
974 maximum_device_type = NI_DEVICE_TYPE_XCODER_MAX;
975 maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
976 number_of_device_types_present = 0;
977 device_type_counter = 0;
978 copied_block_name = false;
979
980 for (device_type = NI_DEVICE_TYPE_DECODER;
981 device_type < maximum_device_type;
982 device_type++)
983 {
984 if (p_device_queue->xcoders[device_type][guid] != -1)
985 {
986 number_of_device_types_present++;
987 }
988 }
989
990 for (device_type = NI_DEVICE_TYPE_DECODER;
991 device_type < maximum_device_type;
992 device_type++)
993 {
994 memcpy(device_name,
995 g_device_type_str[device_type],
997
998 if (p_device_queue->xcoders[device_type][guid] == -1)
999 {
1000 continue;
1001 }
1002
1003 p_device_context =
1004 ni_rsrc_get_device_context(device_type,
1005 p_device_queue->xcoders[device_type][guid]);
1006 if (!open_and_query(device_type,
1007 p_device_context,
1008 p_session_context,
1009 device_name, detail, detail_data_v1))
1010 {
1011 continue;
1012 }
1013
1014 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
1015 "6O") < 0)
1016 {
1017 if (maximum_device_type == NI_DEVICE_TYPE_XCODER_MAX)
1018 {
1019 strcat_dyn_buf(&output_buf,
1020 "%s: Simple output not supported. Try '-o full' "
1021 "instead.\n",
1022 p_device_context->p_device_info->dev_name);
1023 maximum_device_type = NI_DEVICE_TYPE_ENCODER;
1024 }
1025 ni_device_close(p_session_context->device_handle);
1026 ni_rsrc_free_device_context(p_device_context);
1027 continue;
1028 }
1029
1030 if (!copied_block_name)
1031 {
1033 p_device_context->p_device_info->dev_name,
1035 copied_block_name = true;
1036 }
1037
1038 if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.fw_load)
1039 {
1040 *maximum_firmware_loads_per_quadra = p_session_context->load_query.fw_load;
1041 }
1042
1043 device_type_counter++;
1044 if (device_type_counter < number_of_device_types_present)
1045 {
1046 remove_device_from_saved(device_type,
1047 p_device_context->p_device_info->module_id,
1048 p_session_context->device_handle);
1049 ni_device_close(p_session_context->device_handle);
1050 ni_rsrc_free_device_context(p_device_context);
1051 }
1052 }
1053
1054 if (maximum_device_type == NI_DEVICE_TYPE_ENCODER)
1055 {
1056 continue;
1057 }
1058
1059 //Nvme and TP load
1060 {
1061 return_code =
1062 ni_query_nvme_status(p_session_context, &load_query);
1063 if (return_code == NI_RETCODE_SUCCESS)
1064 {
1065 if (*maximum_firmware_loads_per_quadra < load_query.fw_load)
1066 {
1067 *maximum_firmware_loads_per_quadra = load_query.fw_load;
1068 }
1069 if (*maximum_firmware_loads_per_quadra < load_query.tp_fw_load)
1070 {
1071 *maximum_firmware_loads_per_quadra = load_query.tp_fw_load;
1072 }
1073 strcat_dyn_buf(&output_buf, "%s: %u%%\n", block_name,
1074 *maximum_firmware_loads_per_quadra);
1075 }
1076 else
1077 {
1078 fprintf(
1079 stderr, "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1080 return_code, device_name, p_device_context->p_device_info->dev_name,
1081 p_device_context->p_device_info->hw_id);
1082 remove_device_from_saved(device_type,
1083 p_device_context->p_device_info->module_id,
1084 p_session_context->device_handle);
1085 ni_device_close(p_session_context->device_handle);
1086 }
1087 }
1088
1089 ni_rsrc_free_device_context(p_device_context);
1090 }
1091
1092 if (output_buf.str_buf)
1093 printf("%s", output_buf.str_buf);
1094 clear_dyn_str_buf(&output_buf);
1095 free(maximum_firmware_loads);
1096}
1097
1098void 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)
1099{
1100 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1101 unsigned int i, index, device_count;
1102 int instance_count;
1103 int32_t *module_ids;
1104
1105 int detail = 1;
1106
1107 dyn_str_buf_t output_buf = {0};
1108 ni_device_context_t *p_device_context;
1109 ni_device_type_t device_type;
1110 int max_device_type = NI_DEVICE_TYPE_SCALER;
1111 int first_item_printed = 0;
1112 int first_device_type_printed = 0;
1113
1114 strcat_dyn_buf(&output_buf, "{\n");
1115
1116 for (device_type = NI_DEVICE_TYPE_DECODER;
1117 device_type != max_device_type;
1118 device_type++)
1119 {
1120 instance_count = 0;
1121 device_count = get_modules(device_type,
1122 p_device_queue,
1123 device_name,
1124 &module_ids);
1125 if (!device_count)
1126 {
1127 continue;
1128 }
1129
1130 if(first_device_type_printed)
1131 {
1132 strcat_dyn_buf(&output_buf, ",\n");
1133 }
1134 strcat_dyn_buf(&output_buf,
1135 "\t\"%s\" :"
1136 "[\n",
1137 device_name
1138 );
1139 first_item_printed = 0;
1140
1141 for (i = 0; i < device_count; i++)
1142 {
1143 p_device_context =
1144 ni_rsrc_get_device_context(device_type,
1145 module_ids[i]);
1146 if (!open_and_query(device_type,
1147 p_device_context,
1148 p_session_context,
1149 device_name, detail, detail_data_v1))
1150 {
1151 continue;
1152 }
1153
1154 for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
1155 {
1156 if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
1157 {
1158 if(first_item_printed)
1159 {
1160 strcat_dyn_buf(&output_buf, ",\n");
1161 }
1162
1163 if(device_type == NI_DEVICE_TYPE_DECODER)
1164 {
1165 strcat_dyn_buf(&output_buf,
1166 "\t\t{\n"
1167 "\t\t\t\"NUMBER\": %u,\n"
1168 "\t\t\t\"INDEX\": %u,\n"
1169 "\t\t\t\"AvgCost\": %u,\n"
1170 "\t\t\t\"FrameRate\": %u,\n"
1171 "\t\t\t\"IDR\": %u,\n"
1172 "\t\t\t\"InFrame\": %u,\n"
1173 "\t\t\t\"OutFrame\": %u,\n"
1174 "\t\t\t\"Width\": %u,\n"
1175 "\t\t\t\"Height\": %u,\n"
1176 "\t\t\t\"SID\": \"%s\",\n"
1177 "\t\t\t\"DEVICE\": \"%s\"\n"
1178 "\t\t}",
1179 device_count,
1180 instance_count++,
1181 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1182 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1183 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1184 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1185 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1186 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1187 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1188 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1189 p_device_context->p_device_info->dev_name);
1190 }
1191 else if (device_type == NI_DEVICE_TYPE_ENCODER)
1192 {
1193 strcat_dyn_buf(&output_buf,
1194 "\t\t{\n"
1195 "\t\t\t\"NUMBER\": %u,\n"
1196 "\t\t\t\"INDEX\": %u,\n"
1197 "\t\t\t\"AvgCost\": %u,\n"
1198 "\t\t\t\"FrameRate\": %u,\n"
1199 "\t\t\t\"IDR\": %u,\n"
1200 "\t\t\t\"UserIDR\": %u,\n"
1201 "\t\t\t\"InFrame\": %u,\n"
1202 "\t\t\t\"OutFrame\": %u,\n"
1203 "\t\t\t\"BR\": %u,\n"
1204 "\t\t\t\"AvgBR\": %u,\n"
1205 "\t\t\t\"Width\": %u,\n"
1206 "\t\t\t\"Height\": %u,\n"
1207 "\t\t\t\"Format\": \"%s\",\n"
1208 "\t\t\t\"SID\": \"%s\",\n"
1209 "\t\t\t\"DEVICE\": \"%s\"\n"
1210 "\t\t}",
1211 device_count,
1212 instance_count++,
1213 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1214 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1215 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1216 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
1217 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1218 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1219 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
1220 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
1221 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1222 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1223 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
1224 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1225 p_device_context->p_device_info->dev_name);
1226 }
1227 first_item_printed = 1;
1228 }
1229 }
1230 }
1231
1232 strcat_dyn_buf(&output_buf, "\n");
1233 strcat_dyn_buf(&output_buf,
1234 "\t]"
1235 );
1236 first_device_type_printed = 1;
1237 }
1238
1239 strcat_dyn_buf(&output_buf, "\n");
1240 strcat_dyn_buf(&output_buf, "}\n");
1241
1242 if(output_buf.str_buf)
1243 {
1244 printf("%s", output_buf.str_buf);
1245 }
1246
1247 clear_dyn_str_buf(&output_buf);
1248
1249}
1250
1251void print_json(ni_device_queue_t *p_device_queue,
1252 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
1253{
1254 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1255 unsigned int i, index, device_count;
1256 int instance_count;
1257 int32_t *module_ids;
1258 uint32_t total_contexts;
1259 uint32_t vpu_load;
1260 uint32_t model_load;
1261#ifdef __linux__
1262 char pcie[64] = {0};
1263 int numa_node;
1264#endif
1265 dyn_str_buf_t output_buf = {0};
1266
1267 ni_device_context_t *p_device_context;
1268 ni_device_type_t device_type;
1269 ni_load_query_t load_query;
1270 ni_retcode_t return_code;
1271 int max_device_type = NI_DEVICE_TYPE_XCODER_MAX;
1272 if(detail)
1273 max_device_type = NI_DEVICE_TYPE_SCALER;
1274
1275 for (device_type = NI_DEVICE_TYPE_DECODER;
1276 device_type != max_device_type;
1277 device_type++)
1278 {
1279 instance_count = 0;
1280 device_count = get_modules(device_type,
1281 p_device_queue,
1282 device_name,
1283 &module_ids);
1284 if (!device_count)
1285 {
1286 continue;
1287 }
1288
1289UPLOADER:
1290 for (i = 0; i < device_count; i++)
1291 {
1292 p_device_context =
1293 ni_rsrc_get_device_context(device_type,
1294 module_ids[i]);
1295 if (!open_and_query(device_type,
1296 p_device_context,
1297 p_session_context,
1298 device_name, detail, detail_data_v1))
1299 {
1300 continue;
1301 }
1302
1303 if (device_type == NI_DEVICE_TYPE_UPLOAD)
1304 {
1305 total_contexts = p_session_context->load_query.active_hwuploaders;
1306 vpu_load = 0;
1307 model_load = 0;
1308 }
1309 else
1310 {
1311 total_contexts = p_session_context->load_query.total_contexts;
1312 vpu_load = p_session_context->load_query.current_load;
1313 model_load = p_session_context->load_query.fw_model_load;
1314 }
1315#ifdef __linux__
1316 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1317 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1318#endif
1319
1320 if(detail)
1321 {
1322 strcat_dyn_buf(&output_buf,
1323 "{ \"%s\" :\n"
1324 "\t[\n",
1325 device_name
1326 );
1327 for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
1328 {
1329 if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
1330 {
1331 if(device_type == NI_DEVICE_TYPE_DECODER)
1332 {
1333 strcat_dyn_buf(&output_buf,
1334 "\t\t{\n"
1335 "\t\t\t\"NUMBER\": %u,\n"
1336 "\t\t\t\"INDEX\": %u,\n"
1337 "\t\t\t\"AvgCost\": %u,\n"
1338 "\t\t\t\"FrameRate\": %u,\n"
1339 "\t\t\t\"IDR\": %u,\n"
1340 "\t\t\t\"InFrame\": %u,\n"
1341 "\t\t\t\"OutFrame\": %u,\n"
1342 "\t\t\t\"Width\": %u,\n"
1343 "\t\t\t\"Height\": %u,\n"
1344 "\t\t\t\"SID\": %s,\n"
1345 "\t\t\t\"DEVICE\": \"%s\",\n"
1346 "\t\t},\n",
1347 device_count,
1348 instance_count++,
1349 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1350 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1351 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1352 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1353 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1354 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1355 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1356 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1357 p_device_context->p_device_info->dev_name);
1358 }
1359 else if (device_type == NI_DEVICE_TYPE_ENCODER)
1360 {
1361 strcat_dyn_buf(&output_buf,
1362 "\t\t{\n"
1363 "\t\t\t\"NUMBER\": %u,\n"
1364 "\t\t\t\"INDEX\": %u,\n"
1365 "\t\t\t\"AvgCost\": %u,\n"
1366 "\t\t\t\"FrameRate\": %u,\n"
1367 "\t\t\t\"IDR\": %u,\n"
1368 "\t\t\t\"UserIDR\": %u,\n"
1369 "\t\t\t\"InFrame\": %u,\n"
1370 "\t\t\t\"OutFrame\": %u,\n"
1371 "\t\t\t\"BR\": %u,\n"
1372 "\t\t\t\"AvgBR\": %u,\n"
1373 "\t\t\t\"Width\": %u,\n"
1374 "\t\t\t\"Height\": %u,\n"
1375 "\t\t\t\"Format\": %s,\n"
1376 "\t\t\t\"SID\": %s,\n"
1377 "\t\t\t\"DEVICE\": \"%s\",\n"
1378 "\t\t},\n",
1379 device_count,
1380 instance_count++,
1381 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1382 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1383 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1384 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
1385 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1386 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1387 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
1388 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
1389 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1390 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1391 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
1392 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1393 p_device_context->p_device_info->dev_name);
1394 }
1395 }
1396 }
1397 strcat_dyn_buf(&output_buf,
1398 "\t]\n"
1399 "}\n"
1400 );
1401 }
1402 else
1403 {
1404 if (p_session_context->overall_load_query.admin_queried &&
1405 device_type != NI_DEVICE_TYPE_UPLOAD)
1406 {
1407 strcat_dyn_buf(&output_buf,
1408 "{ \"%s\" :\n"
1409 "\t[\n"
1410 "\t\t{\n"
1411 "\t\t\t\"NUMBER\": %u,\n"
1412 "\t\t\t\"INDEX\": %d,\n"
1413 "\t\t\t\"LOAD\": %u,\n"
1414 "\t\t\t\"LOAD-ALL\": %u,\n"
1415 "\t\t\t\"MODEL_LOAD\": %u,\n"
1416 "\t\t\t\"MODEL_LOAD-ALL\": %u,\n"
1417 "\t\t\t\"FW_LOAD\": %u,\n"
1418 "\t\t\t\"INST\": %u,\n"
1419 "\t\t\t\"INST-ALL\": %u,\n"
1420 "\t\t\t\"MAX_INST\": %d,\n"
1421 "\t\t\t\"MEM\": %u,\n"
1422 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1423 "\t\t\t\"SHARE_MEM\": %u,\n"
1424 "\t\t\t\"P2P_MEM\": %u,\n"
1425 "\t\t\t\"DEVICE\": \"%s\",\n"
1426 "\t\t\t\"L_FL2V\": \"%s\",\n"
1427 "\t\t\t\"N_FL2V\": \"%s\",\n"
1428 "\t\t\t\"FR\": \"%.8s\",\n"
1429 "\t\t\t\"N_FR\": \"%.8s\""
1430#ifdef __linux__
1431 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1432 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1433#else
1434 ",\n"
1435#endif
1436 "\t\t}\n"
1437 "\t]\n"
1438 "}\n",
1439 device_name, device_count,
1440 p_device_context->p_device_info->module_id,
1441 vpu_load,
1442 p_session_context->overall_load_query.overall_current_load,
1443 model_load,
1444 p_session_context->overall_load_query.overall_fw_model_load,
1445 p_session_context->load_query.fw_load, total_contexts,
1446 p_session_context->overall_load_query.overall_instance_count,
1447 p_device_context->p_device_info->max_instance_cnt,
1448 p_session_context->load_query.fw_video_mem_usage,
1449 p_session_context->load_query.fw_video_shared_mem_usage,
1450 p_session_context->load_query.fw_share_mem_usage,
1451 p_session_context->load_query.fw_p2p_mem_usage,
1452 p_device_context->p_device_info->dev_name,
1453 p_device_context->p_device_info->fl_ver_last_ran,
1454 p_device_context->p_device_info->fl_ver_nor_flash,
1455 p_device_context->p_device_info->fw_rev,
1456 p_device_context->p_device_info->fw_rev_nor_flash
1457#ifdef __linux__
1458 ,
1459 numa_node, pcie
1460#endif
1461 );
1462 }
1463 else
1464 {
1465 strcat_dyn_buf(&output_buf,
1466 "{ \"%s\" :\n"
1467 "\t[\n"
1468 "\t\t{\n"
1469 "\t\t\t\"NUMBER\": %u,\n"
1470 "\t\t\t\"INDEX\": %d,\n"
1471 "\t\t\t\"LOAD\": %u,\n"
1472 "\t\t\t\"MODEL_LOAD\": %u,\n"
1473 "\t\t\t\"FW_LOAD\": %u,\n"
1474 "\t\t\t\"INST\": %u,\n"
1475 "\t\t\t\"MAX_INST\": %d,\n"
1476 "\t\t\t\"MEM\": %u,\n"
1477 "\t\t\t\"CRITICAL_MEM\": %u,\n"
1478 "\t\t\t\"SHARE_MEM\": %u,\n"
1479 "\t\t\t\"P2P_MEM\": %u,\n"
1480 "\t\t\t\"DEVICE\": \"%s\",\n"
1481 "\t\t\t\"L_FL2V\": \"%s\",\n"
1482 "\t\t\t\"N_FL2V\": \"%s\",\n"
1483 "\t\t\t\"FR\": \"%.8s\",\n"
1484 "\t\t\t\"N_FR\": \"%.8s\""
1485#ifdef __linux__
1486 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1487 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1488#else
1489 ",\n"
1490#endif
1491 "\t\t}\n"
1492 "\t]\n"
1493 "}\n",
1494 device_name, device_count,
1495 p_device_context->p_device_info->module_id,
1496 vpu_load,
1497 model_load,
1498 p_session_context->load_query.fw_load, total_contexts,
1499 p_device_context->p_device_info->max_instance_cnt,
1500 p_session_context->load_query.fw_video_mem_usage,
1501 p_session_context->load_query.fw_video_shared_mem_usage,
1502 p_session_context->load_query.fw_share_mem_usage,
1503 p_session_context->load_query.fw_p2p_mem_usage,
1504 p_device_context->p_device_info->dev_name,
1505 p_device_context->p_device_info->fl_ver_last_ran,
1506 p_device_context->p_device_info->fl_ver_nor_flash,
1507 p_device_context->p_device_info->fw_rev,
1508 p_device_context->p_device_info->fw_rev_nor_flash
1509#ifdef __linux__
1510 , numa_node, pcie
1511#endif
1512 );
1513 }
1514 }
1515 ni_rsrc_free_device_context(p_device_context);
1516 }
1517
1518 if(!detail)
1519 {
1520 if (swap_encoder_and_uploader(&device_type, device_name))
1521 {
1522 goto UPLOADER;
1523 }
1524 }
1525
1526 free(module_ids);
1527 }
1528 if(detail)
1529 {
1530 if (output_buf.str_buf)
1531 printf("%s", output_buf.str_buf);
1532 clear_dyn_str_buf(&output_buf);
1533 return;
1534 }
1535
1536 // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
1537 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
1538 goto PRINT_OUTPUT;
1539 }
1540
1541 //Nvme[0] and TP[1] load and PCIe[3] load
1542 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
1543 {
1544 // ASSUMPTION: Each Quadra has at least and only one encoder.
1545 device_type = NI_DEVICE_TYPE_ENCODER;
1546 device_count = get_modules(device_type,
1547 p_device_queue,
1548 device_name,
1549 &module_ids);
1550
1551 if (!device_count)
1552 {
1553 if (output_buf.str_buf)
1554 printf("%s", output_buf.str_buf);
1555 clear_dyn_str_buf(&output_buf);
1556 return;
1557 }
1558 if (icore == NP_LOAD)
1559 {
1560 ni_strcpy(device_name, MAX_DEVICE_NAME_SIZE, "nvme");
1561 g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1562 if (!g_temp_load)
1563 {
1564 fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
1565 return;
1566 }
1567 g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1568 if (!g_temp_pload)
1569 {
1570 fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
1571 return;
1572 }
1573 g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1574 if (!g_temp_pthroughput)
1575 {
1576 fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
1577 return;
1578 }
1579 g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1580 if (!g_temp_sharemem)
1581 {
1582 fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
1583 return;
1584 }
1585 }
1586 else
1587 {
1588 (icore == TP_LOAD)?ni_strcpy(device_name, MAX_DEVICE_NAME_SIZE, "tp"):ni_strcpy(device_name, MAX_DEVICE_NAME_SIZE, "pcie");
1589 }
1590
1591 for (i = 0; i < device_count; i++)
1592 {
1593 p_device_context = ni_rsrc_get_device_context(device_type, module_ids[i]);
1594 if (icore == NP_LOAD)
1595 {
1596 if (!open_and_query(device_type,
1597 p_device_context,
1598 p_session_context,
1599 device_name, detail, detail_data_v1))
1600 {
1601 continue;
1602 }
1603
1604 return_code =
1605 ni_query_nvme_status(p_session_context, &load_query);
1606 if (return_code != NI_RETCODE_SUCCESS)
1607 {
1608 fprintf(stderr,
1609 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1610 return_code,
1611 device_name,
1612 p_device_context->p_device_info->dev_name,
1613 p_device_context->p_device_info->hw_id);
1614 remove_device_from_saved(device_type,
1615 p_device_context->p_device_info->module_id,
1616 p_session_context->device_handle);
1617 ni_device_close(p_session_context->device_handle);
1618 goto CLOSE;
1619 }
1620 g_temp_load[i] = load_query.tp_fw_load;
1621 g_temp_pload[i] = load_query.pcie_load;
1622 g_temp_pthroughput[i] = load_query.pcie_throughput;
1623 g_temp_sharemem[i] = load_query.fw_share_mem_usage;
1624 }
1625
1626#ifdef __linux__
1627 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1628 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1629#endif
1630
1631 if (icore == PCIE_LOAD)
1632 {
1633 strcat_dyn_buf(&output_buf,
1634 "{ \"%s\" :\n"
1635 "\t[\n"
1636 "\t\t{\n"
1637 "\t\t\t\"NUMBER\": %u,\n"
1638 "\t\t\t\"INDEX\": %d,\n"
1639 "\t\t\t\"LOAD\": 0,\n"
1640 "\t\t\t\"MODEL_LOAD\": 0,\n"
1641 "\t\t\t\"FW_LOAD\": %u,\n"
1642 "\t\t\t\"INST\": 0,\n"
1643 "\t\t\t\"MAX_INST\": 0,\n"
1644 "\t\t\t\"MEM\": 0,\n"
1645 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1646 "\t\t\t\"SHARE_MEM\": %u,\n"
1647 "\t\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1648 "\t\t\t\"P2P_MEM\": 0,\n"
1649 "\t\t\t\"DEVICE\": \"%s\",\n"
1650 "\t\t\t\"L_FL2V\": \"%s\",\n"
1651 "\t\t\t\"N_FL2V\": \"%s\",\n"
1652 "\t\t\t\"FR\": \"%.8s\",\n"
1653 "\t\t\t\"N_FR\": \"%.8s\""
1654#ifdef __linux__
1655 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1656 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1657#else
1658 ",\n"
1659#endif
1660 "\t\t}\n"
1661 "\t]\n"
1662 "}\n",
1663 device_name, device_count,
1664 p_device_context->p_device_info->module_id,
1665 g_temp_pload[i], 0, (float)g_temp_pthroughput[i]/10,
1666 p_device_context->p_device_info->dev_name,
1667 p_device_context->p_device_info->fl_ver_last_ran,
1668 p_device_context->p_device_info->fl_ver_nor_flash,
1669 p_device_context->p_device_info->fw_rev,
1670 p_device_context->p_device_info->fw_rev_nor_flash
1671#ifdef __linux__
1672 , numa_node, pcie
1673#endif
1674 );
1675 }
1676 else
1677 {
1678 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[i]:load_query.fw_load;
1679 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[i]:load_query.fw_share_mem_usage;
1680
1681 strcat_dyn_buf(&output_buf,
1682 "{ \"%s\" :\n"
1683 "\t[\n"
1684 "\t\t{\n"
1685 "\t\t\t\"NUMBER\": %u,\n"
1686 "\t\t\t\"INDEX\": %d,\n"
1687 "\t\t\t\"LOAD\": 0,\n"
1688 "\t\t\t\"MODEL_LOAD\": 0,\n"
1689 "\t\t\t\"FW_LOAD\": %u,\n"
1690 "\t\t\t\"INST\": 0,\n"
1691 "\t\t\t\"MAX_INST\": 0,\n"
1692 "\t\t\t\"MEM\": 0,\n"
1693 "\t\t\t\"CRITICAL_MEM\": 0,\n"
1694 "\t\t\t\"SHARE_MEM\": %u,\n"
1695 "\t\t\t\"P2P_MEM\": 0,\n"
1696 "\t\t\t\"DEVICE\": \"%s\",\n"
1697 "\t\t\t\"L_FL2V\": \"%s\",\n"
1698 "\t\t\t\"N_FL2V\": \"%s\",\n"
1699 "\t\t\t\"FR\": \"%.8s\",\n"
1700 "\t\t\t\"N_FR\": \"%.8s\""
1701#ifdef __linux__
1702 ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1703 "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1704#else
1705 ",\n"
1706#endif
1707 "\t\t}\n"
1708 "\t]\n"
1709 "}\n",
1710 device_name, device_count,
1711 p_device_context->p_device_info->module_id,
1712 load_query.fw_load, load_query.fw_share_mem_usage,
1713 p_device_context->p_device_info->dev_name,
1714 p_device_context->p_device_info->fl_ver_last_ran,
1715 p_device_context->p_device_info->fl_ver_nor_flash,
1716 p_device_context->p_device_info->fw_rev,
1717 p_device_context->p_device_info->fw_rev_nor_flash
1718#ifdef __linux__
1719 , numa_node, pcie
1720#endif
1721 );
1722 }
1723 CLOSE:
1724 ni_rsrc_free_device_context(p_device_context);
1725 }
1726 }
1727
1728 free(g_temp_load);
1729 free(g_temp_pload);
1730 free(g_temp_pthroughput);
1731 free(g_temp_sharemem);
1732 free(module_ids);
1733
1734PRINT_OUTPUT:
1735 if (output_buf.str_buf)
1736 printf("%s", output_buf.str_buf);
1737 clear_dyn_str_buf(&output_buf);
1738}
1739
1740void print_json1(ni_device_queue_t *p_device_queue,
1741 ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1, int format)
1742{
1743 bool has_written_start = false;
1744 char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1745 unsigned int index, device_count;
1746 int32_t *module_ids;
1747 uint32_t total_contexts;
1748 uint32_t vpu_load;
1749 uint32_t model_load;
1750#ifdef __linux__
1751 char pcie[64] = {0};
1752 int numa_node;
1753#endif
1754 dyn_str_buf_t output_buf = {0};
1755 ni_device_extra_info_t p_dev_extra_info = {0};
1756 char power_consumption[16];
1757
1758 uint16_t namespace_id = 0;
1759 uint8_t qos_mode;
1760
1761 ni_device_context_t *p_device_context;
1762 ni_device_type_t device_type;
1763 ni_load_query_t load_query;
1764 ni_retcode_t return_code;
1765
1766 int32_t *extra_temp_per_index = NULL;
1767 uint32_t *extra_power_per_index = NULL;
1768
1769 for (device_type = NI_DEVICE_TYPE_DECODER;
1770 device_type != NI_DEVICE_TYPE_XCODER_MAX;
1771 device_type++)
1772 {
1773 device_count = get_modules(device_type,
1774 p_device_queue,
1775 device_name,
1776 &module_ids);
1777 if (!device_count)
1778 {
1779 continue;
1780 }
1781
1782UPLOADER:
1783 if (!has_written_start)
1784 {
1785 strcat_dyn_buf(&output_buf, "{\n \"%ss\": [\n", device_name);
1786 has_written_start = true;
1787 }
1788 else
1789 {
1790 strcat_dyn_buf(&output_buf, " ],\n \"%ss\": [\n", device_name);
1791 }
1792
1793 for (index = 0; index < device_count; index++)
1794 {
1795 p_device_context =
1796 ni_rsrc_get_device_context(device_type,
1797 module_ids[index]);
1798 if (!open_and_query(device_type,
1799 p_device_context,
1800 p_session_context,
1801 device_name, detail, detail_data_v1))
1802 {
1803 continue;
1804 }
1805
1806 if (device_type == NI_DEVICE_TYPE_UPLOAD)
1807 {
1808 total_contexts = p_session_context->load_query.active_hwuploaders;
1809 vpu_load = 0;
1810 model_load = 0;
1811 }
1812 else
1813 {
1814 total_contexts = p_session_context->load_query.total_contexts;
1815 vpu_load = p_session_context->load_query.current_load;
1816 model_load = p_session_context->load_query.fw_model_load;
1817 }
1818#ifdef __linux__
1819 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1820 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1821#endif
1822 if (format == 2)
1823 {
1824 if (ni_query_extra_info(p_session_context->device_handle,
1825 &p_dev_extra_info,
1826 p_device_context->p_device_info->fw_rev))
1827 {
1828 p_dev_extra_info.composite_temp = 0;
1829 }
1830 if (p_dev_extra_info.power_consumption + 1)
1831 {
1832 ni_sprintf(power_consumption, 16, "%umW", p_dev_extra_info.power_consumption);
1833 }
1834 }
1835 if (p_session_context->overall_load_query.admin_queried &&
1836 device_type != NI_DEVICE_TYPE_UPLOAD)
1837 {
1838 strcat_dyn_buf(&output_buf,
1839 "\t{\n"
1840 "\t\t\"NUMBER\": %u,\n"
1841 "\t\t\"INDEX\": %d,\n"
1842 "\t\t\"LOAD\": %u,\n"
1843 "\t\t\"LOAD-ALL\": %u,\n"
1844 "\t\t\"MODEL_LOAD\": %u,\n"
1845 "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1846 "\t\t\"FW_LOAD\": %u,\n"
1847 "\t\t\"INST\": %u,\n"
1848 "\t\t\"INST-ALL\": %u,\n"
1849 "\t\t\"MAX_INST\": %d,\n"
1850 "\t\t\"MEM\": %u,\n"
1851 "\t\t\"CRITICAL_MEM\": %u,\n"
1852 "\t\t\"SHARE_MEM\": %u,\n"
1853 "\t\t\"P2P_MEM\": %u,\n"
1854 "\t\t\"DEVICE\": \"%s\",\n"
1855 "\t\t\"L_FL2V\": \"%s\",\n"
1856 "\t\t\"N_FL2V\": \"%s\",\n"
1857 "\t\t\"FR\": \"%.8s\",\n"
1858 "\t\t\"N_FR\": \"%.8s\""
1859#ifdef __linux__
1860 ",\n\t\t\"NUMA_NODE\": %d,\n"
1861 "\t\t\"PCIE_ADDR\": \"%s\""
1862#endif
1863 , device_count, p_device_context->p_device_info->module_id,
1864 vpu_load,
1865 p_session_context->overall_load_query.overall_current_load,
1866 model_load,
1867 p_session_context->overall_load_query.overall_fw_model_load,
1868 p_session_context->load_query.fw_load, total_contexts,
1869 p_session_context->overall_load_query.overall_instance_count,
1870 p_device_context->p_device_info->max_instance_cnt,
1871 p_session_context->load_query.fw_video_mem_usage,
1872 p_session_context->load_query.fw_video_shared_mem_usage,
1873 p_session_context->load_query.fw_share_mem_usage,
1874 p_session_context->load_query.fw_p2p_mem_usage,
1875 p_device_context->p_device_info->dev_name,
1876 p_device_context->p_device_info->fl_ver_last_ran,
1877 p_device_context->p_device_info->fl_ver_nor_flash,
1878 p_device_context->p_device_info->fw_rev,
1879 p_device_context->p_device_info->fw_rev_nor_flash
1880#ifdef __linux__
1881 , numa_node, pcie
1882#endif
1883 );
1884 } else
1885 {
1886 strcat_dyn_buf(&output_buf,
1887 "\t{\n"
1888 "\t\t\"NUMBER\": %u,\n"
1889 "\t\t\"INDEX\": %d,\n"
1890 "\t\t\"LOAD\": %u,\n"
1891 "\t\t\"MODEL_LOAD\": %u,\n"
1892 "\t\t\"FW_LOAD\": %u,\n"
1893 "\t\t\"INST\": %u,\n"
1894 "\t\t\"MAX_INST\": %d,\n"
1895 "\t\t\"MEM\": %u,\n"
1896 "\t\t\"CRITICAL_MEM\": %u,\n"
1897 "\t\t\"SHARE_MEM\": %u,\n"
1898 "\t\t\"P2P_MEM\": %u,\n"
1899 "\t\t\"DEVICE\": \"%s\",\n"
1900 "\t\t\"L_FL2V\": \"%s\",\n"
1901 "\t\t\"N_FL2V\": \"%s\",\n"
1902 "\t\t\"FR\": \"%.8s\",\n"
1903 "\t\t\"N_FR\": \"%.8s\""
1904#ifdef __linux__
1905 ",\n\t\t\"NUMA_NODE\": %d,\n"
1906 "\t\t\"PCIE_ADDR\": \"%s\""
1907#endif
1908 ,device_count, p_device_context->p_device_info->module_id,
1909 vpu_load,
1910 model_load,
1911 p_session_context->load_query.fw_load, total_contexts,
1912 p_device_context->p_device_info->max_instance_cnt,
1913 p_session_context->load_query.fw_video_mem_usage,
1914 p_session_context->load_query.fw_video_shared_mem_usage,
1915 p_session_context->load_query.fw_share_mem_usage,
1916 p_session_context->load_query.fw_p2p_mem_usage,
1917 p_device_context->p_device_info->dev_name,
1918 p_device_context->p_device_info->fl_ver_last_ran,
1919 p_device_context->p_device_info->fl_ver_nor_flash,
1920 p_device_context->p_device_info->fw_rev,
1921 p_device_context->p_device_info->fw_rev_nor_flash
1922#ifdef __linux__
1923 ,
1924 numa_node, pcie
1925#endif
1926 );
1927 }
1928 if (format == 2)
1929 {
1930 strcat_dyn_buf(&output_buf,
1931 ",\n\t\t\"TEMP\": %d,\n"
1932 "\t\t\"POWER\": \"%s\"",
1933 p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
1934 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A");
1935 if ((device_type == NI_DEVICE_TYPE_ENCODER) || (device_type == NI_DEVICE_TYPE_DECODER))
1936 {
1937 ni_qos_header_info_log_page_t qos_header = {0};
1938 ni_qos_namespace_info_log_page_t qos_ns_info = {0};
1939 ni_device_vf_ns_id_t ns_vf_id = {0};
1940
1941 if (ni_query_vf_ns_id(p_session_context->device_handle, &ns_vf_id,
1942 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
1943 {
1944 namespace_id = ns_vf_id.ns_id;
1945
1946 if (ni_query_qos_info(p_session_context->device_handle, &qos_header,
1947 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
1948 {
1949 ni_query_qos_namespace_info(p_session_context->device_handle, &qos_ns_info,
1950 p_device_context->p_device_info->fw_rev);
1951
1952 qos_mode = (uint8_t)(qos_header.ui16QosState & 0xFF);
1953 float _opmax = (float)(qos_ns_info.ui32OPmaxUs * 100) / VIDEO_SLICE_TIME;
1954
1955 strcat_dyn_buf(&output_buf,
1956 ",\n\t\t\"QOS MODE\": %u,\n"
1957 "\t\t\"QOS NS\": %u,\n"
1958 "\t\t\"QOS ALLOW\": %.1f,\n"
1959 "\t\t\"QOS OPMAX\": %.1f",
1960 (uint8_t)(qos_header.ui16QosState & 0xFF),
1961 namespace_id,
1962 (qos_mode == 0 ? 0 : qos_ns_info.fAllowance),
1963 (qos_mode == 0 ? 0 :_opmax)
1964 );
1965 }
1966 }
1967 }
1968 strcat_dyn_buf(&output_buf, "\n\t}");
1969 }
1970 else
1971 {
1972 strcat_dyn_buf(&output_buf, "\n\t}");
1973 }
1974 if (index < device_count - 1)
1975 {
1976 strcat_dyn_buf(&output_buf, ",\n");
1977 }
1978 else
1979 {
1980 strcat_dyn_buf(&output_buf, "\n");
1981 }
1982
1983 ni_rsrc_free_device_context(p_device_context);
1984 }
1985
1986 if (swap_encoder_and_uploader(&device_type, device_name))
1987 {
1988 goto UPLOADER;
1989 }
1990
1991 free(module_ids);
1992 }
1993
1994 // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
1995 if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
1996 goto PRINT_OUTPUT;
1997 }
1998 else
1999 {
2000 strcat_dyn_buf(&output_buf, " ],\n");
2001 }
2002
2003 //Nvme[0] and TP[1] load
2004 for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
2005 {
2006 // ASSUMPTION: Each Quadra has at least and only one encoder.
2007 device_type = NI_DEVICE_TYPE_ENCODER;
2008 device_count = get_modules(device_type,
2009 p_device_queue,
2010 device_name,
2011 &module_ids);
2012
2013 if (!device_count)
2014 {
2015 if (output_buf.str_buf)
2016 printf("%s", output_buf.str_buf);
2017 clear_dyn_str_buf(&output_buf);
2018 return;
2019 }
2020 if (icore == NP_LOAD)
2021 {
2022 extra_temp_per_index = (int32_t *)calloc(device_count, sizeof(int32_t));
2023 extra_power_per_index = (uint32_t *)calloc(device_count, sizeof(uint32_t));
2024 if (!extra_temp_per_index || !extra_power_per_index)
2025 {
2026 fprintf(stderr, "ERROR: calloc() failed for extra info arrays\n");
2027 if (extra_temp_per_index) free(extra_temp_per_index);
2028 if (extra_power_per_index) free(extra_power_per_index);
2029 }
2030 strcat_dyn_buf(&output_buf, " \"nvmes\": [\n");
2031 g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2032 if (!g_temp_load)
2033 {
2034 fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
2035 return;
2036 }
2037 g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2038 if (!g_temp_pload)
2039 {
2040 fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
2041 return;
2042 }
2043 g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2044 if (!g_temp_pthroughput)
2045 {
2046 fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
2047 return;
2048 }
2049 g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2050 if (!g_temp_sharemem)
2051 {
2052 fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
2053 return;
2054 }
2055 }
2056 else
2057 {
2058 (icore == TP_LOAD)?strcat_dyn_buf(&output_buf, " \"tps\": [\n"):strcat_dyn_buf(&output_buf, " \"pcies\": [\n");
2059 }
2060 for (index = 0; index < device_count; index++)
2061 {
2062 p_device_context = ni_rsrc_get_device_context(device_type,
2063 module_ids[index]);
2064 if (icore == NP_LOAD)
2065 {
2066 if (!open_and_query(device_type,
2067 p_device_context,
2068 p_session_context,
2069 device_name, detail, detail_data_v1))
2070 {
2071 continue;
2072 }
2073
2074 return_code =
2075 ni_query_nvme_status(p_session_context, &load_query);
2076 if (return_code != NI_RETCODE_SUCCESS)
2077 {
2078 fprintf(stderr,
2079 "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2080 return_code,
2081 device_name,
2082 p_device_context->p_device_info->dev_name,
2083 p_device_context->p_device_info->hw_id);
2084 remove_device_from_saved(device_type,
2085 p_device_context->p_device_info->module_id,
2086 p_session_context->device_handle);
2087 ni_device_close(p_session_context->device_handle);
2088 goto CLOSE;
2089 }
2090 g_temp_load[index] = load_query.tp_fw_load;
2091 g_temp_pload[index] = load_query.pcie_load;
2092 g_temp_pthroughput[index] = load_query.pcie_throughput;
2093 g_temp_sharemem[index] = load_query.fw_share_mem_usage;
2094 if (format == 2)
2095 {
2096 if (ni_query_extra_info(p_session_context->device_handle,
2097 &p_dev_extra_info,
2098 p_device_context->p_device_info->fw_rev))
2099 {
2100 p_dev_extra_info.composite_temp = 0;
2101 }
2102 extra_temp_per_index[index] = p_dev_extra_info.composite_temp;
2103 extra_power_per_index[index] = p_dev_extra_info.power_consumption;
2104 }
2105 }
2106#ifdef __linux__
2107 get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
2108 numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
2109#endif
2110
2111 if (icore==PCIE_LOAD)
2112 {
2113 strcat_dyn_buf(&output_buf,
2114 "\t{\n"
2115 "\t\t\"NUMBER\": %u,\n"
2116 "\t\t\"INDEX\": %d,\n"
2117 "\t\t\"LOAD\": 0,\n"
2118 "\t\t\"MODEL_LOAD\": 0,\n"
2119 "\t\t\"FW_LOAD\": %u,\n"
2120 "\t\t\"INST\": 0,\n"
2121 "\t\t\"MAX_INST\": 0,\n"
2122 "\t\t\"MEM\": 0,\n"
2123 "\t\t\"CRITICAL_MEM\": 0,\n"
2124 "\t\t\"SHARE_MEM\": %u,\n"
2125 "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2126 "\t\t\"P2P_MEM\": 0,\n"
2127 "\t\t\"DEVICE\": \"%s\",\n"
2128 "\t\t\"L_FL2V\": \"%s\",\n"
2129 "\t\t\"N_FL2V\": \"%s\",\n"
2130 "\t\t\"FR\": \"%.8s\",\n"
2131 "\t\t\"N_FR\": \"%.8s\""
2132#ifdef __linux__
2133 ",\n\t\t\"NUMA_NODE\": %d,\n"
2134 "\t\t\"PCIE_ADDR\": \"%s\""
2135#endif
2136 , device_count, p_device_context->p_device_info->module_id,
2137 g_temp_pload[index], 0, (float)g_temp_pthroughput[index]/10,
2138 p_device_context->p_device_info->dev_name,
2139 p_device_context->p_device_info->fl_ver_last_ran,
2140 p_device_context->p_device_info->fl_ver_nor_flash,
2141 p_device_context->p_device_info->fw_rev,
2142 p_device_context->p_device_info->fw_rev_nor_flash
2143#ifdef __linux__
2144 , numa_node, pcie
2145#endif
2146 );
2147 }
2148 else
2149 {
2150 load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
2151 load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
2152
2153 strcat_dyn_buf(&output_buf,
2154 "\t{\n"
2155 "\t\t\"NUMBER\": %u,\n"
2156 "\t\t\"INDEX\": %d,\n"
2157 "\t\t\"LOAD\": 0,\n"
2158 "\t\t\"MODEL_LOAD\": 0,\n"
2159 "\t\t\"FW_LOAD\": %u,\n"
2160 "\t\t\"INST\": 0,\n"
2161 "\t\t\"MAX_INST\": 0,\n"
2162 "\t\t\"MEM\": 0,\n"
2163 "\t\t\"CRITICAL_MEM\": 0,\n"
2164 "\t\t\"SHARE_MEM\": %u,\n"
2165 "\t\t\"P2P_MEM\": 0,\n"
2166 "\t\t\"DEVICE\": \"%s\",\n"
2167 "\t\t\"L_FL2V\": \"%s\",\n"
2168 "\t\t\"N_FL2V\": \"%s\",\n"
2169 "\t\t\"FR\": \"%.8s\",\n"
2170 "\t\t\"N_FR\": \"%.8s\""
2171#ifdef __linux__
2172 ",\n\t\t\"NUMA_NODE\": %d,\n"
2173 "\t\t\"PCIE_ADDR\": \"%s\""
2174#endif
2175 , device_count, p_device_context->p_device_info->module_id,
2176 load_query.fw_load, load_query.fw_share_mem_usage,
2177 p_device_context->p_device_info->dev_name,
2178 p_device_context->p_device_info->fl_ver_last_ran,
2179 p_device_context->p_device_info->fl_ver_nor_flash,
2180 p_device_context->p_device_info->fw_rev,
2181 p_device_context->p_device_info->fw_rev_nor_flash
2182#ifdef __linux__
2183 , numa_node, pcie
2184#endif
2185 );
2186 }
2187 if (format == 2)
2188 {
2189 if (p_dev_extra_info.power_consumption + 1)
2190 {
2191 ni_sprintf(power_consumption, 16, "%umW", extra_power_per_index[index]);
2192 }
2193 strcat_dyn_buf(&output_buf,
2194 ",\n\t\t\"TEMP\": %d,\n"
2195 "\t\t\"POWER\": \"%s\"\n"
2196 "\t}",
2197 extra_temp_per_index[index] + ABSOLUTE_TEMP_ZERO,
2198 (extra_power_per_index[index] + 1) ? power_consumption : "N/A");
2199 }
2200 else
2201 {
2202 strcat_dyn_buf(&output_buf, "\n\t}");
2203 }
2204 if (index < device_count - 1)
2205 {
2206 strcat_dyn_buf(&output_buf, ",\n");
2207 }
2208 else
2209 {
2210 strcat_dyn_buf(&output_buf, "\n");
2211 if (icore != PCIE_LOAD)
2212 {
2213 strcat_dyn_buf(&output_buf, " ],\n");
2214 }
2215 }
2216
2217CLOSE:
2218 ni_rsrc_free_device_context(p_device_context);
2219 }
2220 }
2221
2222 free(g_temp_load);
2223 free(g_temp_pload);
2224 free(g_temp_pthroughput);
2225 free(g_temp_sharemem);
2226 free(module_ids);
2227
2228PRINT_OUTPUT:
2229 strcat_dyn_buf(&output_buf, " ]\n}\n");
2230 if (output_buf.str_buf)
2231 printf("%s", output_buf.str_buf);
2232 clear_dyn_str_buf(&output_buf);
2233}
2234
2236 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)
2237{
2238 int index, instance_count; // used in later FOR-loop when compiled without c99
2239 unsigned int i;
2240 unsigned int module_count;
2241 char module_name[MAX_DEVICE_NAME_SIZE] = {0};
2242 int32_t *module_id_arr = NULL;
2243 dyn_str_buf_t output_buf = {0};
2244 ni_device_context_t *p_device_context = NULL;
2245 ni_device_type_t module_type;
2246 int max_device_type = NI_DEVICE_TYPE_XCODER_MAX;
2247 char _ml[16];
2248
2249 if(detail)
2250 max_device_type = NI_DEVICE_TYPE_SCALER;
2251 for (module_type = NI_DEVICE_TYPE_DECODER;
2252 module_type != max_device_type;
2253 module_type++)
2254 {
2255 instance_count = 0;
2256 module_count = get_modules(module_type,
2257 coders,
2258 module_name,
2259 &module_id_arr);
2260
2261 if (!module_count)
2262 {
2263 continue;
2264 }
2265
2266 strcat_dyn_buf(&output_buf, "Num %ss: %u\n", module_name, module_count);
2267 if(detail)
2268 {
2269 if(module_type == NI_DEVICE_TYPE_DECODER)
2270 {
2271 if(checkInterval)
2272 {
2273 strcat_dyn_buf(&output_buf,
2274 "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n", "INDEX",
2275 "AvgCost", "FrameRate", "IDR", "InFrame", "OutFrame", "fps", "Width", "Height",
2276 "SID", "DEVICE", "NAMESPACE");
2277 }
2278 else
2279 {
2280 strcat_dyn_buf(&output_buf,
2281 "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n", "INDEX",
2282 "AvgCost", "FrameRate", "IDR", "InFrame", "OutFrame", "Width", "Height",
2283 "SID", "DEVICE", "NAMESPACE");
2284 }
2285 }
2286 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2287 {
2288 if(checkInterval)
2289 {
2290 strcat_dyn_buf(&output_buf,
2291 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n", "INDEX",
2292 "AvgCost", "FrameRate", "IDR", "UserIDR", "InFrame", "OutFrame", "fps", "BR", "AvgBR", "Width", "Height",
2293 "Format", "SID", "DEVICE", "NAMESPACE");
2294 }
2295 else
2296 {
2297 strcat_dyn_buf(&output_buf,
2298 "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n", "INDEX",
2299 "AvgCost", "FrameRate", "IDR", "UserIDR", "InFrame", "OutFrame", "BR", "AvgBR", "Width", "Height",
2300 "Format", "SID", "DEVICE", "NAMESPACE");
2301 }
2302 }
2303 }
2304 else
2305 strcat_dyn_buf(&output_buf,
2306 "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n", "INDEX",
2307 "LOAD", "MODEL_LOAD", "INST", "MEM", "SHARE_MEM", "P2P_MEM",
2308 "DEVICE");
2309
2311 for (i = 0; i < module_count; i++)
2312 {
2313 p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[i]);
2314
2316 if (open_and_query(module_type,
2317 p_device_context,
2318 sessionCtxt,
2319 module_name, detail, detail_data_v1))
2320 {
2321 if(detail)
2322 {
2323 for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
2324 {
2325 if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
2326 {
2327 if(previous_detail_data_p && checkInterval)
2328 {
2329 if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2330 {
2331 if(module_type == NI_DEVICE_TYPE_DECODER)
2332 {
2333 strcat_dyn_buf(&output_buf,
2334 "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2335 instance_count++,
2336 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2337 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2338 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2339 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2340 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2341 (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2342 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2343 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2344 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2345 p_device_context->p_device_info->dev_name,
2346 p_device_context->p_device_info->blk_name);
2347 }
2348 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2349 {
2350 strcat_dyn_buf(&output_buf,
2351 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2352 instance_count++,
2353 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2354 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2355 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2356 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2357 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2358 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2359 (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2360 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2361 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2362 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2363 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2364 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2365 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2366 p_device_context->p_device_info->dev_name,
2367 p_device_context->p_device_info->blk_name);
2368 }
2369 }
2370 }
2371 else
2372 {
2373 if(module_type == NI_DEVICE_TYPE_DECODER)
2374 {
2375 strcat_dyn_buf(&output_buf,
2376 "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2377 instance_count++,
2378 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2379 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2380 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2381 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2382 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2383 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2384 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2385 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2386 p_device_context->p_device_info->dev_name,
2387 p_device_context->p_device_info->blk_name);
2388 }
2389 else if (module_type == NI_DEVICE_TYPE_ENCODER)
2390 {
2391 strcat_dyn_buf(&output_buf,
2392 "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2393 instance_count++,
2394 detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2395 detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2396 detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2397 detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2398 detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2399 detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2400 detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2401 detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2402 detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2403 detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2404 get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2405 get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2406 p_device_context->p_device_info->dev_name,
2407 p_device_context->p_device_info->blk_name);
2408 }
2409 }
2410 }
2411 }
2412 if(previous_detail_data_p)
2413 {
2414 memcpy(&previous_detail_data_p[module_type][i], detail_data_v1, sizeof(ni_instance_mgr_detail_status_v1_t));
2415 }
2416 }
2417 else
2418 {
2419 if((module_type == NI_DEVICE_TYPE_DECODER) || (module_type == NI_DEVICE_TYPE_ENCODER))
2420 {
2421 strcat_dyn_buf(&output_buf,
2422 "%-5d %-4u %-10s %-4u %-4u %-9u %-7u %-14s\n",
2423 p_device_context->p_device_info->module_id,
2424#ifdef XCODER_311
2425 sessionCtxt->load_query.current_load,
2426#else
2427 (sessionCtxt->load_query.total_contexts == 0 || sessionCtxt->load_query.current_load > sessionCtxt->load_query.fw_load) ? sessionCtxt->load_query.current_load : sessionCtxt->load_query.fw_load,
2428#endif
2429 (sessionCtxt->load_query.fw_model_load == 4294967295U) ? "N/A" : (snprintf(_ml, sizeof(_ml), "%u", sessionCtxt->load_query.fw_model_load), _ml),
2430 sessionCtxt->load_query.total_contexts,
2431 sessionCtxt->load_query.fw_video_mem_usage,
2432 sessionCtxt->load_query.fw_share_mem_usage,
2433 sessionCtxt->load_query.fw_p2p_mem_usage,
2434 p_device_context->p_device_info->dev_name);
2435 }
2436 else
2437 {
2438 strcat_dyn_buf(&output_buf,
2439 "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2440 p_device_context->p_device_info->module_id,
2441#ifdef XCODER_311
2442 sessionCtxt->load_query.current_load,
2443#else
2444 (sessionCtxt->load_query.total_contexts == 0 || sessionCtxt->load_query.current_load > sessionCtxt->load_query.fw_load) ? sessionCtxt->load_query.current_load : sessionCtxt->load_query.fw_load,
2445#endif
2446 sessionCtxt->load_query.fw_model_load,
2447 sessionCtxt->load_query.total_contexts,
2448 sessionCtxt->load_query.fw_video_mem_usage,
2449 sessionCtxt->load_query.fw_share_mem_usage,
2450 sessionCtxt->load_query.fw_p2p_mem_usage,
2451 p_device_context->p_device_info->dev_name);
2452 }
2453 }
2454
2455 ni_rsrc_free_device_context(p_device_context);
2456 }
2457 }
2458 free(module_id_arr);
2459 }
2460
2461 if (output_buf.str_buf)
2462 printf("%s", output_buf.str_buf);
2463 clear_dyn_str_buf(&output_buf);
2464}
2465
2466void print_extra(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int internal_call, int show_qos_info)
2467{
2468 char device_name[MAX_DEVICE_NAME_SIZE];
2469 unsigned int index, device_count;
2470 int32_t *module_ids;
2471 dyn_str_buf_t output_buf = {0};
2472 ni_device_context_t *p_device_context;
2473 ni_device_type_t device_type;
2474 ni_device_extra_info_t p_dev_extra_info = {0};
2475 char power_consumption[16];
2476 int instance_count = 0;
2477#ifdef __linux__
2478 unsigned int gen3_mismatch_index[NI_MAX_DEVICE_CNT];
2479 unsigned int num_gen3_mismatch = 0;
2480#endif
2481
2482 ni_qos_header_info_log_page_t qos_header = {0};
2483 ni_qos_namespace_info_log_page_t qos_ns_info = {0};
2484 ni_device_vf_ns_id_t ns_vf_id = {0};
2485 bool has_qos_data = false;
2486 char qos_str[64] = {0};
2487 uint16_t namespace_id = 0;
2488
2489 // ASSUMPTION: Each Quadra has at least and only one encoder.
2490 device_type = NI_DEVICE_TYPE_ENCODER;
2491 device_count = get_modules(device_type,
2492 p_device_queue,
2493 device_name,
2494 &module_ids);
2495
2496 if (!device_count)
2497 {
2498 if (output_buf.str_buf)
2499 printf("%s", output_buf.str_buf);
2500 clear_dyn_str_buf(&output_buf);
2501 return;
2502 }
2503
2504 for (index = 0; index < device_count; index++)
2505 {
2506 p_device_context = ni_rsrc_get_device_context(device_type, module_ids[index]);
2507 if (!p_device_context)
2508 {
2509 continue;
2510 }
2511 // check if device has been opened already
2512 ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
2513 int module_id = p_device_context->p_device_info->module_id;
2514 if (device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2515 {
2516 p_session_context->device_handle =
2517 device_handles[xcoder_device_type][module_id];
2518 } else
2519 {
2520 p_session_context->device_handle =
2521 ni_device_open2(p_device_context->p_device_info->dev_name,
2523 if (p_session_context->device_handle != NI_INVALID_DEVICE_HANDLE)
2524 {
2525 device_handles[xcoder_device_type][module_id] =
2526 p_session_context->device_handle;
2527 }
2528 }
2529
2530 if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
2531 {
2532 char errmsg[NI_ERRNO_LEN] = {0};
2534 fprintf(stderr,
2535 "ERROR: ni_device_open2() failed for %s: %s\n",
2536 p_device_context->p_device_info->dev_name,
2537 errmsg);
2538 ni_rsrc_free_device_context(p_device_context);
2539 continue;
2540 }
2541
2542 if (ni_query_extra_info(p_session_context->device_handle,
2543 &p_dev_extra_info,
2544 p_device_context->p_device_info->fw_rev))
2545 {
2546 p_dev_extra_info.composite_temp = 0;
2547 }
2548
2549 if (p_dev_extra_info.power_consumption + 1)
2550 {
2551 ni_sprintf(power_consumption, 16, "%umW", p_dev_extra_info.power_consumption);
2552 }
2553
2554 if (show_qos_info)
2555 {
2556 if (ni_query_vf_ns_id(p_session_context->device_handle, &ns_vf_id,
2557 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2558 {
2559 namespace_id = ns_vf_id.ns_id;
2560 }
2561
2562 if (ni_query_qos_info(p_session_context->device_handle, &qos_header,
2563 p_device_context->p_device_info->fw_rev) == NI_RETCODE_SUCCESS)
2564 {
2565 has_qos_data = true;
2566 ni_query_qos_namespace_info(p_session_context->device_handle, &qos_ns_info,
2567 p_device_context->p_device_info->fw_rev);
2568 }
2569 }
2570
2571 if (show_qos_info && has_qos_data)
2572 {
2573 char _allowance[16];
2574 uint8_t qos_mode = (uint8_t)(qos_header.ui16QosState & 0xFF);
2575 float _opmax = (float) (qos_ns_info.ui32OPmaxUs * 100) / VIDEO_SLICE_TIME;
2576 snprintf(qos_str, sizeof(qos_str), " %-9u %-7u %-10s %-8.1f",
2577 (uint8_t)(qos_header.ui16QosState & 0xFF),
2578 namespace_id,
2579 (qos_mode == 0) ? "N/A" : (snprintf(_allowance, sizeof(_allowance), "%.1f", qos_ns_info.fAllowance), _allowance),
2580 (qos_mode == 0 ? 0 :_opmax));
2581 }
2582
2583 if (!internal_call)
2584 {
2585 strcat_dyn_buf(&output_buf,
2586 "%-4s %-8s %-8s %-14s %s\n", "TEMP", "POWER", "FLAVOR", "DEVICE",
2587 show_qos_info ? " QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" : "");
2588 strcat_dyn_buf(&output_buf,
2589 "%-4d %-8s %-8c %-14s %s\n",
2590 p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2591 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2592 p_dev_extra_info.fw_flavour,
2593 p_device_context->p_device_info->dev_name,
2594 qos_str);
2595 }
2596 else
2597 {
2598 if (instance_count == 0)
2599 {
2600 strcat_dyn_buf(&output_buf,
2601 "%-8s %-8s %-8s %-8s %-8.8s %-20.8s %s\n", "INDEX", "TEMP", "POWER", "FLAVOR", "FR", "SN",
2602 show_qos_info ? "QOS_MODE QOS_NS QOS_ALLOW QOS_OPMAX" : "");
2603 }
2604 strcat_dyn_buf(&output_buf,
2605 "%-8d %-8d %-8s %-8c %-8.8s %-8.*s %s\n",
2606 instance_count++ , p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2607 (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2608 p_dev_extra_info.fw_flavour,
2609 p_device_context->p_device_info->fw_rev,
2610 (int)sizeof(p_device_context->p_device_info->serial_number), p_device_context->p_device_info->serial_number,
2611 qos_str);
2612
2613 }
2614
2615#ifdef __linux__
2616 if (p_device_context->p_device_info->pcie_gen3_on_gen4_host == 1)
2617 {
2618 gen3_mismatch_index[num_gen3_mismatch++] = index;
2619 }
2620#endif
2621
2622 ni_rsrc_free_device_context(p_device_context);
2623 }
2624
2625#ifdef __linux__
2626 if (num_gen3_mismatch > 0)
2627 {
2628 char index_list[128] = {0};
2629 size_t len = 0;
2630 for (unsigned int i = 0; i < num_gen3_mismatch && len < sizeof(index_list) - 4; i++)
2631 {
2632 len += snprintf(index_list + len, sizeof(index_list) - len,
2633 "%s%u", (i > 0) ? ", " : "", gen3_mismatch_index[i]);
2634 }
2635 strcat_dyn_buf(&output_buf,
2636 "This system supports Gen4 PCIe speeds, but the following Quadra cards are "
2637 "currently running firmware that only supports PCIe Gen3 (Index: %s). "
2638 "All Quadra VPUs on this system can be firmware upgraded to support "
2639 "PCIe Gen 4 speeds, please update the firmware on each Quadra card to "
2640 "the default firmware flavor.\n",
2641 index_list);
2642 }
2643#endif
2644
2645 if (output_buf.str_buf)
2646 printf("%s", output_buf.str_buf);
2647 clear_dyn_str_buf(&output_buf);
2648 free(module_ids);
2649}
2650
2651int main(int argc, char *argv[])
2652{
2653 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2654 int checkInterval;
2655 int skip_init_rsrc = 0;
2656 int should_match_rev = 1;
2657 int detail = 0;
2658 ni_instance_mgr_detail_status_v1_t detail_data_v1 = {0};
2659 ni_instance_mgr_detail_status_v1_t (*previous_detail_data)[NI_DEVICE_TYPE_XCODER_MAX] = NULL;
2660 ni_device_pool_t *p_device_pool = NULL;
2661 ni_device_queue_t *coders = NULL;
2662 ni_session_context_t *p_xCtxt = NULL;
2663 time_t startTime = {0}, now = {0};
2664 int timeout_seconds = 0;
2665 struct tm *ltime = NULL;
2666 char buf[64] = {0};
2667 long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2668 int opt;
2669 ni_log_level_t log_level = NI_LOG_INFO;
2670 enum outFormat printFormat = FMT_TEXT;
2671 checkInterval = 0;
2672 bool fw_log_dump = false;
2673 bool core_reset_log_dump = false;
2674 int devid = -1;
2675 int refresh_device_pool = 1;
2676 bool is_first_query = true;
2677 int ret = 0;
2678 int show_qos_info = 0;
2679
2680#ifdef _WIN32
2681 SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2682#elif __linux__
2683 setup_signal_handler();
2684#endif
2685
2686 // arg handling
2687 while ((opt = getopt(argc, argv, "n:o:D:C:k:R:rt:Sl:hvdq")) != -1)
2688 {
2689 switch (opt)
2690 {
2691 case 'o':
2692 // Output print format
2693 if (!strcmp(optarg, "json"))
2694 {
2695 printFormat = FMT_JSON;
2696 }
2697 else if (!strcmp(optarg, "simple"))
2698 {
2699 printFormat = FMT_SIMPLE_TEXT;
2700 }
2701 else if (!strcmp(optarg, "text"))
2702 {
2703 printFormat = FMT_TEXT;
2704 }
2705 else if (!strcmp(optarg, "full"))
2706 {
2707 printFormat = FMT_FULL_TEXT;
2708 }
2709 else if (!strcmp(optarg, "json1"))
2710 {
2711 printFormat = FMT_JSON1;
2712 }
2713 else if (!strcmp(optarg, "json2"))
2714 {
2715 printFormat = FMT_JSON2;
2716 }
2717 else if (!strcmp(optarg, "extra"))
2718 {
2719 printFormat = FMT_EXTRA;
2720 }
2721 else
2722 {
2723 fprintf(stderr, "Error: unknown selection for outputFormat: %s\n", optarg);
2724 return 1;
2725 }
2726 break;
2727 case 'n':
2728 // Output interval
2729 checkInterval = atoi(optarg);
2730 break;
2731 case 'D':
2732 fw_log_dump = atoi(optarg);
2733 break;
2734 case 'C':
2735 core_reset_log_dump = atoi(optarg);
2736 if (core_reset_log_dump)
2737 fw_log_dump = true;
2738 break;
2739 case 'k':
2740 devid = atoi(optarg);
2741 break;
2742 case 'R':
2743 refresh_device_pool = atoi(optarg);
2744 case 'r':
2745 should_match_rev = 0;
2746 break;
2747 case 't':
2748 timeout_seconds = atoi(optarg);
2749 printf("Timeout will be set %d\n", timeout_seconds);
2750 break;
2751 case 'S':
2752 skip_init_rsrc = 1;
2753 break;
2754 case 'l':
2755 log_level = arg_to_ni_log_level(optarg);
2756 if (log_level != NI_LOG_INVALID)
2757 {
2758 ni_log_set_level(log_level);
2759 } else {
2760 fprintf(stderr, "FATAL: invalid log level selected: %s\n", optarg);
2761 return 1;
2762 }
2763 break;
2764 case 'q':
2765 show_qos_info = 1;
2766 break;
2767 case 'h':
2768 // help message (limit to 80 characters wide)
2769 printf("-------- ni_rsrc_mon v%s --------\n"
2770 "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
2771 "running on the system.\n"
2772 "\n"
2773 "Usage: ni_rsrc_mon [OPTIONS]\n"
2774 "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
2775 " report only once.\n"
2776 " Default: 0\n"
2777 "-R Specify if refresh devices on host in each monitor interval.\n"
2778 " If 0, only refresh devices at the start.\n"
2779 " Default: 1\n"
2780 "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
2781 " Default: text\n"
2782 "-D Dump firmware logs to current directory. Default: 0(not dump fw log).\n"
2783 "-C Dump firmware core reset logs to current directory. Default: 0(not dump fw log).\n"
2784 "-k Specify to dump which card's firmware logs.\n"
2785 " Default: -1(dump fw log of all cards).\n"
2786 "-r Initialize Quadra device regardless firmware release version to\n"
2787 " libxcoder version compatibility.\n"
2788 " Default: only initialize devices with compatible firmware version.\n"
2789 "-t Set timeout time in seconds for device polling. Program will exit with\n"
2790 " failure if timeout is reached without finding at least one device. If 0 or\n"
2791 " no selection, poll indefinitely until a Quadra device is found.\n"
2792 " Default: 0\n"
2793 "-S Skip init_rsrc.\n"
2794 "-d Print detailed information for decoder/encoder in text and json formats.\n"
2795 "-l Set loglevel of libxcoder API.\n"
2796 " [none, fatal, error, info, debug, trace]\n"
2797 " Default: info\n"
2798 "-q Show QoS information.\n"
2799 "-h Open this help message.\n"
2800 "-v Print version info.\n"
2801 "\n"
2802 "Simple output shows the maximum firmware load amongst the subsystems on the\n"
2803 "Quadra device.\n"
2804 "\n"
2805 "Reporting columns for text output format\n"
2806 "INDEX index number used by resource manager to identify the resource\n"
2807 "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
2808 "MODEL_LOAD estimated load based on framerate and resolution\n"
2809 "INST number of job instances\n"
2810 "MEM usage of memory by the subsystem\n"
2811 "SHARE_MEM usage of memory shared across subsystems on the same device\n"
2812 "P2P_MEM usage of memory by P2P\n"
2813 "DEVICE path to NVMe device file handle\n"
2814 "NAMESPACE path to NVMe namespace file handle\n"
2815 "Additional information only in text(Default) mode \n"
2816 "TEMP current temperature (degrees Celsius)\n"
2817 "POWER current power(mW), N/A when query power not supported\n"
2818 "FLAVOR current Flavor, N/A when query flavor not supported\n"
2819 "FR current firmware revision\n"
2820 "SN serial number of the Quadra device\n"
2821 "\n"
2822 "Additional reporting columns for full output format\n"
2823 "VPU same as LOAD in JSON outputs\n"
2824 "FW system load\n"
2825 "TOTAL same as MEM\n"
2826 "CRITICAL usage of memory considered critical\n"
2827 "L_FL2V last ran firmware loader 2 version\n"
2828 "N_FL2V nor flash firmware loader 2 version\n"
2829 "FR current firmware revision\n"
2830 "N_FR nor flash firmware revision\n"
2831 "Unique field PCIe_Card2Host_Gbps for PCIE throughput from card to host in GBps(Values in steps of 100 Mbps)\n"
2832 "\n"
2833 "Additional reporting columns for full JSON formats\n"
2834 "LOAD VPU load\n"
2835 "FW_LOAD system load\n"
2836 "\n"
2837 "Extra output shows TEMP and POWER and FLAVOR of the Quadra device \n",
2839 return 0;
2840 case 'v':
2841 printf("Release ver: %s\n"
2842 "API ver: %s\n"
2843 "Date: %s\n"
2844 "ID: %s\n",
2847 return 0;
2848 case '?':
2849 if (isprint(opt))
2850 {
2851 fprintf(stderr, "FATAL: unknown option '-%c'\n", opt);
2852 } else
2853 {
2854 fprintf(stderr, "FATAL: unknown option character '\\x%x'\n", opt);
2855 }
2856 return 1;
2857 case 'd':
2858 detail = 1;
2859 break;
2860 case ':':
2861 fprintf(stderr, "FATAL: option '-%c' lacks arg\n", opt);
2862 return 1;
2863 default:
2864 fprintf(stderr, "FATAL: unhandled option\n");
2865 return 1;
2866 }
2867 }
2868
2869 if(checkInterval > 0 && printFormat == FMT_JSON)
2870 {
2871 fprintf(stderr, "EXIT: -o json cannot use with -n params\n");
2872 return 1;
2873 }
2874
2875 if ((argc <= 2) && (optind == 1))
2876 {
2877 for (; optind < argc; optind++)
2878 {
2879 checkInterval = argToI(argv[optind]);
2880 }
2881 }
2882
2883#ifdef _ANDROID
2884 ni_log_set_log_tag(LOG_TAG);
2885#endif
2886
2888 if(!p_xCtxt)
2889 {
2890 fprintf(stderr, "FATAL: cannot allocate momory for ni_session_context_t\n");
2891 return 1;
2892 }
2893
2894 ni_log_set_level(NI_LOG_ERROR); // silence informational prints
2895 if (!skip_init_rsrc && (ret = ni_rsrc_init(should_match_rev,timeout_seconds)) != 0)
2896 {
2898 ni_rsrc_refresh(should_match_rev);
2899 fprintf(stderr, "FATAL: NI resource unavailable\n");
2900#if defined(__linux__)
2901 if (fw_log_dump)
2902 {
2903 fprintf(stderr, "Proceeding to dump firmware logs as root\n");
2904 if (geteuid() != 0)
2905 {
2906 fprintf(stderr, "This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
2907 exit(1);
2908 }
2909 int rc = ni_rsrc_log_dump(".", core_reset_log_dump);
2910 if (rc == 0)
2911 fprintf(stderr, "Firmware log dump: all devices successful.\n");
2912 else if (rc == 1)
2913 fprintf(stderr, "Firmware log dump: No Quadra devices found. Nothing to dump.\n");
2914 else if (rc == 2)
2915 fprintf(stderr, "Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
2916 else
2917 fprintf(stderr, "Firmware log dump: Unexpected error, return code %d\n", rc);
2918 }
2919#endif
2920 ret = 0;
2921 } else
2922 {
2923 ret = 1;
2924 fprintf(stderr, "FATAL: cannot access NI resource\n");
2925 }
2926 LRETURN;
2927 }
2928 ni_log_set_level(log_level);
2929
2930 p_device_pool = ni_rsrc_get_device_pool();
2931 if (!p_device_pool)
2932 {
2933 fprintf(stderr, "FATAL: cannot get devices info\n");
2934 ret = 1;
2935 LRETURN;
2936 }
2937
2938 if (log_level >= NI_LOG_INFO)
2939 {
2940 printf("**************************************************\n");
2941 }
2942
2943 // initialise device handles
2944 for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
2945 {
2946 for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
2947 {
2948 device_handles[i][j] = NI_INVALID_DEVICE_HANDLE;
2949 }
2950 }
2951
2952 startTime = time(NULL);
2953 if(checkInterval)
2954 {
2956 previous_detail_data = (ni_instance_mgr_detail_status_v1_t (*)[NI_DEVICE_TYPE_XCODER_MAX])malloc(allocate_size);
2957 if(previous_detail_data == NULL)
2958 {
2959 fprintf(stderr, "FATAL: Allocate buffer fail\n");
2960 ret = 1;
2961 LRETURN;
2962 }
2963 memset((void *)previous_detail_data, 0, allocate_size);
2964 }
2965 while (!g_xcoder_stop_process)
2966 {
2967 now = time(NULL);
2968 struct tm temp_time;
2969 ltime = ni_localtime(&temp_time, &now);
2970 if (ltime)
2971 {
2972 strftime(buf, sizeof(buf), "%c", ltime);
2973 }
2974 time_diff_seconds = (long long)difftime(now, startTime);
2975 time_diff_minutes = time_diff_seconds / 60;
2976 time_diff_hours = time_diff_minutes / 60;
2977
2978
2979 if (is_first_query || refresh_device_pool)
2980 {
2981 ni_rsrc_refresh(should_match_rev);
2982 }
2983
2984 if (log_level >= NI_LOG_INFO)
2985 {
2986 printf("%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
2988 }
2989
2992#ifdef _WIN32
2993 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
2994 {
2995 fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
2996 ret = 1;
2997 LRETURN;
2998 }
2999#elif __linux__
3000 if ( lockf(p_device_pool->lock, F_LOCK, 0) )
3001 {
3002 perror("ERROR: cannot lock p_device_pool");
3003 }
3004#endif
3005
3006 coders = p_device_pool->p_device_queue;
3007
3008#ifdef _WIN32
3009 ReleaseMutex((HANDLE)p_device_pool->lock);
3010#elif __linux__
3011 if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
3012 {
3013 perror("ERROR: cannot unlock p_device_pool");
3014 }
3015#endif
3016
3017 switch (printFormat)
3018 {
3019 case FMT_TEXT:
3020 print_extra(coders, p_xCtxt, 1, show_qos_info);
3021 print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
3022 break;
3023 case FMT_FULL_TEXT:
3024 show_qos_info=1;
3025 print_extra(coders, p_xCtxt, 1, show_qos_info);
3026 print_full_text(coders, p_xCtxt, 0, &detail_data_v1);
3027 break;
3028 case FMT_SIMPLE_TEXT:
3029 print_simple_text(coders, p_xCtxt, 0, &detail_data_v1);
3030 break;
3031 case FMT_JSON:
3032 print_json(coders, p_xCtxt, detail, &detail_data_v1);
3033 break;
3034 case FMT_JSON1:
3035 if(!detail)
3036 {
3037 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
3038 }
3039 else
3040 {
3041 print_json_detail(coders, p_xCtxt, &detail_data_v1);
3042 }
3043 break;
3044 case FMT_JSON2:
3045 if(!detail)
3046 {
3047 print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
3048 }
3049 else
3050 {
3051 print_json_detail(coders, p_xCtxt, &detail_data_v1);
3052 }
3053 break;
3054 case FMT_EXTRA:
3055 print_extra(coders, p_xCtxt, 0, show_qos_info);
3056 break;
3057 }
3058
3059 is_first_query = false;
3060
3061 if (log_level >= NI_LOG_INFO)
3062 {
3063 printf("**************************************************\n");
3064 }
3065
3066 fflush(stdout);
3067
3068 if (checkInterval == 0)
3069 {
3070 // run once
3071 break;
3072 }
3073 ni_usleep(checkInterval * 1000 * 1000);
3074 }
3075
3076 if (fw_log_dump)
3077 {
3078 // dump fw log
3079#ifdef _WIN32
3080 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
3081 {
3082 fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
3083 ret = 1;
3084 LRETURN;
3085 }
3086#elif __linux__
3087 if ( lockf(p_device_pool->lock, F_LOCK, 0) )
3088 {
3089 perror("ERROR: cannot lock p_device_pool");
3090 }
3091#endif
3092 coders = p_device_pool->p_device_queue;
3093#ifdef _WIN32
3094 ReleaseMutex((HANDLE)p_device_pool->lock);
3095#elif __linux__
3096 if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
3097 {
3098 perror("ERROR: cannot unlock p_device_pool");
3099 }
3100#endif
3101#if defined(__linux__)
3102 if (core_reset_log_dump)
3103 {
3104 fprintf(stderr, "Proceeding to dump firmware logs as root\n");
3105 if (geteuid() != 0)
3106 {
3107 fprintf(stderr, "This operation requires root (sudo). Please rerun: sudo %s \n", argv[0]);
3108 exit(1);
3109 }
3110 int rc = ni_rsrc_log_dump(".", core_reset_log_dump);
3111 if (rc == 0)
3112 fprintf(stderr, "Firmware log dump: all devices successful.\n");
3113 else if (rc == 1)
3114 fprintf(stderr, "Firmware log dump: No Quadra devices found. Nothing to dump.\n");
3115 else if (rc == 2)
3116 fprintf(stderr, "Firmware log dump: One or more device logs failed to dump. Check previous error messages for details.\n");
3117 else
3118 fprintf(stderr, "Firmware log dump: Unexpected error, return code %d\n", rc);
3119 }
3120 else
3121#endif
3122 {
3123 dump_fw_log(coders, p_xCtxt, devid);
3124 }
3125 }
3126
3127 // close all opened devices
3128 for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
3129 {
3130 for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
3131 {
3132 if (device_handles[i][j] != NI_INVALID_DEVICE_HANDLE)
3133 {
3135 }
3136 }
3137 }
3138
3139#ifdef __OPENHARMONY__
3140 system("chmod -R 777 /dev/shm/");
3141#ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
3142 system("chmod 777 /dev/block/vd* 2>/dev/null");
3143#endif
3144#elif defined(_ANDROID)
3145 system("chmod -R 777 /dev/shm/");
3146 system("chmod 777 /dev/block/nvme* 2>/dev/null");
3147 system("chmod 777 /dev/nvme* 2>/dev/null");
3148 property_set("ni_rsrc_init_completed", "yes");
3149#endif
3150
3151END:
3152 if(checkInterval && previous_detail_data)
3153 {
3154 free(previous_detail_data);
3155 }
3157 ni_rsrc_free_device_pool(p_device_pool);
3158 free(p_xCtxt);
3159 return ret;
3160}
#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:432
#define LRETURN
Definition ni_defs.h:337
ni_retcode_t
Definition ni_defs.h:445
@ NI_RETCODE_SUCCESS
Definition ni_defs.h:446
@ NI_RETCODE_ERROR_RESOURCE_UNAVAILABLE
Definition ni_defs.h:453
#define IS_XCODER_DEVICE_TYPE(t)
Definition ni_defs.h:429
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_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...
#define atoi(p_str)
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 getopt(int argc, char *argv[], const char *optstring)
Definition ni_getopt.c:38
int optind
Definition ni_getopt.c:34
char * optarg
Definition ni_getopt.c:33
Implementation of getopt() and getopt_long() for Windows environment.
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
#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
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:58
char * get_pixel_format(ni_device_context_t *p_device_context, int index)
uint32_t * g_temp_pthroughput
Definition ni_rsrc_mon.c:60
#define DYN_STR_BUF_CHUNK_SIZE
#define NP_LOAD
Definition ni_rsrc_mon.c:50
uint32_t * g_temp_sharemem
Definition ni_rsrc_mon.c:61
#define MAX_DEVICE_NAME_SIZE
Definition ni_rsrc_mon.c:48
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:59
#define TP_LOAD
Definition ni_rsrc_mon.c:51
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:56
@ FMT_JSON2
Definition ni_rsrc_mon.c:80
@ FMT_JSON
Definition ni_rsrc_mon.c:78
@ FMT_SIMPLE_TEXT
Definition ni_rsrc_mon.c:77
@ FMT_FULL_TEXT
Definition ni_rsrc_mon.c:76
@ FMT_EXTRA
Definition ni_rsrc_mon.c:81
@ FMT_JSON1
Definition ni_rsrc_mon.c:79
@ FMT_TEXT
Definition ni_rsrc_mon.c:75
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:64
bool swap_encoder_and_uploader(ni_device_type_t *p_device_type, char *device_name)
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:52
void dump_fw_log(ni_device_queue_t *coders, ni_session_context_t *sessionCtxt, int devid)
unsigned int get_modules(ni_device_type_t device_type, ni_device_queue_t *p_device_queue, char *device_name, int32_t **module_ids)
void print_json(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 ABSOLUTE_TEMP_ZERO
Definition ni_rsrc_mon.c:49
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:518
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition ni_util.c:656
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition ni_util.c:453
void ni_usleep(int64_t usec)
Definition ni_util.c:362
struct tm * ni_localtime(struct tm *dest, const time_t *src)
Definition ni_util.c:1003
int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args)
Definition ni_util.c:1040
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
Definition ni_util.c:1063
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:4302
Utility definitions.
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