From 682e511e8b3428c08be49aece04aff90847f0bc6 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Thu, 10 Oct 2024 11:15:09 +0200 Subject: [PATCH 1/6] Add option to place more `.rodata` in RAM for performance --- esp-hal/build.rs | 60 ++++++++++++++++++++------------- esp-hal/ld/esp32/esp32.x | 4 +-- esp-hal/ld/esp32c2/esp32c2.x | 4 +-- esp-hal/ld/esp32c3/esp32c3.x | 4 +-- esp-hal/ld/esp32c6/esp32c6.x | 4 +-- esp-hal/ld/esp32h2/esp32h2.x | 4 +-- esp-hal/ld/esp32s2/esp32s2.x | 4 +-- esp-hal/ld/esp32s3/esp32s3.x | 4 +-- esp-hal/ld/sections/rwdata.x | 6 ++++ esp-hal/ld/sections/rwtext.x | 8 +++-- esp-hal/src/gpio/mod.rs | 2 ++ esp-hal/src/interrupt/riscv.rs | 27 ++++++++++----- esp-hal/src/interrupt/xtensa.rs | 21 ++++++++---- 13 files changed, 97 insertions(+), 55 deletions(-) diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 65644c7272a..3e6a4912943 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -69,19 +69,51 @@ fn main() -> Result<(), Box> { // Define all necessary configuration symbols for the configured device: config.define_symbols(); - #[allow(unused_mut)] - let mut config_symbols = config.all().collect::>(); - #[cfg(feature = "flip-link")] - config_symbols.push("flip-link"); - // Place all linker scripts in `OUT_DIR`, and instruct Cargo how to find these // files: let out = PathBuf::from(env::var_os("OUT_DIR").unwrap()); println!("cargo:rustc-link-search={}", out.display()); + // emit config + let cfg = generate_config( + "esp_hal", + &[ + ( + "place-spi-driver-in-ram", + Value::Bool(false), + "Places the SPI driver in RAM for better performance", + ), + ( + "spi-address-workaround", + Value::Bool(true), + "(ESP32 only) Enables a workaround for the issue where SPI in half-duplex mode incorrectly transmits the address on a single line if the data buffer is empty.", + ), + ( + "place-more-rodata-in-ram", + Value::Bool(false), + "Places more data (lookup-tables, switch-tables etc.) into RAM - resulting in better performance (especially for interrupts) but more RAM consumption", + ) + ], + true, + ); + // RISC-V and Xtensa devices each require some special handling and processing // of linker scripts: + #[allow(unused_mut)] + let mut config_symbols = config.all().collect::>(); + #[cfg(feature = "flip-link")] + config_symbols.push("flip-link"); + + for (key, value) in &cfg { + match value { + Value::Bool(true) => { + config_symbols.push(&key); + } + _ => (), + } + } + if cfg!(feature = "esp32") || cfg!(feature = "esp32s2") || cfg!(feature = "esp32s3") { // Xtensa devices: @@ -125,24 +157,6 @@ fn main() -> Result<(), Box> { copy_dir_all(&config_symbols, "ld/sections", &out)?; copy_dir_all(&config_symbols, format!("ld/{device_name}"), &out)?; - // emit config - generate_config( - "esp_hal", - &[ - ( - "place-spi-driver-in-ram", - Value::Bool(false), - "Places the SPI driver in RAM for better performance", - ), - ( - "spi-address-workaround", - Value::Bool(true), - "(ESP32 only) Enables a workaround for the issue where SPI in half-duplex mode incorrectly transmits the address on a single line if the data buffer is empty.", - ), - ], - true, - ); - Ok(()) } diff --git a/esp-hal/ld/esp32/esp32.x b/esp-hal/ld/esp32/esp32.x index 5d9ffec825a..a61c7579408 100644 --- a/esp-hal/ld/esp32/esp32.x +++ b/esp-hal/ld/esp32/esp32.x @@ -19,10 +19,10 @@ INCLUDE "fixups/rtc_fast_rwdata_dummy.x" /* END ESP32 fixups */ /* Shared sections - ordering matters */ -INCLUDE "text.x" -INCLUDE "rodata.x" INCLUDE "rwtext.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "rtc_slow.x" INCLUDE "stack.x" diff --git a/esp-hal/ld/esp32c2/esp32c2.x b/esp-hal/ld/esp32c2/esp32c2.x index 8324eb4c31e..a98f753ef1f 100644 --- a/esp-hal/ld/esp32c2/esp32c2.x +++ b/esp-hal/ld/esp32c2/esp32c2.x @@ -80,10 +80,10 @@ PROVIDE(__global_pointer$ = _data_start + 0x800); /* end of esp32c2 fixups */ /* Shared sections - ordering matters */ -INCLUDE "text.x" -INCLUDE "rodata.x" INCLUDE "rwtext.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "stack.x" INCLUDE "dram2.x" /* End of Shared sections */ diff --git a/esp-hal/ld/esp32c3/esp32c3.x b/esp-hal/ld/esp32c3/esp32c3.x index 4d83f420e98..51144d78407 100644 --- a/esp-hal/ld/esp32c3/esp32c3.x +++ b/esp-hal/ld/esp32c3/esp32c3.x @@ -80,10 +80,10 @@ PROVIDE(__global_pointer$ = _data_start + 0x800); /* end of esp32c3 fixups */ /* Shared sections - ordering matters */ -INCLUDE "text.x" -INCLUDE "rodata.x" INCLUDE "rwtext.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "stack.x" INCLUDE "dram2.x" diff --git a/esp-hal/ld/esp32c6/esp32c6.x b/esp-hal/ld/esp32c6/esp32c6.x index 4a3cc337aa3..47f8de2e0ea 100644 --- a/esp-hal/ld/esp32c6/esp32c6.x +++ b/esp-hal/ld/esp32c6/esp32c6.x @@ -72,10 +72,10 @@ INSERT BEFORE .rodata; /* end of esp32c6 fixups */ /* Shared sections - ordering matters */ -INCLUDE "text.x" INCLUDE "rwtext.x" -INCLUDE "rodata.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "stack.x" INCLUDE "dram2.x" diff --git a/esp-hal/ld/esp32h2/esp32h2.x b/esp-hal/ld/esp32h2/esp32h2.x index 635338e1c24..c262159b2f1 100644 --- a/esp-hal/ld/esp32h2/esp32h2.x +++ b/esp-hal/ld/esp32h2/esp32h2.x @@ -65,10 +65,10 @@ SECTIONS { INSERT BEFORE .rodata; /* Shared sections - ordering matters */ -INCLUDE "text.x" INCLUDE "rwtext.x" -INCLUDE "rodata.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "stack.x" INCLUDE "dram2.x" diff --git a/esp-hal/ld/esp32s2/esp32s2.x b/esp-hal/ld/esp32s2/esp32s2.x index 29602c0695f..d7be0cbcd31 100644 --- a/esp-hal/ld/esp32s2/esp32s2.x +++ b/esp-hal/ld/esp32s2/esp32s2.x @@ -27,10 +27,10 @@ INCLUDE "fixups/rtc_fast_rwdata_dummy.x" /* End of fixups for esp32s2 */ /* Shared sections - ordering matters */ -INCLUDE "text.x" -INCLUDE "rodata.x" INCLUDE "rwtext.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "rtc_slow.x" INCLUDE "stack.x" diff --git a/esp-hal/ld/esp32s3/esp32s3.x b/esp-hal/ld/esp32s3/esp32s3.x index 6f333cc8042..a9f130ee005 100644 --- a/esp-hal/ld/esp32s3/esp32s3.x +++ b/esp-hal/ld/esp32s3/esp32s3.x @@ -41,10 +41,10 @@ INCLUDE "fixups/rodata_dummy.x" /* End of ESP32S3 fixups */ /* Shared sections - ordering matters */ -INCLUDE "text.x" -INCLUDE "rodata.x" INCLUDE "rwtext.x" +INCLUDE "text.x" INCLUDE "rwdata.x" +INCLUDE "rodata.x" INCLUDE "rtc_fast.x" INCLUDE "rtc_slow.x" INCLUDE "stack.x" diff --git a/esp-hal/ld/sections/rwdata.x b/esp-hal/ld/sections/rwdata.x index 590a2eb3ecf..017a25d566c 100644 --- a/esp-hal/ld/sections/rwdata.x +++ b/esp-hal/ld/sections/rwdata.x @@ -5,6 +5,12 @@ SECTIONS { { _data_start = ABSOLUTE(.); . = ALIGN (4); + + #IF ESP_HAL_PLACE_MORE_RODATA_IN_RAM + *(.rodata..Lanon .rodata..Lanon.*) + *(.rodata.cst*) + #ENDIF + *(.sdata .sdata.* .sdata2 .sdata2.*); *(.data .data.*); *(.data1) diff --git a/esp-hal/ld/sections/rwtext.x b/esp-hal/ld/sections/rwtext.x index 64535416ee0..8b33ddfd5f9 100644 --- a/esp-hal/ld/sections/rwtext.x +++ b/esp-hal/ld/sections/rwtext.x @@ -1,9 +1,13 @@ - - SECTIONS { .rwtext : ALIGN(4) { . = ALIGN (4); + #IF ESP_HAL_PLACE_MORE_RODATA_IN_RAM + *(.rodata.*_esp_hal_internal_handler*) + *(.rodata.str.*) + *(.rodata.handle_interrupts) + *(.rodata..Lswitch.table.*) + #ENDIF *(.rwtext.literal .rwtext .rwtext.literal.* .rwtext.*) . = ALIGN(4); } > RWTEXT diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index 39833d38557..a9958525acc 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -91,6 +91,7 @@ pub mod rtc_io; /// Convenience constant for `Option::None` pin +#[ram] static USER_INTERRUPT_HANDLER: CFnPtr = CFnPtr::new(); struct CFnPtr(AtomicPtr<()>); @@ -2475,6 +2476,7 @@ mod asynch { use super::*; + #[ram] pub(super) static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [const { AtomicWaker::new() }; NUM_PINS]; diff --git a/esp-hal/src/interrupt/riscv.rs b/esp-hal/src/interrupt/riscv.rs index f21a44bc07a..3381bd82cf4 100644 --- a/esp-hal/src/interrupt/riscv.rs +++ b/esp-hal/src/interrupt/riscv.rs @@ -168,7 +168,8 @@ impl Priority { } /// The interrupts reserved by the HAL -pub const RESERVED_INTERRUPTS: &[usize] = INTERRUPT_TO_PRIORITY; +#[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] +pub static RESERVED_INTERRUPTS: &[usize] = INTERRUPT_TO_PRIORITY; /// # Safety /// @@ -549,14 +550,18 @@ mod classic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::Cpu; - pub(super) const DISABLED_CPU_INTERRUPT: u32 = 0; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static DISABLED_CPU_INTERRUPT: u32 = 0; - pub(super) const EXTERNAL_INTERRUPT_OFFSET: u32 = 0; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; - pub(super) const PRIORITY_TO_INTERRUPT: &[usize] = + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - pub(super) const INTERRUPT_TO_PRIORITY: &[usize] = + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static INTERRUPT_TO_PRIORITY: &[usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; /// Enable a CPU interrupt @@ -667,17 +672,21 @@ mod plic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::Cpu; - pub(super) const DISABLED_CPU_INTERRUPT: u32 = 31; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static DISABLED_CPU_INTERRUPT: u32 = 31; - pub(super) const EXTERNAL_INTERRUPT_OFFSET: u32 = 0; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; // don't use interrupts reserved for CLIC (0,3,4,7) // for some reason also CPU interrupt 8 doesn't work by default since it's // disabled after reset - so don't use that, too - pub(super) const PRIORITY_TO_INTERRUPT: &[usize] = + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]; - pub(super) const INTERRUPT_TO_PRIORITY: &[usize] = &[ + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub(super) static INTERRUPT_TO_PRIORITY: &[usize] = &[ 1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ]; diff --git a/esp-hal/src/interrupt/xtensa.rs b/esp-hal/src/interrupt/xtensa.rs index 844388baed2..fa388f2e560 100644 --- a/esp-hal/src/interrupt/xtensa.rs +++ b/esp-hal/src/interrupt/xtensa.rs @@ -95,7 +95,8 @@ pub enum CpuInterrupt { } /// The interrupts reserved by the HAL -pub const RESERVED_INTERRUPTS: &[usize] = &[ +#[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] +pub static RESERVED_INTERRUPTS: &[usize] = &[ CpuInterrupt::Interrupt1LevelPriority1 as _, CpuInterrupt::Interrupt19LevelPriority2 as _, CpuInterrupt::Interrupt23LevelPriority3 as _, @@ -447,7 +448,8 @@ mod vectored { } // TODO use CpuInterrupt::LevelX.mask() // TODO make it const - const CPU_INTERRUPT_LEVELS: [u32; 8] = [ + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + static CPU_INTERRUPT_LEVELS: [u32; 8] = [ 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Dummy level 0 0b_0000_0000_0000_0110_0011_0111_1111_1111, // Level_1 0b_0000_0000_0011_1000_0000_0000_0000_0000, // Level 2 @@ -457,8 +459,10 @@ mod vectored { 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Level 6 0b_0000_0000_0000_0000_0100_0000_0000_0000, // Level 7 ]; - const CPU_INTERRUPT_INTERNAL: u32 = 0b_0010_0000_0000_0001_1000_1000_1100_0000; - const CPU_INTERRUPT_EDGE: u32 = 0b_0111_0000_0100_0000_0000_1100_1000_0000; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + static CPU_INTERRUPT_INTERNAL: u32 = 0b_0010_0000_0000_0001_1000_1000_1100_0000; + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + static CPU_INTERRUPT_EDGE: u32 = 0b_0111_0000_0100_0000_0000_1100_1000_0000; #[inline] fn cpu_interrupt_nr_to_cpu_interrupt_handler( @@ -558,7 +562,8 @@ mod vectored { #[cfg(esp32)] mod chip_specific { use super::*; - pub const INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1111_1100_0000_0000_0000_0000_0000_0000, 0b0000_0000_0000_0000_0000_0000_0000_0011, @@ -583,7 +588,8 @@ mod vectored { #[cfg(esp32s2)] mod chip_specific { use super::*; - pub const INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1100_0000_0000_0000_0000_0000_0000_0000, 0b0000_0000_0000_0000_0000_0011_1011_1111, @@ -611,7 +617,8 @@ mod vectored { #[cfg(esp32s3)] mod chip_specific { use super::*; - pub const INTERRUPT_EDGE: InterruptStatus = InterruptStatus::empty(); + #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::empty(); #[inline] pub fn interrupt_is_edge(_interrupt: Interrupt) -> bool { false From dea68f1e56eafe8219b80f6d6fb9128adc370a8e Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Thu, 10 Oct 2024 15:38:48 +0200 Subject: [PATCH 2/6] Make CI green, again --- esp-hal/CHANGELOG.md | 1 + esp-hal/build.rs | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 3fc3ade0391..075fa9cce01 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- A new config option `PLACE_MORE_RODATA_IN_RAM` to improve performance (especially for interrupts) at the cost of RAM usage (#2331) ### Changed diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 3e6a4912943..b9f9466f81a 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -106,11 +106,8 @@ fn main() -> Result<(), Box> { config_symbols.push("flip-link"); for (key, value) in &cfg { - match value { - Value::Bool(true) => { - config_symbols.push(&key); - } - _ => (), + if let Value::Bool(true) = value { + config_symbols.push(key); } } From 511c80359e96dcb90103ce1677ad887993277cdb Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Thu, 10 Oct 2024 17:35:36 +0200 Subject: [PATCH 3/6] Removed unnecessaries --- esp-hal/ld/sections/rwtext.x | 2 -- esp-hal/src/gpio/mod.rs | 1 - 2 files changed, 3 deletions(-) diff --git a/esp-hal/ld/sections/rwtext.x b/esp-hal/ld/sections/rwtext.x index 8b33ddfd5f9..7b1f40eb9ef 100644 --- a/esp-hal/ld/sections/rwtext.x +++ b/esp-hal/ld/sections/rwtext.x @@ -4,8 +4,6 @@ SECTIONS { . = ALIGN (4); #IF ESP_HAL_PLACE_MORE_RODATA_IN_RAM *(.rodata.*_esp_hal_internal_handler*) - *(.rodata.str.*) - *(.rodata.handle_interrupts) *(.rodata..Lswitch.table.*) #ENDIF *(.rwtext.literal .rwtext .rwtext.literal.* .rwtext.*) diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index a9958525acc..89877bee39e 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -91,7 +91,6 @@ pub mod rtc_io; /// Convenience constant for `Option::None` pin -#[ram] static USER_INTERRUPT_HANDLER: CFnPtr = CFnPtr::new(); struct CFnPtr(AtomicPtr<()>); From e7d417ccbbdebec2958b4675ab8ce7fab7909897 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Fri, 11 Oct 2024 10:37:20 +0200 Subject: [PATCH 4/6] Split option into two --- esp-hal/CHANGELOG.md | 3 ++- esp-hal/build.rs | 11 ++++++++--- esp-hal/ld/sections/rwdata.x | 7 +++++-- esp-hal/ld/sections/rwtext.x | 2 +- esp-hal/src/interrupt/riscv.rs | 18 +++++++++--------- esp-hal/src/interrupt/xtensa.rs | 14 +++++++------- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 075fa9cce01..abf44b972d8 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- A new config option `PLACE_MORE_RODATA_IN_RAM` to improve performance (especially for interrupts) at the cost of RAM usage (#2331) +- A new config option `PLACE_SWITCH_TABLES_IN_RAM` to improve performance (especially for interrupts) at the cost of slightly more RAM usage (#2331) +- A new config option `PLACE_ANON_IN_RAM` to improve performance (especially for interrupts) at the cost of RAM usage (#2331) ### Changed diff --git a/esp-hal/build.rs b/esp-hal/build.rs index b9f9466f81a..f6456d942c5 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -89,10 +89,15 @@ fn main() -> Result<(), Box> { "(ESP32 only) Enables a workaround for the issue where SPI in half-duplex mode incorrectly transmits the address on a single line if the data buffer is empty.", ), ( - "place-more-rodata-in-ram", + "place-switch-tables-in-ram", Value::Bool(false), - "Places more data (lookup-tables, switch-tables etc.) into RAM - resulting in better performance (especially for interrupts) but more RAM consumption", - ) + "Places switch-tables, some lookup tables and constants related to interrupt handling into RAM - resulting in better performance but slightly more RAM consumption.", + ), + ( + "place-anon-in-ram", + Value::Bool(false), + "Places anonymous symbols into RAM - resulting in better performance at the cost of significant more RAM consumption. Best to be combined with `place-switch-tables-in-ram`.", + ), ], true, ); diff --git a/esp-hal/ld/sections/rwdata.x b/esp-hal/ld/sections/rwdata.x index 017a25d566c..523515a9b79 100644 --- a/esp-hal/ld/sections/rwdata.x +++ b/esp-hal/ld/sections/rwdata.x @@ -6,11 +6,14 @@ SECTIONS { _data_start = ABSOLUTE(.); . = ALIGN (4); - #IF ESP_HAL_PLACE_MORE_RODATA_IN_RAM - *(.rodata..Lanon .rodata..Lanon.*) + #IF ESP_HAL_PLACE_SWITCH_TABLES_IN_RAM *(.rodata.cst*) #ENDIF + #IF ESP_HAL_PLACE_ANON_IN_RAM + *(.rodata..Lanon .rodata..Lanon.*) + #ENDIF + *(.sdata .sdata.* .sdata2 .sdata2.*); *(.data .data.*); *(.data1) diff --git a/esp-hal/ld/sections/rwtext.x b/esp-hal/ld/sections/rwtext.x index 7b1f40eb9ef..747e65dee99 100644 --- a/esp-hal/ld/sections/rwtext.x +++ b/esp-hal/ld/sections/rwtext.x @@ -2,7 +2,7 @@ SECTIONS { .rwtext : ALIGN(4) { . = ALIGN (4); - #IF ESP_HAL_PLACE_MORE_RODATA_IN_RAM + #IF ESP_HAL_PLACE_SWITCH_TABLES_IN_RAM *(.rodata.*_esp_hal_internal_handler*) *(.rodata..Lswitch.table.*) #ENDIF diff --git a/esp-hal/src/interrupt/riscv.rs b/esp-hal/src/interrupt/riscv.rs index 3381bd82cf4..151fa622471 100644 --- a/esp-hal/src/interrupt/riscv.rs +++ b/esp-hal/src/interrupt/riscv.rs @@ -168,7 +168,7 @@ impl Priority { } /// The interrupts reserved by the HAL -#[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] +#[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub static RESERVED_INTERRUPTS: &[usize] = INTERRUPT_TO_PRIORITY; /// # Safety @@ -550,17 +550,17 @@ mod classic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::Cpu; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static DISABLED_CPU_INTERRUPT: u32 = 0; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static INTERRUPT_TO_PRIORITY: &[usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; @@ -672,20 +672,20 @@ mod plic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::Cpu; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static DISABLED_CPU_INTERRUPT: u32 = 31; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; // don't use interrupts reserved for CLIC (0,3,4,7) // for some reason also CPU interrupt 8 doesn't work by default since it's // disabled after reset - so don't use that, too - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub(super) static INTERRUPT_TO_PRIORITY: &[usize] = &[ 1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ]; diff --git a/esp-hal/src/interrupt/xtensa.rs b/esp-hal/src/interrupt/xtensa.rs index fa388f2e560..5ed4138c440 100644 --- a/esp-hal/src/interrupt/xtensa.rs +++ b/esp-hal/src/interrupt/xtensa.rs @@ -95,7 +95,7 @@ pub enum CpuInterrupt { } /// The interrupts reserved by the HAL -#[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] +#[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub static RESERVED_INTERRUPTS: &[usize] = &[ CpuInterrupt::Interrupt1LevelPriority1 as _, CpuInterrupt::Interrupt19LevelPriority2 as _, @@ -448,7 +448,7 @@ mod vectored { } // TODO use CpuInterrupt::LevelX.mask() // TODO make it const - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] static CPU_INTERRUPT_LEVELS: [u32; 8] = [ 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Dummy level 0 0b_0000_0000_0000_0110_0011_0111_1111_1111, // Level_1 @@ -459,9 +459,9 @@ mod vectored { 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Level 6 0b_0000_0000_0000_0000_0100_0000_0000_0000, // Level 7 ]; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] static CPU_INTERRUPT_INTERNAL: u32 = 0b_0010_0000_0000_0001_1000_1000_1100_0000; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] static CPU_INTERRUPT_EDGE: u32 = 0b_0111_0000_0100_0000_0000_1100_1000_0000; #[inline] @@ -562,7 +562,7 @@ mod vectored { #[cfg(esp32)] mod chip_specific { use super::*; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1111_1100_0000_0000_0000_0000_0000_0000, @@ -588,7 +588,7 @@ mod vectored { #[cfg(esp32s2)] mod chip_specific { use super::*; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1100_0000_0000_0000_0000_0000_0000_0000, @@ -617,7 +617,7 @@ mod vectored { #[cfg(esp32s3)] mod chip_specific { use super::*; - #[cfg_attr(place_more_rodata_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::empty(); #[inline] pub fn interrupt_is_edge(_interrupt: Interrupt) -> bool { From 294eb0608453a3f1707c45d5624af83656a9be3b Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Fri, 11 Oct 2024 11:42:10 +0200 Subject: [PATCH 5/6] Make `place-switch-tables-in-ram` default --- esp-hal/build.rs | 2 +- esp-hal/ld/sections/rwtext.x | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/esp-hal/build.rs b/esp-hal/build.rs index f6456d942c5..c507a97bd13 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -90,7 +90,7 @@ fn main() -> Result<(), Box> { ), ( "place-switch-tables-in-ram", - Value::Bool(false), + Value::Bool(true), "Places switch-tables, some lookup tables and constants related to interrupt handling into RAM - resulting in better performance but slightly more RAM consumption.", ), ( diff --git a/esp-hal/ld/sections/rwtext.x b/esp-hal/ld/sections/rwtext.x index 747e65dee99..a40201fbd2d 100644 --- a/esp-hal/ld/sections/rwtext.x +++ b/esp-hal/ld/sections/rwtext.x @@ -5,7 +5,7 @@ SECTIONS { #IF ESP_HAL_PLACE_SWITCH_TABLES_IN_RAM *(.rodata.*_esp_hal_internal_handler*) *(.rodata..Lswitch.table.*) - #ENDIF + #ENDIF *(.rwtext.literal .rwtext .rwtext.literal.* .rwtext.*) . = ALIGN(4); } > RWTEXT From 0ebe9db2658e87f61d66540e3359e69fa04b71fb Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Fri, 11 Oct 2024 13:42:31 +0200 Subject: [PATCH 6/6] Xtensa --- esp-hal/ld/sections/rwdata.x | 6 ++++-- esp-hal/ld/sections/rwtext.x | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/esp-hal/ld/sections/rwdata.x b/esp-hal/ld/sections/rwdata.x index 523515a9b79..b00f877458d 100644 --- a/esp-hal/ld/sections/rwdata.x +++ b/esp-hal/ld/sections/rwdata.x @@ -7,11 +7,13 @@ SECTIONS { . = ALIGN (4); #IF ESP_HAL_PLACE_SWITCH_TABLES_IN_RAM - *(.rodata.cst*) + *(.rodata.*_esp_hal_internal_handler*) + *(.rodata..Lswitch.table.*) + *(.rodata.cst*) #ENDIF #IF ESP_HAL_PLACE_ANON_IN_RAM - *(.rodata..Lanon .rodata..Lanon.*) + *(.rodata..Lanon .rodata..Lanon.*) #ENDIF *(.sdata .sdata.* .sdata2 .sdata2.*); diff --git a/esp-hal/ld/sections/rwtext.x b/esp-hal/ld/sections/rwtext.x index a40201fbd2d..aca9385b5b0 100644 --- a/esp-hal/ld/sections/rwtext.x +++ b/esp-hal/ld/sections/rwtext.x @@ -2,10 +2,6 @@ SECTIONS { .rwtext : ALIGN(4) { . = ALIGN (4); - #IF ESP_HAL_PLACE_SWITCH_TABLES_IN_RAM - *(.rodata.*_esp_hal_internal_handler*) - *(.rodata..Lswitch.table.*) - #ENDIF *(.rwtext.literal .rwtext .rwtext.literal.* .rwtext.*) . = ALIGN(4); } > RWTEXT