1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
11 * EAL Configuration API
18 #include <rte_config.h>
19 #include <rte_compat.h>
20 #include <rte_per_lcore.h>
23 #include <rte_pci_dev_feature_defs.h>
29 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
31 /* Maximum thread_name length. */
32 #define RTE_MAX_THREAD_NAME_LEN 16
35 * The lcore role (used in RTE or not).
37 enum rte_lcore_role_t {
44 * The type of process in a linuxapp, multi-process setup
46 enum rte_proc_type_t {
47 RTE_PROC_AUTO = -1, /* allow auto-detection of primary/secondary */
48 RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */
55 * The global RTE configuration structure.
58 uint32_t master_lcore; /**< Id of the master lcore */
59 uint32_t lcore_count; /**< Number of available logical cores. */
60 uint32_t numa_node_count; /**< Number of detected NUMA nodes. */
61 uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */
62 uint32_t service_lcore_count;/**< Number of available service cores. */
63 enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
65 /** Primary or secondary configuration */
66 enum rte_proc_type_t process_type;
68 /** PA or VA mapping mode */
69 enum rte_iova_mode iova_mode;
72 * Pointer to memory configuration, which may be shared across multiple
75 struct rte_mem_config *mem_config;
76 } __attribute__((__packed__));
79 * Get the global configuration structure.
82 * A pointer to the global configuration structure.
84 struct rte_config *rte_eal_get_configuration(void);
90 * The identifier of the lcore.
92 * The role of the lcore.
94 enum rte_lcore_role_t rte_eal_lcore_role(unsigned lcore_id);
98 * Get the process type in a multi-process setup
103 enum rte_proc_type_t rte_eal_process_type(void);
106 * Request iopl privilege for all RPL.
108 * This function should be called by pmds which need access to ioports.
111 * - On success, returns 0.
112 * - On failure, returns -1.
114 int rte_eal_iopl_init(void);
117 * Initialize the Environment Abstraction Layer (EAL).
119 * This function is to be executed on the MASTER lcore only, as soon
120 * as possible in the application's main() function.
122 * The function finishes the initialization process before main() is called.
123 * It puts the SLAVE lcores in the WAIT state.
125 * When the multi-partition feature is supported, depending on the
126 * configuration (if CONFIG_RTE_EAL_MAIN_PARTITION is disabled), this
127 * function waits to ensure that the magic number is set before
128 * returning. See also the rte_eal_get_configuration() function. Note:
129 * This behavior may change in the future.
132 * A non-negative value. If it is greater than 0, the array members
133 * for argv[0] through argv[argc] (non-inclusive) shall contain pointers
136 * An array of strings. The contents of the array, as well as the strings
137 * which are pointed to by the array, may be modified by this function.
139 * - On success, the number of parsed arguments, which is greater or
140 * equal to zero. After the call to rte_eal_init(),
141 * all arguments argv[x] with x < ret may have been modified by this
142 * function call and should not be further interpreted by the
143 * application. The EAL does not take any ownership of the memory used
144 * for either the argv array, or its members.
145 * - On failure, -1 and rte_errno is set to a value indicating the cause
146 * for failure. In some instances, the application will need to be
147 * restarted as part of clearing the issue.
149 * Error codes returned via rte_errno:
150 * EACCES indicates a permissions issue.
152 * EAGAIN indicates either a bus or system resource was not available,
153 * setup may be attempted again.
155 * EALREADY indicates that the rte_eal_init function has already been
156 * called, and cannot be called again.
158 * EFAULT indicates the tailq configuration name was not found in
159 * memory configuration.
161 * EINVAL indicates invalid parameters were passed as argv/argc.
163 * ENOMEM indicates failure likely caused by an out-of-memory condition.
165 * ENODEV indicates memory setup issues.
167 * ENOTSUP indicates that the EAL cannot initialize on this system.
169 * EPROTO indicates that the PCI bus is either not present, or is not
170 * readable by the eal.
172 * ENOEXEC indicates that a service core failed to launch successfully.
174 int rte_eal_init(int argc, char **argv);
178 * @b EXPERIMENTAL: this API may change without prior notice
180 * Clean up the Environment Abstraction Layer (EAL)
182 * This function must be called to release any internal resources that EAL has
183 * allocated during rte_eal_init(). After this call, no DPDK function calls may
184 * be made. It is expected that common usage of this function is to call it
185 * just before terminating the process.
187 * @return 0 Successfully released all internal EAL resources
188 * @return -EFAULT There was an error in releasing all resources.
190 int __rte_experimental rte_eal_cleanup(void);
193 * Check if a primary process is currently alive
195 * This function returns true when a primary process is currently
198 * @param config_file_path
199 * The config_file_path argument provided should point at the location
200 * that the primary process will create its config file. If NULL, the default
201 * config file path is used.
204 * - If alive, returns 1.
205 * - If dead, returns 0.
207 int rte_eal_primary_proc_alive(const char *config_file_path);
209 #define RTE_MP_MAX_FD_NUM 8 /* The max amount of fds */
210 #define RTE_MP_MAX_NAME_LEN 64 /* The max length of action name */
211 #define RTE_MP_MAX_PARAM_LEN 256 /* The max length of param */
213 char name[RTE_MP_MAX_NAME_LEN];
216 uint8_t param[RTE_MP_MAX_PARAM_LEN];
217 int fds[RTE_MP_MAX_FD_NUM];
220 struct rte_mp_reply {
223 struct rte_mp_msg *msgs; /* caller to free */
227 * Action function typedef used by other components.
229 * As we create socket channel for primary/secondary communication, use
230 * this function typedef to register action for coming messages.
232 typedef int (*rte_mp_t)(const struct rte_mp_msg *msg, const void *peer);
235 * Asynchronous reply function typedef used by other components.
237 * As we create socket channel for primary/secondary communication, use
238 * this function typedef to register action for coming responses to asynchronous
241 typedef int (*rte_mp_async_reply_t)(const struct rte_mp_msg *request,
242 const struct rte_mp_reply *reply);
246 * @b EXPERIMENTAL: this API may change without prior notice
248 * Register an action function for primary/secondary communication.
250 * Call this function to register an action, if the calling component wants
251 * to response the messages from the corresponding component in its primary
252 * process or secondary processes.
255 * The name argument plays as the nonredundant key to find the action.
258 * The action argument is the function pointer to the action function.
264 int __rte_experimental
265 rte_mp_action_register(const char *name, rte_mp_t action);
269 * @b EXPERIMENTAL: this API may change without prior notice
271 * Unregister an action function for primary/secondary communication.
273 * Call this function to unregister an action if the calling component does
274 * not want to response the messages from the corresponding component in its
275 * primary process or secondary processes.
278 * The name argument plays as the nonredundant key to find the action.
281 void __rte_experimental
282 rte_mp_action_unregister(const char *name);
286 * @b EXPERIMENTAL: this API may change without prior notice
288 * Send a message to the peer process.
290 * This function will send a message which will be responsed by the action
291 * identified by name in the peer process.
294 * The msg argument contains the customized message.
297 * - On success, return 0.
298 * - On failure, return -1, and the reason will be stored in rte_errno.
300 int __rte_experimental
301 rte_mp_sendmsg(struct rte_mp_msg *msg);
305 * @b EXPERIMENTAL: this API may change without prior notice
307 * Send a request to the peer process and expect a reply.
309 * This function sends a request message to the peer process, and will
310 * block until receiving reply message from the peer process.
312 * @note The caller is responsible to free reply->replies.
315 * The req argument contains the customized request message.
318 * The reply argument will be for storing all the replied messages;
319 * the caller is responsible for free reply->replies.
322 * The ts argument specifies how long we can wait for the peer(s) to reply.
325 * - On success, return 0.
326 * - On failure, return -1, and the reason will be stored in rte_errno.
328 int __rte_experimental
329 rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
330 const struct timespec *ts);
334 * @b EXPERIMENTAL: this API may change without prior notice
336 * Send a request to the peer process and expect a reply in a separate callback.
338 * This function sends a request message to the peer process, and will not
339 * block. Instead, reply will be received in a separate callback.
342 * The req argument contains the customized request message.
345 * The ts argument specifies how long we can wait for the peer(s) to reply.
348 * The callback to trigger when all responses for this request have arrived.
351 * - On success, return 0.
352 * - On failure, return -1, and the reason will be stored in rte_errno.
354 int __rte_experimental
355 rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
356 rte_mp_async_reply_t clb);
360 * @b EXPERIMENTAL: this API may change without prior notice
362 * Send a reply to the peer process.
364 * This function will send a reply message in response to a request message
365 * received previously.
368 * The msg argument contains the customized message.
371 * The peer argument is the pointer to the peer socket path.
374 * - On success, return 0.
375 * - On failure, return -1, and the reason will be stored in rte_errno.
377 int __rte_experimental
378 rte_mp_reply(struct rte_mp_msg *msg, const char *peer);
381 * Usage function typedef used by the application usage function.
383 * Use this function typedef to define and call rte_set_application_usage_hook()
386 typedef void (*rte_usage_hook_t)(const char * prgname);
389 * Add application usage routine callout from the eal_usage() routine.
391 * This function allows the application to include its usage message
392 * in the EAL system usage message. The routine rte_set_application_usage_hook()
393 * needs to be called before the rte_eal_init() routine in the application.
395 * This routine is optional for the application and will behave as if the set
396 * routine was never called as the default behavior.
399 * The func argument is a function pointer to the application usage routine.
400 * Called function is defined using rte_usage_hook_t typedef, which is of
401 * the form void rte_usage_func(const char * prgname).
403 * Calling this routine with a NULL value will reset the usage hook routine and
404 * return the current value, which could be NULL.
406 * - Returns the current value of the rte_application_usage pointer to allow
407 * the caller to daisy chain the usage routines if needing more then one.
410 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
413 * macro to get the lock of tailq in mem_config
415 #define RTE_EAL_TAILQ_RWLOCK (&rte_eal_get_configuration()->mem_config->qlock)
418 * macro to get the multiple lock of mempool shared by mutiple-instance
420 #define RTE_EAL_MEMPOOL_RWLOCK (&rte_eal_get_configuration()->mem_config->mplock)
423 * Whether EAL is using huge pages (disabled by --no-huge option).
424 * The no-huge mode cannot be used with UIO poll-mode drivers like igb/ixgbe.
425 * It is useful for NIC drivers (e.g. librte_pmd_mlx4, librte_pmd_vmxnet3) or
426 * crypto drivers (e.g. librte_crypto_nitrox) provided by third-parties such
430 * Nonzero if hugepages are enabled.
432 int rte_eal_has_hugepages(void);
435 * Whether EAL is using PCI bus.
436 * Disabled by --no-pci option.
439 * Nonzero if the PCI bus is enabled.
441 int rte_eal_has_pci(void);
444 * Whether the EAL was asked to create UIO device.
449 int rte_eal_create_uio_dev(void);
452 * The user-configured vfio interrupt mode.
455 * Interrupt mode configured with the command line,
456 * RTE_INTR_MODE_NONE by default.
458 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
461 * A wrap API for syscall gettid.
464 * On success, returns the thread ID of calling process.
465 * It is always successful.
467 int rte_sys_gettid(void);
470 * Get system unique thread id.
473 * On success, returns the thread ID of calling process.
474 * It is always successful.
476 static inline int rte_gettid(void)
478 static RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
479 if (RTE_PER_LCORE(_thread_id) == -1)
480 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
481 return RTE_PER_LCORE(_thread_id);
488 * enum rte_iova_mode value.
490 enum rte_iova_mode rte_eal_iova_mode(void);
494 * @b EXPERIMENTAL: this API may change without prior notice
496 * Get user provided pool ops name for mbuf
499 * returns user provided pool ops name.
501 const char * __rte_experimental
502 rte_eal_mbuf_user_pool_ops(void);
505 * Get default pool ops name for mbuf
508 * returns default pool ops name.
511 rte_eal_mbuf_default_mempool_ops(void);
517 #endif /* _RTE_EAL_H_ */