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>
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.
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.
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.
20 #include <common/macros.h>
22 #include "lttng-sessiond.h"
25 * The initialization of the session daemon is done in multiple phases.
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
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.
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
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.
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.
52 * The four (4) support threads are:
54 * - notification_thread
58 #define NR_LTTNG_SESSIOND_SUPPORT_THREADS 4
59 int lttng_sessiond_ready
= NR_LTTNG_SESSIOND_SUPPORT_THREADS
;
62 void sessiond_notify_ready(void)
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.
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
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.
79 uatomic_sub(<tng_sessiond_ready
, 1);