#include "load-session-thread.h"
#include "syscall.h"
#include "agent.h"
+#include "ht-cleanup.h"
#define CONSUMERD_FILE "lttng-consumerd"
* for all threads when receiving an event on the pipe.
*/
static int thread_quit_pipe[2] = { -1, -1 };
-static int ht_cleanup_quit_pipe[2] = { -1, -1 };
/*
* This pipe is used to inform the thread managing application communication
#define NR_LTTNG_SESSIOND_READY 3
int lttng_sessiond_ready = NR_LTTNG_SESSIOND_READY;
+int sessiond_check_thread_quit_pipe(int fd, uint32_t events)
+{
+ return (fd == thread_quit_pipe[0] && (events & LPOLLIN)) ? 1 : 0;
+}
+
/* Notify parents that we are ready for cmd and health check */
LTTNG_HIDDEN
void sessiond_notify_ready(void)
return __sessiond_set_thread_pollset(events, size, thread_quit_pipe);
}
-/*
- * Create a poll set with O_CLOEXEC and add the thread quit pipe to the set.
- */
-int sessiond_set_ht_cleanup_thread_pollset(struct lttng_poll_event *events,
- size_t size)
-{
- return __sessiond_set_thread_pollset(events, size,
- ht_cleanup_quit_pipe);
-}
-
-static
-int __sessiond_check_thread_quit_pipe(int fd, uint32_t events, int a_pipe)
-{
- if (fd == a_pipe && (events & LPOLLIN)) {
- return 1;
- }
- return 0;
-}
-
-/*
- * Check if the thread quit pipe was triggered.
- *
- * Return 1 if it was triggered else 0;
- */
-int sessiond_check_thread_quit_pipe(int fd, uint32_t events)
-{
- return __sessiond_check_thread_quit_pipe(fd, events,
- thread_quit_pipe[0]);
-}
-
-/*
- * Check if the ht_cleanup thread quit pipe was triggered.
- *
- * Return 1 if it was triggered else 0;
- */
-int sessiond_check_ht_cleanup_quit(int fd, uint32_t events)
-{
- return __sessiond_check_thread_quit_pipe(fd, events,
- ht_cleanup_quit_pipe[0]);
-}
-
/*
* Init thread quit pipe.
*
return __init_thread_quit_pipe(thread_quit_pipe);
}
-static int init_ht_cleanup_quit_pipe(void)
-{
- return __init_thread_quit_pipe(ht_cleanup_quit_pipe);
-}
-
/*
* Stop all threads by closing the thread quit pipe.
*/
int ret, clock_ret;
struct timespec timeout;
- /* Make sure we set the readiness flag to 0 because we are NOT ready */
+ /*
+ * Make sure we set the readiness flag to 0 because we are NOT ready.
+ * This access to consumer_thread_is_ready does not need to be
+ * protected by consumer_data.cond_mutex (yet) since the consumer
+ * management thread has not been started at this point.
+ */
consumer_data->consumer_thread_is_ready = 0;
/* Setup pthread condition */
case LTTNG_LIST_EVENTS:
case LTTNG_LIST_SYSCALLS:
case LTTNG_LIST_TRACKER_PIDS:
+ case LTTNG_DATA_PENDING:
break;
default:
/* Setup lttng message with no payload */
/*
* Set open files limit to unlimited. This daemon can open a large number of
- * file descriptors in order to consumer multiple kernel traces.
+ * file descriptors in order to consume multiple kernel traces.
*/
static void set_ulimit(void)
{
int ret;
struct rlimit lim;
- /* The kernel does not allowed an infinite limit for open files */
+ /* The kernel does not allow an infinite limit for open files */
lim.rlim_cur = 65535;
lim.rlim_max = 65535;
goto exit_health_sessiond_cleanup;
}
- if (init_ht_cleanup_quit_pipe()) {
- retval = -1;
- goto exit_ht_cleanup_quit_pipe;
- }
-
- /* Setup the thread ht_cleanup communication pipe. */
- if (utils_create_pipe_cloexec(ht_cleanup_pipe)) {
- retval = -1;
- goto exit_ht_cleanup_pipe;
- }
-
- /* Set up max poll set size */
- if (lttng_poll_set_max_size()) {
- retval = -1;
- goto exit_set_max_size;
- }
-
/* Create thread to clean up RCU hash tables */
- ret = pthread_create(&ht_cleanup_thread, NULL,
- thread_ht_cleanup, (void *) NULL);
- if (ret) {
- errno = ret;
- PERROR("pthread_create ht_cleanup");
+ if (init_ht_cleanup_thread(&ht_cleanup_thread)) {
retval = -1;
goto exit_ht_cleanup;
}
rcu_thread_offline();
rcu_unregister_thread();
- ret = notify_thread_pipe(ht_cleanup_quit_pipe[1]);
- if (ret < 0) {
- ERR("write error on ht_cleanup quit pipe");
- retval = -1;
- }
+ /*
+ * Ensure all prior call_rcu are done. call_rcu callbacks may push
+ * hash tables to the ht_cleanup thread. Therefore, we ensure that
+ * the queue is empty before shutting down the clean-up thread.
+ */
+ rcu_barrier();
- ret = pthread_join(ht_cleanup_thread, &status);
+ ret = fini_ht_cleanup_thread(&ht_cleanup_thread);
if (ret) {
- errno = ret;
- PERROR("pthread_join ht cleanup thread");
retval = -1;
}
exit_ht_cleanup:
-exit_set_max_size:
-
- utils_close_pipe(ht_cleanup_pipe);
-exit_ht_cleanup_pipe:
-
- /*
- * Close the ht_cleanup quit pipe.
- */
- utils_close_pipe(ht_cleanup_quit_pipe);
-exit_ht_cleanup_quit_pipe:
health_app_destroy(health_sessiond);
exit_health_sessiond_cleanup:
exit_create_run_as_worker_cleanup:
exit_options:
- /* Ensure all prior call_rcu are done. */
- rcu_barrier();
-
sessiond_cleanup_options();
exit_set_signal_handler: