service: use id in probe and get name
[dpdk.git] / lib / librte_eal / common / include / rte_service.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
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.
19  *
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.
31  */
32
33 #ifndef _RTE_SERVICE_H_
34 #define _RTE_SERVICE_H_
35
36 /**
37  * @file
38  *
39  * Service functions
40  *
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
43  * its processing.
44  *
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.
52  */
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 #include<stdio.h>
59 #include <stdint.h>
60 #include <sys/queue.h>
61
62 #include <rte_lcore.h>
63
64 /* forward declaration only. Definition in rte_service_private.h */
65 struct rte_service_spec;
66
67 #define RTE_SERVICE_NAME_MAX 32
68
69 /* Capabilities of a service.
70  *
71  * Use the *rte_service_probe_capability* function to check if a service is
72  * capable of a specific capability.
73  */
74 /** When set, the service is capable of having multiple threads run it at the
75  *  same time.
76  */
77 #define RTE_SERVICE_CAP_MT_SAFE (1 << 0)
78
79 /**
80  * @warning
81  * @b EXPERIMENTAL: this API may change without prior notice
82  *
83  *  Return the number of services registered.
84  *
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.
87  *
88  * @return The number of services registered.
89  */
90 uint32_t rte_service_get_count(void);
91
92
93 /**
94  * @warning
95  * @b EXPERIMENTAL: this API may change without prior notice
96  *
97  * Return the specification of a service by integer id.
98  *
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.
103  *
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.
107  */
108 struct rte_service_spec *rte_service_get_by_id(uint32_t id);
109
110 /**
111  * @warning
112  * @b EXPERIMENTAL: this API may change without prior notice
113  *
114  * Return the specification of a service by name.
115  *
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.
120  *
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.
124  */
125 struct rte_service_spec *rte_service_get_by_name(const char *name);
126
127 /**
128  * @warning
129  * @b EXPERIMENTAL: this API may change without prior notice
130  *
131  * Return the name of the service.
132  *
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.
135  */
136 const char *rte_service_get_name(uint32_t id);
137
138 /**
139  * @warning
140  * @b EXPERIMENTAL: this API may change without prior notice
141  *
142  * Check if a service has a specific capability.
143  *
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
148  */
149 int32_t rte_service_probe_capability(uint32_t id, uint32_t capability);
150
151 /**
152  * @warning
153  * @b EXPERIMENTAL: this API may change without prior notice
154  *
155  * Enable a core to run a service.
156  *
157  * Each core can be added or removed from running specific services. This
158  * functions adds *lcore* to the set of cores that will run *service*.
159  *
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.
165  *
166  * @retval 0 lcore added successfully
167  * @retval -EINVAL An invalid service or lcore was provided.
168  */
169 int32_t rte_service_enable_on_lcore(struct rte_service_spec *service,
170                                    uint32_t lcore);
171
172 /**
173  * @warning
174  * @b EXPERIMENTAL: this API may change without prior notice
175  *
176  * Disable a core to run a service.
177  *
178  * Each core can be added or removed from running specific services. This
179  * functions removes *lcore* to the set of cores that will run *service*.
180  *
181  * @retval 0 Lcore removed successfully
182  * @retval -EINVAL An invalid service or lcore was provided.
183  */
184 int32_t rte_service_disable_on_lcore(struct rte_service_spec *service,
185                                    uint32_t lcore);
186
187 /**
188  * @warning
189  * @b EXPERIMENTAL: this API may change without prior notice
190  *
191  * Return if an lcore is enabled for the service.
192  *
193  * This function allows the application to query if *lcore* is currently set to
194  * run *service*.
195  *
196  * @retval 1 Lcore enabled on this lcore
197  * @retval 0 Lcore disabled on this lcore
198  * @retval -EINVAL An invalid service or lcore was provided.
199  */
200 int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service,
201                                         uint32_t lcore);
202
203
204 /**
205  * @warning
206  * @b EXPERIMENTAL: this API may change without prior notice
207  *
208  * Enable *service* to run.
209  *
210  * This function switches on a service during runtime.
211  * @retval 0 The service was successfully started
212  */
213 int32_t rte_service_start(struct rte_service_spec *service);
214
215 /**
216  * @warning
217  * @b EXPERIMENTAL: this API may change without prior notice
218  *
219  * Disable *service*.
220  *
221  * Switch off a service, so it is not run until it is *rte_service_start* is
222  * called on it.
223  * @retval 0 Service successfully switched off
224  */
225 int32_t rte_service_stop(struct rte_service_spec *service);
226
227 /**
228  * @warning
229  * @b EXPERIMENTAL: this API may change without prior notice
230  *
231  * Returns if *service* is currently running.
232  *
233  * This function returns true if the service has been started using
234  * *rte_service_start*, AND a service core is mapped to the service. This
235  * function can be used to ensure that the service will be run.
236  *
237  * @retval 1 Service is currently running, and has a service lcore mapped
238  * @retval 0 Service is currently stopped, or no service lcore is mapped
239  * @retval -EINVAL Invalid service pointer provided
240  */
241 int32_t rte_service_is_running(const struct rte_service_spec *service);
242
243 /**
244  * @warning
245  * @b EXPERIMENTAL: this API may change without prior notice
246  *
247  * Start a service core.
248  *
249  * Starting a core makes the core begin polling. Any services assigned to it
250  * will be run as fast as possible.
251  *
252  * @retval 0 Success
253  * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
254  *          currently assigned to be a service core.
255  */
256 int32_t rte_service_lcore_start(uint32_t lcore_id);
257
258 /**
259  * @warning
260  * @b EXPERIMENTAL: this API may change without prior notice
261  *
262  * Stop a service core.
263  *
264  * Stopping a core makes the core become idle, but remains  assigned as a
265  * service core.
266  *
267  * @retval 0 Success
268  * @retval -EINVAL Invalid *lcore_id* provided
269  * @retval -EALREADY Already stopped core
270  * @retval -EBUSY Failed to stop core, as it would cause a service to not
271  *          be run, as this is the only core currently running the service.
272  *          The application must stop the service first, and then stop the
273  *          lcore.
274  */
275 int32_t rte_service_lcore_stop(uint32_t lcore_id);
276
277 /**
278  * @warning
279  * @b EXPERIMENTAL: this API may change without prior notice
280  *
281  * Adds lcore to the list of service cores.
282  *
283  * This functions can be used at runtime in order to modify the service core
284  * mask.
285  *
286  * @retval 0 Success
287  * @retval -EBUSY lcore is busy, and not available for service core duty
288  * @retval -EALREADY lcore is already added to the service core list
289  * @retval -EINVAL Invalid lcore provided
290  */
291 int32_t rte_service_lcore_add(uint32_t lcore);
292
293 /**
294  * @warning
295  * @b EXPERIMENTAL: this API may change without prior notice
296  *
297  * Removes lcore from the list of service cores.
298  *
299  * This can fail if the core is not stopped, see *rte_service_core_stop*.
300  *
301  * @retval 0 Success
302  * @retval -EBUSY Lcore is not stopped, stop service core before removing.
303  * @retval -EINVAL failed to add lcore to service core mask.
304  */
305 int32_t rte_service_lcore_del(uint32_t lcore);
306
307 /**
308  * @warning
309  * @b EXPERIMENTAL: this API may change without prior notice
310  *
311  * Retrieve the number of service cores currently available.
312  *
313  * This function returns the integer count of service cores available. The
314  * service core count can be used in mapping logic when creating mappings
315  * from service cores to services.
316  *
317  * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
318  * service core.
319  *
320  * @return The number of service cores currently configured.
321  */
322 int32_t rte_service_lcore_count(void);
323
324 /**
325  * @warning
326  * @b EXPERIMENTAL: this API may change without prior notice
327  *
328  * Resets all service core mappings. This does not remove the service cores
329  * from duty, just unmaps all services / cores, and stops() the service cores.
330  * The runstate of services is not modified.
331  *
332  * @retval 0 Success
333  */
334 int32_t rte_service_lcore_reset_all(void);
335
336 /**
337  * @warning
338  * @b EXPERIMENTAL: this API may change without prior notice
339  *
340  * Enable or disable statistics collection for *service*.
341  *
342  * This function enables per core, per-service cycle count collection.
343  * @param service The service to enable statistics gathering on.
344  * @param enable Zero to disable statistics, non-zero to enable.
345  * @retval 0 Success
346  * @retval -EINVAL Invalid service pointer passed
347  */
348 int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
349                                   int32_t enable);
350
351 /**
352  * @warning
353  * @b EXPERIMENTAL: this API may change without prior notice
354  *
355  * Retrieve the list of currently enabled service cores.
356  *
357  * This function fills in an application supplied array, with each element
358  * indicating the lcore_id of a service core.
359  *
360  * Adding and removing service cores can be performed using
361  * *rte_service_lcore_add* and *rte_service_lcore_del*.
362  * @param [out] array An array of at least *rte_service_lcore_count* items.
363  *              If statically allocating the buffer, use RTE_MAX_LCORE.
364  * @param [out] n The size of *array*.
365  * @retval >=0 Number of service cores that have been populated in the array
366  * @retval -ENOMEM The provided array is not large enough to fill in the
367  *          service core list. No items have been populated, call this function
368  *          with a size of at least *rte_service_core_count* items.
369  */
370 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
371
372 /**
373  * @warning
374  * @b EXPERIMENTAL: this API may change without prior notice
375  *
376  * Get the numer of services running on the supplied lcore.
377  *
378  * @param lcore Id of the service core.
379  * @retval >=0 Number of services registered to this core.
380  * @retval -EINVAL Invalid lcore provided
381  * @retval -ENOTSUP The provided lcore is not a service core.
382  */
383 int32_t rte_service_lcore_count_services(uint32_t lcore);
384
385 /**
386  * @warning
387  * @b EXPERIMENTAL: this API may change without prior notice
388  *
389  * Dumps any information available about the service. If service is NULL,
390  * dumps info for all services.
391  */
392 int32_t rte_service_dump(FILE *f, struct rte_service_spec *service);
393
394 #ifdef __cplusplus
395 }
396 #endif
397
398
399 #endif /* _RTE_SERVICE_H_ */