199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_ALARM_H_ 699a2dd95SBruce Richardson #define _RTE_ALARM_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * Alarm functions 1299a2dd95SBruce Richardson * 1399a2dd95SBruce Richardson * Simple alarm-clock functionality supplied by eal. 1499a2dd95SBruce Richardson * Does not require hpet support. 1599a2dd95SBruce Richardson */ 1699a2dd95SBruce Richardson 17*719834a6SMattias Rönnblom #include <stdint.h> 18*719834a6SMattias Rönnblom 1999a2dd95SBruce Richardson #ifdef __cplusplus 2099a2dd95SBruce Richardson extern "C" { 2199a2dd95SBruce Richardson #endif 2299a2dd95SBruce Richardson 2399a2dd95SBruce Richardson /** 2499a2dd95SBruce Richardson * Signature of callback back function called when an alarm goes off. 2599a2dd95SBruce Richardson */ 2699a2dd95SBruce Richardson typedef void (*rte_eal_alarm_callback)(void *arg); 2799a2dd95SBruce Richardson 2899a2dd95SBruce Richardson /** 2999a2dd95SBruce Richardson * Function to set a callback to be triggered when us microseconds 3099a2dd95SBruce Richardson * have expired. Accuracy of timing to the microsecond is not guaranteed. The 3199a2dd95SBruce Richardson * alarm function will not be called *before* the requested time, but may 3299a2dd95SBruce Richardson * be called a short period of time afterwards. 3399a2dd95SBruce Richardson * The alarm handler will be called only once. There is no need to call 3499a2dd95SBruce Richardson * "rte_eal_alarm_cancel" from within the callback function. 3599a2dd95SBruce Richardson * 3699a2dd95SBruce Richardson * @param us 3799a2dd95SBruce Richardson * The time in microseconds before the callback is called 3899a2dd95SBruce Richardson * @param cb 3999a2dd95SBruce Richardson * The function to be called when the alarm expires 4099a2dd95SBruce Richardson * @param cb_arg 4199a2dd95SBruce Richardson * Pointer parameter to be passed to the callback function 4299a2dd95SBruce Richardson * 4399a2dd95SBruce Richardson * @return 4499a2dd95SBruce Richardson * On success, zero. 4599a2dd95SBruce Richardson * On failure, a negative error number 4699a2dd95SBruce Richardson */ 4799a2dd95SBruce Richardson int rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb, void *cb_arg); 4899a2dd95SBruce Richardson 4999a2dd95SBruce Richardson /** 5099a2dd95SBruce Richardson * Function to cancel an alarm callback which has been registered before. If 5199a2dd95SBruce Richardson * used outside alarm callback it wait for all callbacks to finish execution. 5299a2dd95SBruce Richardson * 5399a2dd95SBruce Richardson * @param cb_fn 5499a2dd95SBruce Richardson * alarm callback 5599a2dd95SBruce Richardson * @param cb_arg 5699a2dd95SBruce Richardson * Pointer parameter to be passed to the callback function. To remove all 5799a2dd95SBruce Richardson * copies of a given callback function, irrespective of parameter, (void *)-1 5899a2dd95SBruce Richardson * can be used here. 5999a2dd95SBruce Richardson * 6099a2dd95SBruce Richardson * @return 6199a2dd95SBruce Richardson * - value greater than 0 and rte_errno not changed - returned value is 6299a2dd95SBruce Richardson * the number of canceled alarm callback functions 6399a2dd95SBruce Richardson * - value greater or equal 0 and rte_errno set to EINPROGRESS, at least one 6499a2dd95SBruce Richardson * alarm could not be canceled because cancellation was requested from alarm 6599a2dd95SBruce Richardson * callback context. Returned value is the number of successfully canceled 6699a2dd95SBruce Richardson * alarm callbacks 6799a2dd95SBruce Richardson * - 0 and rte_errno set to ENOENT - no alarm found 6899a2dd95SBruce Richardson * - -1 and rte_errno set to EINVAL - invalid parameter (NULL callback) 6999a2dd95SBruce Richardson */ 7099a2dd95SBruce Richardson int rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg); 7199a2dd95SBruce Richardson 7299a2dd95SBruce Richardson #ifdef __cplusplus 7399a2dd95SBruce Richardson } 7499a2dd95SBruce Richardson #endif 7599a2dd95SBruce Richardson 7699a2dd95SBruce Richardson 7799a2dd95SBruce Richardson #endif /* _RTE_ALARM_H_ */ 78