Skip to content

Commit

Permalink
Restore multiple-integrated timer queues (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored Feb 28, 2025
1 parent fc2a656 commit c8822b4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
2 changes: 2 additions & 0 deletions esp-hal-embassy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Re-added the `multiple-integrated` timer queue flavour (#3166)

### Changed

### Fixed
Expand Down
14 changes: 6 additions & 8 deletions esp-hal-embassy/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fn main() -> Result<(), Box<dyn StdError>> {
),
(
"timer-queue",
//"<p>The flavour of the timer queue provided by this crate. Accepts one of `single-integrated`, `multiple-integrated` or `generic`. Integrated queues require the `executors` feature to be enabled.</p><p>If you use embassy-executor, the `single-integrated` queue is recommended for ease of use, while the `multiple-integrated` queue is recommended for performance. The `multiple-integrated` option needs one timer per executor.</p><p>The `generic` queue allows using embassy-time without the embassy executors.</p>",
"<p>The flavour of the timer queue provided by this crate. Accepts either `single-integrated` or `generic`. Integrated queues require the `executors` feature to be enabled.</p><p>If you use embassy-executor, the `single-integrated` queue is recommended.</p><p>The `generic` queue allows using embassy-time without the embassy executors.</p>",
"<p>The flavour of the timer queue provided by this crate. Accepts one of `single-integrated`, `multiple-integrated` or `generic`. Integrated queues require the `executors` feature to be enabled.</p><p>If you use embassy-executor, the `single-integrated` queue is recommended for ease of use, while the `multiple-integrated` queue is recommended for performance. The `multiple-integrated` option needs one timer per executor.</p><p>The `generic` queue allows using embassy-time without the embassy executors.</p>",
Value::String(if cfg!(feature = "executors") {
String::from("single-integrated")
} else {
Expand All @@ -70,10 +69,9 @@ fn main() -> Result<(), Box<dyn StdError>> {

match string.as_str() {
"single-integrated" => Ok(()), // preferred for ease of use
//"multiple-integrated" => Ok(()), // preferred for performance
"multiple-integrated" => Ok(()), // preferred for performance
"generic" => Ok(()), // allows using embassy-time without the embassy executors
//_ => Err(Error::Validation(format!("Expected 'single-integrated', 'multiple-integrated' or 'generic', found {string}")))
_ => Err(Error::Validation(format!("Expected 'single-integrated' or 'generic', found {string}")))
_ => Err(Error::Validation(format!("Expected 'single-integrated', 'multiple-integrated' or 'generic', found {string}")))
}
})))
),
Expand All @@ -96,9 +94,9 @@ fn main() -> Result<(), Box<dyn StdError>> {
println!("cargo:rustc-cfg=integrated_timers");
println!("cargo:rustc-cfg=single_queue");
}
// Value::String(s) if s.as_str() == "multiple-integrated" => {
// println!("cargo:rustc-cfg=integrated_timers");
//}
Value::String(s) if s.as_str() == "multiple-integrated" => {
println!("cargo:rustc-cfg=integrated_timers");
}
Value::String(s) if s.as_str() == "generic" => {
println!("cargo:rustc-cfg=generic_timers");
println!("cargo:rustc-cfg=single_queue");
Expand Down
18 changes: 9 additions & 9 deletions esp-hal-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
//!
//! Initialization requires a number of timers to be passed in. The number of
//! timers required depends on the timer queue flavour used, as well as the
//! number of executors started.
// TODO restore this:
// If you use the `multiple-integrated` timer
// queue flavour, then you need to pass as many timers as you start executors.
// In other cases, you can pass a single timer.
//! number of executors started. If you use the `multiple-integrated` timer
//! queue flavour, then you need to pass as many timers as you start executors.
//! In other cases, you can pass a single timer.
//!
//! ## Configuration
//!
//! You can configure the behaviour of the embassy runtime by using the
Expand Down Expand Up @@ -156,10 +155,11 @@ impl_array!(4);
/// - A mutable static slice of `OneShotTimer` instances
/// - A mutable static array of `OneShotTimer` instances
/// - A 2, 3, 4 element array of `AnyTimer` instances
// TODO: restore this:
// /// Note that if you use the `multiple-integrated` timer-queue flavour, then
// /// you need to pass as many timers as you start executors. In other cases,
// /// you can pass a single timer.
///
/// Note that if you use the `multiple-integrated` timer-queue flavour, then
/// you need to pass as many timers as you start executors. In other cases,
/// you can pass a single timer.
///
/// # Examples
///
/// ```rust, no_run
Expand Down
13 changes: 6 additions & 7 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,19 @@ impl Alarm {
/// as well as to schedule a wake-up at a certain time.
///
/// We are free to choose how we implement these features, and we provide
/// two options:
/// three options:
///
/// - If the `generic` feature is enabled, we implement a single timer queue,
/// using the implementation provided by embassy-time-queue-driver.
/// - If the `single-integrated` feature is enabled, we implement a single timer
/// queue, using our own integrated timer implementation. Our implementation
/// is a copy of the embassy integrated timer queue, with the addition of
/// clearing the "owner" information upon dequeueing.
// TODO: restore this and update the "two options" above:
// - If the `multiple-integrated` feature is enabled, we provide a separate
// timer queue for each executor. We store a separate timer queue for each
// executor, and we use the scheduled task's owner to determine which queue to
// use. This mode allows us to use less disruptive locks around the timer
// queue, but requires more timers - one per timer queue.
/// - If the `multiple-integrated` feature is enabled, we provide a separate
/// timer queue for each executor. We store a separate timer queue for each
/// executor, and we use the scheduled task's owner to determine which queue
/// to use. This mode allows us to use less disruptive locks around the timer
/// queue, but requires more timers - one per timer queue.
pub(super) struct EmbassyTimer {
/// The timer queue, if we use a single one (single-integrated, or generic).
#[cfg(single_queue)]
Expand Down
4 changes: 1 addition & 3 deletions hil-test/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ rustflags = [

[env]
DEFMT_LOG = "info"
# TODO restore multiple-integrated
#ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="multiple-integrated"
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="single-integrated"
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="multiple-integrated"

[unstable]
build-std = ["core", "alloc"]
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/embassy_interrupt_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable embassy
//% ENV(single_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = single-integrated
// TODO restore multiple-integrated
// ENV(multiple_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = multiple-integrated
//% ENV(multiple_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = multiple-integrated
//% ENV(generic_queue): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = generic
//% ENV(generic_queue): ESP_HAL_EMBASSY_CONFIG_GENERIC_QUEUE_SIZE = 16
//% ENV(default_with_waiti): ESP_HAL_EMBASSY_CONFIG_LOW_POWER_WAIT = true
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/embassy_interrupt_spi_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//% CHIPS: esp32 esp32s2 esp32s3 esp32c3 esp32c6 esp32h2
//% FEATURES: unstable embassy
//% ENV(single_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = single-integrated
// TODO restore multiple-integrated
// ENV(multiple_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = multiple-integrated
//% ENV(multiple_integrated): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = multiple-integrated
//% ENV(generic_queue): ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE = generic
//% ENV(generic_queue): ESP_HAL_EMBASSY_CONFIG_GENERIC_QUEUE_SIZE = 16

Expand Down
4 changes: 1 addition & 3 deletions qa-test/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ rustflags = [

[env]
ESP_LOG = "info"
# TODO restore multiple-integrated
#ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="multiple-integrated"
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="single-integrated"
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="multiple-integrated"

[unstable]
build-std = ["alloc", "core"]

0 comments on commit c8822b4

Please sign in to comment.