eal: introduce thread uninit helper
authorDavid Marchand <david.marchand@redhat.com>
Mon, 6 Jul 2020 20:52:28 +0000 (22:52 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Wed, 8 Jul 2020 12:39:26 +0000 (14:39 +0200)
This is a preparation step for dynamically unregistering threads.

Since we explicitly allocate a per thread trace buffer in
__rte_thread_init, add an internal helper to free this buffer.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
lib/librte_eal/common/eal_common_thread.c
lib/librte_eal/common/eal_common_trace.c
lib/librte_eal/common/eal_private.h
lib/librte_eal/common/eal_trace.h
lib/librte_eal/windows/eal.c

index fb06f8f..6d1c87b 100644 (file)
@@ -20,6 +20,7 @@
 #include "eal_internal_cfg.h"
 #include "eal_private.h"
 #include "eal_thread.h"
+#include "eal_trace.h"
 
 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
 RTE_DEFINE_PER_LCORE(int, _thread_id) = -1;
@@ -161,6 +162,14 @@ __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset)
        __rte_trace_mem_per_thread_alloc();
 }
 
+void
+__rte_thread_uninit(void)
+{
+       trace_mem_per_thread_free();
+
+       RTE_PER_LCORE(_lcore_id) = LCORE_ID_ANY;
+}
+
 struct rte_thread_ctrl_params {
        void *(*start_routine)(void *);
        void *arg;
index 875553d..b6da553 100644 (file)
@@ -101,7 +101,7 @@ eal_trace_fini(void)
 {
        if (!rte_trace_is_enabled())
                return;
-       trace_mem_per_thread_free();
+       trace_mem_free();
        trace_metadata_destroy();
        eal_trace_args_free();
 }
@@ -370,24 +370,59 @@ fail:
        rte_spinlock_unlock(&trace->lock);
 }
 
+static void
+trace_mem_per_thread_free_unlocked(struct thread_mem_meta *meta)
+{
+       if (meta->area == TRACE_AREA_HUGEPAGE)
+               eal_free_no_trace(meta->mem);
+       else if (meta->area == TRACE_AREA_HEAP)
+               free(meta->mem);
+}
+
 void
 trace_mem_per_thread_free(void)
+{
+       struct trace *trace = trace_obj_get();
+       struct __rte_trace_header *header;
+       uint32_t count;
+
+       header = RTE_PER_LCORE(trace_mem);
+       if (header == NULL)
+               return;
+
+       rte_spinlock_lock(&trace->lock);
+       for (count = 0; count < trace->nb_trace_mem_list; count++) {
+               if (trace->lcore_meta[count].mem == header)
+                       break;
+       }
+       if (count != trace->nb_trace_mem_list) {
+               struct thread_mem_meta *meta = &trace->lcore_meta[count];
+
+               trace_mem_per_thread_free_unlocked(meta);
+               if (count != trace->nb_trace_mem_list - 1) {
+                       memmove(meta, meta + 1,
+                               sizeof(*meta) *
+                                (trace->nb_trace_mem_list - count - 1));
+               }
+               trace->nb_trace_mem_list--;
+       }
+       rte_spinlock_unlock(&trace->lock);
+}
+
+void
+trace_mem_free(void)
 {
        struct trace *trace = trace_obj_get();
        uint32_t count;
-       void *mem;
 
        if (!rte_trace_is_enabled())
                return;
 
        rte_spinlock_lock(&trace->lock);
        for (count = 0; count < trace->nb_trace_mem_list; count++) {
-               mem = trace->lcore_meta[count].mem;
-               if (trace->lcore_meta[count].area == TRACE_AREA_HUGEPAGE)
-                       eal_free_no_trace(mem);
-               else if (trace->lcore_meta[count].area == TRACE_AREA_HEAP)
-                       free(mem);
+               trace_mem_per_thread_free_unlocked(&trace->lcore_meta[count]);
        }
+       trace->nb_trace_mem_list = 0;
        rte_spinlock_unlock(&trace->lock);
 }
 
index 5d8b538..a77ac7a 100644 (file)
@@ -709,4 +709,9 @@ eal_get_application_usage_hook(void);
  */
 void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset);
 
+/**
+ * Uninitialize per-lcore info for current thread.
+ */
+void __rte_thread_uninit(void);
+
 #endif /* _EAL_PRIVATE_H_ */
index 8f60616..92c5951 100644 (file)
@@ -106,6 +106,7 @@ int trace_metadata_create(void);
 void trace_metadata_destroy(void);
 int trace_mkdir(void);
 int trace_epoch_time_save(void);
+void trace_mem_free(void);
 void trace_mem_per_thread_free(void);
 
 /* EAL interface */
index 9f5d019..addac62 100644 (file)
 #include <eal_filesystem.h>
 #include <eal_options.h>
 #include <eal_private.h>
-#include <rte_trace_point.h>
 #include <rte_vfio.h>
 
 #include "eal_hugepages.h"
+#include "eal_trace.h"
 #include "eal_windows.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -215,6 +215,11 @@ __rte_trace_mem_per_thread_alloc(void)
 {
 }
 
+void
+trace_mem_per_thread_free(void)
+{
+}
+
 void
 __rte_trace_point_emit_field(size_t sz, const char *field,
        const char *type)