Fix: health subsystem issues with shared code
[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
86acf0da 21#include <assert.h>
8809eec0 22#include <time.h>
927ca06a
DG
23#include <pthread.h>
24#include <urcu/tls-compat.h>
44a5e5eb 25#include <urcu/uatomic.h>
927ca06a 26#include <urcu/list.h>
44a5e5eb
DG
27
28/*
29 * These are the value added to the current state depending of the position in
30 * the thread where is either waiting on a poll() or running in the code.
31 */
139ac872
MD
32#define HEALTH_POLL_VALUE (1UL << 0)
33#define HEALTH_CODE_VALUE (1UL << 1)
44a5e5eb 34
139ac872
MD
35#define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE)
36
37enum health_flags {
927ca06a
DG
38 HEALTH_ERROR = (1U << 0),
39};
40
41enum health_type {
42 HEALTH_TYPE_CMD = 0,
43 HEALTH_TYPE_APP_MANAGE = 1,
44 HEALTH_TYPE_APP_REG = 2,
45 HEALTH_TYPE_KERNEL = 3,
46 HEALTH_TYPE_CONSUMER = 4,
47
48 HEALTH_NUM_TYPE,
49};
50
51struct health_tls_state_list {
52 struct cds_list_head head;
139ac872 53};
44a5e5eb
DG
54
55struct health_state {
139ac872 56 /*
8809eec0 57 * last counter and last_time are only read and updated by the health_check
139ac872
MD
58 * thread (single updater).
59 */
60 unsigned long last;
8809eec0
MD
61 struct timespec last_time;
62
139ac872
MD
63 /*
64 * current and flags are updated by multiple threads concurrently.
65 */
66 unsigned long current; /* progress counter, updated atomically */
67 enum health_flags flags; /* other flags, updated atomically */
927ca06a
DG
68 enum health_type type; /* Indicates the nature of the thread. */
69 /* Node of the global TLS state list. */
70 struct cds_list_head node;
44a5e5eb
DG
71};
72
927ca06a
DG
73/* Declare TLS health state. */
74extern DECLARE_URCU_TLS(struct health_state, health_state);
75
44a5e5eb
DG
76/* Health state counters for the client command thread */
77extern struct health_state health_thread_cmd;
78
139ac872
MD
79/* Health state counters for the application management thread */
80extern struct health_state health_thread_app_manage;
81
44a5e5eb
DG
82/* Health state counters for the application registration thread */
83extern struct health_state health_thread_app_reg;
84
85/* Health state counters for the kernel thread */
86extern struct health_state health_thread_kernel;
87
88/*
139ac872
MD
89 * Update current counter by 1 to indicate that the thread entered or
90 * left a blocking state caused by a poll().
44a5e5eb
DG
91 */
92static inline void health_poll_update(struct health_state *state)
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
DG
100 */
101static inline void health_code_update(struct health_state *state)
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 */
109static inline void health_error(struct health_state *state)
110{
927ca06a 111 uatomic_or(&URCU_TLS(health_state).flags, HEALTH_ERROR);
44a5e5eb
DG
112}
113
927ca06a
DG
114int health_check_state(enum health_type type);
115void health_register(enum health_type type);
116void health_unregister(void);
44a5e5eb
DG
117
118#endif /* _HEALTH_H */
This page took 0.043147 seconds and 4 git commands to generate.