New upstream version 17.08
[deb_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(const struct rte_service_spec *service);
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(const struct rte_service_spec *service,
150                                      uint32_t capability);
151
152 /**
153  * @warning
154  * @b EXPERIMENTAL: this API may change without prior notice
155  *
156  * Enable a core to run a service.
157  *
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*.
160  *
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.
166  *
167  * @retval 0 lcore added successfully
168  * @retval -EINVAL An invalid service or lcore was provided.
169  */
170 int32_t rte_service_enable_on_lcore(struct rte_service_spec *service,
171                                    uint32_t lcore);
172
173 /**
174  * @warning
175  * @b EXPERIMENTAL: this API may change without prior notice
176  *
177  * Disable a core to run a service.
178  *
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*.
181  *
182  * @retval 0 Lcore removed successfully
183  * @retval -EINVAL An invalid service or lcore was provided.
184  */
185 int32_t rte_service_disable_on_lcore(struct rte_service_spec *service,
186                                    uint32_t lcore);
187
188 /**
189  * @warning
190  * @b EXPERIMENTAL: this API may change without prior notice
191  *
192  * Return if an lcore is enabled for the service.
193  *
194  * This function allows the application to query if *lcore* is currently set to
195  * run *service*.
196  *
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.
200  */
201 int32_t rte_service_get_enabled_on_lcore(struct rte_service_spec *service,
202                                         uint32_t lcore);
203
204
205 /**
206  * @warning
207  * @b EXPERIMENTAL: this API may change without prior notice
208  *
209  * Enable *service* to run.
210  *
211  * This function switches on a service during runtime.
212  * @retval 0 The service was successfully started
213  */
214 int32_t rte_service_start(struct rte_service_spec *service);
215
216 /**
217  * @warning
218  * @b EXPERIMENTAL: this API may change without prior notice
219  *
220  * Disable *service*.
221  *
222  * Switch off a service, so it is not run until it is *rte_service_start* is
223  * called on it.
224  * @retval 0 Service successfully switched off
225  */
226 int32_t rte_service_stop(struct rte_service_spec *service);
227
228 /**
229  * @warning
230  * @b EXPERIMENTAL: this API may change without prior notice
231  *
232  * Returns if *service* is currently running.
233  *
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.
237  *
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
241  */
242 int32_t rte_service_is_running(const struct rte_service_spec *service);
243
244 /**
245  * @warning
246  * @b EXPERIMENTAL: this API may change without prior notice
247  *
248  * Start a service core.
249  *
250  * Starting a core makes the core begin polling. Any services assigned to it
251  * will be run as fast as possible.
252  *
253  * @retval 0 Success
254  * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
255  *          currently assigned to be a service core.
256  */
257 int32_t rte_service_lcore_start(uint32_t lcore_id);
258
259 /**
260  * @warning
261  * @b EXPERIMENTAL: this API may change without prior notice
262  *
263  * Stop a service core.
264  *
265  * Stopping a core makes the core become idle, but remains  assigned as a
266  * service core.
267  *
268  * @retval 0 Success
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
274  *          lcore.
275  */
276 int32_t rte_service_lcore_stop(uint32_t lcore_id);
277
278 /**
279  * @warning
280  * @b EXPERIMENTAL: this API may change without prior notice
281  *
282  * Adds lcore to the list of service cores.
283  *
284  * This functions can be used at runtime in order to modify the service core
285  * mask.
286  *
287  * @retval 0 Success
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
291  */
292 int32_t rte_service_lcore_add(uint32_t lcore);
293
294 /**
295  * @warning
296  * @b EXPERIMENTAL: this API may change without prior notice
297  *
298  * Removes lcore from the list of service cores.
299  *
300  * This can fail if the core is not stopped, see *rte_service_core_stop*.
301  *
302  * @retval 0 Success
303  * @retval -EBUSY Lcore is not stopped, stop service core before removing.
304  * @retval -EINVAL failed to add lcore to service core mask.
305  */
306 int32_t rte_service_lcore_del(uint32_t lcore);
307
308 /**
309  * @warning
310  * @b EXPERIMENTAL: this API may change without prior notice
311  *
312  * Retrieve the number of service cores currently available.
313  *
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.
317  *
318  * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
319  * service core.
320  *
321  * @return The number of service cores currently configured.
322  */
323 int32_t rte_service_lcore_count(void);
324
325 /**
326  * @warning
327  * @b EXPERIMENTAL: this API may change without prior notice
328  *
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.
332  *
333  * @retval 0 Success
334  */
335 int32_t rte_service_lcore_reset_all(void);
336
337 /**
338  * @warning
339  * @b EXPERIMENTAL: this API may change without prior notice
340  *
341  * Enable or disable statistics collection for *service*.
342  *
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.
346  * @retval 0 Success
347  * @retval -EINVAL Invalid service pointer passed
348  */
349 int32_t rte_service_set_stats_enable(struct rte_service_spec *service,
350                                   int32_t enable);
351
352 /**
353  * @warning
354  * @b EXPERIMENTAL: this API may change without prior notice
355  *
356  * Retrieve the list of currently enabled service cores.
357  *
358  * This function fills in an application supplied array, with each element
359  * indicating the lcore_id of a service core.
360  *
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.
370  */
371 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
372
373 /**
374  * @warning
375  * @b EXPERIMENTAL: this API may change without prior notice
376  *
377  * Dumps any information available about the service. If service is NULL,
378  * dumps info for all services.
379  */
380 int32_t rte_service_dump(FILE *f, struct rte_service_spec *service);
381
382 #ifdef __cplusplus
383 }
384 #endif
385
386
387 #endif /* _RTE_SERVICE_H_ */