From a93bfc45c7cc2117d27f69eb420ab3333280e026 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 27 Sep 2011 20:39:07 -0400 Subject: [PATCH] Reset vtid after fork in child Signed-off-by: Mathieu Desnoyers --- include/ust/lttng-events.h | 1 + libust/lttng-context-vtid.c | 10 ++++++++++ libust/lttng-ust-comm.c | 2 ++ 3 files changed, 13 insertions(+) diff --git a/include/ust/lttng-events.h b/include/ust/lttng-events.h index 7a8cf6f8..6bb4e8cc 100644 --- a/include/ust/lttng-events.h +++ b/include/ust/lttng-events.h @@ -322,5 +322,6 @@ void lttng_remove_context_field(struct lttng_ctx **ctx_p, void lttng_destroy_context(struct lttng_ctx *ctx); int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); +void lttng_context_vtid_reset(void); #endif /* _UST_LTTNG_EVENTS_H */ diff --git a/libust/lttng-context-vtid.c b/libust/lttng-context-vtid.c index fd1e3200..a7e1c81d 100644 --- a/libust/lttng-context-vtid.c +++ b/libust/lttng-context-vtid.c @@ -38,6 +38,16 @@ static inline pid_t gettid(void) */ static __thread pid_t cached_vtid; +/* + * Upon fork or clone, the TID assigned to our thread is not the same as + * we kept in cache. Luckily, we are the only thread surviving in the + * child process, so we can simply clear our cached version. + */ +void lttng_context_vtid_reset(void) +{ + cached_vtid = 0; +} + static size_t vtid_get_size(size_t offset) { diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c index 6bf9e2b5..7971168c 100644 --- a/libust/lttng-ust-comm.c +++ b/libust/lttng-ust-comm.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -924,6 +925,7 @@ void ust_after_fork_child(ust_fork_info_t *fork_info) /* Release urcu mutexes */ rcu_bp_after_fork_child(); lttng_ust_cleanup(0); + lttng_context_vtid_reset(); /* Release mutexes and reenable signals */ ust_after_fork_common(fork_info); lttng_ust_init(); -- 2.34.1