xref: /dpdk/lib/eal/include/rte_keepalive.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright 2015-2016 Intel Corporation.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson /**
699a2dd95SBruce Richardson  * @file rte_keepalive.h
799a2dd95SBruce Richardson  * DPDK RTE LCore Keepalive Monitor.
83e4c5be9SThomas Monjalon  */
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson #ifndef _KEEPALIVE_H_
1199a2dd95SBruce Richardson #define _KEEPALIVE_H_
1299a2dd95SBruce Richardson 
13*719834a6SMattias Rönnblom #include <rte_config.h>
14*719834a6SMattias Rönnblom #include <rte_memory.h>
15*719834a6SMattias Rönnblom 
16d7e9c02cSBrian Dooley #ifdef __cplusplus
17d7e9c02cSBrian Dooley extern "C" {
18d7e9c02cSBrian Dooley #endif
19d7e9c02cSBrian Dooley 
2099a2dd95SBruce Richardson #ifndef RTE_KEEPALIVE_MAXCORES
2199a2dd95SBruce Richardson /**
2299a2dd95SBruce Richardson  * Number of cores to track.
2399a2dd95SBruce Richardson  * @note Must be larger than the highest core id. */
2499a2dd95SBruce Richardson #define RTE_KEEPALIVE_MAXCORES RTE_MAX_LCORE
2599a2dd95SBruce Richardson #endif
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson enum rte_keepalive_state {
2899a2dd95SBruce Richardson 	RTE_KA_STATE_UNUSED = 0,
2999a2dd95SBruce Richardson 	RTE_KA_STATE_ALIVE = 1,
3099a2dd95SBruce Richardson 	RTE_KA_STATE_MISSING = 4,
3199a2dd95SBruce Richardson 	RTE_KA_STATE_DEAD = 2,
3299a2dd95SBruce Richardson 	RTE_KA_STATE_GONE = 3,
3399a2dd95SBruce Richardson 	RTE_KA_STATE_DOZING = 5,
3499a2dd95SBruce Richardson 	RTE_KA_STATE_SLEEP = 6
3599a2dd95SBruce Richardson };
3699a2dd95SBruce Richardson 
3799a2dd95SBruce Richardson /**
3899a2dd95SBruce Richardson  * Keepalive failure callback.
3999a2dd95SBruce Richardson  *
4099a2dd95SBruce Richardson  *  Receives a data pointer passed to rte_keepalive_create() and the id of the
4199a2dd95SBruce Richardson  *  failed core.
4299a2dd95SBruce Richardson  *  @param data Data pointer passed to rte_keepalive_create()
4399a2dd95SBruce Richardson  *  @param id_core ID of the core that has failed
4499a2dd95SBruce Richardson  */
4599a2dd95SBruce Richardson typedef void (*rte_keepalive_failure_callback_t)(
4699a2dd95SBruce Richardson 	void *data,
4799a2dd95SBruce Richardson 	const int id_core);
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson /**
5099a2dd95SBruce Richardson  * Keepalive relay callback.
5199a2dd95SBruce Richardson  *
5299a2dd95SBruce Richardson  *  Receives a data pointer passed to rte_keepalive_register_relay_callback(),
5399a2dd95SBruce Richardson  *  the id of the core for which state is to be forwarded, and details of the
5499a2dd95SBruce Richardson  *  current core state.
5599a2dd95SBruce Richardson  *  @param data Data pointer passed to rte_keepalive_register_relay_callback()
5699a2dd95SBruce Richardson  *  @param id_core ID of the core for which state is being reported
5799a2dd95SBruce Richardson  *  @param core_state The current state of the core
5899a2dd95SBruce Richardson  *  @param last_seen Timestamp of when core was last seen alive
5999a2dd95SBruce Richardson  */
6099a2dd95SBruce Richardson typedef void (*rte_keepalive_relay_callback_t)(
6199a2dd95SBruce Richardson 	void *data,
6299a2dd95SBruce Richardson 	const int id_core,
6399a2dd95SBruce Richardson 	enum rte_keepalive_state core_state,
6499a2dd95SBruce Richardson 	uint64_t last_seen
6599a2dd95SBruce Richardson 	);
6699a2dd95SBruce Richardson 
6799a2dd95SBruce Richardson /**
6899a2dd95SBruce Richardson  * Keepalive state structure.
6999a2dd95SBruce Richardson  * @internal
7099a2dd95SBruce Richardson  */
7199a2dd95SBruce Richardson struct rte_keepalive;
7299a2dd95SBruce Richardson 
7399a2dd95SBruce Richardson /**
7499a2dd95SBruce Richardson  * Initialise keepalive sub-system.
7599a2dd95SBruce Richardson  * @param callback
7699a2dd95SBruce Richardson  *   Function called upon detection of a dead core.
7799a2dd95SBruce Richardson  * @param data
7899a2dd95SBruce Richardson  *   Data pointer to be passed to function callback.
7999a2dd95SBruce Richardson  * @return
8099a2dd95SBruce Richardson  *   Keepalive structure success, NULL on failure.
8199a2dd95SBruce Richardson  */
8299a2dd95SBruce Richardson struct rte_keepalive *rte_keepalive_create(
8399a2dd95SBruce Richardson 	rte_keepalive_failure_callback_t callback,
8499a2dd95SBruce Richardson 	void *data);
8599a2dd95SBruce Richardson 
8699a2dd95SBruce Richardson /**
8799a2dd95SBruce Richardson  * Checks & handles keepalive state of monitored cores.
8899a2dd95SBruce Richardson  * @param *ptr_timer Triggering timer (unused)
8999a2dd95SBruce Richardson  * @param *ptr_data  Data pointer (keepalive structure)
9099a2dd95SBruce Richardson  */
9199a2dd95SBruce Richardson void rte_keepalive_dispatch_pings(void *ptr_timer, void *ptr_data);
9299a2dd95SBruce Richardson 
9399a2dd95SBruce Richardson /**
9499a2dd95SBruce Richardson  * Registers a core for keepalive checks.
9599a2dd95SBruce Richardson  * @param *keepcfg
9699a2dd95SBruce Richardson  *   Keepalive structure pointer
9799a2dd95SBruce Richardson  * @param id_core
9899a2dd95SBruce Richardson  *   ID number of core to register.
9999a2dd95SBruce Richardson  */
10099a2dd95SBruce Richardson void rte_keepalive_register_core(struct rte_keepalive *keepcfg,
10199a2dd95SBruce Richardson 	const int id_core);
10299a2dd95SBruce Richardson 
10399a2dd95SBruce Richardson /**
10499a2dd95SBruce Richardson  * Per-core keepalive check.
10599a2dd95SBruce Richardson  * @param *keepcfg
10699a2dd95SBruce Richardson  *   Keepalive structure pointer
10799a2dd95SBruce Richardson  *
10899a2dd95SBruce Richardson  * This function needs to be called from within the main process loop of
10999a2dd95SBruce Richardson  * the LCore to be checked.
11099a2dd95SBruce Richardson  */
11199a2dd95SBruce Richardson void
11299a2dd95SBruce Richardson rte_keepalive_mark_alive(struct rte_keepalive *keepcfg);
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson /**
11599a2dd95SBruce Richardson  * Per-core sleep-time indication.
11699a2dd95SBruce Richardson  * @param *keepcfg
11799a2dd95SBruce Richardson  *   Keepalive structure pointer
11899a2dd95SBruce Richardson  *
11999a2dd95SBruce Richardson  * If CPU idling is enabled, this function needs to be called from within
12099a2dd95SBruce Richardson  * the main process loop of the LCore going to sleep, in order to avoid
12199a2dd95SBruce Richardson  * the LCore being mis-detected as dead.
12299a2dd95SBruce Richardson  */
12399a2dd95SBruce Richardson void
12499a2dd95SBruce Richardson rte_keepalive_mark_sleep(struct rte_keepalive *keepcfg);
12599a2dd95SBruce Richardson 
12699a2dd95SBruce Richardson /**
12799a2dd95SBruce Richardson  * Registers a 'live core' callback.
12899a2dd95SBruce Richardson  *
12999a2dd95SBruce Richardson  * The complement of the 'dead core' callback. This is called when a
13099a2dd95SBruce Richardson  * core is known to be alive, and is intended for cases when an app
13199a2dd95SBruce Richardson  * needs to know 'liveness' beyond just knowing when a core has died.
13299a2dd95SBruce Richardson  *
13399a2dd95SBruce Richardson  * @param *keepcfg
13499a2dd95SBruce Richardson  *   Keepalive structure pointer
13599a2dd95SBruce Richardson  * @param callback
13699a2dd95SBruce Richardson  *   Function called upon detection of a dead core.
13799a2dd95SBruce Richardson  * @param data
13899a2dd95SBruce Richardson  *   Data pointer to be passed to function callback.
13999a2dd95SBruce Richardson  */
14099a2dd95SBruce Richardson void
14199a2dd95SBruce Richardson rte_keepalive_register_relay_callback(struct rte_keepalive *keepcfg,
14299a2dd95SBruce Richardson 	rte_keepalive_relay_callback_t callback,
14399a2dd95SBruce Richardson 	void *data);
14499a2dd95SBruce Richardson 
145d7e9c02cSBrian Dooley #ifdef __cplusplus
146d7e9c02cSBrian Dooley }
147d7e9c02cSBrian Dooley #endif
148d7e9c02cSBrian Dooley 
14999a2dd95SBruce Richardson #endif /* _KEEPALIVE_H_ */
150