7a946a1e44663c8eb23bee8935f3030a6673d2a6
[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 it using
89  * *rte_service_set_coremask*.
90  *
91  * @param spec The specification of the service to register
92  * @retval 0 Successfully registered the service.
93  *         -EINVAL Attempted to register an invalid service (eg, no callback
94  *         set)
95  */
96 int32_t rte_service_register(const struct rte_service_spec *spec);
97
98 /**
99  * @warning
100  * @b EXPERIMENTAL: this API may change without prior notice
101  *
102  * Unregister a service.
103  *
104  * The service being removed must be stopped before calling this function.
105  *
106  * @retval 0 The service was successfully unregistered.
107  * @retval -EBUSY The service is currently running, stop the service before
108  *          calling unregister. No action has been taken.
109  */
110 int32_t rte_service_unregister(struct rte_service_spec *service);
111
112 /**
113  * @warning
114  * @b EXPERIMENTAL: this API may change without prior notice
115  *
116  * Private function to allow EAL to initialized default mappings.
117  *
118  * This function iterates all the services, and maps then to the available
119  * cores. Based on the capabilities of the services, they are set to run on the
120  * available cores in a round-robin manner.
121  *
122  * @retval 0 Success
123  * @retval -ENOTSUP No service lcores in use
124  * @retval -EINVAL Error while iterating over services
125  * @retval -ENODEV Error in enabling service lcore on a service
126  * @retval -ENOEXEC Error when starting services
127  */
128 int32_t rte_service_start_with_defaults(void);
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 #endif /* _RTE_SERVICE_PRIVATE_H_ */