Add a simple system monitoring agent that can detect when FW does not execute correctly. The assumption is that FW will always idle from time to time and this idling can be monitored by the SA. The FW wont idle if it's thrashing, continually interrupted, continually running work or continually rescheduling a task.
The SA will emit trace and panic if idle is not entered for a specific time period.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/include/reef/agent.h | 50 ++++++++++++ src/include/reef/debug.h | 1 + src/include/reef/reef.h | 4 + src/include/reef/trace.h | 1 + src/lib/Makefile.am | 3 +- src/lib/agent.c | 96 +++++++++++++++++++++++ src/platform/baytrail/include/platform/platform.h | 3 + 7 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/include/reef/agent.h create mode 100644 src/lib/agent.c
diff --git a/src/include/reef/agent.h b/src/include/reef/agent.h new file mode 100644 index 0000000..53912b5 --- /dev/null +++ b/src/include/reef/agent.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Liam Girdwood liam.r.girdwood@linux.intel.com + */ + +#ifndef __INCLUDE_REEF_AGENT__ +#define __INCLUDE_REEF_AGENT__ + +#include <stdint.h> +#include <stddef.h> +#include <reef/work.h> + +struct reef; + +/* simple agent */ +struct sa { + uint64_t last_idle; /* time of last idle */ + uint64_t ticks; + struct work work; +}; + +void sa_enter_idle(struct reef *reef); +void sa_init(struct reef *reef); + +#endif diff --git a/src/include/reef/debug.h b/src/include/reef/debug.h index 85f91d4..2c5c573 100644 --- a/src/include/reef/debug.h +++ b/src/include/reef/debug.h @@ -47,6 +47,7 @@ #define PANIC_EXCEPTION 6 #define PANIC_DEADLOCK 7 #define PANIC_STACK 8 +#define PANIC_IDLE 9
#define DEBUG
diff --git a/src/include/reef/reef.h b/src/include/reef/reef.h index 842ad94..c872acc 100644 --- a/src/include/reef/reef.h +++ b/src/include/reef/reef.h @@ -36,6 +36,7 @@ #include <arch/reef.h>
struct ipc; +struct sa;
/* use same syntax as Linux for simplicity */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -64,6 +65,9 @@ struct reef { /* ipc */ struct ipc *ipc;
+ /* system agent */ + struct sa *sa; + /* private data */ void *arch_private; void *plat_private; diff --git a/src/include/reef/trace.h b/src/include/reef/trace.h index 9497f98..4656ef7 100644 --- a/src/include/reef/trace.h +++ b/src/include/reef/trace.h @@ -87,6 +87,7 @@ #define TRACE_CLASS_TONE (18 << 24) #define TRACE_CLASS_EQ_FIR (19 << 24) #define TRACE_CLASS_EQ_IIR (20 << 24) +#define TRACE_CLASS_SA (21 << 24)
/* move to config.h */ #define TRACE 1 diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index b4521df..5a6dfbf 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -7,7 +7,8 @@ libcore_a_SOURCES = \ notifier.c \ trace.c \ dma-trace.c \ - schedule.c + schedule.c \ + agent.c
libcore_a_CFLAGS = \ $(ARCH_CFLAGS) \ diff --git a/src/lib/agent.c b/src/lib/agent.c new file mode 100644 index 0000000..1ffee81 --- /dev/null +++ b/src/lib/agent.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2017, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Liam Girdwood liam.r.girdwood@linux.intel.com + * + * System Agent - Simple FW Monitor that can notify host drivers in the event + * of any FW errors. The SA assumes that each core will enter the idle state + * from time to time (within a period of PLATFORM_IDLE_TIME). If the core does + * not enter the idle loop through looping forever or scheduling some work + * continuously then the SA will emit trace and panic(). + */ + +#include <reef/reef.h> +#include <reef/agent.h> +#include <reef/debug.h> +#include <reef/alloc.h> +#include <reef/clock.h> +#include <reef/trace.h> +#include <platform/timer.h> +#include <platform/platform.h> +#include <platform/clk.h> + +#define trace_sa(__e) trace_event_atomic(TRACE_CLASS_SA, __e) +#define trace_sa_value(__e) trace_value_atomic(__e) + +/* + * Notify the SA that we are about to enter idle state (WFI). + */ +void sa_enter_idle(struct reef *reef) +{ + struct sa *sa = reef->sa; + + sa->last_idle = platform_timer_get(platform_timer); +} + +static uint64_t validate(void *data, uint64_t delay) +{ + struct sa *sa = data; + uint64_t current; + uint64_t delta; + + current = platform_timer_get(platform_timer); + delta = current - sa->last_idle; + + /* were we last idle longer than timeout */ + if (delta > sa->ticks) { + trace_sa("tim"); + trace_sa_value(delta); + panic_dump_stack(PANIC_IDLE); + } + + return PLATFORM_IDLE_TIME; +} + +void sa_init(struct reef *reef) +{ + struct sa *sa; + + trace_sa("ini"); + + sa = rzalloc(RZONE_SYS, RFLAGS_NONE, sizeof(*sa)); + reef->sa = sa; + + /* set default tick timout */ + sa->ticks = clock_us_to_ticks(PLATFORM_WORKQ_CLOCK, PLATFORM_IDLE_TIME); + trace_sa_value(sa->ticks); + + /* set lst idle time to now to give time for boot completion */ + sa->last_idle = platform_timer_get(platform_timer) + sa->ticks; + work_init(&sa->work, validate, sa, WORK_ASYNC); + work_schedule_default(&sa->work, PLATFORM_IDLE_TIME); +} diff --git a/src/platform/baytrail/include/platform/platform.h b/src/platform/baytrail/include/platform/platform.h index bc90564..8b713df 100644 --- a/src/platform/baytrail/include/platform/platform.h +++ b/src/platform/baytrail/include/platform/platform.h @@ -94,6 +94,9 @@ struct reef; /* DMAC used for trace DMA */ #define PLATFORM_TRACE_DMAC DMA_ID_DMAC0
+/* DSP should be idle in this time frame */ +#define PLATFORM_IDLE_TIME 750000 + /* Platform defined panic code */ #define platform_panic(__x) \ shim_write(SHIM_IPCDH, (0xdead000 | (__x & 0xfff)))