libxcoder  5.3.1
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 = ni_rsrc_get_device_context(device_type,
868  module_ids[index]);
869  if (icore == NP_LOAD)
870  {
871  if (!open_and_query(device_type,
872  p_device_context,
873  p_session_context,
874  device_name, detail, detail_data_v1))
875  {
876  continue;
877  }
878 
879  return_code = ni_query_nvme_status(p_session_context, &load_query);
880  if (return_code != NI_RETCODE_SUCCESS)
881  {
882  fprintf(stderr,
883  "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
884  return_code,
885  device_name,
886  p_device_context->p_device_info->dev_name,
887  p_device_context->p_device_info->hw_id);
888  remove_device_from_saved(device_type,
889  p_device_context->p_device_info->module_id,
890  p_session_context->device_handle);
891  ni_device_close(p_session_context->device_handle);
892  goto CLOSE;
893  }
894  g_temp_load[index] = load_query.tp_fw_load;
895  g_temp_pload[index] = load_query.pcie_load;
896  g_temp_pthroughput[index] = load_query.pcie_throughput;
897  g_temp_sharemem[index] = load_query.fw_share_mem_usage;
898  }
899  if (icore==PCIE_LOAD)
900  {
901  load_query.fw_load = g_temp_pload[index];
902  load_query.fw_share_mem_usage = g_temp_pthroughput[index];
903 
904  strcat_dyn_buf(&output_buf,
905  "%-5d %-3u %-3.1f "
906  "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
907  p_device_context->p_device_info->module_id,
908  load_query.fw_load,
909  (float)load_query.fw_share_mem_usage/10,
910  p_device_context->p_device_info->dev_name,
911  p_device_context->p_device_info->fl_ver_last_ran,
912  p_device_context->p_device_info->fl_ver_nor_flash,
913  p_device_context->p_device_info->fw_rev,
914  p_device_context->p_device_info->fw_rev_nor_flash);
915  }
916  else
917  {
918  load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
919  load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
920 
921  strcat_dyn_buf(&output_buf,
922  "%-5d %-3u %-3u "
923  "%-11s %-8.8s %-8.8s %-8.8s %-8.8s\n",
924  p_device_context->p_device_info->module_id,
925  load_query.fw_load,
926  load_query.fw_share_mem_usage,
927  p_device_context->p_device_info->dev_name,
928  p_device_context->p_device_info->fl_ver_last_ran,
929  p_device_context->p_device_info->fl_ver_nor_flash,
930  p_device_context->p_device_info->fw_rev,
931  p_device_context->p_device_info->fw_rev_nor_flash);
932  }
933 
934  CLOSE:
935  ni_rsrc_free_device_context(p_device_context);
936  }
937  }
938 
939  free(g_temp_load);
940  free(g_temp_pload);
941  free(g_temp_pthroughput);
942  free(g_temp_sharemem);
943  free(module_ids);
944 
945 PRINT_OUTPUT:
946  if (output_buf.str_buf)
947  printf("%s", output_buf.str_buf);
948  clear_dyn_str_buf(&output_buf);
949 }
950 
952  ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
953 {
954  bool copied_block_name;
955  char block_name[NI_MAX_DEVICE_NAME_LEN] = {0};
956  char device_name[MAX_DEVICE_NAME_SIZE] = {0};
957  int guid;
958  unsigned int number_of_quadras;
959  unsigned int number_of_device_types_present;
960  unsigned int device_type_counter;
961  unsigned int *maximum_firmware_loads;
962  unsigned int *maximum_firmware_loads_per_quadra;
963  dyn_str_buf_t output_buf = {0};
964 
965  ni_device_context_t *p_device_context;
966  ni_device_type_t device_type;
967  ni_device_type_t maximum_device_type;
968  ni_load_query_t load_query;
969  ni_retcode_t return_code;
970 
971  // Use NI_DEVICE_TYPE_ENCODER instead of NI_DEVICE_TYPE_NVME
972  // so that Quadras running older firmware will show up.
973  // Assumption: Each Quadra has at least one encoder.
974  number_of_quadras = p_device_queue->xcoder_cnt[NI_DEVICE_TYPE_ENCODER];
975 
976  maximum_firmware_loads = calloc(number_of_quadras, sizeof(unsigned int));
977  if (!maximum_firmware_loads)
978  {
979  fprintf(stderr, "calloc() returned NULL\n");
980  return;
981  }
982 
983  maximum_firmware_loads_per_quadra = NULL;
984  p_device_context = NULL;
985 
986  for (guid = 0; guid < number_of_quadras; guid++)
987  {
988  maximum_device_type = NI_DEVICE_TYPE_XCODER_MAX;
989  maximum_firmware_loads_per_quadra = maximum_firmware_loads + guid;
990  number_of_device_types_present = 0;
991  device_type_counter = 0;
992  copied_block_name = false;
993 
994  for (device_type = NI_DEVICE_TYPE_DECODER;
995  device_type < maximum_device_type;
996  device_type++)
997  {
998  if (p_device_queue->xcoders[device_type][guid] != -1)
999  {
1000  number_of_device_types_present++;
1001  }
1002  }
1003 
1004  for (device_type = NI_DEVICE_TYPE_DECODER;
1005  device_type < maximum_device_type;
1006  device_type++)
1007  {
1008  memcpy(device_name,
1009  g_device_type_str[device_type],
1011 
1012  if (p_device_queue->xcoders[device_type][guid] == -1)
1013  {
1014  continue;
1015  }
1016 
1017  p_device_context =
1018  ni_rsrc_get_device_context(device_type,
1019  p_device_queue->xcoders[device_type][guid]);
1020  if (!open_and_query(device_type,
1021  p_device_context,
1022  p_session_context,
1023  device_name, detail, detail_data_v1))
1024  {
1025  continue;
1026  }
1027 
1028  if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
1029  "6O") < 0)
1030  {
1031  if (maximum_device_type == NI_DEVICE_TYPE_XCODER_MAX)
1032  {
1033  strcat_dyn_buf(&output_buf,
1034  "%s: Simple output not supported. Try '-o full' "
1035  "instead.\n",
1036  p_device_context->p_device_info->dev_name);
1037  maximum_device_type = NI_DEVICE_TYPE_ENCODER;
1038  }
1039  ni_device_close(p_session_context->device_handle);
1040  ni_rsrc_free_device_context(p_device_context);
1041  continue;
1042  }
1043 
1044  if (!copied_block_name)
1045  {
1046  strncpy(block_name,
1047  p_device_context->p_device_info->dev_name,
1049  copied_block_name = true;
1050  }
1051 
1052  if (*maximum_firmware_loads_per_quadra < p_session_context->load_query.fw_load)
1053  {
1054  *maximum_firmware_loads_per_quadra = p_session_context->load_query.fw_load;
1055  }
1056 
1057  device_type_counter++;
1058  if (device_type_counter < number_of_device_types_present)
1059  {
1060  remove_device_from_saved(device_type,
1061  p_device_context->p_device_info->module_id,
1062  p_session_context->device_handle);
1063  ni_device_close(p_session_context->device_handle);
1064  ni_rsrc_free_device_context(p_device_context);
1065  }
1066  }
1067 
1068  if (maximum_device_type == NI_DEVICE_TYPE_ENCODER)
1069  {
1070  continue;
1071  }
1072 
1073  //Nvme and TP load
1074  {
1075  return_code =
1076  ni_query_nvme_status(p_session_context, &load_query);
1077  if (return_code == NI_RETCODE_SUCCESS)
1078  {
1079  if (*maximum_firmware_loads_per_quadra < load_query.fw_load)
1080  {
1081  *maximum_firmware_loads_per_quadra = load_query.fw_load;
1082  }
1083  if (*maximum_firmware_loads_per_quadra < load_query.tp_fw_load)
1084  {
1085  *maximum_firmware_loads_per_quadra = load_query.tp_fw_load;
1086  }
1087  strcat_dyn_buf(&output_buf, "%s: %u%%\n", block_name,
1088  *maximum_firmware_loads_per_quadra);
1089  }
1090  else
1091  {
1092  fprintf(
1093  stderr, "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1094  return_code, device_name, p_device_context->p_device_info->dev_name,
1095  p_device_context->p_device_info->hw_id);
1096  remove_device_from_saved(device_type,
1097  p_device_context->p_device_info->module_id,
1098  p_session_context->device_handle);
1099  ni_device_close(p_session_context->device_handle);
1100  }
1101  }
1102 
1103  ni_rsrc_free_device_context(p_device_context);
1104  }
1105 
1106  if (output_buf.str_buf)
1107  printf("%s", output_buf.str_buf);
1108  clear_dyn_str_buf(&output_buf);
1109  free(maximum_firmware_loads);
1110 }
1111 
1112 void print_json_detail(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
1113 {
1114  char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1115  unsigned int index, device_count;
1116  int instance_count;
1117  int32_t *module_ids;
1118 
1119  int detail = 1;
1120 
1121  dyn_str_buf_t output_buf = {0};
1122  ni_device_context_t *p_device_context;
1123  ni_device_type_t device_type;
1124  int max_device_type = NI_DEVICE_TYPE_SCALER;
1125  int first_item_printed = 0;
1126  int first_device_type_printed = 0;
1127 
1128  strcat_dyn_buf(&output_buf, "{\n");
1129 
1130  for (device_type = NI_DEVICE_TYPE_DECODER;
1131  device_type != max_device_type;
1132  device_type++)
1133  {
1134  instance_count = 0;
1135  device_count = get_modules(device_type,
1136  p_device_queue,
1137  device_name,
1138  &module_ids);
1139  if (!device_count)
1140  {
1141  continue;
1142  }
1143 
1144  for (index = 0; index < device_count; index++)
1145  {
1146  p_device_context =
1147  ni_rsrc_get_device_context(device_type,
1148  module_ids[index]);
1149  if (!open_and_query(device_type,
1150  p_device_context,
1151  p_session_context,
1152  device_name, detail, detail_data_v1))
1153  {
1154  continue;
1155  }
1156 
1157  if(first_device_type_printed)
1158  {
1159  strcat_dyn_buf(&output_buf, ",\n");
1160  }
1161 
1162  strcat_dyn_buf(&output_buf,
1163  "\t\"%s\" :"
1164  "[\n",
1165  device_name
1166  );
1167  first_item_printed = 0;
1168  for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
1169  {
1170  if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
1171  {
1172  if(first_item_printed)
1173  {
1174  strcat_dyn_buf(&output_buf, ",\n");
1175  }
1176 
1177  if(device_type == NI_DEVICE_TYPE_DECODER)
1178  {
1179  strcat_dyn_buf(&output_buf,
1180  "\t\t{\n"
1181  "\t\t\t\"NUMBER\": %u,\n"
1182  "\t\t\t\"INDEX\": %u,\n"
1183  "\t\t\t\"AvgCost\": %u,\n"
1184  "\t\t\t\"FrameRate\": %u,\n"
1185  "\t\t\t\"IDR\": %u,\n"
1186  "\t\t\t\"InFrame\": %u,\n"
1187  "\t\t\t\"OutFrame\": %u,\n"
1188  "\t\t\t\"Width\": %u,\n"
1189  "\t\t\t\"Height\": %u,\n"
1190  "\t\t\t\"SID\": \"%s\",\n"
1191  "\t\t\t\"DEVICE\": \"%s\"\n"
1192  "\t\t}",
1193  device_count,
1194  instance_count++,
1195  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1196  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1197  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1198  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1199  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1200  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1201  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1202  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1203  p_device_context->p_device_info->dev_name);
1204  }
1205  else if (device_type == NI_DEVICE_TYPE_ENCODER)
1206  {
1207  strcat_dyn_buf(&output_buf,
1208  "\t\t{\n"
1209  "\t\t\t\"NUMBER\": %u,\n"
1210  "\t\t\t\"INDEX\": %u,\n"
1211  "\t\t\t\"AvgCost\": %u,\n"
1212  "\t\t\t\"FrameRate\": %u,\n"
1213  "\t\t\t\"IDR\": %u,\n"
1214  "\t\t\t\"UserIDR\": %u,\n"
1215  "\t\t\t\"InFrame\": %u,\n"
1216  "\t\t\t\"OutFrame\": %u,\n"
1217  "\t\t\t\"BR\": %u,\n"
1218  "\t\t\t\"AvgBR\": %u,\n"
1219  "\t\t\t\"Width\": %u,\n"
1220  "\t\t\t\"Height\": %u,\n"
1221  "\t\t\t\"Format\": \"%s\",\n"
1222  "\t\t\t\"SID\": \"%s\",\n"
1223  "\t\t\t\"DEVICE\": \"%s\"\n"
1224  "\t\t}",
1225  device_count,
1226  instance_count++,
1227  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1228  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1229  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1230  detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
1231  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1232  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1233  detail_data_v1->sInstDetailStatus[index].ui32BitRate,
1234  detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
1235  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1236  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1237  get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
1238  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1239  p_device_context->p_device_info->dev_name);
1240  }
1241  first_item_printed = 1;
1242  }
1243  }
1244  strcat_dyn_buf(&output_buf, "\n");
1245  strcat_dyn_buf(&output_buf,
1246  "\t]"
1247  );
1248  first_device_type_printed = 1;
1249  }
1250  }
1251 
1252  strcat_dyn_buf(&output_buf, "\n");
1253  strcat_dyn_buf(&output_buf, "}\n");
1254 
1255  if(output_buf.str_buf)
1256  {
1257  printf("%s", output_buf.str_buf);
1258  }
1259 
1260  clear_dyn_str_buf(&output_buf);
1261 
1262 }
1263 
1264 void print_json(ni_device_queue_t *p_device_queue,
1265  ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
1266 {
1267  char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1268  unsigned int index, device_count;
1269  int instance_count;
1270  int32_t *module_ids;
1271  uint32_t total_contexts;
1272  uint32_t vpu_load;
1273  uint32_t model_load;
1274 #ifdef __linux__
1275  char pcie[64] = {0};
1276  int numa_node;
1277 #endif
1278  dyn_str_buf_t output_buf = {0};
1279 
1280  ni_device_context_t *p_device_context;
1281  ni_device_type_t device_type;
1282  ni_load_query_t load_query;
1283  ni_retcode_t return_code;
1284  int max_device_type = NI_DEVICE_TYPE_XCODER_MAX;
1285  if(detail)
1286  max_device_type = NI_DEVICE_TYPE_SCALER;
1287 
1288  for (device_type = NI_DEVICE_TYPE_DECODER;
1289  device_type != max_device_type;
1290  device_type++)
1291  {
1292  instance_count = 0;
1293  device_count = get_modules(device_type,
1294  p_device_queue,
1295  device_name,
1296  &module_ids);
1297  if (!device_count)
1298  {
1299  continue;
1300  }
1301 
1302 UPLOADER:
1303  for (index = 0; index < device_count; index++)
1304  {
1305  p_device_context =
1306  ni_rsrc_get_device_context(device_type,
1307  module_ids[index]);
1308  if (!open_and_query(device_type,
1309  p_device_context,
1310  p_session_context,
1311  device_name, detail, detail_data_v1))
1312  {
1313  continue;
1314  }
1315 
1316  if (device_type == NI_DEVICE_TYPE_UPLOAD)
1317  {
1318  total_contexts = p_session_context->load_query.active_hwuploaders;
1319  vpu_load = 0;
1320  model_load = 0;
1321  }
1322  else
1323  {
1324  total_contexts = p_session_context->load_query.total_contexts;
1325  vpu_load = p_session_context->load_query.current_load;
1326  model_load = p_session_context->load_query.fw_model_load;
1327  }
1328 #ifdef __linux__
1329  get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1330  numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1331 #endif
1332 
1333  if(detail)
1334  {
1335  strcat_dyn_buf(&output_buf,
1336  "{ \"%s\" :\n"
1337  "\t[\n",
1338  device_name
1339  );
1340  for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
1341  {
1342  if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
1343  {
1344  if(device_type == NI_DEVICE_TYPE_DECODER)
1345  {
1346  strcat_dyn_buf(&output_buf,
1347  "\t\t{\n"
1348  "\t\t\t\"NUMBER\": %u,\n"
1349  "\t\t\t\"INDEX\": %u,\n"
1350  "\t\t\t\"AvgCost\": %u,\n"
1351  "\t\t\t\"FrameRate\": %u,\n"
1352  "\t\t\t\"IDR\": %u,\n"
1353  "\t\t\t\"InFrame\": %u,\n"
1354  "\t\t\t\"OutFrame\": %u,\n"
1355  "\t\t\t\"Width\": %u,\n"
1356  "\t\t\t\"Height\": %u,\n"
1357  "\t\t\t\"SID\": %s,\n"
1358  "\t\t\t\"DEVICE\": \"%s\",\n"
1359  "\t\t},\n",
1360  device_count,
1361  instance_count++,
1362  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1363  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1364  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1365  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1366  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1367  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1368  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1369  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1370  p_device_context->p_device_info->dev_name);
1371  }
1372  else if (device_type == NI_DEVICE_TYPE_ENCODER)
1373  {
1374  strcat_dyn_buf(&output_buf,
1375  "\t\t{\n"
1376  "\t\t\t\"NUMBER\": %u,\n"
1377  "\t\t\t\"INDEX\": %u,\n"
1378  "\t\t\t\"AvgCost\": %u,\n"
1379  "\t\t\t\"FrameRate\": %u,\n"
1380  "\t\t\t\"IDR\": %u,\n"
1381  "\t\t\t\"UserIDR\": %u,\n"
1382  "\t\t\t\"InFrame\": %u,\n"
1383  "\t\t\t\"OutFrame\": %u,\n"
1384  "\t\t\t\"BR\": %u,\n"
1385  "\t\t\t\"AvgBR\": %u,\n"
1386  "\t\t\t\"Width\": %u,\n"
1387  "\t\t\t\"Height\": %u,\n"
1388  "\t\t\t\"Format\": %s,\n"
1389  "\t\t\t\"SID\": %s,\n"
1390  "\t\t\t\"DEVICE\": \"%s\",\n"
1391  "\t\t},\n",
1392  device_count,
1393  instance_count++,
1394  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
1395  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
1396  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
1397  detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
1398  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
1399  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
1400  detail_data_v1->sInstDetailStatus[index].ui32BitRate,
1401  detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
1402  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
1403  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
1404  get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
1405  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
1406  p_device_context->p_device_info->dev_name);
1407  }
1408  }
1409  }
1410  strcat_dyn_buf(&output_buf,
1411  "\t]\n"
1412  "}\n"
1413  );
1414  }
1415  else
1416  {
1417  if (p_session_context->overall_load_query.admin_queried &&
1418  device_type != NI_DEVICE_TYPE_UPLOAD)
1419  {
1420  strcat_dyn_buf(&output_buf,
1421  "{ \"%s\" :\n"
1422  "\t[\n"
1423  "\t\t{\n"
1424  "\t\t\t\"NUMBER\": %u,\n"
1425  "\t\t\t\"INDEX\": %d,\n"
1426  "\t\t\t\"LOAD\": %u,\n"
1427  "\t\t\t\"LOAD-ALL\": %u,\n"
1428  "\t\t\t\"MODEL_LOAD\": %u,\n"
1429  "\t\t\t\"MODEL_LOAD-ALL\": %u,\n"
1430  "\t\t\t\"FW_LOAD\": %u,\n"
1431  "\t\t\t\"INST\": %u,\n"
1432  "\t\t\t\"INST-ALL\": %u,\n"
1433  "\t\t\t\"MAX_INST\": %d,\n"
1434  "\t\t\t\"MEM\": %u,\n"
1435  "\t\t\t\"CRITICAL_MEM\": %u,\n"
1436  "\t\t\t\"SHARE_MEM\": %u,\n"
1437  "\t\t\t\"P2P_MEM\": %u,\n"
1438  "\t\t\t\"DEVICE\": \"%s\",\n"
1439  "\t\t\t\"L_FL2V\": \"%s\",\n"
1440  "\t\t\t\"N_FL2V\": \"%s\",\n"
1441  "\t\t\t\"FR\": \"%.8s\",\n"
1442  "\t\t\t\"N_FR\": \"%.8s\""
1443 #ifdef __linux__
1444  ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1445  "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1446 #else
1447  ",\n"
1448 #endif
1449  "\t\t}\n"
1450  "\t]\n"
1451  "}\n",
1452  device_name, device_count,
1453  p_device_context->p_device_info->module_id,
1454  vpu_load,
1455  p_session_context->overall_load_query.overall_current_load,
1456  model_load,
1457  p_session_context->overall_load_query.overall_fw_model_load,
1458  p_session_context->load_query.fw_load, total_contexts,
1459  p_session_context->overall_load_query.overall_instance_count,
1460  p_device_context->p_device_info->max_instance_cnt,
1461  p_session_context->load_query.fw_video_mem_usage,
1462  p_session_context->load_query.fw_video_shared_mem_usage,
1463  p_session_context->load_query.fw_share_mem_usage,
1464  p_session_context->load_query.fw_p2p_mem_usage,
1465  p_device_context->p_device_info->dev_name,
1466  p_device_context->p_device_info->fl_ver_last_ran,
1467  p_device_context->p_device_info->fl_ver_nor_flash,
1468  p_device_context->p_device_info->fw_rev,
1469  p_device_context->p_device_info->fw_rev_nor_flash
1470 #ifdef __linux__
1471  ,
1472  numa_node, pcie
1473 #endif
1474  );
1475  }
1476  else
1477  {
1478  strcat_dyn_buf(&output_buf,
1479  "{ \"%s\" :\n"
1480  "\t[\n"
1481  "\t\t{\n"
1482  "\t\t\t\"NUMBER\": %u,\n"
1483  "\t\t\t\"INDEX\": %d,\n"
1484  "\t\t\t\"LOAD\": %u,\n"
1485  "\t\t\t\"MODEL_LOAD\": %u,\n"
1486  "\t\t\t\"FW_LOAD\": %u,\n"
1487  "\t\t\t\"INST\": %u,\n"
1488  "\t\t\t\"MAX_INST\": %d,\n"
1489  "\t\t\t\"MEM\": %u,\n"
1490  "\t\t\t\"CRITICAL_MEM\": %u,\n"
1491  "\t\t\t\"SHARE_MEM\": %u,\n"
1492  "\t\t\t\"P2P_MEM\": %u,\n"
1493  "\t\t\t\"DEVICE\": \"%s\",\n"
1494  "\t\t\t\"L_FL2V\": \"%s\",\n"
1495  "\t\t\t\"N_FL2V\": \"%s\",\n"
1496  "\t\t\t\"FR\": \"%.8s\",\n"
1497  "\t\t\t\"N_FR\": \"%.8s\""
1498 #ifdef __linux__
1499  ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1500  "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1501 #else
1502  ",\n"
1503 #endif
1504  "\t\t}\n"
1505  "\t]\n"
1506  "}\n",
1507  device_name, device_count,
1508  p_device_context->p_device_info->module_id,
1509  vpu_load,
1510  model_load,
1511  p_session_context->load_query.fw_load, total_contexts,
1512  p_device_context->p_device_info->max_instance_cnt,
1513  p_session_context->load_query.fw_video_mem_usage,
1514  p_session_context->load_query.fw_video_shared_mem_usage,
1515  p_session_context->load_query.fw_share_mem_usage,
1516  p_session_context->load_query.fw_p2p_mem_usage,
1517  p_device_context->p_device_info->dev_name,
1518  p_device_context->p_device_info->fl_ver_last_ran,
1519  p_device_context->p_device_info->fl_ver_nor_flash,
1520  p_device_context->p_device_info->fw_rev,
1521  p_device_context->p_device_info->fw_rev_nor_flash
1522 #ifdef __linux__
1523  , numa_node, pcie
1524 #endif
1525  );
1526  }
1527  }
1528  ni_rsrc_free_device_context(p_device_context);
1529  }
1530 
1531  if(!detail)
1532  {
1533  if (swap_encoder_and_uploader(&device_type, device_name))
1534  {
1535  goto UPLOADER;
1536  }
1537  }
1538 
1539  free(module_ids);
1540  }
1541  if(detail)
1542  {
1543  if (output_buf.str_buf)
1544  printf("%s", output_buf.str_buf);
1545  clear_dyn_str_buf(&output_buf);
1546  return;
1547  }
1548 
1549  // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
1550  if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
1551  goto PRINT_OUTPUT;
1552  }
1553 
1554  //Nvme[0] and TP[1] load and PCIe[3] load
1555  for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
1556  {
1557  // ASSUMPTION: Each Quadra has at least and only one encoder.
1558  device_type = NI_DEVICE_TYPE_ENCODER;
1559  device_count = get_modules(device_type,
1560  p_device_queue,
1561  device_name,
1562  &module_ids);
1563 
1564  if (!device_count)
1565  {
1566  if (output_buf.str_buf)
1567  printf("%s", output_buf.str_buf);
1568  clear_dyn_str_buf(&output_buf);
1569  return;
1570  }
1571  if (icore == NP_LOAD)
1572  {
1573  strcpy(device_name, "nvme");
1574  g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1575  if (!g_temp_load)
1576  {
1577  fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
1578  return;
1579  }
1580  g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1581  if (!g_temp_pload)
1582  {
1583  fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
1584  return;
1585  }
1586  g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1587  if (!g_temp_pthroughput)
1588  {
1589  fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
1590  return;
1591  }
1592  g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1593  if (!g_temp_sharemem)
1594  {
1595  fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
1596  return;
1597  }
1598  }
1599  else
1600  {
1601  (icore == TP_LOAD)?strcpy(device_name, "tp"):strcpy(device_name, "pcie");
1602  }
1603  for (index = 0; index < device_count; index++)
1604  {
1605  p_device_context = ni_rsrc_get_device_context(device_type, module_ids[index]);
1606  if (icore == NP_LOAD)
1607  {
1608  if (!open_and_query(device_type,
1609  p_device_context,
1610  p_session_context,
1611  device_name, detail, detail_data_v1))
1612  {
1613  continue;
1614  }
1615 
1616  return_code =
1617  ni_query_nvme_status(p_session_context, &load_query);
1618  if (return_code != NI_RETCODE_SUCCESS)
1619  {
1620  fprintf(stderr,
1621  "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
1622  return_code,
1623  device_name,
1624  p_device_context->p_device_info->dev_name,
1625  p_device_context->p_device_info->hw_id);
1626  remove_device_from_saved(device_type,
1627  p_device_context->p_device_info->module_id,
1628  p_session_context->device_handle);
1629  ni_device_close(p_session_context->device_handle);
1630  goto CLOSE;
1631  }
1632  g_temp_load[index] = load_query.tp_fw_load;
1633  g_temp_pload[index] = load_query.pcie_load;
1634  g_temp_pthroughput[index] = load_query.pcie_throughput;
1635  g_temp_sharemem[index] = load_query.fw_share_mem_usage;
1636  }
1637 
1638 #ifdef __linux__
1639  get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1640  numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1641 #endif
1642 
1643  if (icore == PCIE_LOAD)
1644  {
1645  strcat_dyn_buf(&output_buf,
1646  "{ \"%s\" :\n"
1647  "\t[\n"
1648  "\t\t{\n"
1649  "\t\t\t\"NUMBER\": %u,\n"
1650  "\t\t\t\"INDEX\": %d,\n"
1651  "\t\t\t\"LOAD\": 0,\n"
1652  "\t\t\t\"MODEL_LOAD\": 0,\n"
1653  "\t\t\t\"FW_LOAD\": %u,\n"
1654  "\t\t\t\"INST\": 0,\n"
1655  "\t\t\t\"MAX_INST\": 0,\n"
1656  "\t\t\t\"MEM\": 0,\n"
1657  "\t\t\t\"CRITICAL_MEM\": 0,\n"
1658  "\t\t\t\"SHARE_MEM\": %u,\n"
1659  "\t\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
1660  "\t\t\t\"P2P_MEM\": 0,\n"
1661  "\t\t\t\"DEVICE\": \"%s\",\n"
1662  "\t\t\t\"L_FL2V\": \"%s\",\n"
1663  "\t\t\t\"N_FL2V\": \"%s\",\n"
1664  "\t\t\t\"FR\": \"%.8s\",\n"
1665  "\t\t\t\"N_FR\": \"%.8s\""
1666 #ifdef __linux__
1667  ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1668  "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1669 #else
1670  ",\n"
1671 #endif
1672  "\t\t}\n"
1673  "\t]\n"
1674  "}\n",
1675  device_name, device_count,
1676  p_device_context->p_device_info->module_id,
1677  g_temp_pload[index], 0, (float)g_temp_pthroughput[index]/10,
1678  p_device_context->p_device_info->dev_name,
1679  p_device_context->p_device_info->fl_ver_last_ran,
1680  p_device_context->p_device_info->fl_ver_nor_flash,
1681  p_device_context->p_device_info->fw_rev,
1682  p_device_context->p_device_info->fw_rev_nor_flash
1683 #ifdef __linux__
1684  , numa_node, pcie
1685 #endif
1686  );
1687  }
1688  else
1689  {
1690  load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
1691  load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
1692 
1693  strcat_dyn_buf(&output_buf,
1694  "{ \"%s\" :\n"
1695  "\t[\n"
1696  "\t\t{\n"
1697  "\t\t\t\"NUMBER\": %u,\n"
1698  "\t\t\t\"INDEX\": %d,\n"
1699  "\t\t\t\"LOAD\": 0,\n"
1700  "\t\t\t\"MODEL_LOAD\": 0,\n"
1701  "\t\t\t\"FW_LOAD\": %u,\n"
1702  "\t\t\t\"INST\": 0,\n"
1703  "\t\t\t\"MAX_INST\": 0,\n"
1704  "\t\t\t\"MEM\": 0,\n"
1705  "\t\t\t\"CRITICAL_MEM\": 0,\n"
1706  "\t\t\t\"SHARE_MEM\": %u,\n"
1707  "\t\t\t\"P2P_MEM\": 0,\n"
1708  "\t\t\t\"DEVICE\": \"%s\",\n"
1709  "\t\t\t\"L_FL2V\": \"%s\",\n"
1710  "\t\t\t\"N_FL2V\": \"%s\",\n"
1711  "\t\t\t\"FR\": \"%.8s\",\n"
1712  "\t\t\t\"N_FR\": \"%.8s\""
1713 #ifdef __linux__
1714  ",\n\t\t\t\"NUMA_NODE\": %d,\n"
1715  "\t\t\t\"PCIE_ADDR\": \"%s\"\n"
1716 #else
1717  ",\n"
1718 #endif
1719  "\t\t}\n"
1720  "\t]\n"
1721  "}\n",
1722  device_name, device_count,
1723  p_device_context->p_device_info->module_id,
1724  load_query.fw_load, load_query.fw_share_mem_usage,
1725  p_device_context->p_device_info->dev_name,
1726  p_device_context->p_device_info->fl_ver_last_ran,
1727  p_device_context->p_device_info->fl_ver_nor_flash,
1728  p_device_context->p_device_info->fw_rev,
1729  p_device_context->p_device_info->fw_rev_nor_flash
1730 #ifdef __linux__
1731  , numa_node, pcie
1732 #endif
1733  );
1734  }
1735  CLOSE:
1736  ni_rsrc_free_device_context(p_device_context);
1737  }
1738  }
1739 
1740  free(g_temp_load);
1741  free(g_temp_pload);
1742  free(g_temp_pthroughput);
1743  free(g_temp_sharemem);
1744  free(module_ids);
1745 
1746 PRINT_OUTPUT:
1747  if (output_buf.str_buf)
1748  printf("%s", output_buf.str_buf);
1749  clear_dyn_str_buf(&output_buf);
1750 }
1751 
1752 void print_json1(ni_device_queue_t *p_device_queue,
1753  ni_session_context_t *p_session_context, int detail, ni_instance_mgr_detail_status_v1_t *detail_data_v1, int format)
1754 {
1755  bool has_written_start = false;
1756  char device_name[MAX_DEVICE_NAME_SIZE] = {0};
1757  unsigned int index, device_count;
1758  int32_t *module_ids;
1759  uint32_t total_contexts;
1760  uint32_t vpu_load;
1761  uint32_t model_load;
1762 #ifdef __linux__
1763  char pcie[64] = {0};
1764  int numa_node;
1765 #endif
1766  dyn_str_buf_t output_buf = {0};
1767  ni_device_extra_info_t p_dev_extra_info = {0};
1768  char power_consumption[16];
1769 
1770  ni_device_context_t *p_device_context;
1771  ni_device_type_t device_type;
1772  ni_load_query_t load_query;
1773  ni_retcode_t return_code;
1774 
1775  for (device_type = NI_DEVICE_TYPE_DECODER;
1776  device_type != NI_DEVICE_TYPE_XCODER_MAX;
1777  device_type++)
1778  {
1779  device_count = get_modules(device_type,
1780  p_device_queue,
1781  device_name,
1782  &module_ids);
1783  if (!device_count)
1784  {
1785  continue;
1786  }
1787 
1788 UPLOADER:
1789  if (!has_written_start)
1790  {
1791  strcat_dyn_buf(&output_buf, "{\n \"%ss\": [\n", device_name);
1792  has_written_start = true;
1793  }
1794  else
1795  {
1796  strcat_dyn_buf(&output_buf, " ],\n \"%ss\": [\n", device_name);
1797  }
1798 
1799  for (index = 0; index < device_count; index++)
1800  {
1801  p_device_context =
1802  ni_rsrc_get_device_context(device_type,
1803  module_ids[index]);
1804  if (!open_and_query(device_type,
1805  p_device_context,
1806  p_session_context,
1807  device_name, detail, detail_data_v1))
1808  {
1809  continue;
1810  }
1811 
1812  if (device_type == NI_DEVICE_TYPE_UPLOAD)
1813  {
1814  total_contexts = p_session_context->load_query.active_hwuploaders;
1815  vpu_load = 0;
1816  model_load = 0;
1817  }
1818  else
1819  {
1820  total_contexts = p_session_context->load_query.total_contexts;
1821  vpu_load = p_session_context->load_query.current_load;
1822  model_load = p_session_context->load_query.fw_model_load;
1823  }
1824 #ifdef __linux__
1825  get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
1826  numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
1827 #endif
1828  if (format == 2)
1829  {
1830  if (ni_query_extra_info(p_session_context->device_handle,
1831  &p_dev_extra_info,
1832  p_device_context->p_device_info->fw_rev))
1833  {
1834  p_dev_extra_info.composite_temp = 0;
1835  }
1836  if (p_dev_extra_info.power_consumption + 1)
1837  {
1838  sprintf(power_consumption, "%umW", p_dev_extra_info.power_consumption);
1839  }
1840  }
1841  if (p_session_context->overall_load_query.admin_queried &&
1842  device_type != NI_DEVICE_TYPE_UPLOAD)
1843  {
1844  strcat_dyn_buf(&output_buf,
1845  "\t{\n"
1846  "\t\t\"NUMBER\": %u,\n"
1847  "\t\t\"INDEX\": %d,\n"
1848  "\t\t\"LOAD\": %u,\n"
1849  "\t\t\"LOAD-ALL\": %u,\n"
1850  "\t\t\"MODEL_LOAD\": %u,\n"
1851  "\t\t\"MODEL_LOAD-ALL\": %u,\n"
1852  "\t\t\"FW_LOAD\": %u,\n"
1853  "\t\t\"INST\": %u,\n"
1854  "\t\t\"INST-ALL\": %u,\n"
1855  "\t\t\"MAX_INST\": %d,\n"
1856  "\t\t\"MEM\": %u,\n"
1857  "\t\t\"CRITICAL_MEM\": %u,\n"
1858  "\t\t\"SHARE_MEM\": %u,\n"
1859  "\t\t\"P2P_MEM\": %u,\n"
1860  "\t\t\"DEVICE\": \"%s\",\n"
1861  "\t\t\"L_FL2V\": \"%s\",\n"
1862  "\t\t\"N_FL2V\": \"%s\",\n"
1863  "\t\t\"FR\": \"%.8s\",\n"
1864  "\t\t\"N_FR\": \"%.8s\""
1865 #ifdef __linux__
1866  ",\n\t\t\"NUMA_NODE\": %d,\n"
1867  "\t\t\"PCIE_ADDR\": \"%s\""
1868 #endif
1869  , device_count, p_device_context->p_device_info->module_id,
1870  vpu_load,
1871  p_session_context->overall_load_query.overall_current_load,
1872  model_load,
1873  p_session_context->overall_load_query.overall_fw_model_load,
1874  p_session_context->load_query.fw_load, total_contexts,
1875  p_session_context->overall_load_query.overall_instance_count,
1876  p_device_context->p_device_info->max_instance_cnt,
1877  p_session_context->load_query.fw_video_mem_usage,
1878  p_session_context->load_query.fw_video_shared_mem_usage,
1879  p_session_context->load_query.fw_share_mem_usage,
1880  p_session_context->load_query.fw_p2p_mem_usage,
1881  p_device_context->p_device_info->dev_name,
1882  p_device_context->p_device_info->fl_ver_last_ran,
1883  p_device_context->p_device_info->fl_ver_nor_flash,
1884  p_device_context->p_device_info->fw_rev,
1885  p_device_context->p_device_info->fw_rev_nor_flash
1886 #ifdef __linux__
1887  , numa_node, pcie
1888 #endif
1889  );
1890  } else
1891  {
1892  strcat_dyn_buf(&output_buf,
1893  "\t{\n"
1894  "\t\t\"NUMBER\": %u,\n"
1895  "\t\t\"INDEX\": %d,\n"
1896  "\t\t\"LOAD\": %u,\n"
1897  "\t\t\"MODEL_LOAD\": %u,\n"
1898  "\t\t\"FW_LOAD\": %u,\n"
1899  "\t\t\"INST\": %u,\n"
1900  "\t\t\"MAX_INST\": %d,\n"
1901  "\t\t\"MEM\": %u,\n"
1902  "\t\t\"CRITICAL_MEM\": %u,\n"
1903  "\t\t\"SHARE_MEM\": %u,\n"
1904  "\t\t\"P2P_MEM\": %u,\n"
1905  "\t\t\"DEVICE\": \"%s\",\n"
1906  "\t\t\"L_FL2V\": \"%s\",\n"
1907  "\t\t\"N_FL2V\": \"%s\",\n"
1908  "\t\t\"FR\": \"%.8s\",\n"
1909  "\t\t\"N_FR\": \"%.8s\""
1910 #ifdef __linux__
1911  ",\n\t\t\"NUMA_NODE\": %d,\n"
1912  "\t\t\"PCIE_ADDR\": \"%s\""
1913 #endif
1914  ,device_count, p_device_context->p_device_info->module_id,
1915  vpu_load,
1916  model_load,
1917  p_session_context->load_query.fw_load, total_contexts,
1918  p_device_context->p_device_info->max_instance_cnt,
1919  p_session_context->load_query.fw_video_mem_usage,
1920  p_session_context->load_query.fw_video_shared_mem_usage,
1921  p_session_context->load_query.fw_share_mem_usage,
1922  p_session_context->load_query.fw_p2p_mem_usage,
1923  p_device_context->p_device_info->dev_name,
1924  p_device_context->p_device_info->fl_ver_last_ran,
1925  p_device_context->p_device_info->fl_ver_nor_flash,
1926  p_device_context->p_device_info->fw_rev,
1927  p_device_context->p_device_info->fw_rev_nor_flash
1928 #ifdef __linux__
1929  ,
1930  numa_node, pcie
1931 #endif
1932  );
1933  }
1934  if (format == 2)
1935  {
1936  strcat_dyn_buf(&output_buf,
1937  ",\n\t\t\"TEMP\": %d,\n"
1938  "\t\t\"POWER\": \"%s\"\n"
1939  "\t}",
1940  p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
1941  (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A");
1942  }
1943  else
1944  {
1945  strcat_dyn_buf(&output_buf, "\n\t}");
1946  }
1947  if (index < device_count - 1)
1948  {
1949  strcat_dyn_buf(&output_buf, ",\n");
1950  }
1951  else
1952  {
1953  strcat_dyn_buf(&output_buf, "\n");
1954  }
1955 
1956  ni_rsrc_free_device_context(p_device_context);
1957  }
1958 
1959  if (swap_encoder_and_uploader(&device_type, device_name))
1960  {
1961  goto UPLOADER;
1962  }
1963 
1964  free(module_ids);
1965  }
1966 
1967  // Skip printing NVME, TP and PCIE status if ni_query_nvme_status is not supported in FW
1968  if (ni_cmp_fw_api_ver((char*) &p_session_context->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6O") < 0) {
1969  goto PRINT_OUTPUT;
1970  }
1971  else
1972  {
1973  strcat_dyn_buf(&output_buf, " ],\n");
1974  }
1975 
1976  //Nvme[0] and TP[1] load
1977  for (int icore = NP_LOAD; icore <= PCIE_LOAD; icore++)
1978  {
1979  // ASSUMPTION: Each Quadra has at least and only one encoder.
1980  device_type = NI_DEVICE_TYPE_ENCODER;
1981  device_count = get_modules(device_type,
1982  p_device_queue,
1983  device_name,
1984  &module_ids);
1985 
1986  if (!device_count)
1987  {
1988  if (output_buf.str_buf)
1989  printf("%s", output_buf.str_buf);
1990  clear_dyn_str_buf(&output_buf);
1991  return;
1992  }
1993  if (icore == NP_LOAD)
1994  {
1995  strcat_dyn_buf(&output_buf, " \"nvmes\": [\n");
1996  g_temp_load = (uint32_t*)calloc(device_count, sizeof(uint32_t));
1997  if (!g_temp_load)
1998  {
1999  fprintf(stderr, "ERROR: calloc() failed for g_temp_load\n");
2000  return;
2001  }
2002  g_temp_pload = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2003  if (!g_temp_pload)
2004  {
2005  fprintf(stderr, "ERROR: calloc() failed for g_temp_pload\n");
2006  return;
2007  }
2008  g_temp_pthroughput = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2009  if (!g_temp_pthroughput)
2010  {
2011  fprintf(stderr, "ERROR: calloc() failed for g_temp_pthroughput\n");
2012  return;
2013  }
2014  g_temp_sharemem = (uint32_t*)calloc(device_count, sizeof(uint32_t));
2015  if (!g_temp_sharemem)
2016  {
2017  fprintf(stderr, "ERROR: calloc() failed for g_temp_sharemem\n");
2018  return;
2019  }
2020  }
2021  else
2022  {
2023  (icore == TP_LOAD)?strcat_dyn_buf(&output_buf, " \"tps\": [\n"):strcat_dyn_buf(&output_buf, " \"pcies\": [\n");
2024  }
2025  for (index = 0; index < device_count; index++)
2026  {
2027  p_device_context = ni_rsrc_get_device_context(device_type,
2028  module_ids[index]);
2029  if (icore == NP_LOAD)
2030  {
2031  if (!open_and_query(device_type,
2032  p_device_context,
2033  p_session_context,
2034  device_name, detail, detail_data_v1))
2035  {
2036  continue;
2037  }
2038 
2039  return_code =
2040  ni_query_nvme_status(p_session_context, &load_query);
2041  if (return_code != NI_RETCODE_SUCCESS)
2042  {
2043  fprintf(stderr,
2044  "ERROR: ni_query_nvme_status() returned %d for %s:%s:%d\n",
2045  return_code,
2046  device_name,
2047  p_device_context->p_device_info->dev_name,
2048  p_device_context->p_device_info->hw_id);
2049  remove_device_from_saved(device_type,
2050  p_device_context->p_device_info->module_id,
2051  p_session_context->device_handle);
2052  ni_device_close(p_session_context->device_handle);
2053  goto CLOSE;
2054  }
2055  g_temp_load[index] = load_query.tp_fw_load;
2056  g_temp_pload[index] = load_query.pcie_load;
2057  g_temp_pthroughput[index] = load_query.pcie_throughput;
2058  g_temp_sharemem[index] = load_query.fw_share_mem_usage;
2059  }
2060 #ifdef __linux__
2061  get_pcie_addr(p_device_context->p_device_info->dev_name, pcie);
2062  numa_node = get_numa_node(p_device_context->p_device_info->dev_name);
2063 #endif
2064  if (format == 2)
2065  {
2066  if (ni_query_extra_info(p_session_context->device_handle,
2067  &p_dev_extra_info,
2068  p_device_context->p_device_info->fw_rev))
2069  {
2070  p_dev_extra_info.composite_temp = 0;
2071  }
2072  if (p_dev_extra_info.power_consumption + 1)
2073  {
2074  sprintf(power_consumption, "%umW", p_dev_extra_info.power_consumption);
2075  }
2076  }
2077 
2078  if (icore==PCIE_LOAD)
2079  {
2080  strcat_dyn_buf(&output_buf,
2081  "\t{\n"
2082  "\t\t\"NUMBER\": %u,\n"
2083  "\t\t\"INDEX\": %d,\n"
2084  "\t\t\"LOAD\": 0,\n"
2085  "\t\t\"MODEL_LOAD\": 0,\n"
2086  "\t\t\"FW_LOAD\": %u,\n"
2087  "\t\t\"INST\": 0,\n"
2088  "\t\t\"MAX_INST\": 0,\n"
2089  "\t\t\"MEM\": 0,\n"
2090  "\t\t\"CRITICAL_MEM\": 0,\n"
2091  "\t\t\"SHARE_MEM\": %u,\n"
2092  "\t\t\"PCIE_THROUGHPUT\": %.1f,\n"
2093  "\t\t\"P2P_MEM\": 0,\n"
2094  "\t\t\"DEVICE\": \"%s\",\n"
2095  "\t\t\"L_FL2V\": \"%s\",\n"
2096  "\t\t\"N_FL2V\": \"%s\",\n"
2097  "\t\t\"FR\": \"%.8s\",\n"
2098  "\t\t\"N_FR\": \"%.8s\""
2099 #ifdef __linux__
2100  ",\n\t\t\"NUMA_NODE\": %d,\n"
2101  "\t\t\"PCIE_ADDR\": \"%s\""
2102 #endif
2103  , device_count, p_device_context->p_device_info->module_id,
2104  g_temp_pload[index], 0, (float)g_temp_pthroughput[index]/10,
2105  p_device_context->p_device_info->dev_name,
2106  p_device_context->p_device_info->fl_ver_last_ran,
2107  p_device_context->p_device_info->fl_ver_nor_flash,
2108  p_device_context->p_device_info->fw_rev,
2109  p_device_context->p_device_info->fw_rev_nor_flash
2110 #ifdef __linux__
2111  , numa_node, pcie
2112 #endif
2113  );
2114  }
2115  else
2116  {
2117  load_query.fw_load = (icore==TP_LOAD)?g_temp_load[index]:load_query.fw_load;
2118  load_query.fw_share_mem_usage = (icore==TP_LOAD)?g_temp_sharemem[index]:load_query.fw_share_mem_usage;
2119 
2120  strcat_dyn_buf(&output_buf,
2121  "\t{\n"
2122  "\t\t\"NUMBER\": %u,\n"
2123  "\t\t\"INDEX\": %d,\n"
2124  "\t\t\"LOAD\": 0,\n"
2125  "\t\t\"MODEL_LOAD\": 0,\n"
2126  "\t\t\"FW_LOAD\": %u,\n"
2127  "\t\t\"INST\": 0,\n"
2128  "\t\t\"MAX_INST\": 0,\n"
2129  "\t\t\"MEM\": 0,\n"
2130  "\t\t\"CRITICAL_MEM\": 0,\n"
2131  "\t\t\"SHARE_MEM\": %u,\n"
2132  "\t\t\"P2P_MEM\": 0,\n"
2133  "\t\t\"DEVICE\": \"%s\",\n"
2134  "\t\t\"L_FL2V\": \"%s\",\n"
2135  "\t\t\"N_FL2V\": \"%s\",\n"
2136  "\t\t\"FR\": \"%.8s\",\n"
2137  "\t\t\"N_FR\": \"%.8s\""
2138 #ifdef __linux__
2139  ",\n\t\t\"NUMA_NODE\": %d,\n"
2140  "\t\t\"PCIE_ADDR\": \"%s\""
2141 #endif
2142  , device_count, p_device_context->p_device_info->module_id,
2143  load_query.fw_load, load_query.fw_share_mem_usage,
2144  p_device_context->p_device_info->dev_name,
2145  p_device_context->p_device_info->fl_ver_last_ran,
2146  p_device_context->p_device_info->fl_ver_nor_flash,
2147  p_device_context->p_device_info->fw_rev,
2148  p_device_context->p_device_info->fw_rev_nor_flash
2149 #ifdef __linux__
2150  , numa_node, pcie
2151 #endif
2152  );
2153  }
2154  if (format == 2)
2155  {
2156  strcat_dyn_buf(&output_buf,
2157  ",\n\t\t\"TEMP\": %d,\n"
2158  "\t\t\"POWER\": \"%s\"\n"
2159  "\t}",
2160  p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2161  (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A");
2162  }
2163  else
2164  {
2165  strcat_dyn_buf(&output_buf, "\n\t}");
2166  }
2167  if (index < device_count - 1)
2168  {
2169  strcat_dyn_buf(&output_buf, ",\n");
2170  }
2171  else
2172  {
2173  strcat_dyn_buf(&output_buf, "\n");
2174  if (icore != PCIE_LOAD)
2175  {
2176  strcat_dyn_buf(&output_buf, " ],\n");
2177  }
2178  }
2179 
2180 CLOSE:
2181  ni_rsrc_free_device_context(p_device_context);
2182  }
2183  }
2184 
2185  free(g_temp_load);
2186  free(g_temp_pload);
2187  free(g_temp_pthroughput);
2188  free(g_temp_sharemem);
2189  free(module_ids);
2190 
2191 PRINT_OUTPUT:
2192  strcat_dyn_buf(&output_buf, " ]\n}\n");
2193  if (output_buf.str_buf)
2194  printf("%s", output_buf.str_buf);
2195  clear_dyn_str_buf(&output_buf);
2196 }
2197 
2199  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)
2200 {
2201  int i, index, instance_count; // used in later FOR-loop when compiled without c99
2202  unsigned int module_count;
2203  char module_name[MAX_DEVICE_NAME_SIZE] = {0};
2204  int32_t *module_id_arr = NULL;
2205  dyn_str_buf_t output_buf = {0};
2206  ni_device_context_t *p_device_context = NULL;
2207  ni_device_type_t module_type;
2208  int max_device_type = NI_DEVICE_TYPE_XCODER_MAX;
2209 
2210  if(detail)
2211  max_device_type = NI_DEVICE_TYPE_SCALER;
2212  for (module_type = NI_DEVICE_TYPE_DECODER;
2213  module_type != max_device_type;
2214  module_type++)
2215  {
2216  instance_count = 0;
2217  module_count = get_modules(module_type,
2218  coders,
2219  module_name,
2220  &module_id_arr);
2221 
2222  if (!module_count)
2223  {
2224  continue;
2225  }
2226 
2227  strcat_dyn_buf(&output_buf, "Num %ss: %u\n", module_name, module_count);
2228  if(detail)
2229  {
2230  if(module_type == NI_DEVICE_TYPE_DECODER)
2231  {
2232  if(checkInterval)
2233  {
2234  strcat_dyn_buf(&output_buf,
2235  "%-5s %-7s %-9s %-5s %-7s %-8s %-4s %-5s %-6s %-5s %-14s %-20s\n", "INDEX",
2236  "AvgCost", "FrameRate", "IDR", "InFrame", "OutFrame", "fps", "Width", "Height",
2237  "SID", "DEVICE", "NAMESPACE");
2238  }
2239  else
2240  {
2241  strcat_dyn_buf(&output_buf,
2242  "%-5s %-7s %-9s %-5s %-7s %-8s %-5s %-6s %-5s %-14s %-20s\n", "INDEX",
2243  "AvgCost", "FrameRate", "IDR", "InFrame", "OutFrame", "Width", "Height",
2244  "SID", "DEVICE", "NAMESPACE");
2245  }
2246  }
2247  else if (module_type == NI_DEVICE_TYPE_ENCODER)
2248  {
2249  if(checkInterval)
2250  {
2251  strcat_dyn_buf(&output_buf,
2252  "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-4s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n", "INDEX",
2253  "AvgCost", "FrameRate", "IDR", "UserIDR", "InFrame", "OutFrame", "fps", "BR", "AvgBR", "Width", "Height",
2254  "Format", "SID", "DEVICE", "NAMESPACE");
2255  }
2256  else
2257  {
2258  strcat_dyn_buf(&output_buf,
2259  "%-5s %-7s %-9s %-5s %-7s %-7s %-8s %-10s %-10s %-5s %-6s %-9s %-5s %-14s %-20s\n", "INDEX",
2260  "AvgCost", "FrameRate", "IDR", "UserIDR", "InFrame", "OutFrame", "BR", "AvgBR", "Width", "Height",
2261  "Format", "SID", "DEVICE", "NAMESPACE");
2262  }
2263  }
2264  }
2265  else
2266  strcat_dyn_buf(&output_buf,
2267  "%-5s %-4s %-10s %-4s %-4s %-9s %-7s %-14s\n", "INDEX",
2268  "LOAD", "MODEL_LOAD", "INST", "MEM", "SHARE_MEM", "P2P_MEM",
2269  "DEVICE");
2270 
2272  for (i = 0; i < module_count; i++)
2273  {
2274  p_device_context = ni_rsrc_get_device_context(module_type, module_id_arr[i]);
2275 
2277  if (open_and_query(module_type,
2278  p_device_context,
2279  sessionCtxt,
2280  module_name, detail, detail_data_v1))
2281  {
2282  if(detail)
2283  {
2284  for(index = 0; index < NI_MAX_CONTEXTS_PER_HW_INSTANCE; index++)
2285  {
2286  if(detail_data_v1->sInstDetailStatus[index].ui16FrameRate)
2287  {
2288  if(previous_detail_data_p && checkInterval)
2289  {
2290  if(previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui16FrameRate)
2291  {
2292  if(module_type == NI_DEVICE_TYPE_DECODER)
2293  {
2294  strcat_dyn_buf(&output_buf,
2295  "%-5d %-7d %-9d %-5u %-7d %-8d %-4d %-5d %-6d %-5s %-14s %-20s\n",
2296  instance_count++,
2297  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2298  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2299  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2300  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2301  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2302  (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2303  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2304  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2305  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2306  p_device_context->p_device_info->dev_name,
2307  p_device_context->p_device_info->blk_name);
2308  }
2309  else if (module_type == NI_DEVICE_TYPE_ENCODER)
2310  {
2311  strcat_dyn_buf(&output_buf,
2312  "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-4d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2313  instance_count++,
2314  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2315  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2316  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2317  detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2318  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2319  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2320  (detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame - previous_detail_data_p[module_type][i].sInstDetailStatus[index].ui32NumOutFrame) / checkInterval,
2321  detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2322  detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2323  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2324  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2325  get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2326  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2327  p_device_context->p_device_info->dev_name,
2328  p_device_context->p_device_info->blk_name);
2329  }
2330  }
2331  }
2332  else
2333  {
2334  if(module_type == NI_DEVICE_TYPE_DECODER)
2335  {
2336  strcat_dyn_buf(&output_buf,
2337  "%-5d %-7d %-9d %-5u %-7d %-8d %-5d %-6d %-5s %-14s %-20s\n",
2338  instance_count++,
2339  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2340  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2341  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2342  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2343  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2344  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2345  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2346  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2347  p_device_context->p_device_info->dev_name,
2348  p_device_context->p_device_info->blk_name);
2349  }
2350  else if (module_type == NI_DEVICE_TYPE_ENCODER)
2351  {
2352  strcat_dyn_buf(&output_buf,
2353  "%-5d %-7d %-9d %-5u %-7d %-7d %-8d %-10d %-10d %-5d %-6d %-9s %-5s %-14s %-20s\n",
2354  instance_count++,
2355  detail_data_v1->sInstDetailStatus[index].ui8AvgCost,
2356  detail_data_v1->sInstDetailStatus[index].ui16FrameRate,
2357  detail_data_v1->sInstDetailStatus[index].ui32NumIDR,
2358  detail_data_v1->sInstDetailStatusAppend[index].ui32UserIDR,
2359  detail_data_v1->sInstDetailStatus[index].ui32NumInFrame,
2360  detail_data_v1->sInstDetailStatus[index].ui32NumOutFrame,
2361  detail_data_v1->sInstDetailStatus[index].ui32BitRate,
2362  detail_data_v1->sInstDetailStatus[index].ui32AvgBitRate,
2363  detail_data_v1->sInstDetailStatusAppend[index].ui32Width,
2364  detail_data_v1->sInstDetailStatusAppend[index].ui32Height,
2365  get_pixel_format(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u8PixelFormat),
2366  get_session_id(p_device_context, detail_data_v1->sInstDetailStatusAppend[index].u32InstanceId),
2367  p_device_context->p_device_info->dev_name,
2368  p_device_context->p_device_info->blk_name);
2369  }
2370  }
2371  }
2372  }
2373  if(previous_detail_data_p)
2374  {
2375  memcpy(&previous_detail_data_p[module_type][i], detail_data_v1, sizeof(ni_instance_mgr_detail_status_v1_t));
2376  }
2377  }
2378  else
2379  {
2380  strcat_dyn_buf(&output_buf,
2381  "%-5d %-4u %-10u %-4u %-4u %-9u %-7u %-14s\n",
2382  p_device_context->p_device_info->module_id,
2383 #ifdef XCODER_311
2384  sessionCtxt->load_query.current_load,
2385 #else
2386  (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,
2387 #endif
2388  sessionCtxt->load_query.fw_model_load,
2389  sessionCtxt->load_query.total_contexts,
2390  sessionCtxt->load_query.fw_video_mem_usage,
2391  sessionCtxt->load_query.fw_share_mem_usage,
2392  sessionCtxt->load_query.fw_p2p_mem_usage,
2393  p_device_context->p_device_info->dev_name);
2394 
2395  }
2396 
2397  ni_rsrc_free_device_context(p_device_context);
2398  }
2399  }
2400  free(module_id_arr);
2401  }
2402 
2403  if (output_buf.str_buf)
2404  printf("%s", output_buf.str_buf);
2405  clear_dyn_str_buf(&output_buf);
2406 }
2407 
2408 void print_extra(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, int internal_call)
2409 {
2410  char device_name[MAX_DEVICE_NAME_SIZE];
2411  unsigned int index, device_count;
2412  int32_t *module_ids;
2413  dyn_str_buf_t output_buf = {0};
2414  ni_device_context_t *p_device_context;
2415  ni_device_type_t device_type;
2416  ni_device_extra_info_t p_dev_extra_info = {0};
2417  char power_consumption[16];
2418  int instance_count = 0;
2419 
2420  // ASSUMPTION: Each Quadra has at least and only one encoder.
2421  device_type = NI_DEVICE_TYPE_ENCODER;
2422  device_count = get_modules(device_type,
2423  p_device_queue,
2424  device_name,
2425  &module_ids);
2426 
2427  if (!device_count)
2428  {
2429  if (output_buf.str_buf)
2430  printf("%s", output_buf.str_buf);
2431  clear_dyn_str_buf(&output_buf);
2432  return;
2433  }
2434 
2435  for (index = 0; index < device_count; index++)
2436  {
2437  p_device_context = ni_rsrc_get_device_context(device_type, module_ids[index]);
2438  if (!p_device_context)
2439  {
2440  continue;
2441  }
2442  // check if device has been opened already
2443  ni_device_type_t xcoder_device_type = GET_XCODER_DEVICE_TYPE(device_type);
2444  int module_id = p_device_context->p_device_info->module_id;
2445  if (device_handles[xcoder_device_type][module_id] != NI_INVALID_DEVICE_HANDLE)
2446  {
2447  p_session_context->device_handle =
2448  device_handles[xcoder_device_type][module_id];
2449  } else
2450  {
2451  p_session_context->device_handle =
2452  ni_device_open(p_device_context->p_device_info->dev_name,
2453  &p_session_context->max_nvme_io_size);
2454  if (p_session_context->device_handle != NI_INVALID_DEVICE_HANDLE)
2455  {
2456  device_handles[xcoder_device_type][module_id] =
2457  p_session_context->device_handle;
2458  }
2459  }
2460 
2461  if (p_session_context->device_handle == NI_INVALID_DEVICE_HANDLE)
2462  {
2463  fprintf(stderr,
2464  "ERROR: ni_device_open() failed for %s: %s\n",
2465  p_device_context->p_device_info->dev_name,
2466  strerror(NI_ERRNO));
2467  ni_rsrc_free_device_context(p_device_context);
2468  continue;
2469  }
2470 
2471  if (ni_query_extra_info(p_session_context->device_handle,
2472  &p_dev_extra_info,
2473  p_device_context->p_device_info->fw_rev))
2474  {
2475  p_dev_extra_info.composite_temp = 0;
2476  }
2477 
2478  if (p_dev_extra_info.power_consumption + 1)
2479  {
2480  sprintf(power_consumption, "%umW", p_dev_extra_info.power_consumption);
2481  }
2482  if (!internal_call)
2483  {
2484  strcat_dyn_buf(&output_buf,
2485  "%-4s %-8s %-14s\n", "TEMP", "POWER", "DEVICE");
2486  strcat_dyn_buf(&output_buf,
2487  "%-4d %-8s %-14s\n",
2488  p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2489  (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2490  p_device_context->p_device_info->dev_name);
2491  }
2492  else
2493  {
2494  if (instance_count == 0)
2495  {
2496  strcat_dyn_buf(&output_buf,
2497  "%-8s %-8s %-8s %-8.8s %-8.8s \n", "INDEX", "TEMP", "POWER", "FR", "SN");
2498  }
2499  strcat_dyn_buf(&output_buf,
2500  "%-8d %-8d %-8s %-8.8s %-8.*s \n",
2501  instance_count++ , p_dev_extra_info.composite_temp + ABSOLUTE_TEMP_ZERO,
2502  (p_dev_extra_info.power_consumption + 1) ? power_consumption : "N/A",
2503  p_device_context->p_device_info->fw_rev,
2504  (int)sizeof(p_device_context->p_device_info->serial_number), p_device_context->p_device_info->serial_number);
2505 
2506  }
2507  ni_rsrc_free_device_context(p_device_context);
2508  }
2509 
2510  if (output_buf.str_buf)
2511  printf("%s", output_buf.str_buf);
2512  clear_dyn_str_buf(&output_buf);
2513  free(module_ids);
2514 }
2515 
2516 int main(int argc, char *argv[])
2517 {
2518  setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
2519  int checkInterval;
2520  int skip_init_rsrc = 0;
2521  int should_match_rev = 1;
2522  int detail = 0;
2523  ni_instance_mgr_detail_status_v1_t detail_data_v1 = {0};
2524  ni_instance_mgr_detail_status_v1_t (*previous_detail_data)[NI_DEVICE_TYPE_XCODER_MAX] = NULL;
2525  ni_device_pool_t *p_device_pool = NULL;
2526  ni_device_queue_t *coders = NULL;
2527  ni_session_context_t *p_xCtxt = NULL;
2528  time_t startTime = {0}, now = {0};
2529  int timeout_seconds = 0;
2530  struct tm *ltime = NULL;
2531  char buf[64] = {0};
2532  long long time_diff_hours, time_diff_minutes, time_diff_seconds;
2533  int opt;
2534  ni_log_level_t log_level = NI_LOG_INFO;
2535  enum outFormat printFormat = FMT_TEXT;
2536  checkInterval = 0;
2537  bool fw_log_dump = false;
2538  int devid = -1;
2539  int refresh_device_pool = 1;
2540  bool is_first_query = true;
2541  int ret = 0;
2542 
2543 #ifdef _WIN32
2544  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
2545 #elif __linux__
2546  setup_signal_handler();
2547 #endif
2548 
2549  // arg handling
2550  while ((opt = getopt(argc, argv, "n:o:D:k:R:rt:Sl:hvd")) != -1)
2551  {
2552  switch (opt)
2553  {
2554  case 'o':
2555  // Output print format
2556  if (!strcmp(optarg, "json"))
2557  {
2558  printFormat = FMT_JSON;
2559  }
2560  else if (!strcmp(optarg, "simple"))
2561  {
2562  printFormat = FMT_SIMPLE_TEXT;
2563  }
2564  else if (!strcmp(optarg, "text"))
2565  {
2566  printFormat = FMT_TEXT;
2567  }
2568  else if (!strcmp(optarg, "full"))
2569  {
2570  printFormat = FMT_FULL_TEXT;
2571  }
2572  else if (!strcmp(optarg, "json1"))
2573  {
2574  printFormat = FMT_JSON1;
2575  }
2576  else if (!strcmp(optarg, "json2"))
2577  {
2578  printFormat = FMT_JSON2;
2579  }
2580  else if (!strcmp(optarg, "extra"))
2581  {
2582  printFormat = FMT_EXTRA;
2583  }
2584  else
2585  {
2586  fprintf(stderr, "Error: unknown selection for outputFormat: %s\n", optarg);
2587  return 1;
2588  }
2589  break;
2590  case 'n':
2591  // Output interval
2592  checkInterval = atoi(optarg);
2593  break;
2594  case 'D':
2595  fw_log_dump = atoi(optarg);
2596  break;
2597  case 'k':
2598  devid = atoi(optarg);
2599  break;
2600  case 'R':
2601  refresh_device_pool = atoi(optarg);
2602  case 'r':
2603  should_match_rev = 0;
2604  break;
2605  case 't':
2606  timeout_seconds = atoi(optarg);
2607  printf("Timeout will be set %d\n", timeout_seconds);
2608  break;
2609  case 'S':
2610  skip_init_rsrc = 1;
2611  break;
2612  case 'l':
2613  log_level = arg_to_ni_log_level(optarg);
2614  if (log_level != NI_LOG_INVALID)
2615  {
2616  ni_log_set_level(log_level);
2617  } else {
2618  fprintf(stderr, "FATAL: invalid log level selected: %s\n", optarg);
2619  return 1;
2620  }
2621  break;
2622  case 'h':
2623  // help message (limit to 80 characters wide)
2624  printf("-------- ni_rsrc_mon v%s --------\n"
2625  "The ni_rsrc_mon program provides a real-time view of NETINT Quadra resources\n"
2626  "running on the system.\n"
2627  "\n"
2628  "Usage: ni_rsrc_mon [OPTIONS]\n"
2629  "-n Specify reporting interval in one second interval. If 0 or no selection,\n"
2630  " report only once.\n"
2631  " Default: 0\n"
2632  "-R Specify if refresh devices on host in each monitor interval.\n"
2633  " If 0, only refresh devices at the start.\n"
2634  " Default: 1\n"
2635  "-o Output format. [text, simple, full, json, json1, json2, extra]\n"
2636  " Default: text\n"
2637  "-D Dump firmware logs to current directory. Default: 0(not dump fw log).\n"
2638  "-k Specify to dump which card's firmware logs.\n"
2639  " Default: -1(dump fw log of all cards).\n"
2640  "-r Initialize Quadra device regardless firmware release version to\n"
2641  " libxcoder version compatibility.\n"
2642  " Default: only initialize devices with compatible firmware version.\n"
2643  "-t Set timeout time in seconds for device polling. Program will exit with\n"
2644  " failure if timeout is reached without finding at least one device. If 0 or\n"
2645  " no selection, poll indefinitely until a Quadra device is found.\n"
2646  " Default: 0\n"
2647  "-S Skip init_rsrc.\n"
2648  "-d Print detailed information for decoder/encoder in text and json formats.\n"
2649  "-l Set loglevel of libxcoder API.\n"
2650  " [none, fatal, error, info, debug, trace]\n"
2651  " Default: info\n"
2652  "-h Open this help message.\n"
2653  "-v Print version info.\n"
2654  "\n"
2655  "Simple output shows the maximum firmware load amongst the subsystems on the\n"
2656  "Quadra device.\n"
2657  "\n"
2658  "Reporting columns for text output format\n"
2659  "INDEX index number used by resource manager to identify the resource\n"
2660  "LOAD realtime load given in percentage. This value is max of VPU and FW load reported in full output format\n"
2661  "MODEL_LOAD estimated load based on framerate and resolution\n"
2662  "INST number of job instances\n"
2663  "MEM usage of memory by the subsystem\n"
2664  "SHARE_MEM usage of memory shared across subsystems on the same device\n"
2665  "P2P_MEM usage of memory by P2P\n"
2666  "DEVICE path to NVMe device file handle\n"
2667  "NAMESPACE path to NVMe namespace file handle\n"
2668  "Additional information only in text(Default) mode \n"
2669  "TEMP current temperature (degrees Celsius)\n"
2670  "POWER current power(mW), N/A when query power not supported\n"
2671  "FR current firmware revision\n"
2672  "SN serial number of the Quadra device\n"
2673  "\n"
2674  "Additional reporting columns for full output format\n"
2675  "VPU same as LOAD in JSON outputs\n"
2676  "FW system load\n"
2677  "TOTAL same as MEM\n"
2678  "CRITICAL usage of memory considered critical\n"
2679  "L_FL2V last ran firmware loader 2 version\n"
2680  "N_FL2V nor flash firmware loader 2 version\n"
2681  "FR current firmware revision\n"
2682  "N_FR nor flash firmware revision\n"
2683  "\n"
2684  "Additional reporting columns for full JSON formats\n"
2685  "LOAD VPU load\n"
2686  "FW_LOAD system load\n"
2687  "\n"
2688  "Extra output shows TEMP and POWER of the Quadra device \n",
2690  return 0;
2691  case 'v':
2692  printf("Release ver: %s\n"
2693  "API ver: %s\n"
2694  "Date: %s\n"
2695  "ID: %s\n",
2698  return 0;
2699  case '?':
2700  if (isprint(opt))
2701  {
2702  fprintf(stderr, "FATAL: unknown option '-%c'\n", opt);
2703  } else
2704  {
2705  fprintf(stderr, "FATAL: unknown option character '\\x%x'\n", opt);
2706  }
2707  return 1;
2708  case 'd':
2709  detail = 1;
2710  break;
2711  case ':':
2712  fprintf(stderr, "FATAL: option '-%c' lacks arg\n", opt);
2713  return 1;
2714  default:
2715  fprintf(stderr, "FATAL: unhandled option\n");
2716  return 1;
2717  }
2718  }
2719 
2720  if(checkInterval > 0 && printFormat == FMT_JSON)
2721  {
2722  fprintf(stderr, "EXIT: -o json cannot use with -n params\n");
2723  return 1;
2724  }
2725 
2726  if ((argc <= 2) && (optind == 1))
2727  {
2728  for (; optind < argc; optind++)
2729  {
2730  checkInterval = argToI(argv[optind]);
2731  }
2732  }
2733 
2734 #ifdef _ANDROID
2735  ni_log_set_log_tag(LOG_TAG);
2736 #endif
2737 
2739  if(!p_xCtxt)
2740  {
2741  fprintf(stderr, "FATAL: cannot allocate momory for ni_session_context_t\n");
2742  return 1;
2743  }
2744 
2745  ni_log_set_level(NI_LOG_ERROR); // silence informational prints
2746  if (!skip_init_rsrc && (ret = ni_rsrc_init(should_match_rev,timeout_seconds)) != 0)
2747  {
2749  ni_rsrc_refresh(should_match_rev);
2750  fprintf(stderr, "FATAL: NI resource unavailable\n");
2751  ret = 0;
2752  } else
2753  {
2754  ret = 1;
2755  fprintf(stderr, "FATAL: cannot access NI resource\n");
2756  }
2757  LRETURN;
2758  }
2759  ni_log_set_level(log_level);
2760 
2761  p_device_pool = ni_rsrc_get_device_pool();
2762  if (!p_device_pool)
2763  {
2764  fprintf(stderr, "FATAL: cannot get devices info\n");
2765  ret = 1;
2766  LRETURN;
2767  }
2768 
2769  if (log_level >= NI_LOG_INFO)
2770  {
2771  printf("**************************************************\n");
2772  }
2773 
2774  // initialise device handles
2775  for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
2776  {
2777  for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
2778  {
2779  device_handles[i][j] = NI_INVALID_DEVICE_HANDLE;
2780  }
2781  }
2782 
2783  startTime = time(NULL);
2784  if(checkInterval)
2785  {
2787  previous_detail_data = (ni_instance_mgr_detail_status_v1_t (*)[NI_DEVICE_TYPE_XCODER_MAX])malloc(allocate_size);
2788  if(previous_detail_data == NULL)
2789  {
2790  fprintf(stderr, "FATAL: Allocate buffer fail\n");
2791  ret = 1;
2792  LRETURN;
2793  }
2794  memset((void *)previous_detail_data, 0, allocate_size);
2795  }
2796  while (!g_xcoder_stop_process)
2797  {
2798  now = time(NULL);
2799  ltime = localtime(&now);
2800  if (ltime)
2801  {
2802  strftime(buf, sizeof(buf), "%c", ltime);
2803  }
2804  time_diff_seconds = (long long)difftime(now, startTime);
2805  time_diff_minutes = time_diff_seconds / 60;
2806  time_diff_hours = time_diff_minutes / 60;
2807 
2808 
2809  if (is_first_query || refresh_device_pool)
2810  {
2811  ni_rsrc_refresh(should_match_rev);
2812  }
2813 
2814  if (log_level >= NI_LOG_INFO)
2815  {
2816  printf("%s up %02lld" ":%02lld" ":%02lld" " v%s\n", buf, time_diff_hours, time_diff_minutes % 60, time_diff_seconds % 60,
2818  }
2819 
2822 #ifdef _WIN32
2823  if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
2824  {
2825  fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
2826  ret = 1;
2827  LRETURN;
2828  }
2829 #elif __linux__
2830  if ( lockf(p_device_pool->lock, F_LOCK, 0) )
2831  {
2832  perror("ERROR: cannot lock p_device_pool");
2833  }
2834 #endif
2835 
2836  coders = p_device_pool->p_device_queue;
2837 
2838 #ifdef _WIN32
2839  ReleaseMutex((HANDLE)p_device_pool->lock);
2840 #elif __linux__
2841  if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
2842  {
2843  perror("ERROR: cannot unlock p_device_pool");
2844  }
2845 #endif
2846 
2847  switch (printFormat)
2848  {
2849  case FMT_TEXT:
2850  print_extra(coders, p_xCtxt, 1);
2851  print_text(coders, p_xCtxt, detail, &detail_data_v1, previous_detail_data, checkInterval);
2852  break;
2853  case FMT_FULL_TEXT:
2854  print_full_text(coders, p_xCtxt, 0, &detail_data_v1);
2855  break;
2856  case FMT_SIMPLE_TEXT:
2857  print_simple_text(coders, p_xCtxt, 0, &detail_data_v1);
2858  break;
2859  case FMT_JSON:
2860  print_json(coders, p_xCtxt, detail, &detail_data_v1);
2861  break;
2862  case FMT_JSON1:
2863  if(!detail)
2864  {
2865  print_json1(coders, p_xCtxt, 0, &detail_data_v1, 1);
2866  }
2867  else
2868  {
2869  print_json_detail(coders, p_xCtxt, &detail_data_v1);
2870  }
2871  break;
2872  case FMT_JSON2:
2873  if(!detail)
2874  {
2875  print_json1(coders, p_xCtxt, 0, &detail_data_v1, 2);
2876  }
2877  else
2878  {
2879  print_json_detail(coders, p_xCtxt, &detail_data_v1);
2880  }
2881  break;
2882  case FMT_EXTRA:
2883  print_extra(coders, p_xCtxt, 0);
2884  break;
2885  }
2886 
2887  is_first_query = false;
2888 
2889  if (log_level >= NI_LOG_INFO)
2890  {
2891  printf("**************************************************\n");
2892  }
2893 
2894  fflush(stdout);
2895 
2896  if (checkInterval == 0)
2897  {
2898  // run once
2899  break;
2900  }
2901  ni_usleep(checkInterval * 1000 * 1000);
2902  }
2903 
2904  if (fw_log_dump)
2905  {
2906  // dump fw log
2907 #ifdef _WIN32
2908  if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->lock, INFINITE)) // no time-out interval)
2909  {
2910  fprintf(stderr, "ERROR: Failed to obtain mutex: %p\n", p_device_pool->lock);
2911  ret = 1;
2912  LRETURN;
2913  }
2914 #elif __linux__
2915  if ( lockf(p_device_pool->lock, F_LOCK, 0) )
2916  {
2917  perror("ERROR: cannot lock p_device_pool");
2918  }
2919 #endif
2920  coders = p_device_pool->p_device_queue;
2921 #ifdef _WIN32
2922  ReleaseMutex((HANDLE)p_device_pool->lock);
2923 #elif __linux__
2924  if ( lockf(p_device_pool->lock, F_ULOCK, 0) )
2925  {
2926  perror("ERROR: cannot unlock p_device_pool");
2927  }
2928 #endif
2929  dump_fw_log(coders, p_xCtxt, devid);
2930  }
2931 
2932  // close all opened devices
2933  for (int i = 0; i < NI_DEVICE_TYPE_XCODER_MAX; i++)
2934  {
2935  for (int j = 0; j < NI_MAX_DEVICE_CNT; j++)
2936  {
2937  if (device_handles[i][j] != NI_INVALID_DEVICE_HANDLE)
2938  {
2940  }
2941  }
2942  }
2943 
2944 #ifdef __OPENHARMONY__
2945  system("chmod -R 777 /dev/shm/");
2946 #ifdef XCODER_LINUX_VIRTIO_DRIVER_ENABLED
2947  system("chmod 777 /dev/block/vd* 2>/dev/null");
2948 #endif
2949 #elif defined(_ANDROID)
2950  system("chmod -R 777 /dev/shm/");
2951  system("chmod 777 /dev/block/nvme* 2>/dev/null");
2952  system("chmod 777 /dev/nvme* 2>/dev/null");
2953  property_set("ni_rsrc_init_completed", "yes");
2954 #endif
2955 
2956 END:
2957  if(checkInterval && previous_detail_data)
2958  {
2959  free(previous_detail_data);
2960  }
2962  ni_rsrc_free_device_pool(p_device_pool);
2963  free(p_xCtxt);
2964  return ret;
2965 }
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:11815
_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:1256
_ni_load_query::fw_p2p_mem_usage
uint32_t fw_p2p_mem_usage
Definition: ni_device_api.h:1213
_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:359
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:1234
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:2640
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:1200
_ni_load_query::total_contexts
uint32_t total_contexts
Definition: ni_device_api.h:1203
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:1264
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:358
_ni_instance_mgr_detail_status::ui16FrameRate
uint16_t ui16FrameRate
Definition: ni_device_api.h:1236
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:353
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:439
FMT_SIMPLE_TEXT
@ FMT_SIMPLE_TEXT
Definition: ni_rsrc_mon.c:72
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:365
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:1206
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:98
_ni_device_info::fl_ver_nor_flash
uint8_t fl_ver_nor_flash[8]
Definition: ni_rsrc_api.h:112
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1467
_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:1212
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:951
_ni_instance_mgr_detail_status::ui32NumOutFrame
uint32_t ui32NumOutFrame
Definition: ni_device_api.h:1241
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:11549
_ni_instance_mgr_detail_status::ui32BitRate
uint32_t ui32BitRate
Definition: ni_device_api.h:1237
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:2408
_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:1210
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1480
_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:1246
_ni_load_query::fw_video_shared_mem_usage
uint32_t fw_video_shared_mem_usage
Definition: ni_device_api.h:1209
_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:437
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:1201
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:2198
_ni_session_context::fw_rev
uint8_t fw_rev[8]
Definition: ni_device_api.h:1627
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:248
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:11719
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:422
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:361
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:1216
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:1205
_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:1464
_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:1255
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:1322
NI_SW_RELEASE_TIME
#define NI_SW_RELEASE_TIME
Definition: ni_release_info.h:28
_ni_device_queue
Definition: ni_rsrc_api.h:67
NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition: ni_defs.h:99
NI_LOG_INVALID
@ NI_LOG_INVALID
Definition: ni_log.h: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:425
ni_usleep
void ni_usleep(int64_t usec)
Definition: ni_util.c:358
LRETURN
#define LRETURN
Definition: ni_defs.h:335
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:1239
_ni_overall_load_query::overall_fw_model_load
uint32_t overall_fw_model_load
Definition: ni_device_api.h:1227
_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:360
_ni_instance_mgr_detail_status_append::ui32UserIDR
uint32_t ui32UserIDR
Definition: ni_device_api.h:1247
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:229
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:1410
NI_MAX_DEVICE_CNT
#define NI_MAX_DEVICE_CNT
Definition: ni_defs.h:235
ni_device_session_query_detail
ni_retcode_t ni_device_session_query_detail(ni_session_context_t *p_ctx, ni_device_type_t device_type, ni_instance_mgr_detail_status_t *detail_data)
Query detail session data from the device - If device_type is valid, will query session data from spe...
Definition: ni_device_api.c: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:236
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:1228
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:1245
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:1505
_ni_load_query::fw_load
uint32_t fw_load
Definition: ni_device_api.h:1202
getopt
int getopt(int argc, char *argv[], const char *optstring)
Definition: ni_getopt.c:38
_ni_load_query
Definition: ni_device_api.h:1198
_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:1502
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:1250
g_temp_pload
uint32_t * g_temp_pload
Definition: ni_rsrc_mon.c:54
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7263
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:1232
END
#define END
Definition: ni_defs.h:336
_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:1752
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:115
dyn_str_buf::str_buf
char * str_buf
Definition: ni_rsrc_list.c:62
main
int main(int argc, char *argv[])
Definition: ni_rsrc_mon.c:2516
_ni_instance_mgr_detail_status::ui32NumInFrame
uint32_t ui32NumInFrame
Definition: ni_device_api.h:1240
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:362
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1478
_ni_overall_load_query::admin_queried
uint32_t admin_queried
Definition: ni_device_api.h:1229
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:1248
_ni_device_pool
Definition: ni_rsrc_api.h:96
_ni_instance_mgr_detail_status_v1
Definition: ni_device_api.h:1254
_ni_overall_load_query::overall_current_load
uint32_t overall_current_load
Definition: ni_device_api.h:1226
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
print_json_detail
void print_json_detail(ni_device_queue_t *p_device_queue, ni_session_context_t *p_session_context, ni_instance_mgr_detail_status_v1_t *detail_data_v1)
Definition: ni_rsrc_mon.c:1112
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:446
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:1215
_ni_instance_mgr_detail_status::ui32AvgBitRate
uint32_t ui32AvgBitRate
Definition: ni_device_api.h:1238