Launch the ht-cleanup thread using lttng_thread util
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 26 Nov 2018 20:15:24 +0000 (15:15 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 5 Dec 2018 17:25:11 +0000 (12:25 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/ht-cleanup.c
src/bin/lttng-sessiond/ht-cleanup.h
src/bin/lttng-sessiond/main.c
tests/unit/Makefile.am
tests/unit/test_session.c

index a3b046b8834a2eaaa7dd74b9bb0bb0beb6cff806..09c13fe003d7d40c5af423a5bf98634e853e0162 100644 (file)
@@ -27,8 +27,9 @@
 #include "health-sessiond.h"
 #include "testpoint.h"
 #include "utils.h"
+#include "ht-cleanup.h"
 
-int ht_cleanup_quit_pipe[2] = { -1, -1 };
+static int ht_cleanup_quit_pipe[2] = { -1, -1 };
 
 /*
  * Check if the ht_cleanup thread quit pipe was triggered.
@@ -91,6 +92,12 @@ error:
        return ret;
 }
 
+static void cleanup_ht_cleanup_thread(void *data)
+{
+       utils_close_pipe(ht_cleanup_quit_pipe);
+       utils_close_pipe(ht_cleanup_pipe);
+}
+
 static void *thread_ht_cleanup(void *data)
 {
        int ret, i, pollfd, err = -1;
@@ -225,9 +232,23 @@ error_testpoint:
        return NULL;
 }
 
-int init_ht_cleanup_thread(pthread_t *thread)
+static bool shutdown_ht_cleanup_thread(void *data)
+{
+       int ret;
+
+       ret = notify_thread_pipe(ht_cleanup_quit_pipe[1]);
+       if (ret < 0) {
+               ERR("write error on ht_cleanup quit pipe");
+               goto end;
+       }
+end:
+       return ret;
+}
+
+struct lttng_thread *launch_ht_cleanup_thread(void)
 {
        int ret;
+       struct lttng_thread *thread;
 
        ret = init_pipe(ht_cleanup_pipe);
        if (ret) {
@@ -236,44 +257,20 @@ int init_ht_cleanup_thread(pthread_t *thread)
 
        ret = init_pipe(ht_cleanup_quit_pipe);
        if (ret) {
-               goto error_quit_pipe;
+               goto error;
        }
 
-       ret = pthread_create(thread, default_pthread_attr(), thread_ht_cleanup,
+       thread = lttng_thread_create("HT cleanup",
+                       thread_ht_cleanup,
+                       shutdown_ht_cleanup_thread,
+                       cleanup_ht_cleanup_thread,
                        NULL);
-       if (ret) {
-               errno = ret;
-               PERROR("pthread_create ht_cleanup");
-               goto error_thread;
+       if (!thread) {
+               ret = -1;
+               goto error;
        }
-
+       return thread;
 error:
-       return ret;
-
-error_thread:
-       utils_close_pipe(ht_cleanup_quit_pipe);
-error_quit_pipe:
-       utils_close_pipe(ht_cleanup_pipe);
-       return ret;
-}
-
-int fini_ht_cleanup_thread(pthread_t *thread)
-{
-       int ret;
-
-       ret = notify_thread_pipe(ht_cleanup_quit_pipe[1]);
-       if (ret < 0) {
-               ERR("write error on ht_cleanup quit pipe");
-               goto end;
-       }
-
-       ret = pthread_join(*thread, NULL);
-       if (ret) {
-               errno = ret;
-               PERROR("pthread_join ht cleanup thread");
-       }
-       utils_close_pipe(ht_cleanup_pipe);
-       utils_close_pipe(ht_cleanup_quit_pipe);
-end:
-       return ret;
+       cleanup_ht_cleanup_thread(NULL);
+       return NULL;
 }
index 8ca0e312398cbbc9cd51f473a374e2d8e6da43c5..89445e554cf094fce328e57ba0f32428ac149655 100644 (file)
@@ -19,8 +19,8 @@
 #define _LTTNG_HT_CLEANUP_H
 
 #include <pthread.h>
+#include "thread.h"
 
-int init_ht_cleanup_thread(pthread_t *thread);
-int fini_ht_cleanup_thread(pthread_t *thread);
+struct lttng_thread *launch_ht_cleanup_thread(void);
 
 #endif /* _LTTNG_HT_CLEANUP_H */
index abae17fd65570400ac7f6a2aa955cd80ce0064d6..7e4e2950b19e9cf1903a793553cca0351fa1b225 100644 (file)
@@ -82,6 +82,7 @@
 #include "ht-cleanup.h"
 #include "sessiond-config.h"
 #include "timer.h"
+#include "thread.h"
 
 static const char *help_msg =
 #ifdef LTTNG_EMBED_HELP
@@ -192,7 +193,6 @@ static pthread_t client_thread;
 static pthread_t kernel_thread;
 static pthread_t dispatch_thread;
 static pthread_t health_thread;
-static pthread_t ht_cleanup_thread;
 static pthread_t agent_reg_thread;
 static pthread_t load_session_thread;
 static pthread_t notification_thread;
@@ -5691,6 +5691,7 @@ int main(int argc, char **argv)
        bool notification_thread_launched = false;
        bool rotation_thread_launched = false;
        bool timer_thread_launched = false;
+       struct lttng_thread *ht_cleanup_thread = NULL;
        struct timer_thread_parameters timer_thread_ctx;
        /* Queue of rotation jobs populated by the sessiond-timer. */
        struct rotation_thread_timer_queue *rotation_timer_queue = NULL;
@@ -5830,7 +5831,8 @@ int main(int argc, char **argv)
        }
 
        /* Create thread to clean up RCU hash tables */
-       if (init_ht_cleanup_thread(&ht_cleanup_thread)) {
+       ht_cleanup_thread = launch_ht_cleanup_thread();
+       if (!ht_cleanup_thread) {
                retval = -1;
                goto exit_ht_cleanup;
        }
@@ -6293,6 +6295,7 @@ exit_notification:
                PERROR("pthread_join health thread");
                retval = -1;
        }
+       lttng_thread_list_shutdown_orphans();
 
 exit_health:
 exit_init_data:
@@ -6357,6 +6360,11 @@ exit_init_data:
                }
        }
 
+       if (ht_cleanup_thread) {
+               lttng_thread_shutdown(ht_cleanup_thread);
+               lttng_thread_put(ht_cleanup_thread);
+       }
+
        /*
         * After the rotation and timer thread have quit, we can safely destroy
         * the rotation_timer_queue.
@@ -6366,10 +6374,6 @@ exit_init_data:
        rcu_thread_offline();
        rcu_unregister_thread();
 
-       ret = fini_ht_cleanup_thread(&ht_cleanup_thread);
-       if (ret) {
-               retval = -1;
-       }
        lttng_pipe_destroy(ust32_channel_monitor_pipe);
        lttng_pipe_destroy(ust64_channel_monitor_pipe);
        lttng_pipe_destroy(kernel_channel_monitor_pipe);
index 0f8a8bb1db3f545af0025913dc7a481581fed3fc..8f7c11978cd6bd142b00a2d23381d84f0054501f 100644 (file)
@@ -71,6 +71,7 @@ SESSIOND_OBJS = $(top_builddir)/src/bin/lttng-sessiond/buffer-registry.$(OBJEXT)
         $(top_builddir)/src/bin/lttng-sessiond/globals.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/thread-utils.$(OBJEXT) \
         $(top_builddir)/src/bin/lttng-sessiond/process-utils.$(OBJEXT) \
+        $(top_builddir)/src/bin/lttng-sessiond/thread.$(OBJEXT) \
         $(top_builddir)/src/common/libcommon.la \
         $(top_builddir)/src/common/testpoint/libtestpoint.la \
         $(top_builddir)/src/common/compat/libcompat.la \
index 74643221c6aa4b93e7d41a63398a9e5b6946bf4b..5db1e758fc8fcbe5641ca6b4498d99eb8fe875cb 100644 (file)
@@ -32,6 +32,7 @@
 #include <bin/lttng-sessiond/ust-app.h>
 #include <bin/lttng-sessiond/ht-cleanup.h>
 #include <bin/lttng-sessiond/health-sessiond.h>
+#include <bin/lttng-sessiond/thread.h>
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/common.h>
 
@@ -45,7 +46,6 @@
 
 struct health_app *health_sessiond;
 static struct ltt_session_list *session_list;
-static pthread_t ht_cleanup_thread;
 
 /* For error.h */
 int lttng_opt_quiet = 1;
@@ -315,10 +315,14 @@ void test_large_session_number(void)
 
 int main(int argc, char **argv)
 {
+       struct lttng_thread *ht_cleanup_thread;
+
        plan_tests(NUM_TESTS);
 
        health_sessiond = health_app_create(NR_HEALTH_SESSIOND_TYPES);
-       assert(!init_ht_cleanup_thread(&ht_cleanup_thread));
+       ht_cleanup_thread = launch_ht_cleanup_thread();
+       assert(ht_cleanup_thread);
+       lttng_thread_put(ht_cleanup_thread);
 
        diag("Sessions unit tests");
 
@@ -341,7 +345,7 @@ int main(int argc, char **argv)
        test_large_session_number();
 
        rcu_unregister_thread();
-       assert(!fini_ht_cleanup_thread(&ht_cleanup_thread));
+       lttng_thread_list_shutdown_orphans();
 
        return exit_status();
 }
This page took 0.032881 seconds and 4 git commands to generate.