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