Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traceSTARTING_SCHEDULER tracing hook. #1082

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

schilkp
Copy link
Contributor

@schilkp schilkp commented Jun 5, 2024

Description

Discussed here: https://forums.freertos.org/t/tracing-improvements/20097

This hook enables tracers to run code on startup after all RTOS resources are created and to detect that the scheduler is starting without relying on traceENTER/traceEXIT macros.

It also provides tracers access to the task handle of all IDLE tasks, allowing them to be identified unambiguously and without relying on INCLUDE_xTaskGetIdleTaskHandle.

Notes:
I had another think about the above discussion regarding a traceTASK_IS_IDLE_TASK and traceTASK_IS_TIMER_TASK hook. I agree that they are probably very specific and maybe not the best solution. Instead I propose a traceSTARTING_SCHEDULER hook that is called just before xPortStartScheduler and exposes the idle task TCBs.

This is probably a much more generic solution. It allows tracers to cleanly detect that the scheduler has started, and gives them an opportunity to inject code after the idle and timer tasks have been created. This allows a tracer to, if they wish, identify those tasks unambiguously.

I opted to expose xIdleTaskHandles as a macro parameter so the tracer does not have rely on "unhygienically" accessing this static variable or on INCLUDE_xTaskGetIdleTaskHandle being enabled.

I am happy for feedback here if you think this is appropriate.

Test Steps

The CMOCK test suite in https://github.com/FreeRTOS/FreeRTOS continues to pass with no regressions, after the fallback tracing hook has also been added to the duplicate FreeRTOS.h header file in that repo used during mock code generation:

diff --git a/FreeRTOS/Test/CMock/tasks/tasks_freertos/FreeRTOS.h b/FreeRTOS/Test/CMock/tasks/tasks_freertos/FreeRTOS.h
index bd7b65c10..1e6b6a72f 100644
--- a/FreeRTOS/Test/CMock/tasks/tasks_freertos/FreeRTOS.h
+++ b/FreeRTOS/Test/CMock/tasks/tasks_freertos/FreeRTOS.h
@@ -565,6 +565,13 @@
     #define traceTASK_SWITCHED_IN()
 #endif
 
+#ifndef traceSTARTING_SCHEDULER
+
+/* Called after all idle tasks and timer task (if enabled) have been created
+ * sucesfully, just before the scheduler is started. */
+    #define traceSTARTING_SCHEDULER( xIdleTaskHandles )
+#endif
+
 #ifndef traceINCREASE_TICK_COUNT
 
 /* Called before stepping the tick count after waking from tickless idle

Please let me know how, if you are looking at merging, how I should go about updating this?

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@schilkp schilkp requested a review from a team as a code owner June 5, 2024 08:39
Discussed here: https://forums.freertos.org/t/tracing-improvements/20097

This hook enables tracers to run code on startup after all RTOS
resources are created and to detect that the scheduler is starting without
relying on traceENTER/traceEXIT macros.

It also provides tracers access to the task handle of all IDLE tasks,
allowing them to be identified unambiguously and without relying on
INCLUDE_xTaskGetIdleTaskHandle.
@schilkp schilkp force-pushed the schilkp/sched_started_tracing_hook branch from db66f8f to df0b764 Compare June 5, 2024 21:20
@schilkp
Copy link
Contributor Author

schilkp commented Jun 5, 2024

Fixed spelling error. CMock tests continue to fail due to missing fallback macro in FreeRTOS.h in "FreeRTOS" repo as described above.

@shubnil
Copy link
Member

shubnil commented Jun 6, 2024

Hi @schilkp , Thanks for creating the PR. Please fix the spell check errors. After that we can merge the PR.

@schilkp
Copy link
Contributor Author

schilkp commented Jun 6, 2024

Hi @shubnil!

Thanks for the review. Sure - It seems I still can't get that word correct after 2 tries :)

In general, what is the preferred workflow here? Do you want to me to force-push a fixed version (including possibly a re-base) or stack a commit?

@shubnil
Copy link
Member

shubnil commented Jun 7, 2024

You can abandon this PR and create a new one with the fix.

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@aggarg aggarg merged commit e64d1e0 into FreeRTOS:main Jun 10, 2024
16 checks passed
AhmedIsmail02 pushed a commit to AhmedIsmail02/FreeRTOS-Kernel that referenced this pull request Jun 12, 2024
* Add traceSTARTING_SCHEDULER tracing hook.

Discussed here: https://forums.freertos.org/t/tracing-improvements/20097

This hook enables tracers to run code on startup after all RTOS
resources are created and to detect that the scheduler is starting without
relying on traceENTER/traceEXIT macros.

It also provides tracers access to the task handle of all IDLE tasks,
allowing them to be identified unambiguously and without relying on
INCLUDE_xTaskGetIdleTaskHandle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants