From: Pierre-Marc Fournier Date: Mon, 1 Mar 2010 21:19:38 +0000 (-0500) Subject: convert ltt_nesting to a per_thread variable, and access it with volatile access X-Git-Tag: v1.9.1~689 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=015d08b66af5ebd10665aa90f5426930e56c540d;p=lttng-ust.git convert ltt_nesting to a per_thread variable, and access it with volatile access This fixes an ltt_nesting corruption bug. --- diff --git a/libust/buffers.h b/libust/buffers.h index 28faad79..db4b7089 100644 --- a/libust/buffers.h +++ b/libust/buffers.h @@ -356,7 +356,7 @@ static __inline__ int ltt_reserve_slot(struct ust_trace *trace, * Perform retryable operations. */ /* FIXME: make this rellay per cpu? */ - if (unlikely(__get_cpu_var(ltt_nesting) > 4)) { + if (unlikely(LOAD_SHARED(ltt_nesting) > 4)) { local_inc(&buf->events_lost); return -EPERM; } diff --git a/libust/serialize.c b/libust/serialize.c index 011206af..4c23e8dd 100644 --- a/libust/serialize.c +++ b/libust/serialize.c @@ -623,11 +623,11 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, return; rcu_read_lock(); //ust// rcu_read_lock_sched_notrace(); -//ust// cpu = smp_processor_id(); cpu = ust_get_cpu(); -//ust// __get_cpu_var(ltt_nesting)++; - /* FIXME: should nesting be per-cpu? */ - ltt_nesting++; + + /* Force volatile access. */ + STORE_SHARED(ltt_nesting, LOAD_SHARED(ltt_nesting) + 1); + barrier(); pdata = (struct ltt_active_marker *)probe_data; eID = mdata->event_id; @@ -712,8 +712,10 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, ltt_commit_slot(channel, buf, buf_offset, data_size, slot_size); DBG("just commited event (%s/%s) at offset %ld and size %zd", mdata->channel, mdata->name, buf_offset, slot_size); } -//ust// __get_cpu_var(ltt_nesting)--; - ltt_nesting--; + + barrier(); + STORE_SHARED(ltt_nesting, LOAD_SHARED(ltt_nesting) - 1); + rcu_read_unlock(); //ust// rcu_read_unlock_sched_notrace(); } diff --git a/libust/tracercore.c b/libust/tracercore.c index 51f9a708..72c2887d 100644 --- a/libust/tracercore.c +++ b/libust/tracercore.c @@ -42,7 +42,7 @@ void ltt_unlock_traces(void) //ust// DEFINE_PER_CPU(unsigned int, ltt_nesting); //ust// EXPORT_PER_CPU_SYMBOL(ltt_nesting); -unsigned int ltt_nesting; +__thread int ltt_nesting; int ltt_run_filter_default(void *trace, uint16_t eID) { diff --git a/libust/tracercore.h b/libust/tracercore.h index 3113383c..2f3d7c4a 100644 --- a/libust/tracercore.h +++ b/libust/tracercore.h @@ -42,8 +42,7 @@ struct ltt_traces { extern struct ltt_traces ltt_traces; /* Keep track of trap nesting inside LTT */ -//ust// DECLARE_PER_CPU(unsigned int, ltt_nesting); -extern unsigned int ltt_nesting; +extern __thread int ltt_nesting; typedef int (*ltt_run_filter_functor)(void *trace, uint16_t eID); //typedef int (*ltt_run_filter_functor)(void *, __u16);