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