199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _SERVICE_PRIVATE_H_ 699a2dd95SBruce Richardson #define _SERVICE_PRIVATE_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /* This file specifies the internal service specification. 999a2dd95SBruce Richardson * Include this file if you are writing a component that requires CPU cycles to 1099a2dd95SBruce Richardson * operate, and you wish to run the component using service cores 1199a2dd95SBruce Richardson */ 1299a2dd95SBruce Richardson 13*719834a6SMattias Rönnblom #include <rte_service.h> 14*719834a6SMattias Rönnblom 1599a2dd95SBruce Richardson #ifdef __cplusplus 1699a2dd95SBruce Richardson extern "C" { 1799a2dd95SBruce Richardson #endif 1899a2dd95SBruce Richardson 1999a2dd95SBruce Richardson /** 2099a2dd95SBruce Richardson * Signature of callback function to run a service. 21809bd244SMattias Rönnblom * 22809bd244SMattias Rönnblom * A service function call resulting in no actual work being 23809bd244SMattias Rönnblom * performed, should return -EAGAIN. In that case, the (presumbly few) 24809bd244SMattias Rönnblom * cycles spent will not be counted toward the lcore or service-level 25809bd244SMattias Rönnblom * cycles attributes. 2699a2dd95SBruce Richardson */ 2799a2dd95SBruce Richardson typedef int32_t (*rte_service_func)(void *args); 2899a2dd95SBruce Richardson 2999a2dd95SBruce Richardson /** 3099a2dd95SBruce Richardson * The specification of a service. 3199a2dd95SBruce Richardson * 3299a2dd95SBruce Richardson * This struct contains metadata about the service itself, the callback 3399a2dd95SBruce Richardson * function to run one iteration of the service, a userdata pointer, flags etc. 3499a2dd95SBruce Richardson */ 3599a2dd95SBruce Richardson struct rte_service_spec { 3699a2dd95SBruce Richardson /** The name of the service. This should be used by the application to 3799a2dd95SBruce Richardson * understand what purpose this service provides. 3899a2dd95SBruce Richardson */ 3999a2dd95SBruce Richardson char name[RTE_SERVICE_NAME_MAX]; 4099a2dd95SBruce Richardson /** The callback to invoke to run one iteration of the service. */ 4199a2dd95SBruce Richardson rte_service_func callback; 4299a2dd95SBruce Richardson /** The userdata pointer provided to the service callback. */ 4399a2dd95SBruce Richardson void *callback_userdata; 4499a2dd95SBruce Richardson /** Flags to indicate the capabilities of this service. See defines in 4599a2dd95SBruce Richardson * the public header file for values of RTE_SERVICE_CAP_* 4699a2dd95SBruce Richardson */ 4799a2dd95SBruce Richardson uint32_t capabilities; 4899a2dd95SBruce Richardson /** NUMA socket ID that this service is affinitized to */ 4999a2dd95SBruce Richardson int socket_id; 5099a2dd95SBruce Richardson }; 5199a2dd95SBruce Richardson 5299a2dd95SBruce Richardson /** 5399a2dd95SBruce Richardson * Register a new service. 5499a2dd95SBruce Richardson * 5599a2dd95SBruce Richardson * A service represents a component that requires CPU time periodically to 5699a2dd95SBruce Richardson * achieve its purpose. 5799a2dd95SBruce Richardson * 5899a2dd95SBruce Richardson * For example the eventdev SW PMD requires CPU cycles to perform its 5999a2dd95SBruce Richardson * scheduling. This can be achieved by registering it as a service, and the 6099a2dd95SBruce Richardson * application can then assign CPU resources to that service. 6199a2dd95SBruce Richardson * 6299a2dd95SBruce Richardson * Note that when a service component registers itself, it is not permitted to 6399a2dd95SBruce Richardson * add or remove service-core threads, or modify lcore-to-service mappings. The 6499a2dd95SBruce Richardson * only API that may be called by the service-component is 6599a2dd95SBruce Richardson * *rte_service_component_runstate_set*, which indicates that the service 6699a2dd95SBruce Richardson * component is ready to be executed. 6799a2dd95SBruce Richardson * 6899a2dd95SBruce Richardson * If the service is known to be mapped to a single lcore, setting the 6999a2dd95SBruce Richardson * capability of the service to RTE_SERVICE_CAP_MT_SAFE can achieve 7099a2dd95SBruce Richardson * better performance. 7199a2dd95SBruce Richardson * 7299a2dd95SBruce Richardson * @param spec The specification of the service to register 7399a2dd95SBruce Richardson * @param[out] service_id A pointer to a uint32_t, which will be filled in 7499a2dd95SBruce Richardson * during registration of the service. It is set to the integers 7599a2dd95SBruce Richardson * service number given to the service. This parameter may be NULL. 7699a2dd95SBruce Richardson * @retval 0 Successfully registered the service. 7799a2dd95SBruce Richardson * -EINVAL Attempted to register an invalid service (eg, no callback 7899a2dd95SBruce Richardson * set) 7999a2dd95SBruce Richardson */ 8099a2dd95SBruce Richardson int32_t rte_service_component_register(const struct rte_service_spec *spec, 8199a2dd95SBruce Richardson uint32_t *service_id); 8299a2dd95SBruce Richardson 8399a2dd95SBruce Richardson /** 8499a2dd95SBruce Richardson * Unregister a service component. 8599a2dd95SBruce Richardson * 8699a2dd95SBruce Richardson * The service being removed must be stopped before calling this function. 8799a2dd95SBruce Richardson * 8899a2dd95SBruce Richardson * @retval 0 The service was successfully unregistered. 8999a2dd95SBruce Richardson * @retval -EBUSY The service is currently running, stop the service before 9099a2dd95SBruce Richardson * calling unregister. No action has been taken. 9199a2dd95SBruce Richardson */ 9299a2dd95SBruce Richardson int32_t rte_service_component_unregister(uint32_t id); 9399a2dd95SBruce Richardson 9499a2dd95SBruce Richardson /** 9599a2dd95SBruce Richardson * Private function to allow EAL to initialized default mappings. 9699a2dd95SBruce Richardson * 9799a2dd95SBruce Richardson * This function iterates all the services, and maps then to the available 9899a2dd95SBruce Richardson * cores. Based on the capabilities of the services, they are set to run on the 9999a2dd95SBruce Richardson * available cores in a round-robin manner. 10099a2dd95SBruce Richardson * 10199a2dd95SBruce Richardson * @retval 0 Success 10299a2dd95SBruce Richardson * @retval -ENOTSUP No service lcores in use 10399a2dd95SBruce Richardson * @retval -EINVAL Error while iterating over services 10499a2dd95SBruce Richardson * @retval -ENODEV Error in enabling service lcore on a service 10599a2dd95SBruce Richardson * @retval -ENOEXEC Error when starting services 10699a2dd95SBruce Richardson */ 10799a2dd95SBruce Richardson int32_t rte_service_start_with_defaults(void); 10899a2dd95SBruce Richardson 10999a2dd95SBruce Richardson /** 11099a2dd95SBruce Richardson * Set the backend runstate of a component. 11199a2dd95SBruce Richardson * 11299a2dd95SBruce Richardson * This function allows services to be registered at startup, but not yet 11399a2dd95SBruce Richardson * enabled to run by default. When the service has been configured (via the 11499a2dd95SBruce Richardson * usual method; eg rte_eventdev_configure, the service can mark itself as 11599a2dd95SBruce Richardson * ready to run. The differentiation between backend runstate and 11699a2dd95SBruce Richardson * service_runstate is that the backend runstate is set by the service 11799a2dd95SBruce Richardson * component while the service runstate is reserved for application usage. 11899a2dd95SBruce Richardson * 11999a2dd95SBruce Richardson * @retval 0 Success 12099a2dd95SBruce Richardson */ 12199a2dd95SBruce Richardson int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate); 12299a2dd95SBruce Richardson 12399a2dd95SBruce Richardson /** 12499a2dd95SBruce Richardson * Initialize the service library. 12599a2dd95SBruce Richardson * 12699a2dd95SBruce Richardson * In order to use the service library, it must be initialized. EAL initializes 12799a2dd95SBruce Richardson * the library at startup. 12899a2dd95SBruce Richardson * 12999a2dd95SBruce Richardson * @retval 0 Success 13099a2dd95SBruce Richardson * @retval -EALREADY Service library is already initialized 13199a2dd95SBruce Richardson */ 13299a2dd95SBruce Richardson int32_t rte_service_init(void); 13399a2dd95SBruce Richardson 13499a2dd95SBruce Richardson /** 13599a2dd95SBruce Richardson * @internal Free up the memory that has been initialized. 13699a2dd95SBruce Richardson * This routine is to be invoked prior to process termination. 13799a2dd95SBruce Richardson * 13899a2dd95SBruce Richardson * @retval None 13999a2dd95SBruce Richardson */ 14099a2dd95SBruce Richardson void rte_service_finalize(void); 14199a2dd95SBruce Richardson 14299a2dd95SBruce Richardson #ifdef __cplusplus 14399a2dd95SBruce Richardson } 14499a2dd95SBruce Richardson #endif 14599a2dd95SBruce Richardson 14699a2dd95SBruce Richardson #endif /* _SERVICE_PRIVATE_H_ */ 147