.TH "rte_lcore.h" 3 "Version 25.11.0" "DPDK" \" -*- nroff -*-
.ad l
.nh
.SH NAME
rte_lcore.h
.SH SYNOPSIS
.br
.PP
\fR#include <stdio\&.h>\fP
.br
\fR#include <rte_compat\&.h>\fP
.br
\fR#include <rte_config\&.h>\fP
.br
\fR#include <rte_per_lcore\&.h>\fP
.br
\fR#include <rte_eal\&.h>\fP
.br
\fR#include <rte_launch\&.h>\fP
.br
\fR#include <rte_thread\&.h>\fP
.br

.SS "Data Structures"

.in +1c
.ti -1c
.RI "struct \fBrte_lcore_usage\fP"
.br
.in -1c
.SS "Macros"

.in +1c
.ti -1c
.RI "#define \fBLCORE_ID_ANY\fP   UINT32_MAX"
.br
.ti -1c
.RI "#define \fBRTE_LCORE_FOREACH\fP(i)"
.br
.ti -1c
.RI "#define \fBRTE_LCORE_FOREACH_WORKER\fP(i)"
.br
.in -1c
.SS "Typedefs"

.in +1c
.ti -1c
.RI "\fBtypedef\fP int(* \fBrte_lcore_init_cb\fP) (unsigned int lcore_id, void *arg)"
.br
.ti -1c
.RI "\fBtypedef\fP void(* \fBrte_lcore_uninit_cb\fP) (unsigned int lcore_id, void *arg)"
.br
.ti -1c
.RI "\fBtypedef\fP int(* \fBrte_lcore_iterate_cb\fP) (unsigned int lcore_id, void *arg)"
.br
.ti -1c
.RI "\fBtypedef\fP int(* \fBrte_lcore_usage_cb\fP) (unsigned int lcore_id, struct \fBrte_lcore_usage\fP *usage)"
.br
.in -1c
.SS "Enumerations"

.in +1c
.ti -1c
.RI "enum \fBrte_lcore_role_t\fP "
.br
.in -1c
.SS "Functions"

.in +1c
.ti -1c
.RI "\fBRTE_DECLARE_PER_LCORE\fP (unsigned, _lcore_id)"
.br
.ti -1c
.RI "enum \fBrte_lcore_role_t\fP \fBrte_eal_lcore_role\fP (unsigned int lcore_id)"
.br
.ti -1c
.RI "int \fBrte_lcore_has_role\fP (unsigned int lcore_id, enum \fBrte_lcore_role_t\fP role)"
.br
.ti -1c
.RI "static unsigned \fBrte_lcore_id\fP (void)"
.br
.ti -1c
.RI "unsigned int \fBrte_get_main_lcore\fP (void)"
.br
.ti -1c
.RI "unsigned int \fBrte_lcore_count\fP (void)"
.br
.ti -1c
.RI "int \fBrte_lcore_index\fP (int lcore_id)"
.br
.ti -1c
.RI "unsigned int \fBrte_socket_id\fP (void)"
.br
.ti -1c
.RI "unsigned int \fBrte_socket_count\fP (void)"
.br
.ti -1c
.RI "int \fBrte_socket_id_by_idx\fP (unsigned int idx)"
.br
.ti -1c
.RI "unsigned int \fBrte_lcore_to_socket_id\fP (unsigned int lcore_id)"
.br
.ti -1c
.RI "int \fBrte_lcore_to_cpu_id\fP (int lcore_id)"
.br
.ti -1c
.RI "rte_cpuset_t \fBrte_lcore_cpuset\fP (unsigned int lcore_id)"
.br
.ti -1c
.RI "int \fBrte_lcore_is_enabled\fP (unsigned int lcore_id)"
.br
.ti -1c
.RI "unsigned int \fBrte_get_next_lcore\fP (unsigned int i, int skip_main, int wrap)"
.br
.ti -1c
.RI "void * \fBrte_lcore_callback_register\fP (const char *name, \fBrte_lcore_init_cb\fP init, \fBrte_lcore_uninit_cb\fP uninit, void *arg)"
.br
.ti -1c
.RI "void \fBrte_lcore_callback_unregister\fP (void *handle)"
.br
.ti -1c
.RI "int \fBrte_lcore_iterate\fP (\fBrte_lcore_iterate_cb\fP cb, void *arg)"
.br
.ti -1c
.RI "void \fBrte_lcore_register_usage_cb\fP (\fBrte_lcore_usage_cb\fP cb)"
.br
.ti -1c
.RI "void \fBrte_lcore_dump\fP (FILE *f)"
.br
.ti -1c
.RI "int \fBrte_thread_register\fP (void)"
.br
.ti -1c
.RI "void \fBrte_thread_unregister\fP (void)"
.br
.in -1c
.SH "Detailed Description"
.PP 
API for lcore and socket manipulation 
.PP
Definition in file \fBrte_lcore\&.h\fP\&.
.SH "Macro Definition Documentation"
.PP 
.SS "#define LCORE_ID_ANY   UINT32_MAX"
Any lcore\&. 
.PP
Definition at line \fB26\fP of file \fBrte_lcore\&.h\fP\&.
.SS "#define RTE_LCORE_FOREACH( i)"
\fBValue:\fP
.nf
    for (i = rte_get_next_lcore(\-1, 0, 0);              \\
         i < RTE_MAX_LCORE;                     \\
         i = rte_get_next_lcore(i, 0, 0))
.PP
.fi
Macro to browse all running lcores\&. 
.PP
Definition at line \fB216\fP of file \fBrte_lcore\&.h\fP\&.
.SS "#define RTE_LCORE_FOREACH_WORKER( i)"
\fBValue:\fP
.nf
    for (i = rte_get_next_lcore(\-1, 1, 0);              \\
         i < RTE_MAX_LCORE;                     \\
         i = rte_get_next_lcore(i, 1, 0))
.PP
.fi
Macro to browse all running lcores except the main lcore\&. 
.PP
Definition at line \fB224\fP of file \fBrte_lcore\&.h\fP\&.
.SH "Typedef Documentation"
.PP 
.SS "\fBtypedef\fP int(* rte_lcore_init_cb) (unsigned int lcore_id, void *arg)"
Callback prototype for initializing lcores\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The lcore to consider\&. 
.br
\fIarg\fP An opaque pointer passed at callback registration\&. 
.RE
.PP
\fBReturns\fP
.RS 4
.IP "\(bu" 2
-1 when refusing this operation,
.IP "\(bu" 2
0 otherwise\&. 
.PP
.RE
.PP

.PP
Definition at line \fB240\fP of file \fBrte_lcore\&.h\fP\&.
.SS "\fBtypedef\fP void(* rte_lcore_uninit_cb) (unsigned int lcore_id, void *arg)"
Callback prototype for uninitializing lcores\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The lcore to consider\&. 
.br
\fIarg\fP An opaque pointer passed at callback registration\&. 
.RE
.PP

.PP
Definition at line \fB250\fP of file \fBrte_lcore\&.h\fP\&.
.SS "\fBtypedef\fP int(* rte_lcore_iterate_cb) (unsigned int lcore_id, void *arg)"
Callback prototype for iterating over lcores\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The lcore to consider\&. 
.br
\fIarg\fP An opaque pointer coming from the caller\&. 
.RE
.PP
\fBReturns\fP
.RS 4
.IP "\(bu" 2
0 lets the iteration continue\&.
.IP "\(bu" 2
!0 makes the iteration stop\&. 
.PP
.RE
.PP

.PP
Definition at line \fB308\fP of file \fBrte_lcore\&.h\fP\&.
.SS "\fBtypedef\fP int(* rte_lcore_usage_cb) (unsigned int lcore_id, struct \fBrte_lcore_usage\fP *usage)"
Callback to allow applications to report lcore usage\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The lcore to consider\&. 
.br
\fIusage\fP Counters representing this lcore usage\&. This can never be NULL\&. 
.RE
.PP
\fBReturns\fP
.RS 4
.IP "\(bu" 2
0 if fields in usage were updated successfully\&. The fields that the application does not support must not be modified\&.
.IP "\(bu" 2
a negative value if the information is not available or if any error occurred\&. 
.PP
.RE
.PP

.PP
Definition at line \fB358\fP of file \fBrte_lcore\&.h\fP\&.
.SH "Enumeration Type Documentation"
.PP 
.SS "enum \fBrte_lcore_role_t\fP"
The lcore role (used in RTE or not)\&. 
.PP
Definition at line \fB33\fP of file \fBrte_lcore\&.h\fP\&.
.SH "Function Documentation"
.PP 
.SS "RTE_DECLARE_PER_LCORE (unsigned , _lcore_id )"
Per thread "lcore id"\&. 
.SS "enum \fBrte_lcore_role_t\fP rte_eal_lcore_role (unsigned int lcore_id)"
Get a lcore's role\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The identifier of the lcore, which MUST be between 0 and RTE_MAX_LCORE-1\&. 
.RE
.PP
\fBReturns\fP
.RS 4
The role of the lcore\&. 
.RE
.PP

.SS "int rte_lcore_has_role (unsigned int lcore_id, enum \fBrte_lcore_role_t\fP role)"
Test if the core supplied has a specific role

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The identifier of the lcore, which MUST be between 0 and RTE_MAX_LCORE-1\&. 
.br
\fIrole\fP The role to be checked against\&. 
.RE
.PP
\fBReturns\fP
.RS 4
Boolean value: positive if test is true; otherwise returns 0\&. 
.RE
.PP

.SS "unsigned rte_lcore_id (void )\fR [inline]\fP, \fR [static]\fP"
Return the Application thread ID of the execution unit\&.

.PP
Note: in most cases the lcore id returned here will also correspond to the processor id of the CPU on which the thread is pinned, this will not be the case if the user has explicitly changed the thread to core affinities using --lcores EAL argument e\&.g\&. --lcores '(0-3)@10' to run threads with lcore IDs 0, 1, 2 and 3 on physical core 10\&.\&.

.PP
\fBReturns\fP
.RS 4
Logical core ID (in EAL thread or registered non-EAL thread) or LCORE_ID_ANY (in unregistered non-EAL thread) 
.RE
.PP

.PP
Definition at line \fB78\fP of file \fBrte_lcore\&.h\fP\&.
.SS "unsigned int rte_get_main_lcore (void )"
Get the id of the main lcore

.PP
\fBReturns\fP
.RS 4
the id of the main lcore 
.RE
.PP

.SS "unsigned int rte_lcore_count (void )"
Return the number of execution units (lcores) on the system\&.

.PP
\fBReturns\fP
.RS 4
the number of execution units (lcores) on the system\&. 
.RE
.PP

.SS "int rte_lcore_index (int lcore_id)"
Return the index of the lcore starting from zero\&.

.PP
When option -c or -l is given, the index corresponds to the order in the list\&. For example: -l 22,18 lcore 22 has index 0, and 18 has index 1\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The targeted lcore, or -1 for the current one\&. 
.RE
.PP
\fBReturns\fP
.RS 4
The relative index, or -1 if not enabled\&. 
.RE
.PP

.SS "unsigned int rte_socket_id (void )"
Return the ID of NUMA node of the logical core we are running on\&. 
.PP
\fBReturns\fP
.RS 4
the ID of current lcoreid's NUMA node 
.RE
.PP

.SS "unsigned int rte_socket_count (void )"
Return number of NUMA nodes detected on the system\&.

.PP
Note that number of nodes may not be correspondent to their NUMA ID's: for example, a system may report two NUMA ID's, but the actual NUMA ID's may be 0 and 8\&.

.PP
\fBReturns\fP
.RS 4
the number of NUMA ID's as recognized by EAL 
.RE
.PP

.SS "int rte_socket_id_by_idx (unsigned int idx)"
Return socket id with a particular index\&.

.PP
This will return socket id at a particular position in list of all detected NUMA node ID's\&. For example, on a machine with NUMA nodes [0, 8], passing 1 as a parameter will return 8\&.

.PP
\fBParameters\fP
.RS 4
\fIidx\fP index of NUMA node ID to return
.RE
.PP
\fBReturns\fP
.RS 4
.IP "\(bu" 2
NUMA node ID as recognized by EAL
.IP "\(bu" 2
-1 on error, with errno set to EINVAL 
.PP
.RE
.PP

.SS "unsigned int rte_lcore_to_socket_id (unsigned int lcore_id)"
Get the ID of the NUMA node of the specified lcore

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP the targeted lcore, which MUST be between 0 and RTE_MAX_LCORE-1\&. 
.RE
.PP
\fBReturns\fP
.RS 4
the ID of lcoreid's NUMA node 
.RE
.PP

.SS "int rte_lcore_to_cpu_id (int lcore_id)"
Return the id of the lcore on a socket starting from zero\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The targeted lcore, or -1 for the current one\&. 
.RE
.PP
\fBReturns\fP
.RS 4
The relative index, or -1 if not enabled\&. 
.RE
.PP

.SS "rte_cpuset_t rte_lcore_cpuset (unsigned int lcore_id)"
Return the cpuset for a given lcore\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP the targeted lcore, which MUST be between 0 and RTE_MAX_LCORE-1\&. 
.RE
.PP
\fBReturns\fP
.RS 4
The cpuset of that lcore 
.RE
.PP

.SS "int rte_lcore_is_enabled (unsigned int lcore_id)"
Test if an lcore is enabled\&.

.PP
\fBParameters\fP
.RS 4
\fIlcore_id\fP The identifier of the lcore, which MUST be between 0 and RTE_MAX_LCORE-1\&. 
.RE
.PP
\fBReturns\fP
.RS 4
True if the given lcore is enabled; false otherwise\&. 
.RE
.PP

.SS "unsigned int rte_get_next_lcore (unsigned int i, int skip_main, int wrap)"
Get the next enabled lcore ID\&.

.PP
\fBParameters\fP
.RS 4
\fIi\fP The current lcore (reference)\&. 
.br
\fIskip_main\fP If true, do not return the ID of the main lcore\&. 
.br
\fIwrap\fP If true, go back to 0 when RTE_MAX_LCORE is reached; otherwise, return RTE_MAX_LCORE\&. 
.RE
.PP
\fBReturns\fP
.RS 4
The next lcore_id or RTE_MAX_LCORE if not found\&. 
.RE
.PP

.SS "void * rte_lcore_callback_register (const char * name, \fBrte_lcore_init_cb\fP init, \fBrte_lcore_uninit_cb\fP uninit, void * arg)"
Register callbacks invoked when initializing and uninitializing a lcore\&.

.PP
This function calls the init callback with all initialized lcores\&. Any error reported by the init callback triggers a rollback calling the uninit callback for each lcore\&. If this step succeeds, the callbacks are put in the lcore callbacks list that will get called for each lcore allocation/release\&.

.PP
Note: callbacks execution is serialised under a write lock protecting the lcores and callbacks list\&.

.PP
\fBParameters\fP
.RS 4
\fIname\fP A name serving as a small description for this callback\&. 
.br
\fIinit\fP The callback invoked when a lcore_id is initialized\&. init can be NULL\&. 
.br
\fIuninit\fP The callback invoked when a lcore_id is uninitialized\&. uninit can be NULL\&. 
.br
\fIarg\fP An optional argument that gets passed to the callback when it gets invoked\&. 
.RE
.PP
\fBReturns\fP
.RS 4
On success, returns an opaque pointer for the registered object\&. On failure (either memory allocation issue in the function itself or an error is returned by the init callback itself), returns NULL\&. 
.RE
.PP

.SS "void rte_lcore_callback_unregister (void * handle)"
Unregister callbacks previously registered with rte_lcore_callback_register\&.

.PP
This function calls the uninit callback with all initialized lcores\&. The callbacks are then removed from the lcore callbacks list\&.

.PP
\fBParameters\fP
.RS 4
\fIhandle\fP The handle pointer returned by a former successful call to rte_lcore_callback_register\&. 
.RE
.PP

.SS "int rte_lcore_iterate (\fBrte_lcore_iterate_cb\fP cb, void * arg)"
Iterate on all active lcores (ROLE_RTE, ROLE_SERVICE and ROLE_NON_EAL)\&. No modification on the lcore states is allowed in the callback\&.

.PP
Note: as opposed to init/uninit callbacks, iteration callbacks can be invoked in parallel as they are run under a read lock protecting the lcores and callbacks list\&.

.PP
\fBParameters\fP
.RS 4
\fIcb\fP The callback that gets passed each lcore\&. 
.br
\fIarg\fP An opaque pointer passed to cb\&. 
.RE
.PP
\fBReturns\fP
.RS 4
Same return code as the callback last invocation (see \fBrte_lcore_iterate_cb\fP description)\&. 
.RE
.PP

.SS "void rte_lcore_register_usage_cb (\fBrte_lcore_usage_cb\fP cb)"
Register a callback from an application to be called in \fBrte_lcore_dump()\fP and the /eal/lcore/info telemetry endpoint handler\&. Applications are expected to report lcore usage statistics via this callback\&.

.PP
If a callback was already registered, it can be replaced with another callback or unregistered with NULL\&. The previously registered callback may remain in use for an undetermined period of time\&.

.PP
\fBParameters\fP
.RS 4
\fIcb\fP The callback function\&. 
.RE
.PP

.SS "void rte_lcore_dump (FILE * f)"
List all lcores\&.

.PP
\fBParameters\fP
.RS 4
\fIf\fP The output stream where the dump should be sent\&. 
.RE
.PP

.SS "int rte_thread_register (void )"
Register current non-EAL thread as a lcore\&.

.PP
\fBNote\fP
.RS 4
This API is not compatible with the multi-process feature:
.IP "\(bu" 2
if a primary process registers a non-EAL thread, then no secondary process will initialise\&.
.IP "\(bu" 2
if a secondary process initialises successfully, trying to register a non-EAL thread from either primary or secondary processes will always end up with the thread getting LCORE_ID_ANY as lcore\&.
.PP
.RE
.PP
\fBReturns\fP
.RS 4
On success, return 0; otherwise return -1 with rte_errno set\&. 
.RE
.PP

.SS "void rte_thread_unregister (void )"
Unregister current thread and release lcore if one was associated\&. 
.SH "Author"
.PP 
Generated automatically by Doxygen for DPDK from the source code\&.
