aboutsummaryrefslogtreecommitdiff
path: root/embassy-executor/src/raw/trace.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-12-09 15:16:03 +0100
committerUlf Lilleengen <[email protected]>2024-12-09 15:16:03 +0100
commitf0be2fdce4856888bd412fe9475ae55e05cf20a2 (patch)
treeae14a1f758a13d4b9d6ea079edeea8f7ce711a6c /embassy-executor/src/raw/trace.rs
parent86578acaa4d4dbed06ed4fcecec25884f6883e82 (diff)
Extend tracing api to support executor id and end task
Allow applications to provide a trace implementation that only needs to implement APIs used by the embassy executor, and provide more context in the event of multiple executors being used.
Diffstat (limited to 'embassy-executor/src/raw/trace.rs')
-rw-r--r--embassy-executor/src/raw/trace.rs90
1 files changed, 90 insertions, 0 deletions
diff --git a/embassy-executor/src/raw/trace.rs b/embassy-executor/src/raw/trace.rs
new file mode 100644
index 000000000..c7bcf9c11
--- /dev/null
+++ b/embassy-executor/src/raw/trace.rs
@@ -0,0 +1,90 @@
1#![allow(unused)]
2use crate::raw::{SyncExecutor, TaskRef};
3
4#[cfg(not(feature = "rtos-trace"))]
5extern "Rust" {
6 fn _embassy_trace_task_new(executor_id: u32, task_id: u32);
7 fn _embassy_trace_task_exec_begin(executor_id: u32, task_id: u32);
8 fn _embassy_trace_task_exec_end(excutor_id: u32, task_id: u32);
9 fn _embassy_trace_task_ready_begin(executor_id: u32, task_id: u32);
10 fn _embassy_trace_executor_idle(executor_id: u32);
11}
12
13#[inline]
14pub(crate) fn task_new(executor: &SyncExecutor, task: &TaskRef) {
15 #[cfg(not(feature = "rtos-trace"))]
16 unsafe {
17 _embassy_trace_task_new(executor as *const _ as u32, task.as_ptr() as u32)
18 }
19
20 #[cfg(feature = "rtos-trace")]
21 rtos_trace::trace::task_new(task.as_ptr() as u32);
22}
23
24#[inline]
25pub(crate) fn task_ready_begin(executor: &SyncExecutor, task: &TaskRef) {
26 #[cfg(not(feature = "rtos-trace"))]
27 unsafe {
28 _embassy_trace_task_ready_begin(executor as *const _ as u32, task.as_ptr() as u32)
29 }
30 #[cfg(feature = "rtos-trace")]
31 rtos_trace::trace::task_ready_begin(task.as_ptr() as u32);
32}
33
34#[inline]
35pub(crate) fn task_exec_begin(executor: &SyncExecutor, task: &TaskRef) {
36 #[cfg(not(feature = "rtos-trace"))]
37 unsafe {
38 _embassy_trace_task_exec_begin(executor as *const _ as u32, task.as_ptr() as u32)
39 }
40 #[cfg(feature = "rtos-trace")]
41 rtos_trace::trace::task_exec_begin(task.as_ptr() as u32);
42}
43
44#[inline]
45pub(crate) fn task_exec_end(executor: &SyncExecutor, task: &TaskRef) {
46 #[cfg(not(feature = "rtos-trace"))]
47 unsafe {
48 _embassy_trace_task_exec_end(executor as *const _ as u32, task.as_ptr() as u32)
49 }
50 #[cfg(feature = "rtos-trace")]
51 rtos_trace::trace::task_exec_end();
52}
53
54#[inline]
55pub(crate) fn executor_idle(executor: &SyncExecutor) {
56 #[cfg(not(feature = "rtos-trace"))]
57 unsafe {
58 _embassy_trace_executor_idle(executor as *const _ as u32)
59 }
60 #[cfg(feature = "rtos-trace")]
61 rtos_trace::trace::system_idle();
62}
63
64#[cfg(all(feature = "rtos-trace", feature = "integrated-timers"))]
65const fn gcd(a: u64, b: u64) -> u64 {
66 if b == 0 {
67 a
68 } else {
69 gcd(b, a % b)
70 }
71}
72
73#[cfg(feature = "rtos-trace")]
74impl rtos_trace::RtosTraceOSCallbacks for crate::raw::SyncExecutor {
75 fn task_list() {
76 // We don't know what tasks exist, so we can't send them.
77 }
78 #[cfg(feature = "integrated-timers")]
79 fn time() -> u64 {
80 const GCD_1M: u64 = gcd(embassy_time_driver::TICK_HZ, 1_000_000);
81 embassy_time_driver::now() * (1_000_000 / GCD_1M) / (embassy_time_driver::TICK_HZ / GCD_1M)
82 }
83 #[cfg(not(feature = "integrated-timers"))]
84 fn time() -> u64 {
85 0
86 }
87}
88
89#[cfg(feature = "rtos-trace")]
90rtos_trace::global_os_callbacks! {SyncExecutor}