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