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