Skip to content

Commit

Permalink
dram: add a debug option to track bad cold code
Browse files Browse the repository at this point in the history
It is important not to run in DRAM code, that can be called on hot
paths, i.e. in LL-scheduler context. Add a Kconfig option to catch
such cases and enable it in debug builds.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh committed Mar 5, 2025
1 parent 9228f20 commit 82af434
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Kconfig.sof
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ config COLD_STORE_EXECUTE_DRAM
option to enable this feature to save SRAM and to speed up SRAM
copying of performance-critical data and code.


config COLD_STORE_EXECUTE_DEBUG
bool "Enable checks for cold code on hot paths"
help
This enables an assert_can_be_cold() check, which causes an exception
if called in the LL task context and assert() evaluation is enabled.

config FAST_GET
bool "Enable simple refcounting DRAM data copier"
default n
Expand Down
2 changes: 2 additions & 0 deletions app/debug_overlay.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ CONFIG_DAI_VERBOSE_GLITCH_WARNINGS=y
# CONFIG_SYS_HEAP_VALIDATE=y
# CONFIG_SPIN_VALIDATE=y
# CONFIG_SPIN_LOCK_TIME_LIMIT=50000

CONFIG_COLD_STORE_EXECUTE_DEBUG=y
2 changes: 2 additions & 0 deletions posix/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
#define __cold_rodata
#endif

#define assert_can_be_cold() do {} while (0)

#endif /* __SOF_LIB_MEMORY_H__ */
1 change: 1 addition & 0 deletions src/include/sof/schedule/ll_schedule_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ struct ll_schedule_domain *zephyr_dma_domain_init(struct dma *dma_array,
uint32_t num_dma,
int clk);
#endif /* CONFIG_DMA_DOMAIN */
struct ll_schedule_domain *zephyr_ll_domain(void);
struct ll_schedule_domain *zephyr_domain_init(int clk);
#define timer_domain_init(timer, clk) zephyr_domain_init(clk)
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/schedule/zephyr_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <rtos/timer.h>
#include <rtos/alloc.h>
#include <rtos/symbol.h>
#include <sof/lib/cpu.h>
#include <sof/lib/memory.h>
#include <sof/lib/watchdog.h>
Expand Down Expand Up @@ -321,3 +322,16 @@ struct ll_schedule_domain *zephyr_domain_init(int clk)

return domain;
}

bool ll_sch_is_current(void)
{
struct zephyr_domain *zephyr_domain = ll_sch_domain_get_pdata(zephyr_ll_domain());

if (!zephyr_domain)
return false;

struct zephyr_domain_thread *dt = zephyr_domain->domain_thread + cpu_get_id();

return k_current_get() == &dt->ll_thread;
}
EXPORT_SYMBOL(ll_sch_is_current);
7 changes: 7 additions & 0 deletions src/schedule/zephyr_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,10 @@ void scheduler_get_task_info_ll(struct scheduler_props *scheduler_props,
scheduler_get_task_info(scheduler_props, data_off_size, &ll_sch->tasks);
zephyr_ll_unlock(ll_sch, &flags);
}

struct ll_schedule_domain *zephyr_ll_domain(void)
{
struct zephyr_ll *ll_sch = scheduler_get_data(SOF_SCHEDULE_LL_TIMER);

return ll_sch->ll_domain;
}
2 changes: 2 additions & 0 deletions xtos/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
#define __cold_rodata
#endif

#define assert_can_be_cold() do {} while (0)

#endif /* __SOF_LIB_MEMORY_H__ */
17 changes: 17 additions & 0 deletions zephyr/include/sof/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,21 @@
#define __cold_rodata
#endif

#if CONFIG_COLD_STORE_EXECUTE_DEBUG
#include <rtos/panic.h>

#ifdef __ZEPHYR__
bool ll_sch_is_current(void);
#else
#define ll_sch_is_current() false
#endif

static inline void assert_can_be_cold(void)
{
assert(!ll_sch_is_current());
}
#else
#define assert_can_be_cold() do {} while (0)
#endif

#endif /* __SOF_LIB_MEMORY_H__ */

0 comments on commit 82af434

Please sign in to comment.