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