xref: /dpdk/lib/eal/include/rte_service_component.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #ifndef _SERVICE_PRIVATE_H_
6 #define _SERVICE_PRIVATE_H_
7 
8 /* This file specifies the internal service specification.
9  * Include this file if you are writing a component that requires CPU cycles to
10  * operate, and you wish to run the component using service cores
11  */
12 
13 #include <rte_service.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /**
20  * Signature of callback function to run a service.
21  *
22  * A service function call resulting in no actual work being
23  * performed, should return -EAGAIN. In that case, the (presumbly few)
24  * cycles spent will not be counted toward the lcore or service-level
25  * cycles attributes.
26  */
27 typedef int32_t (*rte_service_func)(void *args);
28 
29 /**
30  * The specification of a service.
31  *
32  * This struct contains metadata about the service itself, the callback
33  * function to run one iteration of the service, a userdata pointer, flags etc.
34  */
35 struct rte_service_spec {
36 	/** The name of the service. This should be used by the application to
37 	 * understand what purpose this service provides.
38 	 */
39 	char name[RTE_SERVICE_NAME_MAX];
40 	/** The callback to invoke to run one iteration of the service. */
41 	rte_service_func callback;
42 	/** The userdata pointer provided to the service callback. */
43 	void *callback_userdata;
44 	/** Flags to indicate the capabilities of this service. See defines in
45 	 * the public header file for values of RTE_SERVICE_CAP_*
46 	 */
47 	uint32_t capabilities;
48 	/** NUMA socket ID that this service is affinitized to */
49 	int socket_id;
50 };
51 
52 /**
53  * Register a new service.
54  *
55  * A service represents a component that requires CPU time periodically to
56  * achieve its purpose.
57  *
58  * For example the eventdev SW PMD requires CPU cycles to perform its
59  * scheduling. This can be achieved by registering it as a service, and the
60  * application can then assign CPU resources to that service.
61  *
62  * Note that when a service component registers itself, it is not permitted to
63  * add or remove service-core threads, or modify lcore-to-service mappings. The
64  * only API that may be called by the service-component is
65  * *rte_service_component_runstate_set*, which indicates that the service
66  * component is ready to be executed.
67  *
68  * If the service is known to be mapped to a single lcore, setting the
69  * capability of the service to RTE_SERVICE_CAP_MT_SAFE can achieve
70  * better performance.
71  *
72  * @param spec The specification of the service to register
73  * @param[out] service_id A pointer to a uint32_t, which will be filled in
74  *             during registration of the service. It is set to the integers
75  *             service number given to the service. This parameter may be NULL.
76  * @retval 0 Successfully registered the service.
77  *         -EINVAL Attempted to register an invalid service (eg, no callback
78  *         set)
79  */
80 int32_t rte_service_component_register(const struct rte_service_spec *spec,
81 		uint32_t *service_id);
82 
83 /**
84  * Unregister a service component.
85  *
86  * The service being removed must be stopped before calling this function.
87  *
88  * @retval 0 The service was successfully unregistered.
89  * @retval -EBUSY The service is currently running, stop the service before
90  *          calling unregister. No action has been taken.
91  */
92 int32_t rte_service_component_unregister(uint32_t id);
93 
94 /**
95  * Private function to allow EAL to initialized default mappings.
96  *
97  * This function iterates all the services, and maps then to the available
98  * cores. Based on the capabilities of the services, they are set to run on the
99  * available cores in a round-robin manner.
100  *
101  * @retval 0 Success
102  * @retval -ENOTSUP No service lcores in use
103  * @retval -EINVAL Error while iterating over services
104  * @retval -ENODEV Error in enabling service lcore on a service
105  * @retval -ENOEXEC Error when starting services
106  */
107 int32_t rte_service_start_with_defaults(void);
108 
109 /**
110  * Set the backend runstate of a component.
111  *
112  * This function allows services to be registered at startup, but not yet
113  * enabled to run by default. When the service has been configured (via the
114  * usual method; eg rte_eventdev_configure, the service can mark itself as
115  * ready to run. The differentiation between backend runstate and
116  * service_runstate is that the backend runstate is set by the service
117  * component while the service runstate is reserved for application usage.
118  *
119  * @retval 0 Success
120  */
121 int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
122 
123 /**
124  * Initialize the service library.
125  *
126  * In order to use the service library, it must be initialized. EAL initializes
127  * the library at startup.
128  *
129  * @retval 0 Success
130  * @retval -EALREADY Service library is already initialized
131  */
132 int32_t rte_service_init(void);
133 
134 /**
135  * @internal Free up the memory that has been initialized.
136  * This routine is to be invoked prior to process termination.
137  *
138  * @retval None
139  */
140 void rte_service_finalize(void);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /* _SERVICE_PRIVATE_H_ */
147