[Sound-open-firmware] [PATCH] trace: provide locking around trace output.
Make sure trace mailbox writes are atomic and provide reef context.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/include/reef/trace.h | 2 ++ src/init/init.c | 2 ++ src/lib/trace.c | 41 +++++++++++++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/src/include/reef/trace.h b/src/include/reef/trace.h index 00dbb5b..300e8d8 100644 --- a/src/include/reef/trace.h +++ b/src/include/reef/trace.h @@ -34,6 +34,7 @@
#include <stdint.h> #include <stdlib.h> +#include <reef/reef.h> #include <reef/mailbox.h> #include <reef/debug.h> #include <reef/timer.h> @@ -94,6 +95,7 @@
void _trace_event(uint32_t event); void trace_off(void); +void trace_init(struct reef * reef);
#if TRACE
diff --git a/src/init/init.c b/src/init/init.c index 1dc1237..491a6ad 100644 --- a/src/init/init.c +++ b/src/init/init.c @@ -65,6 +65,8 @@ int main(int argc, char *argv[]) trace_point(TRACE_BOOT_SYS_HEAP); init_heap(&reef);
+ trace_init(&reef); + trace_point(TRACE_BOOT_SYS_NOTE); init_system_notify(&reef);
diff --git a/src/lib/trace.c b/src/lib/trace.c index 79d026e..5da7c95 100644 --- a/src/lib/trace.c +++ b/src/lib/trace.c @@ -29,34 +29,55 @@ */
#include <reef/trace.h> +#include <reef/reef.h> +#include <reef/alloc.h> #include <arch/cache.h> +#include <platform/timer.h> +#include <reef/lock.h> #include <stdint.h>
-/* trace position */ -static uint32_t trace_pos = 0; -static uint32_t trace_enable = 1; +struct trace { + uint32_t pos ; /* trace position */ + uint32_t enable; + spinlock_t lock; +}; + +static struct trace trace;
void _trace_event(uint32_t event) { - volatile uint32_t *t = - (volatile uint32_t*)(MAILBOX_TRACE_BASE + trace_pos); + unsigned long flags; + volatile uint32_t *t;
- if (!trace_enable) + if (!trace.enable) return;
+ spin_lock_irq(&trace.lock, flags); + /* write timestamp and event to trace buffer */ + t =(volatile uint32_t*)(MAILBOX_TRACE_BASE + trace.pos); t[0] = platform_timer_get(0); t[1] = event;
/* writeback trace data */ dcache_writeback_region((void*)t, sizeof(uint32_t) * 2);
- trace_pos += (sizeof(uint32_t) << 1); - if (trace_pos >= MAILBOX_TRACE_SIZE) - trace_pos = 0; + trace.pos += (sizeof(uint32_t) << 1); + + if (trace.pos >= MAILBOX_TRACE_SIZE) + trace.pos = 0; + + spin_unlock_irq(&trace.lock, flags); }
void trace_off(void) { - trace_enable = 0; + trace.enable = 0; }; + +void trace_init(struct reef *reef) +{ + trace.enable = 1; + trace.pos = 0; + spinlock_init(&trace.lock); +}
participants (1)
-
Liam Girdwood