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>
24 #include <rte_pci_dev_feature_defs.h>
30 #define RTE_MAGIC 19820526 /**< Magic number written by the main partition when ready. */
32 /* Maximum thread_name length. */
33 #define RTE_MAX_THREAD_NAME_LEN 16
36 * The type of process in a linux, multi-process setup
38 enum rte_proc_type_t {
39 RTE_PROC_AUTO = -1, /* allow auto-detection of primary/secondary */
40 RTE_PROC_PRIMARY = 0, /* set to zero, so primary is the default */
47 * Get the process type in a multi-process setup
52 enum rte_proc_type_t rte_eal_process_type(void);
55 * Request iopl privilege for all RPL.
57 * This function should be called by pmds which need access to ioports.
60 * - On success, returns 0.
61 * - On failure, returns -1.
63 int rte_eal_iopl_init(void);
66 * Initialize the Environment Abstraction Layer (EAL).
68 * This function is to be executed on the MASTER lcore only, as soon
69 * as possible in the application's main() function.
71 * The function finishes the initialization process before main() is called.
72 * It puts the SLAVE lcores in the WAIT state.
74 * When the multi-partition feature is supported, depending on the
75 * configuration (if CONFIG_RTE_EAL_MAIN_PARTITION is disabled), this
76 * function waits to ensure that the magic number is set before
77 * returning. See also the rte_eal_get_configuration() function. Note:
78 * This behavior may change in the future.
81 * A non-negative value. If it is greater than 0, the array members
82 * for argv[0] through argv[argc] (non-inclusive) shall contain pointers
85 * An array of strings. The contents of the array, as well as the strings
86 * which are pointed to by the array, may be modified by this function.
88 * - On success, the number of parsed arguments, which is greater or
89 * equal to zero. After the call to rte_eal_init(),
90 * all arguments argv[x] with x < ret may have been modified by this
91 * function call and should not be further interpreted by the
92 * application. The EAL does not take any ownership of the memory used
93 * for either the argv array, or its members.
94 * - On failure, -1 and rte_errno is set to a value indicating the cause
95 * for failure. In some instances, the application will need to be
96 * restarted as part of clearing the issue.
98 * Error codes returned via rte_errno:
99 * EACCES indicates a permissions issue.
101 * EAGAIN indicates either a bus or system resource was not available,
102 * setup may be attempted again.
104 * EALREADY indicates that the rte_eal_init function has already been
105 * called, and cannot be called again.
107 * EFAULT indicates the tailq configuration name was not found in
108 * memory configuration.
110 * EINVAL indicates invalid parameters were passed as argv/argc.
112 * ENOMEM indicates failure likely caused by an out-of-memory condition.
114 * ENODEV indicates memory setup issues.
116 * ENOTSUP indicates that the EAL cannot initialize on this system.
118 * EPROTO indicates that the PCI bus is either not present, or is not
119 * readable by the eal.
121 * ENOEXEC indicates that a service core failed to launch successfully.
123 int rte_eal_init(int argc, char **argv);
126 * Clean up the Environment Abstraction Layer (EAL)
128 * This function must be called to release any internal resources that EAL has
129 * allocated during rte_eal_init(). After this call, no DPDK function calls may
130 * be made. It is expected that common usage of this function is to call it
131 * just before terminating the process.
133 * @return 0 Successfully released all internal EAL resources
134 * @return -EFAULT There was an error in releasing all resources.
136 int rte_eal_cleanup(void);
139 * Check if a primary process is currently alive
141 * This function returns true when a primary process is currently
144 * @param config_file_path
145 * The config_file_path argument provided should point at the location
146 * that the primary process will create its config file. If NULL, the default
147 * config file path is used.
150 * - If alive, returns 1.
151 * - If dead, returns 0.
153 int rte_eal_primary_proc_alive(const char *config_file_path);
155 #define RTE_MP_MAX_FD_NUM 8 /* The max amount of fds */
156 #define RTE_MP_MAX_NAME_LEN 64 /* The max length of action name */
157 #define RTE_MP_MAX_PARAM_LEN 256 /* The max length of param */
159 char name[RTE_MP_MAX_NAME_LEN];
162 uint8_t param[RTE_MP_MAX_PARAM_LEN];
163 int fds[RTE_MP_MAX_FD_NUM];
166 struct rte_mp_reply {
169 struct rte_mp_msg *msgs; /* caller to free */
173 * Action function typedef used by other components.
175 * As we create socket channel for primary/secondary communication, use
176 * this function typedef to register action for coming messages.
178 * @note When handling IPC request callbacks, the reply must be sent even in
179 * cases of error handling. Simply returning success or failure will *not*
180 * send a response to the requestor.
181 * Implementation of error signalling mechanism is up to the application.
183 * @note No memory allocations should take place inside the callback.
185 typedef int (*rte_mp_t)(const struct rte_mp_msg *msg, const void *peer);
188 * Asynchronous reply function typedef used by other components.
190 * As we create socket channel for primary/secondary communication, use
191 * this function typedef to register action for coming responses to asynchronous
194 * @note When handling IPC request callbacks, the reply must be sent even in
195 * cases of error handling. Simply returning success or failure will *not*
196 * send a response to the requestor.
197 * Implementation of error signalling mechanism is up to the application.
199 * @note No memory allocations should take place inside the callback.
201 typedef int (*rte_mp_async_reply_t)(const struct rte_mp_msg *request,
202 const struct rte_mp_reply *reply);
206 * @b EXPERIMENTAL: this API may change without prior notice
208 * Register an action function for primary/secondary communication.
210 * Call this function to register an action, if the calling component wants
211 * to response the messages from the corresponding component in its primary
212 * process or secondary processes.
214 * @note IPC may be unsupported in certain circumstances, so caller should check
218 * The name argument plays as the nonredundant key to find the action.
221 * The action argument is the function pointer to the action function.
229 rte_mp_action_register(const char *name, rte_mp_t action);
233 * @b EXPERIMENTAL: this API may change without prior notice
235 * Unregister an action function for primary/secondary communication.
237 * Call this function to unregister an action if the calling component does
238 * not want to response the messages from the corresponding component in its
239 * primary process or secondary processes.
241 * @note IPC may be unsupported in certain circumstances, so caller should check
245 * The name argument plays as the nonredundant key to find the action.
250 rte_mp_action_unregister(const char *name);
254 * @b EXPERIMENTAL: this API may change without prior notice
256 * Send a message to the peer process.
258 * This function will send a message which will be responded by the action
259 * identified by name in the peer process.
262 * The msg argument contains the customized message.
265 * - On success, return 0.
266 * - On failure, return -1, and the reason will be stored in rte_errno.
270 rte_mp_sendmsg(struct rte_mp_msg *msg);
274 * @b EXPERIMENTAL: this API may change without prior notice
276 * Send a request to the peer process and expect a reply.
278 * This function sends a request message to the peer process, and will
279 * block until receiving reply message from the peer process.
281 * @note The caller is responsible to free reply->replies.
283 * @note This API must not be used inside memory-related or IPC callbacks, and
284 * no memory allocations should take place inside such callback.
286 * @note IPC may be unsupported in certain circumstances, so caller should check
290 * The req argument contains the customized request message.
293 * The reply argument will be for storing all the replied messages;
294 * the caller is responsible for free reply->msgs.
297 * The ts argument specifies how long we can wait for the peer(s) to reply.
300 * - On success, return 0.
301 * - On failure, return -1, and the reason will be stored in rte_errno.
305 rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
306 const struct timespec *ts);
310 * @b EXPERIMENTAL: this API may change without prior notice
312 * Send a request to the peer process and expect a reply in a separate callback.
314 * This function sends a request message to the peer process, and will not
315 * block. Instead, reply will be received in a separate callback.
317 * @note IPC may be unsupported in certain circumstances, so caller should check
321 * The req argument contains the customized request message.
324 * The ts argument specifies how long we can wait for the peer(s) to reply.
327 * The callback to trigger when all responses for this request have arrived.
330 * - On success, return 0.
331 * - On failure, return -1, and the reason will be stored in rte_errno.
335 rte_mp_request_async(struct rte_mp_msg *req, const struct timespec *ts,
336 rte_mp_async_reply_t clb);
340 * @b EXPERIMENTAL: this API may change without prior notice
342 * Send a reply to the peer process.
344 * This function will send a reply message in response to a request message
345 * received previously.
347 * @note When handling IPC request callbacks, the reply must be sent even in
348 * cases of error handling. Simply returning success or failure will *not*
349 * send a response to the requestor.
350 * Implementation of error signalling mechanism is up to the application.
353 * The msg argument contains the customized message.
356 * The peer argument is the pointer to the peer socket path.
359 * - On success, return 0.
360 * - On failure, return -1, and the reason will be stored in rte_errno.
364 rte_mp_reply(struct rte_mp_msg *msg, const char *peer);
367 * Usage function typedef used by the application usage function.
369 * Use this function typedef to define and call rte_set_application_usage_hook()
372 typedef void (*rte_usage_hook_t)(const char * prgname);
375 * Add application usage routine callout from the eal_usage() routine.
377 * This function allows the application to include its usage message
378 * in the EAL system usage message. The routine rte_set_application_usage_hook()
379 * needs to be called before the rte_eal_init() routine in the application.
381 * This routine is optional for the application and will behave as if the set
382 * routine was never called as the default behavior.
385 * The func argument is a function pointer to the application usage routine.
386 * Called function is defined using rte_usage_hook_t typedef, which is of
387 * the form void rte_usage_func(const char * prgname).
389 * Calling this routine with a NULL value will reset the usage hook routine and
390 * return the current value, which could be NULL.
392 * - Returns the current value of the rte_application_usage pointer to allow
393 * the caller to daisy chain the usage routines if needing more then one.
396 rte_set_application_usage_hook(rte_usage_hook_t usage_func);
399 * Whether EAL is using huge pages (disabled by --no-huge option).
400 * The no-huge mode is not compatible with all drivers or features.
403 * Nonzero if hugepages are enabled.
405 int rte_eal_has_hugepages(void);
408 * Whether EAL is using PCI bus.
409 * Disabled by --no-pci option.
412 * Nonzero if the PCI bus is enabled.
414 int rte_eal_has_pci(void);
417 * Whether the EAL was asked to create UIO device.
422 int rte_eal_create_uio_dev(void);
425 * The user-configured vfio interrupt mode.
428 * Interrupt mode configured with the command line,
429 * RTE_INTR_MODE_NONE by default.
431 enum rte_intr_mode rte_eal_vfio_intr_mode(void);
435 * @b EXPERIMENTAL: this API may change without prior notice
437 * Copy the user-configured vfio VF token.
440 * vfio VF token configured with the command line is copied
441 * into this parameter, zero uuid by default.
444 void rte_eal_vfio_get_vf_token(rte_uuid_t vf_token);
447 * A wrap API for syscall gettid.
450 * On success, returns the thread ID of calling process.
451 * It is always successful.
453 int rte_sys_gettid(void);
455 RTE_DECLARE_PER_LCORE(int, _thread_id);
458 * Get system unique thread id.
461 * On success, returns the thread ID of calling process.
462 * It is always successful.
464 static inline int rte_gettid(void)
466 if (RTE_PER_LCORE(_thread_id) == -1)
467 RTE_PER_LCORE(_thread_id) = rte_sys_gettid();
468 return RTE_PER_LCORE(_thread_id);
475 * enum rte_iova_mode value.
477 enum rte_iova_mode rte_eal_iova_mode(void);
480 * Get user provided pool ops name for mbuf
483 * returns user provided pool ops name.
486 rte_eal_mbuf_user_pool_ops(void);
489 * Get the runtime directory of DPDK
492 * The runtime directory path of DPDK
495 rte_eal_get_runtime_dir(void);
501 #endif /* _RTE_EAL_H_ */