From 3925e4022bca540716ccefd17bc0e72fffb41b58 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 26 May 2023 20:48:17 +0100 Subject: [PATCH] preempt improvements (#185) * [Xtensa] ensure CPU interrupts are re-enabled Once the scheduler is enabled. * [Xtensa] preempt: reduce from 2000hz -> 1000hz This brings the task switching hz inline with the values for the RISCV chips * reduce preempt hz to 100 (freertos default) * remove WIFI_BB interrupt from esp32_timer * fix typo in timer_esp32s3 --- esp-wifi/src/timer_esp32.rs | 37 +++++++---------------------------- esp-wifi/src/timer_esp32c2.rs | 4 ++-- esp-wifi/src/timer_esp32c3.rs | 4 ++-- esp-wifi/src/timer_esp32c6.rs | 4 ++-- esp-wifi/src/timer_esp32s2.rs | 14 ++++++------- esp-wifi/src/timer_esp32s3.rs | 14 ++++++------- 6 files changed, 27 insertions(+), 50 deletions(-) diff --git a/esp-wifi/src/timer_esp32.rs b/esp-wifi/src/timer_esp32.rs index d47b16db4d4..594e6ab1fb8 100644 --- a/esp-wifi/src/timer_esp32.rs +++ b/esp-wifi/src/timer_esp32.rs @@ -21,9 +21,9 @@ pub const TICKS_PER_SECOND: u64 = 40_000_000; pub const COUNTER_BIT_MASK: u64 = 0xFFFF_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(4000); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(500); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(100); static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); @@ -54,13 +54,6 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { ) .unwrap(); - #[cfg(feature = "wifi")] - interrupt::enable( - peripherals::Interrupt::WIFI_BB, - interrupt::Priority::Priority1, - ) - .unwrap(); - #[cfg(feature = "ble")] { interrupt::enable(peripherals::Interrupt::RWBT, interrupt::Priority::Priority1).unwrap(); @@ -77,7 +70,7 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { } timer1.listen(); - timer1.start(TIMER_DELAY.convert()); + timer1.start(TIMER_DELAY.into_duration()); critical_section::with(|cs| { TIMER1.borrow_ref_mut(cs).replace(timer1); }); @@ -85,12 +78,12 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { xtensa_lx::timer::set_ccompare0(0xffffffff); unsafe { - xtensa_lx::interrupt::disable(); + let enabled = esp32_hal::xtensa_lx::interrupt::disable(); xtensa_lx::interrupt::enable_mask( 1 << 6 // Timer0 | 1 << 29 // Software1 | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level2.mask() - | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask(), + | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask() | enabled, ); } @@ -134,22 +127,6 @@ fn WIFI_MAC() { } } -#[cfg(feature = "wifi")] -#[interrupt] -fn WIFI_BB() { - unsafe { - let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; - trace!("interrupt WIFI_BB {:p} {:p}", fnc, arg); - - if !fnc.is_null() { - let fnc: fn(*mut crate::binary::c_types::c_void) = core::mem::transmute(fnc); - fnc(arg); - } - - trace!("interrupt 1 done"); - }; -} - #[cfg(feature = "ble")] #[interrupt] fn RWBT() { @@ -202,7 +179,7 @@ fn TG1_T0_LEVEL(context: &mut Context) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); } @@ -222,7 +199,7 @@ fn Software1(_level: u32, context: &mut Context) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); } diff --git a/esp-wifi/src/timer_esp32c2.rs b/esp-wifi/src/timer_esp32c2.rs index 410a3dee782..fb76807d924 100644 --- a/esp-wifi/src/timer_esp32c2.rs +++ b/esp-wifi/src/timer_esp32c2.rs @@ -16,9 +16,9 @@ pub const TICKS_PER_SECOND: u64 = 16_000_000; pub const COUNTER_BIT_MASK: u64 = 0x000F_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(500); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(1_000); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(100); static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); diff --git a/esp-wifi/src/timer_esp32c3.rs b/esp-wifi/src/timer_esp32c3.rs index d0e75408ecb..0df12275d24 100644 --- a/esp-wifi/src/timer_esp32c3.rs +++ b/esp-wifi/src/timer_esp32c3.rs @@ -16,9 +16,9 @@ pub const TICKS_PER_SECOND: u64 = 16_000_000; pub const COUNTER_BIT_MASK: u64 = 0x000F_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(500); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(1_000); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(100); static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); diff --git a/esp-wifi/src/timer_esp32c6.rs b/esp-wifi/src/timer_esp32c6.rs index 4a8ebd1d3d2..7ee51d10660 100644 --- a/esp-wifi/src/timer_esp32c6.rs +++ b/esp-wifi/src/timer_esp32c6.rs @@ -16,9 +16,9 @@ pub const TICKS_PER_SECOND: u64 = 16_000_000; pub const COUNTER_BIT_MASK: u64 = 0x000F_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(500); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(1_000); +const TIMER_DELAY: fugit::HertzU32 = fugit::HertzU32::from_raw(100); static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); diff --git a/esp-wifi/src/timer_esp32s2.rs b/esp-wifi/src/timer_esp32s2.rs index cff6173bb17..289fed0d830 100644 --- a/esp-wifi/src/timer_esp32s2.rs +++ b/esp-wifi/src/timer_esp32s2.rs @@ -21,9 +21,9 @@ pub const TICKS_PER_SECOND: u64 = 40_000_000; pub const COUNTER_BIT_MASK: u64 = 0xFFFF_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(4000); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(500); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(100); static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); @@ -62,7 +62,7 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { .unwrap(); timer1.listen(); - timer1.start(TIMER_DELAY.convert()); + timer1.start(TIMER_DELAY.into_duration()); critical_section::with(|cs| { TIMER1.borrow_ref_mut(cs).replace(timer1); }); @@ -70,12 +70,12 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { xtensa_lx::timer::set_ccompare0(0xffffffff); unsafe { - xtensa_lx::interrupt::disable(); + let enabled = esp32s2_hal::xtensa_lx::interrupt::disable(); xtensa_lx::interrupt::enable_mask( 1 << 6 // Timer0 | 1 << 29 // Software1 | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level2.mask() - | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask(), + | xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask() | enabled, ); } @@ -131,7 +131,7 @@ fn TG1_T0_LEVEL(context: &mut Context) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); } @@ -151,7 +151,7 @@ fn Software1(_level: u32, context: &mut Context) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); } diff --git a/esp-wifi/src/timer_esp32s3.rs b/esp-wifi/src/timer_esp32s3.rs index fda1a084aea..8cdb8a4a6aa 100644 --- a/esp-wifi/src/timer_esp32s3.rs +++ b/esp-wifi/src/timer_esp32s3.rs @@ -19,9 +19,9 @@ pub const TICKS_PER_SECOND: u64 = 40_000_000; pub const COUNTER_BIT_MASK: u64 = 0xFFFF_FFFF_FFFF_FFFF; #[cfg(debug_assertions)] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(4000); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(50); #[cfg(not(debug_assertions))] -const TIMER_DELAY: fugit::MicrosDurationU64 = fugit::MicrosDurationU64::micros(500); +const TIMER_DELAY: fugit::HertzU64 = fugit::HertzU64::from_raw(100); static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); @@ -74,7 +74,7 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { } timer1.listen(); - timer1.start(TIMER_DELAY.convert()); + timer1.start(TIMER_DELAY.into_duration()); critical_section::with(|cs| { TIMER1.borrow_ref_mut(cs).replace(timer1); }); @@ -82,12 +82,12 @@ pub fn setup_timer_isr(timg1_timer0: Timer>) { esp32s3_hal::xtensa_lx::timer::set_ccompare0(0xffffffff); unsafe { - esp32s3_hal::xtensa_lx::interrupt::disable(); + let enabled = esp32s3_hal::xtensa_lx::interrupt::disable(); esp32s3_hal::xtensa_lx::interrupt::enable_mask( 1 << 6 // Timer0 | 1 << 29 // Software1 | esp32s3_hal::xtensa_lx_rt::interrupt::CpuInterruptLevel::Level2.mask() - | esp32s3_hal::xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask(), + | esp32s3_hal::xtensa_lx_rt::interrupt::CpuInterruptLevel::Level6.mask() | enabled, ); } @@ -169,7 +169,7 @@ fn TG1_T0_LEVEL(context: &mut TrapFrame) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); } @@ -189,7 +189,7 @@ fn Software1(_level: u32, context: &mut TrapFrame) { let mut timer = TIMER1.borrow_ref_mut(cs); let timer = timer.as_mut().unwrap(); timer.clear_interrupt(); - timer.start(TIMER_DELAY.convert()); + timer.start(TIMER_DELAY.into_duration()); }); }