service: add component runstate
[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 it using
89  * *rte_service_set_coremask*.
90  *
91  * @param spec The specification of the service to register
92  * @param[out] service_id A pointer to a uint32_t, which will be filled in
93  *             during registration of the service. It is set to the integers
94  *             service number given to the service. This parameter may be NULL.
95  * @retval 0 Successfully registered the service.
96  *         -EINVAL Attempted to register an invalid service (eg, no callback
97  *         set)
98  */
99 int32_t rte_service_component_register(const struct rte_service_spec *spec,
100                                        uint32_t *service_id);
101
102 /**
103  * @warning
104  * @b EXPERIMENTAL: this API may change without prior notice
105  *
106  * Unregister a service component.
107  *
108  * The service being removed must be stopped before calling this function.
109  *
110  * @retval 0 The service was successfully unregistered.
111  * @retval -EBUSY The service is currently running, stop the service before
112  *          calling unregister. No action has been taken.
113  */
114 int32_t rte_service_component_unregister(uint32_t id);
115
116 /**
117  * @warning
118  * @b EXPERIMENTAL: this API may change without prior notice
119  *
120  * Private function to allow EAL to initialized default mappings.
121  *
122  * This function iterates all the services, and maps then to the available
123  * cores. Based on the capabilities of the services, they are set to run on the
124  * available cores in a round-robin manner.
125  *
126  * @retval 0 Success
127  * @retval -ENOTSUP No service lcores in use
128  * @retval -EINVAL Error while iterating over services
129  * @retval -ENODEV Error in enabling service lcore on a service
130  * @retval -ENOEXEC Error when starting services
131  */
132 int32_t rte_service_start_with_defaults(void);
133
134 /**
135  * @warning
136  * @b EXPERIMENTAL: this API may change without prior notice
137  *
138  * Set the backend runstate of a component.
139  *
140  * This function allows services to be registered at startup, but not yet
141  * enabled to run by default. When the service has been configured (via the
142  * usual method; eg rte_eventdev_configure, the service can mark itself as
143  * ready to run. The differentiation between backend runstate and
144  * service_runstate is that the backend runstate is set by the service
145  * component while the service runstate is reserved for application usage.
146  *
147  * @retval 0 Success
148  */
149 int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
150
151 /**
152  * @warning
153  * @b EXPERIMENTAL: this API may change without prior notice
154  *
155  * Initialize the service library.
156  *
157  * In order to use the service library, it must be initialized. EAL initializes
158  * the library at startup.
159  *
160  * @retval 0 Success
161  * @retval -EALREADY Service library is already initialized
162  */
163 int32_t rte_service_init(void);
164
165 #endif /* _RTE_SERVICE_PRIVATE_H_ */