1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
5 #ifndef _EAL_PRIVATE_H_
6 #define _EAL_PRIVATE_H_
13 #include <rte_lcore.h>
14 #include <rte_memory.h>
16 #include "eal_internal_cfg.h"
19 * Structure storing internal configuration (per-lcore)
22 pthread_t thread_id; /**< pthread identifier */
23 int pipe_main2worker[2]; /**< communication pipe with main */
24 int pipe_worker2main[2]; /**< communication pipe with main */
26 lcore_function_t * volatile f; /**< function to call */
27 void * volatile arg; /**< argument of function */
28 volatile int ret; /**< return value of function */
30 volatile enum rte_lcore_state_t state; /**< lcore state */
31 unsigned int socket_id; /**< physical socket id for this lcore */
32 unsigned int core_id; /**< core number on socket for this lcore */
33 int core_index; /**< relative index, starting from 0 */
34 uint8_t core_role; /**< role of core eg: OFF, RTE, SERVICE */
36 rte_cpuset_t cpuset; /**< cpu set which the lcore affinity to */
39 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
42 * The global RTE configuration structure.
45 uint32_t main_lcore; /**< Id of the main lcore */
46 uint32_t lcore_count; /**< Number of available logical cores. */
47 uint32_t numa_node_count; /**< Number of detected NUMA nodes. */
48 uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */
49 uint32_t service_lcore_count;/**< Number of available service cores. */
50 enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
52 /** Primary or secondary configuration */
53 enum rte_proc_type_t process_type;
55 /** PA or VA mapping mode */
56 enum rte_iova_mode iova_mode;
59 * Pointer to memory configuration, which may be shared across multiple
62 struct rte_mem_config *mem_config;
66 * Get the global configuration structure.
69 * A pointer to the global configuration structure.
71 struct rte_config *rte_eal_get_configuration(void);
74 * Initialize the memzone subsystem (private to eal).
80 int rte_eal_memzone_init(void);
83 * Common log initialization function (private to eal). Determines
84 * where log data is written when no call to rte_openlog_stream is
88 * The default log stream to be used.
93 void eal_log_set_default(FILE *default_log);
96 * Fill configuration with number of physical and logical processors
98 * This function is private to EAL.
100 * Parse /proc/cpuinfo to get the number of physical and logical
101 * processors on the machine.
104 * 0 on success, negative on error
106 int rte_eal_cpu_init(void);
109 * Create memseg lists
111 * This function is private to EAL.
113 * Preallocate virtual memory.
116 * 0 on success, negative on error
118 int rte_eal_memseg_init(void);
123 * This function is private to EAL.
125 * Fill configuration structure with these infos, and return 0 on success.
128 * 0 on success, negative on error
130 int rte_eal_memory_init(void);
135 * This function is private to EAL.
137 * Mmap memory areas used by HPET (high precision event timer) that will
138 * provide our time reference, and configure the TSC frequency also for it
139 * to be used as a reference.
142 * 0 on success, negative on error
144 int rte_eal_timer_init(void);
147 * Init the default log stream
149 * This function is private to EAL.
152 * 0 on success, negative on error
154 int rte_eal_log_init(const char *id, int facility);
157 * Save the log regexp for later
159 int rte_log_save_regexp(const char *type, int priority);
160 int rte_log_save_pattern(const char *pattern, int priority);
163 * Init tail queues for non-EAL library structures. This is to allow
164 * the rings, mempools, etc. lists to be shared among multiple processes
166 * This function is private to EAL
169 * 0 on success, negative on error
171 int rte_eal_tailqs_init(void);
174 * Init interrupt handling.
176 * This function is private to EAL.
179 * 0 on success, negative on error
181 int rte_eal_intr_init(void);
184 * Init alarm mechanism. This is to allow a callback be called after
187 * This function is private to EAL.
190 * 0 on success, negative on error
192 int rte_eal_alarm_init(void);
195 * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
199 * The module's name which need to be checked
202 * -1 means some error happens(NULL pointer or open failure)
203 * 0 means the module not loaded
204 * 1 means the module loaded
206 int rte_eal_check_module(const char *module_name);
209 * Memory reservation flags.
211 enum eal_mem_reserve_flags {
213 * Reserve hugepages. May be unsupported by some platforms.
215 EAL_RESERVE_HUGEPAGES = 1 << 0,
217 * Force reserving memory at the requested address.
218 * This can be a destructive action depending on the implementation.
220 * @see RTE_MAP_FORCE_ADDRESS for description of possible consequences
221 * (although implementations are not required to use it).
223 EAL_RESERVE_FORCE_ADDRESS = 1 << 1
227 * Get virtual area of specified size from the OS.
229 * This function is private to the EAL.
231 * @param requested_addr
232 * Address where to request address space.
234 * Size of requested area.
236 * Page size on which to align requested virtual area.
238 * EAL_VIRTUAL_AREA_* flags.
239 * @param reserve_flags
240 * Extra flags passed directly to eal_mem_reserve().
243 * Virtual area address if successful.
244 * NULL if unsuccessful.
247 #define EAL_VIRTUAL_AREA_ADDR_IS_HINT (1 << 0)
248 /**< don't fail if cannot get exact requested address. */
249 #define EAL_VIRTUAL_AREA_ALLOW_SHRINK (1 << 1)
250 /**< try getting smaller sized (decrement by page size) virtual areas if cannot
251 * get area of requested size.
253 #define EAL_VIRTUAL_AREA_UNMAP (1 << 2)
254 /**< immediately unmap reserved virtual area. */
256 eal_get_virtual_area(void *requested_addr, size_t *size,
257 size_t page_sz, int flags, int reserve_flags);
260 * Initialize a memory segment list and create its backing storage.
263 * Memory segment list to be filled.
265 * Name for the backing storage.
267 * Size of segment pages in the MSL.
269 * Number of segments.
271 * Socket ID. Must not be SOCKET_ID_ANY.
273 * Mark MSL as pointing to a heap.
275 * 0 on success, (-1) on failure and rte_errno is set.
278 eal_memseg_list_init_named(struct rte_memseg_list *msl, const char *name,
279 uint64_t page_sz, int n_segs, int socket_id, bool heap);
282 * Initialize memory segment list and create its backing storage
283 * with a name corresponding to MSL parameters.
285 * @param type_msl_idx
286 * Index of the MSL among other MSLs of the same socket and page size.
288 * @see eal_memseg_list_init_named for remaining parameters description.
291 eal_memseg_list_init(struct rte_memseg_list *msl, uint64_t page_sz,
292 int n_segs, int socket_id, int type_msl_idx, bool heap);
295 * Reserve VA space for a memory segment list
296 * previously initialized with eal_memseg_list_init().
299 * Initialized memory segment list with page size defined.
300 * @param reserve_flags
301 * Extra memory reservation flags. Can be 0 if unnecessary.
303 * 0 on success, (-1) on failure and rte_errno is set.
306 eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags);
309 * Populate MSL, each segment is one page long.
312 * Initialized memory segment list with page size defined.
314 * Starting address of list segments.
316 * Number of segments to populate.
319 eal_memseg_list_populate(struct rte_memseg_list *msl, void *addr, int n_segs);
322 * Distribute available memory between MSLs.
325 * 0 on success, (-1) on failure.
328 eal_dynmem_memseg_lists_init(void);
331 * Preallocate hugepages for dynamic allocation.
334 * 0 on success, (-1) on failure.
337 eal_dynmem_hugepage_init(void);
340 * Given the list of hugepage sizes and the number of pages thereof,
341 * calculate the best number of pages of each size to fulfill the request
342 * for RAM on each NUMA node.
345 * Amounts of memory requested for each NUMA node of RTE_MAX_NUMA_NODES.
347 * Information about hugepages of different size.
349 * Receives information about used hugepages of each size.
351 * Number of elements in hp_info and hp_used.
353 * 0 on success, (-1) on failure.
356 eal_dynmem_calc_num_pages_per_socket(
357 uint64_t *memory, struct hugepage_info *hp_info,
358 struct hugepage_info *hp_used, unsigned int num_hp_info);
363 * This function is private to the EAL.
365 unsigned eal_cpu_core_id(unsigned lcore_id);
368 * Check if cpu is present.
370 * This function is private to the EAL.
372 int eal_cpu_detected(unsigned lcore_id);
375 * Set TSC frequency from precise value or estimation
377 * This function is private to the EAL.
379 void set_tsc_freq(void);
382 * Get precise TSC frequency from system
384 * This function is private to the EAL.
386 uint64_t get_tsc_freq(void);
389 * Get TSC frequency if the architecture supports.
391 * This function is private to the EAL.
394 * The number of TSC cycles in one second.
395 * Returns zero if the architecture support is not available.
397 uint64_t get_tsc_freq_arch(void);
400 * Allocate a free lcore to associate to a non-EAL thread.
403 * - the id of a lcore with role ROLE_NON_EAL on success.
404 * - RTE_MAX_LCORE if none was available or initializing was refused (see
405 * rte_lcore_callback_register).
407 unsigned int eal_lcore_non_eal_allocate(void);
410 * Release the lcore used by a non-EAL thread.
411 * Counterpart of eal_lcore_non_eal_allocate().
414 * The lcore with role ROLE_NON_EAL to release.
416 void eal_lcore_non_eal_release(unsigned int lcore_id);
419 * Prepare physical memory mapping
420 * i.e. hugepages on Linux and
423 * This function is private to the EAL.
425 int rte_eal_hugepage_init(void);
428 * Creates memory mapping in secondary process
429 * i.e. hugepages on Linux and
432 * This function is private to the EAL.
434 int rte_eal_hugepage_attach(void);
437 * Find a bus capable of identifying a device.
440 * A device identifier (PCI address, virtual PMD name, ...).
443 * A valid bus handle if found.
444 * NULL if no bus is able to parse this device.
446 struct rte_bus *rte_bus_find_by_device_name(const char *str);
449 * Create the unix channel for primary/secondary communication.
455 int rte_mp_channel_init(void);
458 * Primary/secondary communication cleanup.
460 void rte_mp_channel_cleanup(void);
464 * Parse a device string and store its information in an
465 * rte_devargs structure.
467 * A device description is split by layers of abstraction of the device:
468 * bus, class and driver. Each layer will offer a set of properties that
469 * can be applied either to configure or recognize a device.
471 * This function will parse those properties and prepare the rte_devargs
472 * to be given to each layers for processing.
474 * Note: if the "data" field of the devargs points to devstr,
475 * then no dynamic allocation is performed and the rte_devargs
476 * can be safely discarded.
478 * Otherwise ``data`` will hold a workable copy of devstr, that will be
479 * used by layers descriptors within rte_devargs. In this case,
480 * any rte_devargs should be cleaned-up before being freed.
483 * rte_devargs structure to fill.
490 * Negative errno values on error (rte_errno is set).
493 rte_devargs_layers_parse(struct rte_devargs *devargs,
497 * probe a device at local process.
500 * Device arguments including bus, class and driver properties.
502 * new device be probed as output.
504 * 0 on success, negative on error.
506 int local_dev_probe(const char *devargs, struct rte_device **new_dev);
509 * Hotplug remove a given device from a specific bus at local process.
512 * Data structure of the device to remove.
514 * 0 on success, negative on error.
516 int local_dev_remove(struct rte_device *dev);
519 * Iterate over all buses to find the corresponding bus to handle the sigbus
521 * @param failure_addr
522 * Pointer of the fault address of the sigbus error.
525 * 0 success to handle the sigbus.
526 * -1 failed to handle the sigbus
527 * 1 no bus can handler the sigbus
529 int rte_bus_sigbus_handler(const void *failure_addr);
533 * Register the sigbus handler.
536 * - On success, zero.
537 * - On failure, a negative value.
540 dev_sigbus_handler_register(void);
544 * Unregister the sigbus handler.
547 * - On success, zero.
548 * - On failure, a negative value.
551 dev_sigbus_handler_unregister(void);
554 * Get OS-specific EAL mapping base address.
557 eal_get_baseaddr(void);
560 eal_malloc_no_trace(const char *type, size_t size, unsigned int align);
562 void eal_free_no_trace(void *addr);
564 /** Options for eal_file_open(). */
565 enum eal_open_flags {
566 /** Open file for reading. */
567 EAL_OPEN_READONLY = 0x00,
568 /** Open file for reading and writing. */
569 EAL_OPEN_READWRITE = 0x02,
571 * Create the file if it doesn't exist.
572 * New files are only accessible to the owner (0600 equivalent).
574 EAL_OPEN_CREATE = 0x04
578 * Open or create a file.
583 * A combination of eal_open_flags controlling operation and FD behavior.
585 * Open file descriptor on success, (-1) on failure and rte_errno is set.
588 eal_file_open(const char *path, int flags);
590 /** File locking operation. */
592 EAL_FLOCK_SHARED, /**< Acquire a shared lock. */
593 EAL_FLOCK_EXCLUSIVE, /**< Acquire an exclusive lock. */
594 EAL_FLOCK_UNLOCK /**< Release a previously taken lock. */
597 /** Behavior on file locking conflict. */
598 enum eal_flock_mode {
599 EAL_FLOCK_WAIT, /**< Wait until the file gets unlocked to lock it. */
600 EAL_FLOCK_RETURN /**< Return immediately if the file is locked. */
604 * Lock or unlock the file.
606 * On failure @code rte_errno @endcode is set to the error code
607 * specified by POSIX flock(3) description.
610 * Opened file descriptor.
612 * Operation to perform.
614 * Behavior on conflict.
616 * 0 on success, (-1) on failure.
619 eal_file_lock(int fd, enum eal_flock_op op, enum eal_flock_mode mode);
622 * Truncate or extend the file to the specified size.
624 * On failure @code rte_errno @endcode is set to the error code
625 * specified by POSIX ftruncate(3) description.
628 * Opened file descriptor.
632 * 0 on success, (-1) on failure.
635 eal_file_truncate(int fd, ssize_t size);
638 * Reserve a region of virtual memory.
640 * Use eal_mem_free() to free reserved memory.
642 * @param requested_addr
643 * A desired reservation address which must be page-aligned.
644 * The system might not respect it.
645 * NULL means the address will be chosen by the system.
647 * Reservation size. Must be a multiple of system page size.
649 * Reservation options, a combination of eal_mem_reserve_flags.
651 * Starting address of the reserved area on success, NULL on failure.
652 * Callers must not access this memory until remapping it.
655 eal_mem_reserve(void *requested_addr, size_t size, int flags);
658 * Free memory obtained by eal_mem_reserve() and possibly allocated.
660 * If *virt* and *size* describe a part of the reserved region,
661 * only this part of the region is freed (accurately up to the system
662 * page size). If *virt* points to allocated memory, *size* must match
663 * the one specified on allocation. The behavior is undefined
664 * if the memory pointed by *virt* is obtained from another source
668 * A virtual address in a region previously reserved.
670 * Number of bytes to unreserve.
673 eal_mem_free(void *virt, size_t size);
676 * Configure memory region inclusion into dumps.
679 * Starting address of the region.
681 * Size of the region.
683 * True to include memory into dumps, false to exclude.
685 * 0 on success, (-1) on failure and rte_errno is set.
688 eal_mem_set_dump(void *virt, size_t size, bool dump);
691 * Sets the runtime directory of DPDK
694 * The new runtime directory path of DPDK
696 * The size of the new runtime directory path in bytes.
698 * 0 on success, (-1) on failure.
701 eal_set_runtime_dir(char *run_dir, size_t size);
704 * Get the internal configuration structure.
707 * A pointer to the internal configuration structure.
709 struct internal_config *
710 eal_get_internal_configuration(void);
713 * Get the current value of the rte_application_usage pointer
716 * Pointer to the current value of rte_application_usage .
719 eal_get_application_usage_hook(void);
722 * Instruct primary process that a secondary process wants to attach.
724 bool __rte_mp_enable(void);
727 * Init per-lcore info in current thread.
730 * identifier of lcore.
732 * CPU affinity for this thread.
734 void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
737 * Uninitialize per-lcore info for current thread.
739 void __rte_thread_uninit(void);
741 #endif /* _EAL_PRIVATE_H_ */