Session daemon health check support
[lttng-tools.git] / src / bin / lttng-sessiond / health.h
CommitLineData
44a5e5eb
DG
1/*
2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef _HEALTH_H
19#define _HEALTH_H
20
21#include <stdint.h>
22#include <urcu/uatomic.h>
23
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 */
28#define HEALTH_POLL_VALUE 1
29#define HEALTH_CODE_VALUE 2
30
31#define HEALTH_IS_IN_POLL(x) (x % HEALTH_CODE_VALUE)
32#define HEALTH_IS_IN_CODE(x) (x % HEALTH_POLL_VALUE)
33
34struct health_state {
35 uint64_t last;
36 uint64_t current;
37};
38
39/* Health state counters for the client command thread */
40extern struct health_state health_thread_cmd;
41
42/* Health state counters for the application registration thread */
43extern struct health_state health_thread_app_reg;
44
45/* Health state counters for the kernel thread */
46extern struct health_state health_thread_kernel;
47
48/*
49 * Update current counter by 1 to indicate that the thread is in a blocking
50 * state cause by a poll().
51 */
52static inline void health_poll_update(struct health_state *state)
53{
54 assert(state);
55
56 uatomic_add(&state->current, HEALTH_POLL_VALUE);
57}
58
59/*
60 * Update current counter by 2 which indicates that we are currently running in
61 * a thread and NOT blocked at a poll().
62 */
63static inline void health_code_update(struct health_state *state)
64{
65 assert(state);
66
67 uatomic_add(&state->current, HEALTH_CODE_VALUE);
68}
69
70/*
71 * Reset health state. A value of zero indicate a bad health state.
72 */
73static inline void health_reset(struct health_state *state)
74{
75 assert(state);
76
77 uatomic_set(&state->current, 0);
78 uatomic_set(&state->last, 0);
79}
80
81/*
82 * Init health state.
83 */
84static inline void health_init(struct health_state *state)
85{
86 assert(state);
87
88 uatomic_set(&state->last, 0);
89 uatomic_set(&state->current, HEALTH_CODE_VALUE);
90}
91
92int health_check_state(struct health_state *state);
93
94#endif /* _HEALTH_H */
This page took 0.025639 seconds and 4 git commands to generate.