Commit | Line | Data |
---|---|---|
a7333da7 JG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | * 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License, version 2 only, | |
8 | * as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
20 | #include <common/macros.h> | |
21 | #include <urcu.h> | |
22 | #include "lttng-sessiond.h" | |
23 | ||
24 | /* | |
25 | * The initialization of the session daemon is done in multiple phases. | |
26 | * | |
27 | * While all threads are launched near-simultaneously, only some of them | |
28 | * are needed to ensure the session daemon can start to respond to client | |
29 | * requests. | |
30 | * | |
31 | * There are two important guarantees that we wish to offer with respect | |
32 | * to the initialisation of the session daemon: | |
33 | * - When the daemonize/background launcher process exits, the sessiond | |
34 | * is fully able to respond to client requests, | |
35 | * - Auto-loaded sessions are visible to clients. | |
36 | * | |
37 | * In order to achieve this, a number of support threads have to be launched | |
38 | * to allow the "client" thread to function properly. Moreover, since the | |
39 | * "load session" thread needs the client thread, we must provide a way | |
40 | * for the "load session" thread to know that the "client" thread is up | |
41 | * and running. | |
42 | * | |
43 | * Hence, the support threads decrement the lttng_sessiond_ready counter | |
44 | * while the "client" threads waits for it to reach 0. Once the "client" thread | |
45 | * unblocks, it posts the message_thread_ready semaphore which allows the | |
46 | * "load session" thread to progress. | |
47 | * | |
48 | * This implies that the "load session" thread is the last to be initialized | |
49 | * and will explicitly call sessiond_signal_parents(), which signals the parents | |
50 | * that the session daemon is fully initialized. | |
51 | * | |
52 | * The four (4) support threads are: | |
53 | * - agent_thread | |
54 | * - notification_thread | |
55 | * - rotation_thread | |
56 | * - health_thread | |
57 | */ | |
58 | #define NR_LTTNG_SESSIOND_SUPPORT_THREADS 4 | |
59 | int lttng_sessiond_ready = NR_LTTNG_SESSIOND_SUPPORT_THREADS; | |
60 | ||
61 | LTTNG_HIDDEN | |
62 | void sessiond_notify_ready(void) | |
63 | { | |
64 | /* | |
65 | * This memory barrier is paired with the one performed by | |
66 | * the client thread after it has seen that 'lttng_sessiond_ready' is 0. | |
67 | * | |
68 | * The purpose of these memory barriers is to ensure that all | |
69 | * initialization operations of the various threads that call this | |
70 | * function to signal that they are ready are commited/published | |
71 | * before the client thread can see the 'lttng_sessiond_ready' counter | |
72 | * reach 0. | |
73 | * | |
74 | * Note that this could be a 'write' memory barrier, but a full barrier | |
75 | * is used in case the code using this utility changes. The performance | |
76 | * implications of this choice are minimal since this is a slow path. | |
77 | */ | |
78 | cmm_smp_mb(); | |
79 | uatomic_sub(<tng_sessiond_ready, 1); | |
80 | } |