2 * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <common/hashtable/hashtable.h>
22 #include <common/common.h>
23 #include <common/utils.h>
25 #include "lttng-sessiond.h"
26 #include "health-sessiond.h"
27 #include "testpoint.h"
29 void *thread_ht_cleanup(void *data
)
31 int ret
, i
, pollfd
, err
= -1;
33 uint32_t revents
, nb_fd
;
34 struct lttng_poll_event events
;
36 DBG("[ht-thread] startup.");
38 rcu_register_thread();
41 health_register(health_sessiond
, HEALTH_SESSIOND_TYPE_HT_CLEANUP
);
43 if (testpoint(sessiond_thread_ht_cleanup
)) {
44 DBG("[ht-thread] testpoint.");
50 ret
= sessiond_set_ht_cleanup_thread_pollset(&events
, 2);
52 DBG("[ht-thread] sessiond_set_ht_cleanup_thread_pollset error %d.", ret
);
53 goto error_poll_create
;
56 /* Add pipe to the pollset. */
57 ret
= lttng_poll_add(&events
, ht_cleanup_pipe
[0], LPOLLIN
| LPOLLERR
);
59 DBG("[ht-thread] lttng_poll_add error %d.", ret
);
66 DBG3("[ht-thread] Polling.");
68 /* Inifinite blocking call, waiting for transmission */
71 ret
= lttng_poll_wait(&events
, -1);
72 DBG3("[ht-thread] Returning from poll on %d fds.",
73 LTTNG_POLL_GETNB(&events
));
77 * Restart interrupted system call.
87 for (i
= 0; i
< nb_fd
; i
++) {
92 /* Fetch once the poll data */
93 revents
= LTTNG_POLL_GETEV(&events
, i
);
94 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
97 /* No activity for this FD (poll implementation). */
101 if (pollfd
!= ht_cleanup_pipe
[0]) {
105 if (revents
& LPOLLIN
) {
106 /* Get socket from dispatch thread. */
107 size_ret
= lttng_read(ht_cleanup_pipe
[0], &ht
,
109 if (size_ret
< sizeof(ht
)) {
110 PERROR("ht cleanup notify pipe");
113 health_code_update();
115 * The whole point of this thread is to call
116 * lttng_ht_destroy from a context that is NOT:
117 * 1) a read-side RCU lock,
118 * 2) a call_rcu thread.
120 lttng_ht_destroy(ht
);
122 health_code_update();
123 } else if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
124 ERR("ht cleanup pipe error");
127 ERR("Unexpected poll events %u for sock %d", revents
, pollfd
);
132 for (i
= 0; i
< nb_fd
; i
++) {
133 health_code_update();
135 /* Fetch once the poll data */
136 revents
= LTTNG_POLL_GETEV(&events
, i
);
137 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
140 /* No activity for this FD (poll implementation). */
144 if (pollfd
== ht_cleanup_pipe
[0]) {
148 /* Thread quit pipe has been closed. Killing thread. */
149 ret
= sessiond_check_ht_cleanup_quit(pollfd
, revents
);
152 DBG("[ht-cleanup] quit.");
160 lttng_poll_clean(&events
);
163 DBG("[ht-cleanup] Thread terminates.");
166 ERR("Health error occurred in %s", __func__
);
168 health_unregister(health_sessiond
);
169 rcu_thread_offline();
170 rcu_unregister_thread();