fix(cache): disable branch predictor when cache freeze

This commit is contained in:
armando
2025-03-26 18:59:37 +08:00
parent df1f0f51f4
commit 6bb78e4573
3 changed files with 50 additions and 11 deletions
+15
View File
@@ -16,6 +16,7 @@
#include "hal/mmu_hal.h"
#include "hal/cache_hal.h"
#include "hal/cache_ll.h"
#include "esp_cpu.h"
#include "esp_cache.h"
#include "esp_private/esp_cache_private.h"
#include "esp_private/critical_section.h"
@@ -95,6 +96,10 @@ esp_err_t esp_cache_msync(void *addr, size_t size, int flags)
void esp_cache_suspend_ext_mem_cache(void)
{
#if SOC_BRANCH_PREDICTOR_SUPPORTED
//branch predictor will start cache request as well
esp_cpu_branch_prediction_disable();
#endif
#if (CONFIG_SPIRAM && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE)
/**
* before suspending the external mem cache, writeback internal mem cache content back to external mem cache
@@ -108,11 +113,18 @@ void esp_cache_suspend_ext_mem_cache(void)
void esp_cache_resume_ext_mem_cache(void)
{
cache_hal_resume(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
#if SOC_BRANCH_PREDICTOR_SUPPORTED
esp_cpu_branch_prediction_enable();
#endif
}
#if SOC_CACHE_FREEZE_SUPPORTED
void esp_cache_freeze_ext_mem_cache(void)
{
#if SOC_BRANCH_PREDICTOR_SUPPORTED
//branch predictor will start cache request as well
esp_cpu_branch_prediction_disable();
#endif
#if (CONFIG_SPIRAM && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE)
/**
* before freezing the external mem cache, writeback internal mem cache content back to external mem cache
@@ -126,6 +138,9 @@ void esp_cache_freeze_ext_mem_cache(void)
void esp_cache_unfreeze_ext_mem_cache(void)
{
cache_hal_unfreeze(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
#if SOC_BRANCH_PREDICTOR_SUPPORTED
esp_cpu_branch_prediction_enable();
#endif
}
#endif //#if SOC_CACHE_FREEZE_SUPPORTED