1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2015-2016 Intel Corporation. 3 */ 4 5 /** 6 * @file rte_keepalive.h 7 * DPDK RTE LCore Keepalive Monitor. 8 * 9 **/ 10 11 #ifndef _KEEPALIVE_H_ 12 #define _KEEPALIVE_H_ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #include <rte_config.h> 19 #include <rte_memory.h> 20 21 #ifndef RTE_KEEPALIVE_MAXCORES 22 /** 23 * Number of cores to track. 24 * @note Must be larger than the highest core id. */ 25 #define RTE_KEEPALIVE_MAXCORES RTE_MAX_LCORE 26 #endif 27 28 enum rte_keepalive_state { 29 RTE_KA_STATE_UNUSED = 0, 30 RTE_KA_STATE_ALIVE = 1, 31 RTE_KA_STATE_MISSING = 4, 32 RTE_KA_STATE_DEAD = 2, 33 RTE_KA_STATE_GONE = 3, 34 RTE_KA_STATE_DOZING = 5, 35 RTE_KA_STATE_SLEEP = 6 36 }; 37 38 /** 39 * Keepalive failure callback. 40 * 41 * Receives a data pointer passed to rte_keepalive_create() and the id of the 42 * failed core. 43 * @param data Data pointer passed to rte_keepalive_create() 44 * @param id_core ID of the core that has failed 45 */ 46 typedef void (*rte_keepalive_failure_callback_t)( 47 void *data, 48 const int id_core); 49 50 /** 51 * Keepalive relay callback. 52 * 53 * Receives a data pointer passed to rte_keepalive_register_relay_callback(), 54 * the id of the core for which state is to be forwarded, and details of the 55 * current core state. 56 * @param data Data pointer passed to rte_keepalive_register_relay_callback() 57 * @param id_core ID of the core for which state is being reported 58 * @param core_state The current state of the core 59 * @param last_seen Timestamp of when core was last seen alive 60 */ 61 typedef void (*rte_keepalive_relay_callback_t)( 62 void *data, 63 const int id_core, 64 enum rte_keepalive_state core_state, 65 uint64_t last_seen 66 ); 67 68 /** 69 * Keepalive state structure. 70 * @internal 71 */ 72 struct rte_keepalive; 73 74 /** 75 * Initialise keepalive sub-system. 76 * @param callback 77 * Function called upon detection of a dead core. 78 * @param data 79 * Data pointer to be passed to function callback. 80 * @return 81 * Keepalive structure success, NULL on failure. 82 */ 83 struct rte_keepalive *rte_keepalive_create( 84 rte_keepalive_failure_callback_t callback, 85 void *data); 86 87 /** 88 * Checks & handles keepalive state of monitored cores. 89 * @param *ptr_timer Triggering timer (unused) 90 * @param *ptr_data Data pointer (keepalive structure) 91 */ 92 void rte_keepalive_dispatch_pings(void *ptr_timer, void *ptr_data); 93 94 /** 95 * Registers a core for keepalive checks. 96 * @param *keepcfg 97 * Keepalive structure pointer 98 * @param id_core 99 * ID number of core to register. 100 */ 101 void rte_keepalive_register_core(struct rte_keepalive *keepcfg, 102 const int id_core); 103 104 /** 105 * Per-core keepalive check. 106 * @param *keepcfg 107 * Keepalive structure pointer 108 * 109 * This function needs to be called from within the main process loop of 110 * the LCore to be checked. 111 */ 112 void 113 rte_keepalive_mark_alive(struct rte_keepalive *keepcfg); 114 115 /** 116 * Per-core sleep-time indication. 117 * @param *keepcfg 118 * Keepalive structure pointer 119 * 120 * If CPU idling is enabled, this function needs to be called from within 121 * the main process loop of the LCore going to sleep, in order to avoid 122 * the LCore being mis-detected as dead. 123 */ 124 void 125 rte_keepalive_mark_sleep(struct rte_keepalive *keepcfg); 126 127 /** 128 * Registers a 'live core' callback. 129 * 130 * The complement of the 'dead core' callback. This is called when a 131 * core is known to be alive, and is intended for cases when an app 132 * needs to know 'liveness' beyond just knowing when a core has died. 133 * 134 * @param *keepcfg 135 * Keepalive structure pointer 136 * @param callback 137 * Function called upon detection of a dead core. 138 * @param data 139 * Data pointer to be passed to function callback. 140 */ 141 void 142 rte_keepalive_register_relay_callback(struct rte_keepalive *keepcfg, 143 rte_keepalive_relay_callback_t callback, 144 void *data); 145 146 #ifdef __cplusplus 147 } 148 #endif 149 150 #endif /* _KEEPALIVE_H_ */ 151