From: nils.carlson@ericsson.com (Nils Carlson)
Subject: [ltt-dev] [UST PATCH 2/3] ust-consumerd: fix exit race log corruption
Date: Thu, 28 Apr 2011 15:20:30 +0200 [thread overview]
Message-ID: <alpine.DEB.2.00.1104281520250.28575@as68123.uab.ericsson.se> (raw)
In-Reply-To: <1303935736-29208-2-git-send-email-jason.wessel@windriver.com>
merged.
On Wed, 27 Apr 2011, Jason Wessel wrote:
> In the following scenario on an SMP system the ust-consumerd can end
> up not properly closing out file handles which leads to log
> corruption:
> * usttrace -m -l small_quick_app_lots_of_malloc_and_free
> * The app completes and usttrace sees and sends the SIGTERM to ust-consumerd
> * The ust-consumerd main thread will exit and the _exit() handlers
> kills off the remaining pthreads without everything getting closed out
>
> The solution to the problem is to introduce an active_thread count for
> the private ustconsumer_instance. This counter will be zeroed out
> when it is safe to completely shutdown the main thread, which will
> subsequently run the _exit() handlers.
>
> Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
> ---
> include/ust/ustconsumer.h | 1 +
> libustconsumer/libustconsumer.c | 10 +++++++++-
> 2 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/include/ust/ustconsumer.h b/include/ust/ustconsumer.h
> index f99f8f1..cde8440 100644
> --- a/include/ust/ustconsumer.h
> +++ b/include/ust/ustconsumer.h
> @@ -89,6 +89,7 @@ struct ustconsumer_instance {
> char *sock_path;
> pthread_mutex_t mutex;
> int active_buffers;
> + int active_threads;
> };
>
> /**
> diff --git a/libustconsumer/libustconsumer.c b/libustconsumer/libustconsumer.c
> index 6f6d4bb..a723540 100644
> --- a/libustconsumer/libustconsumer.c
> +++ b/libustconsumer/libustconsumer.c
> @@ -543,6 +543,10 @@ void *consumer_thread(void *arg)
> int result;
> sigset_t sigset;
>
> + pthread_mutex_lock(&args->instance->mutex);
> + args->instance->active_threads++;
> + pthread_mutex_unlock(&args->instance->mutex);
> +
> if(args->instance->callbacks->on_new_thread)
> args->instance->callbacks->on_new_thread(args->instance->callbacks);
>
> @@ -584,6 +588,10 @@ void *consumer_thread(void *arg)
> if(args->instance->callbacks->on_close_thread)
> args->instance->callbacks->on_close_thread(args->instance->callbacks);
>
> + pthread_mutex_lock(&args->instance->mutex);
> + args->instance->active_threads--;
> + pthread_mutex_unlock(&args->instance->mutex);
> +
> free((void *)args->channel);
> free(args);
> return NULL;
> @@ -735,7 +743,7 @@ int ustconsumer_start_instance(struct ustconsumer_instance *instance)
>
> if (instance->quit_program) {
> pthread_mutex_lock(&instance->mutex);
> - if(instance->active_buffers == 0) {
> + if(instance->active_buffers == 0 && instance->active_threads == 0) {
> pthread_mutex_unlock(&instance->mutex);
> break;
> }
> --
> 1.7.1
>
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>
next prev parent reply other threads:[~2011-04-28 13:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 20:22 [ltt-dev] [UST PATCH 1/3] ust-consumerd: fix exit race crashes Jason Wessel
2011-04-27 20:22 ` [ltt-dev] [UST PATCH 2/3] ust-consumerd: fix exit race log corruption Jason Wessel
2011-04-28 13:20 ` Nils Carlson [this message]
2011-04-28 14:57 ` Mathieu Desnoyers
2011-04-27 20:22 ` [ltt-dev] [UST PATCH 3/3] support busybox for manual trace tests Jason Wessel
2011-04-28 13:20 ` Nils Carlson
2011-04-28 13:20 ` [ltt-dev] [UST PATCH 1/3] ust-consumerd: fix exit race crashes Nils Carlson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.00.1104281520250.28575@as68123.uab.ericsson.se \
--to=nils.carlson@ericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox