docs: Add supported versions and fix-backport policy
[lttng-tools.git] / include / lttng / health-internal.hpp
CommitLineData
55d09795
MD
1#ifndef HEALTH_INTERNAL_H
2#define HEALTH_INTERNAL_H
3
44a5e5eb 4/*
ab5be9fa
MJ
5 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
6 * Copyright (C) 2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
44a5e5eb 7 *
ab5be9fa 8 * SPDX-License-Identifier: GPL-2.0-only
44a5e5eb 9 *
44a5e5eb
DG
10 */
11
c9e313bc 12#include <common/compat/time.hpp>
28f23191
JG
13#include <common/macros.hpp>
14
15#include <lttng/health.h>
16
927ca06a 17#include <pthread.h>
28f23191 18#include <urcu/list.h>
927ca06a 19#include <urcu/tls-compat.h>
44a5e5eb
DG
20#include <urcu/uatomic.h>
21
22/*
23 * These are the value added to the current state depending of the position in
24 * the thread where is either waiting on a poll() or running in the code.
25 */
28f23191
JG
26#define HEALTH_POLL_VALUE (1UL << 0)
27#define HEALTH_CODE_VALUE (1UL << 1)
44a5e5eb 28
28f23191 29#define HEALTH_IS_IN_POLL(x) ((x) &HEALTH_POLL_VALUE)
139ac872 30
8782cc74
MD
31struct health_app;
32
139ac872 33enum health_flags {
28f23191 34 HEALTH_ERROR = (1U << 0),
927ca06a
DG
35};
36
44a5e5eb 37struct health_state {
139ac872 38 /*
8809eec0 39 * last counter and last_time are only read and updated by the health_check
139ac872
MD
40 * thread (single updater).
41 */
42 unsigned long last;
8809eec0
MD
43 struct timespec last_time;
44
139ac872
MD
45 /*
46 * current and flags are updated by multiple threads concurrently.
47 */
28f23191
JG
48 unsigned long current; /* progress counter, updated atomically */
49 enum health_flags flags; /* other flags, updated atomically */
50 int type; /* Indicates the nature of the thread. */
927ca06a
DG
51 /* Node of the global TLS state list. */
52 struct cds_list_head node;
44a5e5eb
DG
53};
54
0c89d795 55enum health_cmd {
28f23191 56 HEALTH_CMD_CHECK = 0,
0c89d795
MD
57};
58
59struct health_comm_msg {
28f23191 60 uint32_t cmd; /* enum health_cmd */
0c89d795
MD
61} LTTNG_PACKED;
62
63struct health_comm_reply {
28f23191 64 uint64_t ret_code; /* bitmask of threads in bad health */
0c89d795
MD
65} LTTNG_PACKED;
66
927ca06a 67/* Declare TLS health state. */
9fd09ab6 68extern thread_local struct health_state health_state;
927ca06a 69
44a5e5eb 70/*
a78af745
DG
71 * Update current counter by 1 to indicate that the thread entered or left a
72 * blocking state caused by a poll(). If the counter's value is not an even
a0377dfe 73 * number (meaning a code execution flow), an LTTNG_ASSERT() is raised.
44a5e5eb 74 */
cd9adb8b 75static inline void health_poll_entry()
44a5e5eb 76{
a78af745 77 /* Code MUST be in code execution state which is an even number. */
9fd09ab6 78 LTTNG_ASSERT(!(uatomic_read(&health_state.current) & HEALTH_POLL_VALUE));
a78af745 79
9fd09ab6 80 uatomic_add(&health_state.current, HEALTH_POLL_VALUE);
a78af745
DG
81}
82
83/*
84 * Update current counter by 1 indicating the exit of a poll or blocking call.
a0377dfe 85 * If the counter's value is not an odd number (a poll execution), an LTTNG_ASSERT()
a78af745
DG
86 * is raised.
87 */
cd9adb8b 88static inline void health_poll_exit()
a78af745
DG
89{
90 /* Code MUST be in poll execution state which is an odd number. */
9fd09ab6 91 LTTNG_ASSERT(uatomic_read(&health_state.current) & HEALTH_POLL_VALUE);
a78af745 92
9fd09ab6 93 uatomic_add(&health_state.current, HEALTH_POLL_VALUE);
44a5e5eb
DG
94}
95
96/*
139ac872
MD
97 * Update current counter by 2 indicates progress in execution of a
98 * thread.
44a5e5eb 99 */
cd9adb8b 100static inline void health_code_update()
44a5e5eb 101{
9fd09ab6 102 uatomic_add(&health_state.current, HEALTH_CODE_VALUE);
139ac872 103}
44a5e5eb 104
139ac872
MD
105/*
106 * Set health "error" flag.
107 */
cd9adb8b 108static inline void health_error()
139ac872 109{
9fd09ab6 110 uatomic_or(&health_state.flags, HEALTH_ERROR);
44a5e5eb
DG
111}
112
8782cc74
MD
113struct health_app *health_app_create(int nr_types);
114void health_app_destroy(struct health_app *ha);
115int health_check_state(struct health_app *ha, int type);
116void health_register(struct health_app *ha, int type);
117void health_unregister(struct health_app *ha);
44a5e5eb 118
55d09795 119#endif /* HEALTH_INTERNAL_H */
This page took 0.066644 seconds and 4 git commands to generate.