Merge branch 'fix/fix_l2_cache_miss_issue_5.3_2' into 'release/v5.3'

cache: fixed l2 cache suspended/frozen but l1cache triggers l2 writeback issue (v5.3 full version)

See merge request espressif/esp-idf!38204
This commit is contained in:
Jiang Jiang Jian
2025-04-03 19:52:37 +08:00
3 changed files with 16 additions and 15 deletions

View File

@@ -16,7 +16,6 @@
#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"
@@ -96,10 +95,6 @@ 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
@@ -113,18 +108,11 @@ 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
@@ -138,9 +126,6 @@ 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

View File

@@ -19,7 +19,10 @@ extern "C" {
/**
* @brief Suspend external memory cache
*
* @note CPU branch predictor should be disabled before calling this API
* @note This API is only for internal usage, no thread safety guaranteed
* @note This API is Non-Nestable and Non-Reentrant
* @note Call to this API must be followed by a `esp_cache_resume_ext_mem_cache`
*/
void esp_cache_suspend_ext_mem_cache(void);
@@ -27,6 +30,8 @@ void esp_cache_suspend_ext_mem_cache(void);
* @brief Resume external memory cache
*
* @note This API is only for internal usage, no thread safety guaranteed
* @note This API is Non-Nestable and Non-Reentrant
* @note This API must be called after a `esp_cache_suspend_ext_mem_cache`
*/
void esp_cache_resume_ext_mem_cache(void);
@@ -35,6 +40,8 @@ void esp_cache_resume_ext_mem_cache(void);
* @brief Freeze external memory cache
*
* @note This API is only for internal usage, no thread safety guaranteed
* @note This API is Non-Nestable and Non-Reentrant
* @note Call to this API must be followed by a `esp_cache_unfreeze_ext_mem_cache`
*/
void esp_cache_freeze_ext_mem_cache(void);
@@ -42,6 +49,8 @@ void esp_cache_freeze_ext_mem_cache(void);
* @brief Unfreeze external memory cache
*
* @note This API is only for internal usage, no thread safety guaranteed
* @note This API is Non-Nestable and Non-Reentrant
* @note This API must be called after a `esp_cache_freeze_ext_mem_cache`
*/
void esp_cache_unfreeze_ext_mem_cache(void);
#endif

View File

@@ -364,12 +364,19 @@ void IRAM_ATTR spi_flash_enable_cache(uint32_t cpuid)
void IRAM_ATTR spi_flash_disable_cache(uint32_t cpuid, uint32_t *saved_state)
{
#if SOC_BRANCH_PREDICTOR_SUPPORTED
//branch predictor will start cache request as well
esp_cpu_branch_prediction_disable();
#endif
esp_cache_suspend_ext_mem_cache();
}
void IRAM_ATTR spi_flash_restore_cache(uint32_t cpuid, uint32_t saved_state)
{
esp_cache_resume_ext_mem_cache();
#if SOC_BRANCH_PREDICTOR_SUPPORTED
esp_cpu_branch_prediction_enable();
#endif
}
bool IRAM_ATTR spi_flash_cache_enabled(void)