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