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