diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-07-09 01:18:04 +0200 |
|---|---|---|
| committer | diondokter <[email protected]> | 2025-08-29 13:22:59 +0200 |
| commit | da9cdf0c536ec4fa7bdfb649750c44f70ef1cd55 (patch) | |
| tree | a080b8663037d8d4af8fc3998360faa80c45fb02 /embassy-executor/src/raw | |
| parent | 2ba34ce2178d576f339f0b0dac70ac125f81cc5b (diff) | |
executor: add "task metadata" concept, make name a task metadata.
Diffstat (limited to 'embassy-executor/src/raw')
| -rw-r--r-- | embassy-executor/src/raw/mod.rs | 14 | ||||
| -rw-r--r-- | embassy-executor/src/raw/trace.rs | 29 |
2 files changed, 11 insertions, 32 deletions
diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 87328df5a..a7e65360d 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs | |||
| @@ -41,6 +41,7 @@ use self::state::State; | |||
| 41 | use self::util::{SyncUnsafeCell, UninitCell}; | 41 | use self::util::{SyncUnsafeCell, UninitCell}; |
| 42 | pub use self::waker::task_from_waker; | 42 | pub use self::waker::task_from_waker; |
| 43 | use super::SpawnToken; | 43 | use super::SpawnToken; |
| 44 | use crate::Metadata; | ||
| 44 | 45 | ||
| 45 | #[no_mangle] | 46 | #[no_mangle] |
| 46 | extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem { | 47 | extern "Rust" fn __embassy_time_queue_item_from_waker(waker: &Waker) -> &'static mut TimerQueueItem { |
| @@ -94,8 +95,9 @@ pub(crate) struct TaskHeader { | |||
| 94 | 95 | ||
| 95 | /// Integrated timer queue storage. This field should not be accessed outside of the timer queue. | 96 | /// Integrated timer queue storage. This field should not be accessed outside of the timer queue. |
| 96 | pub(crate) timer_queue_item: TimerQueueItem, | 97 | pub(crate) timer_queue_item: TimerQueueItem, |
| 97 | #[cfg(feature = "_any_trace")] | 98 | |
| 98 | pub(crate) name: Option<&'static str>, | 99 | pub(crate) metadata: Metadata, |
| 100 | |||
| 99 | #[cfg(feature = "rtos-trace")] | 101 | #[cfg(feature = "rtos-trace")] |
| 100 | all_tasks_next: AtomicPtr<TaskHeader>, | 102 | all_tasks_next: AtomicPtr<TaskHeader>, |
| 101 | } | 103 | } |
| @@ -127,6 +129,10 @@ impl TaskRef { | |||
| 127 | unsafe { self.ptr.as_ref() } | 129 | unsafe { self.ptr.as_ref() } |
| 128 | } | 130 | } |
| 129 | 131 | ||
| 132 | pub(crate) fn metadata(self) -> &'static Metadata { | ||
| 133 | unsafe { &self.ptr.as_ref().metadata } | ||
| 134 | } | ||
| 135 | |||
| 130 | /// Returns a reference to the executor that the task is currently running on. | 136 | /// Returns a reference to the executor that the task is currently running on. |
| 131 | pub unsafe fn executor(self) -> Option<&'static Executor> { | 137 | pub unsafe fn executor(self) -> Option<&'static Executor> { |
| 132 | let executor = self.header().executor.load(Ordering::Relaxed); | 138 | let executor = self.header().executor.load(Ordering::Relaxed); |
| @@ -193,8 +199,7 @@ impl<F: Future + 'static> TaskStorage<F> { | |||
| 193 | poll_fn: SyncUnsafeCell::new(None), | 199 | poll_fn: SyncUnsafeCell::new(None), |
| 194 | 200 | ||
| 195 | timer_queue_item: TimerQueueItem::new(), | 201 | timer_queue_item: TimerQueueItem::new(), |
| 196 | #[cfg(feature = "_any_trace")] | 202 | metadata: Metadata::new(), |
| 197 | name: None, | ||
| 198 | #[cfg(feature = "rtos-trace")] | 203 | #[cfg(feature = "rtos-trace")] |
| 199 | all_tasks_next: AtomicPtr::new(core::ptr::null_mut()), | 204 | all_tasks_next: AtomicPtr::new(core::ptr::null_mut()), |
| 200 | }, | 205 | }, |
| @@ -281,6 +286,7 @@ impl<F: Future + 'static> AvailableTask<F> { | |||
| 281 | 286 | ||
| 282 | fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> { | 287 | fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> { |
| 283 | unsafe { | 288 | unsafe { |
| 289 | self.task.raw.metadata.reset(); | ||
| 284 | self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll)); | 290 | self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll)); |
| 285 | self.task.future.write_in_place(future); | 291 | self.task.future.write_in_place(future); |
| 286 | 292 | ||
diff --git a/embassy-executor/src/raw/trace.rs b/embassy-executor/src/raw/trace.rs index 636608d02..ab0c1b8b6 100644 --- a/embassy-executor/src/raw/trace.rs +++ b/embassy-executor/src/raw/trace.rs | |||
| @@ -168,32 +168,6 @@ impl TaskTracker { | |||
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | /// Extension trait for `TaskRef` that provides tracing functionality. | ||
| 172 | /// | ||
| 173 | /// This trait is only available when the `trace` feature is enabled. | ||
| 174 | /// It extends `TaskRef` with methods for accessing and modifying task identifiers | ||
| 175 | /// and names, which are useful for debugging, logging, and performance analysis. | ||
| 176 | pub trait TaskRefTrace { | ||
| 177 | /// Get the name for a task | ||
| 178 | fn name(&self) -> Option<&'static str>; | ||
| 179 | |||
| 180 | /// Set the name for a task | ||
| 181 | fn set_name(&self, name: Option<&'static str>); | ||
| 182 | } | ||
| 183 | |||
| 184 | impl TaskRefTrace for TaskRef { | ||
| 185 | fn name(&self) -> Option<&'static str> { | ||
| 186 | self.header().name | ||
| 187 | } | ||
| 188 | |||
| 189 | fn set_name(&self, name: Option<&'static str>) { | ||
| 190 | unsafe { | ||
| 191 | let header_ptr = self.ptr.as_ptr() as *mut TaskHeader; | ||
| 192 | (*header_ptr).name = name; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | #[cfg(feature = "trace")] | 171 | #[cfg(feature = "trace")] |
| 198 | extern "Rust" { | 172 | extern "Rust" { |
| 199 | /// This callback is called when the executor begins polling. This will always | 173 | /// This callback is called when the executor begins polling. This will always |
| @@ -383,9 +357,8 @@ where | |||
| 383 | impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor { | 357 | impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor { |
| 384 | fn task_list() { | 358 | fn task_list() { |
| 385 | with_all_active_tasks(|task| { | 359 | with_all_active_tasks(|task| { |
| 386 | let name = task.name().unwrap_or("unnamed task\0"); | ||
| 387 | let info = rtos_trace::TaskInfo { | 360 | let info = rtos_trace::TaskInfo { |
| 388 | name, | 361 | name: task.metadata().name().unwrap_or("unnamed task\0"), |
| 389 | priority: 0, | 362 | priority: 0, |
| 390 | stack_base: 0, | 363 | stack_base: 0, |
| 391 | stack_size: 0, | 364 | stack_size: 0, |
