From 015d08b66af5ebd10665aa90f5426930e56c540d Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Mon, 1 Mar 2010 16:19:38 -0500 Subject: [PATCH] convert ltt_nesting to a per_thread variable, and access it with volatile access This fixes an ltt_nesting corruption bug. --- libust/buffers.h | 2 +- libust/serialize.c | 14 ++++++++------ libust/tracercore.c | 2 +- libust/tracercore.h | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libust/buffers.h b/libust/buffers.h index 28faad7..db4b708 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 011206a..4c23e8d 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 51f9a70..72c2887 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 3113383..2f3d7c4 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); -- 2.34.1