Challenge - 5 Problems
Trace Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a Trace Hook Callback
Consider a FreeRTOS trace hook function that logs task switches. What will be the output when the following trace hook is called during a context switch from TaskA to TaskB?
FreeRTOS
void traceTASK_SWITCHED_IN(void) {
static char *lastTask = NULL;
char *currentTask = pcTaskGetName(NULL);
if (lastTask != currentTask) {
printf("Switching from %s to %s\n", lastTask ? lastTask : "None", currentTask);
lastTask = currentTask;
}
}
// Assume TaskA runs first, then TaskB is switched in.Attempts:
2 left
💡 Hint
Remember that the static variable retains its value between calls.
✗ Incorrect
The first time the hook runs, lastTask is NULL, so it prints switching from None to TaskA. Then lastTask is set to TaskA. When TaskB is switched in, the hook detects the change and prints switching from TaskA to TaskB.
🧠 Conceptual
intermediate1:30remaining
Purpose of Trace Hooks in FreeRTOS
What is the main purpose of using trace hooks in FreeRTOS?
Attempts:
2 left
💡 Hint
Think about what trace hooks help you observe.
✗ Incorrect
Trace hooks allow developers to monitor kernel events like task switches, queue operations, and interrupts for debugging and performance analysis.
🔧 Debug
advanced2:30remaining
Debugging a Trace Hook Causing System Crash
A developer added a trace hook to log task names on every context switch. After adding it, the system crashes intermittently. Which of the following is the most likely cause?
Attempts:
2 left
💡 Hint
Consider what functions are safe to call inside interrupt or trace hooks.
✗ Incorrect
printf is not thread-safe and can cause reentrancy problems when called inside trace hooks that run in critical sections or interrupts, leading to crashes.
🚀 Application
advanced3:00remaining
Using FreeRTOS+Trace to Analyze Task Behavior
You want to analyze task execution times using FreeRTOS+Trace. Which of the following steps is NOT required to correctly collect trace data?
Attempts:
2 left
💡 Hint
Think about how trace hooks are integrated with the kernel.
✗ Incorrect
traceTASK_SWITCHED_IN() is a trace hook macro called automatically by the kernel during context switches; manually calling it in application code is unnecessary and incorrect.
❓ Predict Output
expert3:00remaining
Output of Custom Trace Hook with Task Priorities
Given the following trace hook code that logs the priority of the task being switched in, what will be the output if Task1 (priority 3) is switched in, then Task2 (priority 5) is switched in?
FreeRTOS
void traceTASK_SWITCHED_IN(void) {
TaskHandle_t current = xTaskGetCurrentTaskHandle();
UBaseType_t priority = uxTaskPriorityGet(current);
printf("Task switched in: %s with priority %u\n", pcTaskGetName(current), (unsigned int)priority);
}
// Assume Task1 runs first, then Task2 is switched in.Attempts:
2 left
💡 Hint
The hook runs every time a task is switched in, printing its name and priority.
✗ Incorrect
The hook prints the current task's name and priority each time it runs. Since Task1 runs first, it prints its info, then when Task2 switches in, it prints Task2's info.