Revert "fix(cache): disable branch predictor when cache freeze"

This reverts commit 6bb78e4573.
This commit is contained in:
armando
2025-04-02 18:07:40 +08:00
parent 517e489c75
commit 7948c53dde
3 changed files with 11 additions and 50 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

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -7,7 +7,6 @@
#include <stdlib.h>
#include <stdint.h>
#include "soc/soc_caps.h"
#include "esp_err.h"
#include "esp_bit_defs.h"
#include "esp_heap_caps.h"
@@ -16,36 +15,6 @@
extern "C" {
#endif
/**
* @brief Suspend external memory cache
*
* @note This API is only for internal usage, no thread safety guaranteed
*/
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
*/
void esp_cache_resume_ext_mem_cache(void);
#if SOC_CACHE_FREEZE_SUPPORTED
/**
* @brief Freeze external memory cache
*
* @note This API is only for internal usage, no thread safety guaranteed
*/
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
*/
void esp_cache_unfreeze_ext_mem_cache(void);
#endif
/**
* @brief Helper function for malloc a cache aligned data memory buffer
*

View File

@@ -58,11 +58,11 @@
#include "esp_memory_utils.h"
#include "esp_intr_alloc.h"
#include "spi_flash_override.h"
#include "esp_private/esp_cache_private.h"
#include "esp_private/cache_utils.h"
#include "esp_private/spi_flash_os.h"
#include "esp_private/freertos_idf_additions_priv.h"
#include "esp_log.h"
#include "esp_cpu.h"
static __attribute__((unused)) const char *TAG = "cache";
@@ -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)
{
esp_cache_suspend_ext_mem_cache();
#if SOC_BRANCH_PREDICTOR_SUPPORTED
//branch predictor will start cache request as well
esp_cpu_branch_prediction_disable();
#endif
cache_hal_suspend(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
}
void IRAM_ATTR spi_flash_restore_cache(uint32_t cpuid, uint32_t saved_state)
{
esp_cache_resume_ext_mem_cache();
cache_hal_resume(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
#if SOC_BRANCH_PREDICTOR_SUPPORTED
esp_cpu_branch_prediction_enable();
#endif
}
bool IRAM_ATTR spi_flash_cache_enabled(void)