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