Transitioning to ThreadX®: Getting over the Jitters

In the last several posts, we have been exploring common issues that developers encounter when designing an embedded system within an RTOS. In today’s post, we are going to look at a commonly overlooked issue with real-time embedded systems, thread jitter.

Thread jitter should be a topic that every embedded software developer is familiar with even if they are nothing more than a super loop programmer. Thread jitter occurs when there is a variation in the timing at which a periodic thread executes. For example, a system might have a thread that needs to execute every ten milliseconds but occasionally that ten millisecond periodic thread executes at 10.5 milliseconds, or 11 milliseconds. In a system with an RTOS, a ten-millisecond thread should execute every ten milliseconds period. No variation in the time domain which means no jitter.

What is really happening underneath the hood, is that the thread is most likely being delayed by either a higher priority thread that needs access to the CPU or it is being delayed by an interrupt. If thread jitter is occurring in a system, there are several different solutions that developers can employ to resolve the issue.

First, a developer should check to make sure that their RTOS tick-rate is at least twice the frequency of the shortest thread. Personally, I prefer to set the tick rate at five times the slowest periodic thread but this value will vary based on the application and whether the device is battery operated. The jitter could be caused by the scheduler not running frequently enough.

Second, use a trace tool such as TraceX® to figure out what is causing the jitter. The most common causes for thread jitter are

  • Thread is being delayed by a higher priority thread
  • External interrupts are delaying the thread

If the jitter is being caused by a higher priority thread, there are several fixes a developer could employ. A developer could re-examine the priority setting and perform an RMA analysis. Minor adjustments to the priority settings for the systems threads could solve the problem. Alternatively, a developer could investigate ways to decrease the execution times for the higher priority thread such as more compiler optimizations, breaking the thread up into multiple threads and so on.

If the trace tool reveals that interrupts are causing the thread jitter, there are again a few options available to developers to remove the jitter. The interrupt service routine should be examined to see if its execution time can be reduced by breaking the interrupt code into smaller pieces or delegating some of the work to a thread rather than performing it in the interrupt. The only code that should be placed in an interrupt is time-critical code and everything else should be moved to another thread.

The final solution that a developer should investigate is how critical sections are being handled. Sometimes a developer will have a time critical piece of code and decide to disable interrupts or even the RTOS itself! This is generally a bad idea and if any critical sections are being controlled this way, they could be the cause for the thread jitter. In this case, RTOS synchronization tools such as mutexes or semaphores can be used to protect the critical section while leaving the interrupts and RTOS alone.

Jitter is a fairly common problem but often overlooked by developers. Don’t forget to verify that periodic threads are always executing within the expected time frame. If jitter occurs, the solutions that we discussed in this post should resolve the issue.  In the next post, we will examine the an advanced ThreadX technique known as event chaining and close out our series on real-time operating systems.


Until next time,

Live long and profit!



Hot Tip of the Week

Don’t forget to sign up for email notifications when SSP issues and work arounds are published on the Renesas Rulz Technical Bulletin Board System (TBBS). The TBBS is located here. Click on the Join button at the bottom right of the TBBS page to Join the Group. You can then select the Email Digest Option to select email frequency for TBBS post notifications. You can also turn notifications On or Off using the Turn Forum notifications on/off button on the top right of the page.