eal: add function to release internal resources
[dpdk.git] / lib / librte_eal / common / include / rte_eal.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4
5 #ifndef _RTE_EAL_H_
6 #define _RTE_EAL_H_
7
8 /**
9  * @file
10  *
11  * EAL Configuration API
12  */
13
14 #include <stdint.h>
15 #include <sched.h>
16
17 #include <rte_config.h>
18 #include <rte_per_lcore.h>
19 #include <rte_bus.h>
20
21 #include <rte_pci_dev_feature_defs.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
28
29 /* Maximum thread_name length. */
30 #define RTE_MAX_THREAD_NAME_LEN 16
31
32 /**
33  * The lcore role (used in RTE or not).
34  */
35 enum rte_lcore_role_t {
36         ROLE_RTE,
37         ROLE_OFF,
38         ROLE_SERVICE,
39 };
40
41 /**
42  * The type of process in a linuxapp, multi-process setup
43  */
44 enum rte_proc_type_t {
45         RTE_PROC_AUTO = -1,   /* allow auto-detection of primary/secondary */
46         RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */
47         RTE_PROC_SECONDARY,
48
49         RTE_PROC_INVALID
50 };
51
52 /**
53  * The global RTE configuration structure.
54  */
55 struct rte_config {
56         uint32_t master_lcore;       /**< Id of the master lcore */
57         uint32_t lcore_count;        /**< Number of available logical cores. */
58         uint32_t service_lcore_count;/**< Number of available service cores. */
59         enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
60
61         /** Primary or secondary configuration */
62         enum rte_proc_type_t process_type;
63
64         /** PA or VA mapping mode */
65         enum rte_iova_mode iova_mode;
66
67         /**
68          * Pointer to memory configuration, which may be shared across multiple
69          * DPDK instances
70          */
71         struct rte_mem_config *mem_config;
72 } __attribute__((__packed__));
73
74 /**
75  * Get the global configuration structure.
76  *
77  * @return
78  *   A pointer to the global configuration structure.
79  */
80 struct rte_config *rte_eal_get_configuration(void);
81
82 /**
83  * Get a lcore's role.
84  *
85  * @param lcore_id
86  *   The identifier of the lcore.
87  * @return
88  *   The role of the lcore.
89  */
90 enum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id);
91
92
93 /**
94  * Get the process type in a multi-process setup
95  *
96  * @return
97  *   The process type
98  */
99 enum rte_proc_type_t rte_eal_process_type(void);
100
101 /**
102  * Request iopl privilege for all RPL.
103  *
104  * This function should be called by pmds which need access to ioports.
105
106  * @return
107  *   - On success, returns 0.
108  *   - On failure, returns -1.
109  */
110 int rte_eal_iopl_init(void);
111
112 /**
113  * Initialize the Environment Abstraction Layer (EAL).
114  *
115  * This function is to be executed on the MASTER lcore only, as soon
116  * as possible in the application's main() function.
117  *
118  * The function finishes the initialization process before main() is called.
119  * It puts the SLAVE lcores in the WAIT state.
120  *
121  * When the multi-partition feature is supported, depending on the
122  * configuration (if CONFIG_RTE_EAL_MAIN_PARTITION is disabled), this
123  * function waits to ensure that the magic number is set before
124  * returning. See also the rte_eal_get_configuration() function. Note:
125  * This behavior may change in the future.
126  *
127  * @param argc
128  *   A non-negative value.  If it is greater than 0, the array members
129  *   for argv[0] through argv[argc] (non-inclusive) shall contain pointers
130  *   to strings.
131  * @param argv
132  *   An array of strings.  The contents of the array, as well as the strings
133  *   which are pointed to by the array, may be modified by this function.
134  * @return
135  *   - On success, the number of parsed arguments, which is greater or
136  *     equal to zero. After the call to rte_eal_init(),
137  *     all arguments argv[x] with x < ret may have been modified by this
138  *     function call and should not be further interpreted by the
139  *     application.  The EAL does not take any ownership of the memory used
140  *     for either the argv array, or its members.
141  *   - On failure, -1 and rte_errno is set to a value indicating the cause
142  *     for failure.  In some instances, the application will need to be
143  *     restarted as part of clearing the issue.
144  *
145  *   Error codes returned via rte_errno:
146  *     EACCES indicates a permissions issue.
147  *
148  *     EAGAIN indicates either a bus or system resource was not available,
149  *            setup may be attempted again.
150  *
151  *     EALREADY indicates that the rte_eal_init function has already been
152  *              called, and cannot be called again.
153  *
154  *     EFAULT indicates the tailq configuration name was not found in
155  *            memory configuration.
156  *
157  *     EINVAL indicates invalid parameters were passed as argv/argc.
158  *
159  *     ENOMEM indicates failure likely caused by an out-of-memory condition.
160  *
161  *     ENODEV indicates memory setup issues.
162  *
163  *     ENOTSUP indicates that the EAL cannot initialize on this system.
164  *
165  *     EPROTO indicates that the PCI bus is either not present, or is not
166  *            readable by the eal.
167  *
168  *     ENOEXEC indicates that a service core failed to launch successfully.
169  */
170 int rte_eal_init(int argc, char **argv);
171
172 /**
173  * @warning
174  * @b EXPERIMENTAL: this API may change without prior notice
175  *
176  * Clean up the Environment Abstraction Layer (EAL)
177  *
178  * This function must be called to release any internal resources that EAL has
179  * allocated during rte_eal_init(). After this call, no DPDK function calls may
180  * be made. It is expected that common usage of this function is to call it
181  * just before terminating the process.
182  *
183  * @return 0 Successfully released all internal EAL resources
184  * @return -EFAULT There was an error in releasing all resources.
185  */
186 int rte_eal_cleanup(void);
187
188 /**
189  * Check if a primary process is currently alive
190  *
191  * This function returns true when a primary process is currently
192  * active.
193  *
194  * @param config_file_path
195  *   The config_file_path argument provided should point at the location
196  *   that the primary process will create its config file. If NULL, the default
197  *   config file path is used.
198  *
199  * @return
200  *  - If alive, returns 1.
201  *  - If dead, returns 0.
202  */
203 int rte_eal_primary_proc_alive(const char *config_file_path);
204
205 /**
206  * Usage function typedef used by the application usage function.
207  *
208  * Use this function typedef to define and call rte_set_application_usage_hook()
209  * routine.
210  */
211 typedef void    (*rte_usage_hook_t)(const char * prgname);
212
213 /**
214  * Add application usage routine callout from the eal_usage() routine.
215  *
216  * This function allows the application to include its usage message
217  * in the EAL system usage message. The routine rte_set_application_usage_hook()
218  * needs to be called before the rte_eal_init() routine in the application.
219  *
220  * This routine is optional for the application and will behave as if the set
221  * routine was never called as the default behavior.
222  *
223  * @param usage_func
224  *   The func argument is a function pointer to the application usage routine.
225  *   Called function is defined using rte_usage_hook_t typedef, which is of
226  *   the form void rte_usage_func(const char * prgname).
227  *
228  *   Calling this routine with a NULL value will reset the usage hook routine and
229  *   return the current value, which could be NULL.
230  * @return
231  *   - Returns the current value of the rte_application_usage pointer to allow
232  *     the caller to daisy chain the usage routines if needing more then one.
233  */
234 rte_usage_hook_t
235 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
236
237 /**
238  * macro to get the lock of tailq in mem_config
239  */
240 #define RTE_EAL_TAILQ_RWLOCK         (&rte_eal_get_configuration()->mem_config->qlock)
241
242 /**
243  * macro to get the multiple lock of mempool shared by mutiple-instance
244  */
245 #define RTE_EAL_MEMPOOL_RWLOCK            (&rte_eal_get_configuration()->mem_config->mplock)
246
247 /**
248  * Whether EAL is using huge pages (disabled by --no-huge option).
249  * The no-huge mode cannot be used with UIO poll-mode drivers like igb/ixgbe.
250  * It is useful for NIC drivers (e.g. librte_pmd_mlx4, librte_pmd_vmxnet3) or
251  * crypto drivers (e.g. librte_crypto_nitrox) provided by third-parties such
252  * as 6WIND.
253  *
254  * @return
255  *   Nonzero if hugepages are enabled.
256  */
257 int rte_eal_has_hugepages(void);
258
259 /**
260  * Whether EAL is using PCI bus.
261  * Disabled by --no-pci option.
262  *
263  * @return
264  *   Nonzero if the PCI bus is enabled.
265  */
266 int rte_eal_has_pci(void);
267
268 /**
269  * Whether the EAL was asked to create UIO device.
270  *
271  * @return
272  *   Nonzero if true.
273  */
274 int rte_eal_create_uio_dev(void);
275
276 /**
277  * The user-configured vfio interrupt mode.
278  *
279  * @return
280  *   Interrupt mode configured with the command line,
281  *   RTE_INTR_MODE_NONE by default.
282  */
283 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
284
285 /**
286  * A wrap API for syscall gettid.
287  *
288  * @return
289  *   On success, returns the thread ID of calling process.
290  *   It is always successful.
291  */
292 int rte_sys_gettid(void);
293
294 /**
295  * Get system unique thread id.
296  *
297  * @return
298  *   On success, returns the thread ID of calling process.
299  *   It is always successful.
300  */
301 static inline int rte_gettid(void)
302 {
303         static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
304         if (RTE_PER_LCORE(_thread_id) == -1)
305                 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
306         return RTE_PER_LCORE(_thread_id);
307 }
308
309 /**
310  * Get the iova mode
311  *
312  * @return
313  *   enum rte_iova_mode value.
314  */
315 enum rte_iova_mode rte_eal_iova_mode(void);
316
317 /**
318  * Get default pool ops name for mbuf
319  *
320  * @return
321  *   returns default pool ops name.
322  */
323 const char *
324 rte_eal_mbuf_default_mempool_ops(void);
325
326 #ifdef __cplusplus
327 }
328 #endif
329
330 #endif /* _RTE_EAL_H_ */