4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _RTE_SERVICE_H_
34 #define _RTE_SERVICE_H_
41 * The service functionality provided by this header allows a DPDK component
42 * to indicate that it requires a function call in order for it to perform
45 * An example usage of this functionality would be a component that registers
46 * a service to perform a particular packet processing duty: for example the
47 * eventdev software PMD. At startup the application requests all services
48 * that have been registered, and the cores in the service-coremask run the
49 * required services. The EAL removes these number of cores from the available
50 * runtime cores, and dedicates them to performing service-core workloads. The
51 * application has access to the remaining lcores as normal.
60 #include <sys/queue.h>
62 #include <rte_lcore.h>
64 /* forward declaration only. Definition in rte_service_private.h */
65 struct rte_service_spec;
67 #define RTE_SERVICE_NAME_MAX 32
69 /* Capabilities of a service.
71 * Use the *rte_service_probe_capability* function to check if a service is
72 * capable of a specific capability.
74 /** When set, the service is capable of having multiple threads run it at the
77 #define RTE_SERVICE_CAP_MT_SAFE (1 << 0)
81 * @b EXPERIMENTAL: this API may change without prior notice
83 * Return the number of services registered.
85 * The number of services registered can be passed to *rte_service_get_by_id*,
86 * enabling the application to retrieve the specification of each service.
88 * @return The number of services registered.
90 uint32_t rte_service_get_count(void);
95 * @b EXPERIMENTAL: this API may change without prior notice
97 * Return the specification of a service by integer id.
99 * This function provides the specification of a service. This can be used by
100 * the application to understand what the service represents. The service
101 * must not be modified by the application directly, only passed to the various
102 * rte_service_* functions.
104 * @param id The integer id of the service to retrieve
105 * @retval non-zero A valid pointer to the service_spec
106 * @retval NULL Invalid *id* provided.
108 struct rte_service_spec *rte_service_get_by_id(uint32_t id);
112 * @b EXPERIMENTAL: this API may change without prior notice
114 * Return the specification of a service by name.
116 * This function provides the specification of a service using the service name
117 * as lookup key. This can be used by the application to understand what the
118 * service represents. The service must not be modified by the application
119 * directly, only passed to the various rte_service_* functions.
121 * @param name The name of the service to retrieve
122 * @retval non-zero A valid pointer to the service_spec
123 * @retval NULL Invalid *name* provided.
125 struct rte_service_spec *rte_service_get_by_name(const char *name);
129 * @b EXPERIMENTAL: this API may change without prior notice
131 * Return the name of the service.
133 * @return A pointer to the name of the service. The returned pointer remains
134 * in ownership of the service, and the application must not free it.
136 const char *rte_service_get_name(uint32_t id);
140 * @b EXPERIMENTAL: this API may change without prior notice
142 * Check if a service has a specific capability.
144 * This function returns if *service* has implements *capability*.
145 * See RTE_SERVICE_CAP_* defines for a list of valid capabilities.
146 * @retval 1 Capability supported by this service instance
147 * @retval 0 Capability not supported by this service instance
149 int32_t rte_service_probe_capability(uint32_t id, uint32_t capability);
153 * @b EXPERIMENTAL: this API may change without prior notice
155 * Map or unmap a lcore to a service.
157 * Each core can be added or removed from running a specific service. This
158 * function enables or disables *lcore* to run *service_id*.
160 * If multiple cores are enabled on a service, an atomic is used to ensure that
161 * only one cores runs the service at a time. The exception to this is when
162 * a service indicates that it is multi-thread safe by setting the capability
163 * called RTE_SERVICE_CAP_MT_SAFE. With the multi-thread safe capability set,
164 * the service function can be run on multiple threads at the same time.
166 * @param service_id the service to apply the lcore to
167 * @param lcore The lcore that will be mapped to service
168 * @param enable Zero to unmap or disable the core, non-zero to enable
170 * @retval 0 lcore map updated successfully
171 * @retval -EINVAL An invalid service or lcore was provided.
173 int32_t rte_service_map_lcore_set(uint32_t service_id, uint32_t lcore,
178 * @b EXPERIMENTAL: this API may change without prior notice
180 * Retrieve the mapping of an lcore to a service.
182 * @param service_id the service to apply the lcore to
183 * @param lcore The lcore that will be mapped to service
185 * @retval 1 lcore is mapped to service
186 * @retval 0 lcore is not mapped to service
187 * @retval -EINVAL An invalid service or lcore was provided.
189 int32_t rte_service_map_lcore_get(uint32_t service_id, uint32_t lcore);
193 * @b EXPERIMENTAL: this API may change without prior notice
195 * Set the runstate of the service.
197 * Each service is either running or stopped. Setting a non-zero runstate
198 * enables the service to run, while setting runstate zero disables it.
200 * @param id The id of the service
201 * @param runstate The run state to apply to the service
203 * @retval 0 The service was successfully started
204 * @retval -EINVAL Invalid service id
206 int32_t rte_service_runstate_set(uint32_t id, uint32_t runstate);
210 * @b EXPERIMENTAL: this API may change without prior notice
212 * Get the runstate for the service with *id*. See *rte_service_runstate_set*
213 * for details of runstates.
215 * @retval 1 Service is running
216 * @retval 0 Service is stopped
217 * @retval -EINVAL Invalid service id
219 int32_t rte_service_runstate_get(uint32_t id);
223 * @b EXPERIMENTAL: this API may change without prior notice
225 * Start a service core.
227 * Starting a core makes the core begin polling. Any services assigned to it
228 * will be run as fast as possible.
231 * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
232 * currently assigned to be a service core.
234 int32_t rte_service_lcore_start(uint32_t lcore_id);
238 * @b EXPERIMENTAL: this API may change without prior notice
240 * Stop a service core.
242 * Stopping a core makes the core become idle, but remains assigned as a
246 * @retval -EINVAL Invalid *lcore_id* provided
247 * @retval -EALREADY Already stopped core
248 * @retval -EBUSY Failed to stop core, as it would cause a service to not
249 * be run, as this is the only core currently running the service.
250 * The application must stop the service first, and then stop the
253 int32_t rte_service_lcore_stop(uint32_t lcore_id);
257 * @b EXPERIMENTAL: this API may change without prior notice
259 * Adds lcore to the list of service cores.
261 * This functions can be used at runtime in order to modify the service core
265 * @retval -EBUSY lcore is busy, and not available for service core duty
266 * @retval -EALREADY lcore is already added to the service core list
267 * @retval -EINVAL Invalid lcore provided
269 int32_t rte_service_lcore_add(uint32_t lcore);
273 * @b EXPERIMENTAL: this API may change without prior notice
275 * Removes lcore from the list of service cores.
277 * This can fail if the core is not stopped, see *rte_service_core_stop*.
280 * @retval -EBUSY Lcore is not stopped, stop service core before removing.
281 * @retval -EINVAL failed to add lcore to service core mask.
283 int32_t rte_service_lcore_del(uint32_t lcore);
287 * @b EXPERIMENTAL: this API may change without prior notice
289 * Retrieve the number of service cores currently available.
291 * This function returns the integer count of service cores available. The
292 * service core count can be used in mapping logic when creating mappings
293 * from service cores to services.
295 * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
298 * @return The number of service cores currently configured.
300 int32_t rte_service_lcore_count(void);
304 * @b EXPERIMENTAL: this API may change without prior notice
306 * Resets all service core mappings. This does not remove the service cores
307 * from duty, just unmaps all services / cores, and stops() the service cores.
308 * The runstate of services is not modified.
312 int32_t rte_service_lcore_reset_all(void);
316 * @b EXPERIMENTAL: this API may change without prior notice
318 * Enable or disable statistics collection for *service*.
320 * This function enables per core, per-service cycle count collection.
321 * @param service The service to enable statistics gathering on.
322 * @param enable Zero to disable statistics, non-zero to enable.
324 * @retval -EINVAL Invalid service pointer passed
326 int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
331 * @b EXPERIMENTAL: this API may change without prior notice
333 * Retrieve the list of currently enabled service cores.
335 * This function fills in an application supplied array, with each element
336 * indicating the lcore_id of a service core.
338 * Adding and removing service cores can be performed using
339 * *rte_service_lcore_add* and *rte_service_lcore_del*.
340 * @param [out] array An array of at least *rte_service_lcore_count* items.
341 * If statically allocating the buffer, use RTE_MAX_LCORE.
342 * @param [out] n The size of *array*.
343 * @retval >=0 Number of service cores that have been populated in the array
344 * @retval -ENOMEM The provided array is not large enough to fill in the
345 * service core list. No items have been populated, call this function
346 * with a size of at least *rte_service_core_count* items.
348 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
352 * @b EXPERIMENTAL: this API may change without prior notice
354 * Get the numer of services running on the supplied lcore.
356 * @param lcore Id of the service core.
357 * @retval >=0 Number of services registered to this core.
358 * @retval -EINVAL Invalid lcore provided
359 * @retval -ENOTSUP The provided lcore is not a service core.
361 int32_t rte_service_lcore_count_services(uint32_t lcore);
365 * @b EXPERIMENTAL: this API may change without prior notice
367 * Dumps any information available about the service. If service is NULL,
368 * dumps info for all services.
370 int32_t rte_service_dump(FILE *f, struct rte_service_spec *service);
377 #endif /* _RTE_SERVICE_H_ */