Skip to main content
Knowledgebase
Home
Renesas India - Knowledgebase

How to measure CPU load on an SSP threaded application

Latest Updated:10/04/2016

Overview

Explains how to measure the CPU load on a Threaded SSP design and provides a simple example you can use to create your own measurement routine.

Goal

After completing this how-to you will be able to better understand how to measure the CPU load in your threaded SSP applications.

Prerequisites

You will need to have SSP and e2 studio (or IAR EW for Renesas Synergy) loaded on your computer. You should also have verified the installation is working by running one of the example designs (like Threaded Blinky) on your set-up. You will also need a Synergy kit to download and test the example CPU load design.

Setup

Overview
 
In order to run the example design, connect your kit to your computer and use the example design, attached below, to measure CPU load for the example design. Extensive comments in cpu_load_thread_entry.c describe the details of the algorithm and implementation. A short overview is given below.
 
To measure overall CPU loading a possible way is to have a thread with the lowest priority run for a short period of time without any other threads running incrementing a count variable. At the end of the time the value will be the reference value with no other threads running. Now with all other threads running if the same procedure is carried out the end count value will be lower as the low priority counting thread is blocked by higher priority threads and so can't count as high in the time period allowed. From this the CPU loading can be calculated.
 
If you have a SK-S7G2 Kit you can try out the example design attached below.
 
 
If you don't have the SK-S7G2 you can read over the design description in cpu_load_thread_entry.c and follow the implementation guidelines there (and shown below) to create a design on your own kit.
 
Implementation
 
To use this approach in a Synergy project:

 1.  Add a new thread with the following properties modified:
      Symbol:      cpu_load_counter_thread_entry
      Name:        CPU Load Counter Thread
      Priority:    30 (or another value ensuring it is the lowest priority thread (higher number = lower priority)
      Auto start:  enabled
 
 2.  Add a new thread with the following properties modified:
      Symbol:      cpu_load_thread_entry
      Name:        CPU Load Thread
      Priority:    1 (or another value ensuring it is the highest priority thread (lower number = highest priority)
                   Priority 0 is reserved for ThreadX internal use.
      Auto start:  enabled
 
 3.  Add the contents of the supplied files "cpu_load_counter_thread_entry.c" and "cpu_load_thread_entry.c" to the
      generated equivalents.
 
 4.  Add any other threads to the system as required ensuring their "Auto start" settings is set to "disabled".
 
 5.  Add any threads which would normally auto-start to the g_threadsToResume[] array.
 
 

What's Next

You should now be able to implement this measurement technique in a full application and determine the CPU load for that design.