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(const struct rte_service_spec *service);
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(const struct rte_service_spec *service,
150 uint32_t capability);
154 * @b EXPERIMENTAL: this API may change without prior notice
156 * Enable a core to run a service.
158 * Each core can be added or removed from running specific services. This
159 * functions adds *lcore* to the set of cores that will run *service*.
161 * If multiple cores are enabled on a service, an atomic is used to ensure that
162 * only one cores runs the service at a time. The exception to this is when
163 * a service indicates that it is multi-thread safe by setting the capability
164 * called RTE_SERVICE_CAP_MT_SAFE. With the multi-thread safe capability set,
165 * the service function can be run on multiple threads at the same time.
167 * @retval 0 lcore added successfully
168 * @retval -EINVAL An invalid service or lcore was provided.
170 int32_t rte_service_enable_on_lcore(struct rte_service_spec *service,
175 * @b EXPERIMENTAL: this API may change without prior notice
177 * Disable a core to run a service.
179 * Each core can be added or removed from running specific services. This
180 * functions removes *lcore* to the set of cores that will run *service*.
182 * @retval 0 Lcore removed successfully
183 * @retval -EINVAL An invalid service or lcore was provided.
185 int32_t rte_service_disable_on_lcore(struct rte_service_spec *service,
190 * @b EXPERIMENTAL: this API may change without prior notice
192 * Return if an lcore is enabled for the service.
194 * This function allows the application to query if *lcore* is currently set to
197 * @retval 1 Lcore enabled on this lcore
198 * @retval 0 Lcore disabled on this lcore
199 * @retval -EINVAL An invalid service or lcore was provided.
201 int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service,
207 * @b EXPERIMENTAL: this API may change without prior notice
209 * Enable *service* to run.
211 * This function switches on a service during runtime.
212 * @retval 0 The service was successfully started
214 int32_t rte_service_start(struct rte_service_spec *service);
218 * @b EXPERIMENTAL: this API may change without prior notice
222 * Switch off a service, so it is not run until it is *rte_service_start* is
224 * @retval 0 Service successfully switched off
226 int32_t rte_service_stop(struct rte_service_spec *service);
230 * @b EXPERIMENTAL: this API may change without prior notice
232 * Returns if *service* is currently running.
234 * This function returns true if the service has been started using
235 * *rte_service_start*, AND a service core is mapped to the service. This
236 * function can be used to ensure that the service will be run.
238 * @retval 1 Service is currently running, and has a service lcore mapped
239 * @retval 0 Service is currently stopped, or no service lcore is mapped
240 * @retval -EINVAL Invalid service pointer provided
242 int32_t rte_service_is_running(const struct rte_service_spec *service);
246 * @b EXPERIMENTAL: this API may change without prior notice
248 * Start a service core.
250 * Starting a core makes the core begin polling. Any services assigned to it
251 * will be run as fast as possible.
254 * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
255 * currently assigned to be a service core.
257 int32_t rte_service_lcore_start(uint32_t lcore_id);
261 * @b EXPERIMENTAL: this API may change without prior notice
263 * Stop a service core.
265 * Stopping a core makes the core become idle, but remains assigned as a
269 * @retval -EINVAL Invalid *lcore_id* provided
270 * @retval -EALREADY Already stopped core
271 * @retval -EBUSY Failed to stop core, as it would cause a service to not
272 * be run, as this is the only core currently running the service.
273 * The application must stop the service first, and then stop the
276 int32_t rte_service_lcore_stop(uint32_t lcore_id);
280 * @b EXPERIMENTAL: this API may change without prior notice
282 * Adds lcore to the list of service cores.
284 * This functions can be used at runtime in order to modify the service core
288 * @retval -EBUSY lcore is busy, and not available for service core duty
289 * @retval -EALREADY lcore is already added to the service core list
290 * @retval -EINVAL Invalid lcore provided
292 int32_t rte_service_lcore_add(uint32_t lcore);
296 * @b EXPERIMENTAL: this API may change without prior notice
298 * Removes lcore from the list of service cores.
300 * This can fail if the core is not stopped, see *rte_service_core_stop*.
303 * @retval -EBUSY Lcore is not stopped, stop service core before removing.
304 * @retval -EINVAL failed to add lcore to service core mask.
306 int32_t rte_service_lcore_del(uint32_t lcore);
310 * @b EXPERIMENTAL: this API may change without prior notice
312 * Retrieve the number of service cores currently available.
314 * This function returns the integer count of service cores available. The
315 * service core count can be used in mapping logic when creating mappings
316 * from service cores to services.
318 * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
321 * @return The number of service cores currently configured.
323 int32_t rte_service_lcore_count(void);
327 * @b EXPERIMENTAL: this API may change without prior notice
329 * Resets all service core mappings. This does not remove the service cores
330 * from duty, just unmaps all services / cores, and stops() the service cores.
331 * The runstate of services is not modified.
335 int32_t rte_service_lcore_reset_all(void);
339 * @b EXPERIMENTAL: this API may change without prior notice
341 * Enable or disable statistics collection for *service*.
343 * This function enables per core, per-service cycle count collection.
344 * @param service The service to enable statistics gathering on.
345 * @param enable Zero to disable statistics, non-zero to enable.
347 * @retval -EINVAL Invalid service pointer passed
349 int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
354 * @b EXPERIMENTAL: this API may change without prior notice
356 * Retrieve the list of currently enabled service cores.
358 * This function fills in an application supplied array, with each element
359 * indicating the lcore_id of a service core.
361 * Adding and removing service cores can be performed using
362 * *rte_service_lcore_add* and *rte_service_lcore_del*.
363 * @param [out] array An array of at least *rte_service_lcore_count* items.
364 * If statically allocating the buffer, use RTE_MAX_LCORE.
365 * @param [out] n The size of *array*.
366 * @retval >=0 Number of service cores that have been populated in the array
367 * @retval -ENOMEM The provided array is not large enough to fill in the
368 * service core list. No items have been populated, call this function
369 * with a size of at least *rte_service_core_count* items.
371 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
375 * @b EXPERIMENTAL: this API may change without prior notice
377 * Dumps any information available about the service. If service is NULL,
378 * dumps info for all services.
380 int32_t rte_service_dump(FILE *f, struct rte_service_spec *service);
387 #endif /* _RTE_SERVICE_H_ */