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 * Enable *service* to run.
197 * This function switches on a service during runtime.
198 * @retval 0 The service was successfully started
200 int32_t rte_service_start(struct rte_service_spec *service);
204 * @b EXPERIMENTAL: this API may change without prior notice
208 * Switch off a service, so it is not run until it is *rte_service_start* is
210 * @retval 0 Service successfully switched off
212 int32_t rte_service_stop(struct rte_service_spec *service);
216 * @b EXPERIMENTAL: this API may change without prior notice
218 * Returns if *service* is currently running.
220 * This function returns true if the service has been started using
221 * *rte_service_start*, AND a service core is mapped to the service. This
222 * function can be used to ensure that the service will be run.
224 * @retval 1 Service is currently running, and has a service lcore mapped
225 * @retval 0 Service is currently stopped, or no service lcore is mapped
226 * @retval -EINVAL Invalid service pointer provided
228 int32_t rte_service_is_running(const struct rte_service_spec *service);
232 * @b EXPERIMENTAL: this API may change without prior notice
234 * Start a service core.
236 * Starting a core makes the core begin polling. Any services assigned to it
237 * will be run as fast as possible.
240 * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
241 * currently assigned to be a service core.
243 int32_t rte_service_lcore_start(uint32_t lcore_id);
247 * @b EXPERIMENTAL: this API may change without prior notice
249 * Stop a service core.
251 * Stopping a core makes the core become idle, but remains assigned as a
255 * @retval -EINVAL Invalid *lcore_id* provided
256 * @retval -EALREADY Already stopped core
257 * @retval -EBUSY Failed to stop core, as it would cause a service to not
258 * be run, as this is the only core currently running the service.
259 * The application must stop the service first, and then stop the
262 int32_t rte_service_lcore_stop(uint32_t lcore_id);
266 * @b EXPERIMENTAL: this API may change without prior notice
268 * Adds lcore to the list of service cores.
270 * This functions can be used at runtime in order to modify the service core
274 * @retval -EBUSY lcore is busy, and not available for service core duty
275 * @retval -EALREADY lcore is already added to the service core list
276 * @retval -EINVAL Invalid lcore provided
278 int32_t rte_service_lcore_add(uint32_t lcore);
282 * @b EXPERIMENTAL: this API may change without prior notice
284 * Removes lcore from the list of service cores.
286 * This can fail if the core is not stopped, see *rte_service_core_stop*.
289 * @retval -EBUSY Lcore is not stopped, stop service core before removing.
290 * @retval -EINVAL failed to add lcore to service core mask.
292 int32_t rte_service_lcore_del(uint32_t lcore);
296 * @b EXPERIMENTAL: this API may change without prior notice
298 * Retrieve the number of service cores currently available.
300 * This function returns the integer count of service cores available. The
301 * service core count can be used in mapping logic when creating mappings
302 * from service cores to services.
304 * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
307 * @return The number of service cores currently configured.
309 int32_t rte_service_lcore_count(void);
313 * @b EXPERIMENTAL: this API may change without prior notice
315 * Resets all service core mappings. This does not remove the service cores
316 * from duty, just unmaps all services / cores, and stops() the service cores.
317 * The runstate of services is not modified.
321 int32_t rte_service_lcore_reset_all(void);
325 * @b EXPERIMENTAL: this API may change without prior notice
327 * Enable or disable statistics collection for *service*.
329 * This function enables per core, per-service cycle count collection.
330 * @param service The service to enable statistics gathering on.
331 * @param enable Zero to disable statistics, non-zero to enable.
333 * @retval -EINVAL Invalid service pointer passed
335 int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
340 * @b EXPERIMENTAL: this API may change without prior notice
342 * Retrieve the list of currently enabled service cores.
344 * This function fills in an application supplied array, with each element
345 * indicating the lcore_id of a service core.
347 * Adding and removing service cores can be performed using
348 * *rte_service_lcore_add* and *rte_service_lcore_del*.
349 * @param [out] array An array of at least *rte_service_lcore_count* items.
350 * If statically allocating the buffer, use RTE_MAX_LCORE.
351 * @param [out] n The size of *array*.
352 * @retval >=0 Number of service cores that have been populated in the array
353 * @retval -ENOMEM The provided array is not large enough to fill in the
354 * service core list. No items have been populated, call this function
355 * with a size of at least *rte_service_core_count* items.
357 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
361 * @b EXPERIMENTAL: this API may change without prior notice
363 * Get the numer of services running on the supplied lcore.
365 * @param lcore Id of the service core.
366 * @retval >=0 Number of services registered to this core.
367 * @retval -EINVAL Invalid lcore provided
368 * @retval -ENOTSUP The provided lcore is not a service core.
370 int32_t rte_service_lcore_count_services(uint32_t lcore);
374 * @b EXPERIMENTAL: this API may change without prior notice
376 * Dumps any information available about the service. If service is NULL,
377 * dumps info for all services.
379 int32_t rte_service_dump(FILE *f, struct rte_service_spec *service);
386 #endif /* _RTE_SERVICE_H_ */