New upstream version 18.02
[deb_dpdk.git] / lib / librte_eal / common / include / rte_service_component.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _RTE_SERVICE_PRIVATE_H_
6 #define _RTE_SERVICE_PRIVATE_H_
7
8 /* This file specifies the internal service specification.
9  * Include this file if you are writing a component that requires CPU cycles to
10  * operate, and you wish to run the component using service cores
11  */
12 #include <rte_compat.h>
13 #include <rte_service.h>
14
15 /**
16  * @warning
17  * @b EXPERIMENTAL: this API may change without prior notice
18  *
19  * Signature of callback function to run a service.
20  */
21 typedef int32_t (*rte_service_func)(void *args);
22
23 /**
24  * @warning
25  * @b EXPERIMENTAL: this API may change without prior notice
26  *
27  * The specification of a service.
28  *
29  * This struct contains metadata about the service itself, the callback
30  * function to run one iteration of the service, a userdata pointer, flags etc.
31  */
32 struct rte_service_spec {
33         /** The name of the service. This should be used by the application to
34          * understand what purpose this service provides.
35          */
36         char name[RTE_SERVICE_NAME_MAX];
37         /** The callback to invoke to run one iteration of the service. */
38         rte_service_func callback;
39         /** The userdata pointer provided to the service callback. */
40         void *callback_userdata;
41         /** Flags to indicate the capabilities of this service. See defines in
42          * the public header file for values of RTE_SERVICE_CAP_*
43          */
44         uint32_t capabilities;
45         /** NUMA socket ID that this service is affinitized to */
46         int socket_id;
47 };
48
49 /**
50  * @warning
51  * @b EXPERIMENTAL: this API may change without prior notice
52  *
53  * Register a new service.
54  *
55  * A service represents a component that the requires CPU time periodically to
56  * achieve its purpose.
57  *
58  * For example the eventdev SW PMD requires CPU cycles to perform its
59  * scheduling. This can be achieved by registering it as a service, and the
60  * application can then assign CPU resources to that service.
61  *
62  * Note that when a service component registers itself, it is not permitted to
63  * add or remove service-core threads, or modify lcore-to-service mappings. The
64  * only API that may be called by the service-component is
65  * *rte_service_component_runstate_set*, which indicates that the service
66  * component is ready to be executed.
67  *
68  * @param spec The specification of the service to register
69  * @param[out] service_id A pointer to a uint32_t, which will be filled in
70  *             during registration of the service. It is set to the integers
71  *             service number given to the service. This parameter may be NULL.
72  * @retval 0 Successfully registered the service.
73  *         -EINVAL Attempted to register an invalid service (eg, no callback
74  *         set)
75  */
76 int32_t __rte_experimental
77 rte_service_component_register(const struct rte_service_spec *spec,
78                                uint32_t *service_id);
79
80 /**
81  * @warning
82  * @b EXPERIMENTAL: this API may change without prior notice
83  *
84  * Unregister a service component.
85  *
86  * The service being removed must be stopped before calling this function.
87  *
88  * @retval 0 The service was successfully unregistered.
89  * @retval -EBUSY The service is currently running, stop the service before
90  *          calling unregister. No action has been taken.
91  */
92 int32_t __rte_experimental rte_service_component_unregister(uint32_t id);
93
94 /**
95  * @warning
96  * @b EXPERIMENTAL: this API may change without prior notice
97  *
98  * Private function to allow EAL to initialized default mappings.
99  *
100  * This function iterates all the services, and maps then to the available
101  * cores. Based on the capabilities of the services, they are set to run on the
102  * available cores in a round-robin manner.
103  *
104  * @retval 0 Success
105  * @retval -ENOTSUP No service lcores in use
106  * @retval -EINVAL Error while iterating over services
107  * @retval -ENODEV Error in enabling service lcore on a service
108  * @retval -ENOEXEC Error when starting services
109  */
110 int32_t __rte_experimental rte_service_start_with_defaults(void);
111
112 /**
113  * @warning
114  * @b EXPERIMENTAL: this API may change without prior notice
115  *
116  * Set the backend runstate of a component.
117  *
118  * This function allows services to be registered at startup, but not yet
119  * enabled to run by default. When the service has been configured (via the
120  * usual method; eg rte_eventdev_configure, the service can mark itself as
121  * ready to run. The differentiation between backend runstate and
122  * service_runstate is that the backend runstate is set by the service
123  * component while the service runstate is reserved for application usage.
124  *
125  * @retval 0 Success
126  */
127 int32_t __rte_experimental rte_service_component_runstate_set(uint32_t id,
128                                                           uint32_t runstate);
129
130 /**
131  * @warning
132  * @b EXPERIMENTAL: this API may change without prior notice
133  *
134  * Initialize the service library.
135  *
136  * In order to use the service library, it must be initialized. EAL initializes
137  * the library at startup.
138  *
139  * @retval 0 Success
140  * @retval -EALREADY Service library is already initialized
141  */
142 int32_t rte_service_init(void);
143
144 /**
145  * @warning
146  * @b EXPERIMENTAL: this API may change without prior notice
147  *
148  * @internal Free up the memory that has been initialized.
149  * This routine is to be invoked prior to process termination.
150  *
151  * @retval None
152  */
153 void __rte_experimental rte_service_finalize(void);
154
155 #endif /* _RTE_SERVICE_PRIVATE_H_ */