NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
apsh_libs_get_main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <stdlib.h>
27 
28 #include <doca_argp.h>
29 #include <doca_log.h>
30 
31 #include "apsh_common.h"
32 
33 DOCA_LOG_REGISTER(LIBS_GET::MAIN);
34 
35 /* Sample's Logic */
36 doca_error_t libs_get(const char *dma_device_name,
37  const char *pci_vuid,
38  enum doca_apsh_system_os os_type,
40  const char *mem_region,
41  const char *os_symbols);
42 
43 /*
44  * Sample main function
45  *
46  * @argc [in]: command line arguments size
47  * @argv [in]: array of command line arguments
48  * @return: EXIT_SUCCESS on success and EXIT_FAILURE otherwise
49  */
50 int main(int argc, char *argv[])
51 {
53  struct apsh_config apsh_conf = {0};
54  bool os_enabled = true;
55  bool pid_enabled = true;
56  struct doca_log_backend *sdk_log;
57  int exit_status = EXIT_FAILURE;
58 
59  /* Set the default configuration values (Example values) */
60  strcpy(apsh_conf.dma_dev_name, "mlx5_0");
61  strcpy(apsh_conf.system_vuid, "MT2125X03335MLNXS0D0F0");
62  apsh_conf.os_type = DOCA_APSH_SYSTEM_LINUX;
63  apsh_conf.pid = 1;
64  strcpy(apsh_conf.system_os_symbol_map_path, "/tmp/symbols.json");
65  strcpy(apsh_conf.system_mem_region_path, "/tmp/mem_regions.json");
66 
67  /* Register a logger backend */
69  if (result != DOCA_SUCCESS)
70  goto sample_exit;
71 
72  /* Register a logger backend for internal SDK errors and warnings */
74  if (result != DOCA_SUCCESS)
75  goto sample_exit;
77  if (result != DOCA_SUCCESS)
78  goto sample_exit;
79 
80  DOCA_LOG_INFO("Starting the sample");
81 
82  /* Parse cmdline/json arguments */
83  result = doca_argp_init(NULL, &apsh_conf);
84  if (result != DOCA_SUCCESS) {
85  DOCA_LOG_ERR("Failed to init ARGP resources: %s", doca_error_get_descr(result));
86  goto sample_exit;
87  }
88 
89  result = register_apsh_params(os_enabled, pid_enabled);
90  if (result != DOCA_SUCCESS) {
91  DOCA_LOG_ERR("Failed to register sample parameters: %s", doca_error_get_descr(result));
92  goto argp_cleanup;
93  }
94 
95  result = doca_argp_start(argc, argv);
96  if (result != DOCA_SUCCESS) {
97  DOCA_LOG_ERR("Failed to parse sample input: %s", doca_error_get_descr(result));
98  goto argp_cleanup;
99  }
100 
101  /* Invoke the sample's logic */
102  result = libs_get(apsh_conf.dma_dev_name,
103  apsh_conf.system_vuid,
104  apsh_conf.os_type,
105  apsh_conf.pid,
106  apsh_conf.system_mem_region_path,
107  apsh_conf.system_os_symbol_map_path);
108  if (result != DOCA_SUCCESS) {
109  DOCA_LOG_ERR("libs_get() encountered an error: %s", doca_error_get_descr(result));
110  goto argp_cleanup;
111  }
112 
113  exit_status = EXIT_SUCCESS;
114 
115 argp_cleanup:
117 sample_exit:
118  if (exit_status == EXIT_SUCCESS)
119  DOCA_LOG_INFO("Sample finished successfully");
120  else
121  DOCA_LOG_INFO("Sample finished with errors");
122  return exit_status;
123 }
#define NULL
Definition: __stddef_null.h:26
doca_error_t register_apsh_params(void)
int32_t pid
int32_t result
int main(int argc, char *argv[])
doca_error_t libs_get(const char *dma_device_name, const char *pci_vuid, enum doca_apsh_system_os os_type, DOCA_APSH_PROCESS_PID_TYPE pid, const char *mem_region, const char *os_symbols)
DOCA_LOG_REGISTER(LIBS_GET::MAIN)
uint32_t DOCA_APSH_PROCESS_PID_TYPE
process pid type
doca_apsh_system_os
system os types
@ DOCA_APSH_SYSTEM_LINUX
DOCA_EXPERIMENTAL doca_error_t doca_argp_start(int argc, char **argv)
Parse incoming arguments (cmd line/json).
DOCA_EXPERIMENTAL doca_error_t doca_argp_init(const char *program_name, void *program_config)
Initialize the parser interface.
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_SUCCESS
Definition: doca_error.h:38
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
@ DOCA_LOG_LEVEL_WARNING
Definition: doca_log.h:47
char system_vuid[DOCA_DEVINFO_VUID_SIZE+1]
DOCA_APSH_PROCESS_PID_TYPE pid
char dma_dev_name[DOCA_DEVINFO_IBDEV_NAME_SIZE+1]
char system_mem_region_path[MAX_PATH_LEN]
char system_os_symbol_map_path[MAX_PATH_LEN]
enum doca_apsh_system_os os_type