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