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