[ltt-dev] [Autotest] [PATCH] LTTng trace destroy wait for readers to complete

Mathieu Desnoyers compudj at krystal.dyndns.org
Thu Oct 2 01:34:32 EDT 2008


Excellent! :)

It will be integrated in the next release. Given I already had my files
modified, I merged it by hand.

Thanks a lot!

Mathieu

* Jiaying Zhang (jiayingz at google.com) wrote:
> Hi Mathieu,
> 
> Regarding to your comment about we should probably use a waitqueue
> to synchronize lttd readers and trace destroy, how about we implement
> one now? See the attached patch.
> 
> Jiaying
> 
> On Mon, Sep 15, 2008 at 12:08 PM, Mathieu Desnoyers <
> compudj at krystal.dyndns.org> wrote:
> 
> > Hi John,
> >
> > Please try the following patch instead. It should make lttctl wait until
> > all lttd instances release the trace kref.
> >
> > Mathieu
> >
> >
> > LTTng trace destroy wait for readers to complete
> >
> > Make lttctl sleep until all the lttd readers complete.
> >
> > Hopefully this will brighten Martin's day.
> >
> > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>
> > CC: Martin J. Bligh <mbligh at google.com>
> > CC: Jiaying Zhang <jiayingz at google.com>
> > CC: John Admanski <jadmanski at google.com>
> > ---
> >  ltt/ltt-tracer.c |    9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > Index: linux-2.6-lttng/ltt/ltt-tracer.c
> > ===================================================================
> > --- linux-2.6-lttng.orig/ltt/ltt-tracer.c       2008-09-15
> > 14:43:00.000000000 -0400
> > +++ linux-2.6-lttng/ltt/ltt-tracer.c    2008-09-15 14:58:03.000000000 -0400
> > @@ -40,6 +40,7 @@
> >  #include <linux/fs.h>
> >  #include <linux/cpu.h>
> >  #include <linux/kref.h>
> > +#include <linux/delay.h>
> >  #include <asm/atomic.h>
> >
> >  static void async_wakeup(unsigned long data);
> > @@ -635,6 +636,14 @@ static void __ltt_trace_destroy(struct l
> >
> >        module_put(trace->transport->owner);
> >
> > +       /*
> > +        * Wait for lttd readers to release the files, therefore making
> > sure
> > +        * the last subbuffers have been read. Currently use a sleep,
> > should
> > +        * probably use a waitqueue.
> > +        */
> > +       while (atomic_read(&trace->kref.refcount) > 1)
> > +               ssleep(1);
> > +
> >        kref_put(&trace->kref, ltt_release_trace);
> >  }
> >
> >
> > --
> > Mathieu Desnoyers
> > OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
> > _______________________________________________
> > Autotest mailing list
> > Autotest at test.kernel.org
> > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
> >

> --- linux-2.6.26/include/linux/ltt-tracer.h	2008-08-28 16:11:44.000000000 -0700
> +++ linux-2.6.26-old/include/linux/ltt-tracer.h	2008-09-19 17:12:46.000000000 -0700
> @@ -270,6 +270,7 @@ struct ltt_trace_struct {
>  	} channel;
>  	struct rchan_callbacks callbacks;
>  	struct kref kref; /* Each channel has a kref of the trace struct */
> +	wait_queue_head_t kref_wq; /* Place for ltt_trace_destroy to sleep */
>  } ____cacheline_aligned;
>  
>  /*
> --- linux-2.6.26/ltt/ltt-tracer.c	2008-08-28 16:11:44.000000000 -0700
> +++ linux-2.6.26-old/ltt/ltt-tracer.c	2008-09-22 11:33:57.000000000 -0700
> @@ -389,6 +389,7 @@ static int ltt_trace_create(char *trace_
>  
>  	kref_init(&new_trace->kref);
>  	kref_init(&new_trace->ltt_transport_kref);
> +	init_waitqueue_head(&new_trace->kref_wq);
>  	new_trace->active = 0;
>  	strncpy(new_trace->trace_name, trace_name, NAME_MAX);
>  	new_trace->paused = 0;
> @@ -537,6 +538,7 @@ dirs_error:
>  	module_put(transport->owner);
>  trace_error:
>  	kref_put(&new_trace->kref, ltt_release_trace);
> +	wake_up_interruptible(&trace->kref_wq);
>  	ltt_unlock_traces();
>  traces_error:
>  	return err;
> @@ -612,6 +614,15 @@ static void __ltt_trace_destroy(struct l
>  
>  	module_put(trace->transport->owner);
>  
> +	/*
> +	 * Wait for lttd readers to release the files, therefore making sure
> +	 * the last subbuffers have been read.
> +	 */
> +	if (atomic_read(&trace->kref.refcount) > 1) {
> +		int ret = 0;
> +		__wait_event_interruptible(trace->kref_wq, (atomic_read(&trace->kref.refcount) == 1), ret);
> +	}
> +
>  	kref_put(&trace->kref, ltt_release_trace);
>  }
>  
> --- linux-2.6.26/ltt/ltt-relay.c	2008-09-10 13:11:44.000000000 -0700
> +++ linux-2.6.26-old/ltt/ltt-relay.c	2008-09-22 11:20:07.000000000 -0700
> @@ -472,6 +472,7 @@ static void ltt_relay_destroy_buffer(str
>  	ltt_chan->buf[cpu].commit_count = NULL;
>  	kref_put(&ltt_chan->kref, ltt_relay_release_channel);
>  	kref_put(&trace->kref, ltt_release_trace);
> +	wake_up_interruptible(&trace->kref_wq);
>  }
>  
>  /*


-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




More information about the lttng-dev mailing list