service: use id in service stats functions
[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  * Map or unmap a lcore to a service.
156  *
157  * Each core can be added or removed from running a specific service. This
158  * function enables or disables *lcore* to run *service_id*.
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  * @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
169  *
170  * @retval 0 lcore map updated successfully
171  * @retval -EINVAL An invalid service or lcore was provided.
172  */
173 int32_t rte_service_map_lcore_set(uint32_t service_id, uint32_t lcore,
174                                   uint32_t enable);
175
176 /**
177  * @warning
178  * @b EXPERIMENTAL: this API may change without prior notice
179  *
180  * Retrieve the mapping of an lcore to a service.
181  *
182  * @param service_id the service to apply the lcore to
183  * @param lcore The lcore that will be mapped to service
184  *
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.
188  */
189 int32_t rte_service_map_lcore_get(uint32_t service_id, uint32_t lcore);
190
191 /**
192  * @warning
193  * @b EXPERIMENTAL: this API may change without prior notice
194  *
195  * Set the runstate of the service.
196  *
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.
199  *
200  * @param id The id of the service
201  * @param runstate The run state to apply to the service
202  *
203  * @retval 0 The service was successfully started
204  * @retval -EINVAL Invalid service id
205  */
206 int32_t rte_service_runstate_set(uint32_t id, uint32_t runstate);
207
208 /**
209  * @warning
210  * @b EXPERIMENTAL: this API may change without prior notice
211  *
212  * Get the runstate for the service with *id*. See *rte_service_runstate_set*
213  * for details of runstates.
214  *
215  * @retval 1 Service is running
216  * @retval 0 Service is stopped
217  * @retval -EINVAL Invalid service id
218  */
219 int32_t rte_service_runstate_get(uint32_t id);
220
221 /**
222  * @warning
223  * @b EXPERIMENTAL: this API may change without prior notice
224  *
225  * Start a service core.
226  *
227  * Starting a core makes the core begin polling. Any services assigned to it
228  * will be run as fast as possible.
229  *
230  * @retval 0 Success
231  * @retval -EINVAL Failed to start core. The *lcore_id* passed in is not
232  *          currently assigned to be a service core.
233  */
234 int32_t rte_service_lcore_start(uint32_t lcore_id);
235
236 /**
237  * @warning
238  * @b EXPERIMENTAL: this API may change without prior notice
239  *
240  * Stop a service core.
241  *
242  * Stopping a core makes the core become idle, but remains  assigned as a
243  * service core.
244  *
245  * @retval 0 Success
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
251  *          lcore.
252  */
253 int32_t rte_service_lcore_stop(uint32_t lcore_id);
254
255 /**
256  * @warning
257  * @b EXPERIMENTAL: this API may change without prior notice
258  *
259  * Adds lcore to the list of service cores.
260  *
261  * This functions can be used at runtime in order to modify the service core
262  * mask.
263  *
264  * @retval 0 Success
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
268  */
269 int32_t rte_service_lcore_add(uint32_t lcore);
270
271 /**
272  * @warning
273  * @b EXPERIMENTAL: this API may change without prior notice
274  *
275  * Removes lcore from the list of service cores.
276  *
277  * This can fail if the core is not stopped, see *rte_service_core_stop*.
278  *
279  * @retval 0 Success
280  * @retval -EBUSY Lcore is not stopped, stop service core before removing.
281  * @retval -EINVAL failed to add lcore to service core mask.
282  */
283 int32_t rte_service_lcore_del(uint32_t lcore);
284
285 /**
286  * @warning
287  * @b EXPERIMENTAL: this API may change without prior notice
288  *
289  * Retrieve the number of service cores currently available.
290  *
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.
294  *
295  * See *rte_service_lcore_list* for details on retrieving the lcore_id of each
296  * service core.
297  *
298  * @return The number of service cores currently configured.
299  */
300 int32_t rte_service_lcore_count(void);
301
302 /**
303  * @warning
304  * @b EXPERIMENTAL: this API may change without prior notice
305  *
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.
309  *
310  * @retval 0 Success
311  */
312 int32_t rte_service_lcore_reset_all(void);
313
314 /**
315  * @warning
316  * @b EXPERIMENTAL: this API may change without prior notice
317  *
318  * Enable or disable statistics collection for *service*.
319  *
320  * This function enables per core, per-service cycle count collection.
321  * @param id The service to enable statistics gathering on.
322  * @param enable Zero to disable statistics, non-zero to enable.
323  * @retval 0 Success
324  * @retval -EINVAL Invalid service pointer passed
325  */
326 int32_t rte_service_set_stats_enable(uint32_t id, int32_t enable);
327
328 /**
329  * @warning
330  * @b EXPERIMENTAL: this API may change without prior notice
331  *
332  * Retrieve the list of currently enabled service cores.
333  *
334  * This function fills in an application supplied array, with each element
335  * indicating the lcore_id of a service core.
336  *
337  * Adding and removing service cores can be performed using
338  * *rte_service_lcore_add* and *rte_service_lcore_del*.
339  * @param [out] array An array of at least *rte_service_lcore_count* items.
340  *              If statically allocating the buffer, use RTE_MAX_LCORE.
341  * @param [out] n The size of *array*.
342  * @retval >=0 Number of service cores that have been populated in the array
343  * @retval -ENOMEM The provided array is not large enough to fill in the
344  *          service core list. No items have been populated, call this function
345  *          with a size of at least *rte_service_core_count* items.
346  */
347 int32_t rte_service_lcore_list(uint32_t array[], uint32_t n);
348
349 /**
350  * @warning
351  * @b EXPERIMENTAL: this API may change without prior notice
352  *
353  * Get the numer of services running on the supplied lcore.
354  *
355  * @param lcore Id of the service core.
356  * @retval >=0 Number of services registered to this core.
357  * @retval -EINVAL Invalid lcore provided
358  * @retval -ENOTSUP The provided lcore is not a service core.
359  */
360 int32_t rte_service_lcore_count_services(uint32_t lcore);
361
362 /**
363  * @warning
364  * @b EXPERIMENTAL: this API may change without prior notice
365  *
366  * Dumps any information available about the service. When id is UINT32_MAX,
367  * this function dumps info for all services.
368  *
369  * @retval 0 Statistics have been successfully dumped
370  * @retval -EINVAL Invalid service id provided
371  */
372 int32_t rte_service_dump(FILE *f, uint32_t id);
373
374 #ifdef __cplusplus
375 }
376 #endif
377
378
379 #endif /* _RTE_SERVICE_H_ */