Make integrated-timers the default, remove Cargo feature.

This commit is contained in:
Dario Nieuwenhuis
2024-12-09 00:28:14 +01:00
committed by Dániel Buga
parent b268b1795f
commit 2f2e2c6031
70 changed files with 96 additions and 142 deletions

View File

@@ -35,7 +35,6 @@ rtos-trace = { version = "0.1.3", optional = true }
embassy-executor-macros = { version = "0.6.2", path = "../embassy-executor-macros" }
embassy-time-driver = { version = "0.1.0", path = "../embassy-time-driver", optional = true }
embassy-time-queue-driver = { version = "0.1.0", path = "../embassy-time-queue-driver", optional = true }
critical-section = "1.1"
document-features = "0.2.7"
@@ -67,9 +66,6 @@ nightly = ["embassy-executor-macros/nightly"]
# See: https://github.com/embassy-rs/embassy/pull/1263
turbowakers = []
## Use the executor-integrated `embassy-time` timer queue.
integrated-timers = ["dep:embassy-time-driver"]
#! ### Architecture
_arch = [] # some arch was picked
## std
@@ -94,7 +90,7 @@ executor-interrupt = []
## Enable tracing support (adds some overhead)
trace = []
## Enable support for rtos-trace framework
rtos-trace = ["dep:rtos-trace", "trace"]
rtos-trace = ["dep:rtos-trace", "trace", "dep:embassy-time-driver"]
#! ### Task Arena Size
#! Sets the [task arena](#task-arena) size. Necessary if youre not using `nightly`.

View File

@@ -16,7 +16,6 @@ mod run_queue;
#[cfg_attr(not(target_has_atomic = "8"), path = "state_critical_section.rs")]
mod state;
#[cfg(feature = "integrated-timers")]
pub mod timer_queue;
#[cfg(feature = "trace")]
mod trace;
@@ -45,7 +44,6 @@ pub(crate) struct TaskHeader {
poll_fn: SyncUnsafeCell<Option<unsafe fn(TaskRef)>>,
/// Integrated timer queue storage. This field should not be accessed outside of the timer queue.
#[cfg(feature = "integrated-timers")]
pub(crate) timer_queue_item: timer_queue::TimerQueueItem,
}
@@ -87,13 +85,11 @@ impl TaskRef {
}
/// Returns a reference to the executor that the task is currently running on.
#[cfg(feature = "integrated-timers")]
pub unsafe fn executor(self) -> Option<&'static Executor> {
self.header().executor.get().map(|e| Executor::wrap(e))
}
/// Returns a reference to the timer queue item.
#[cfg(feature = "integrated-timers")]
pub fn timer_queue_item(&self) -> &'static timer_queue::TimerQueueItem {
&self.header().timer_queue_item
}
@@ -106,7 +102,6 @@ impl TaskRef {
///
/// This functions should only be called by the timer queue implementation, before
/// enqueueing the timer item.
#[cfg(feature = "integrated-timers")]
pub unsafe fn timer_enqueue(&self) -> timer_queue::TimerEnqueueOperation {
self.header().state.timer_enqueue()
}
@@ -117,7 +112,6 @@ impl TaskRef {
///
/// This functions should only be called by the timer queue implementation, after the task has
/// been removed from the timer queue.
#[cfg(feature = "integrated-timers")]
pub unsafe fn timer_dequeue(&self) {
self.header().state.timer_dequeue()
}
@@ -162,7 +156,6 @@ impl<F: Future + 'static> TaskStorage<F> {
// Note: this is lazily initialized so that a static `TaskStorage` will go in `.bss`
poll_fn: SyncUnsafeCell::new(None),
#[cfg(feature = "integrated-timers")]
timer_queue_item: timer_queue::TimerQueueItem::new(),
},
future: UninitCell::uninit(),

View File

@@ -1,6 +1,5 @@
use core::sync::atomic::{AtomicU32, Ordering};
#[cfg(feature = "integrated-timers")]
use super::timer_queue::TimerEnqueueOperation;
/// Task is spawned (has a future)
@@ -8,7 +7,6 @@ pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
/// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
/// Task is in the executor timer queue
#[cfg(feature = "integrated-timers")]
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
pub(crate) struct State {
@@ -60,7 +58,6 @@ impl State {
}
/// Mark the task as timer-queued. Return whether it can be enqueued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
if self
@@ -83,7 +80,6 @@ impl State {
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.state.fetch_and(!STATE_TIMER_QUEUED, Ordering::Relaxed);

View File

@@ -1,13 +1,11 @@
use core::arch::asm;
use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering};
#[cfg(feature = "integrated-timers")]
use super::timer_queue::TimerEnqueueOperation;
// Must be kept in sync with the layout of `State`!
pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 8;
#[cfg(feature = "integrated-timers")]
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 16;
#[repr(C, align(4))]
@@ -93,7 +91,6 @@ impl State {
}
/// Mark the task as timer-queued. Return whether it can be enqueued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
if self
@@ -116,7 +113,6 @@ impl State {
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.timer_queued.store(false, Ordering::Relaxed);

View File

@@ -2,7 +2,6 @@ use core::cell::Cell;
use critical_section::Mutex;
#[cfg(feature = "integrated-timers")]
use super::timer_queue::TimerEnqueueOperation;
/// Task is spawned (has a future)
@@ -10,7 +9,6 @@ pub(crate) const STATE_SPAWNED: u32 = 1 << 0;
/// Task is in the executor run queue
pub(crate) const STATE_RUN_QUEUED: u32 = 1 << 1;
/// Task is in the executor timer queue
#[cfg(feature = "integrated-timers")]
pub(crate) const STATE_TIMER_QUEUED: u32 = 1 << 2;
pub(crate) struct State {
@@ -77,7 +75,6 @@ impl State {
}
/// Mark the task as timer-queued. Return whether it can be enqueued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_enqueue(&self) -> TimerEnqueueOperation {
self.update(|s| {
@@ -93,7 +90,6 @@ impl State {
}
/// Unmark the task as timer-queued.
#[cfg(feature = "integrated-timers")]
#[inline(always)]
pub fn timer_dequeue(&self) {
self.update(|s| *s &= !STATE_TIMER_QUEUED);

View File

@@ -61,29 +61,23 @@ pub(crate) fn executor_idle(executor: &SyncExecutor) {
rtos_trace::trace::system_idle();
}
#[cfg(all(feature = "rtos-trace", feature = "integrated-timers"))]
const fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
a
} else {
gcd(b, a % b)
}
}
#[cfg(feature = "rtos-trace")]
impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor {
fn task_list() {
// We don't know what tasks exist, so we can't send them.
}
#[cfg(feature = "integrated-timers")]
fn time() -> u64 {
const fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
a
} else {
gcd(b, a % b)
}
}
const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000);
embassy_time_driver::now() * (1_000_000 / GCD_1M) / (embassy_time_driver::TICK_HZ / GCD_1M)
}
#[cfg(not(feature = "integrated-timers"))]
fn time() -> u64 {
0
}
}
#[cfg(feature = "rtos-trace")]