Difference between revisions of "OCEOS/oceos profiling"

From wiki
Jump to navigation Jump to search
Line 36: Line 36:
==<span style="color:#0000ff">Configuration</span>==
==<span style="color:#0000ff">Configuration</span>==
<blockquote>
<blockquote>
User must define CS_LOG_DEF_ENTRIES_BASE2 and value 0 if Context switch logging is disabled or  
User must define CS_LOG_DEF_ENTRIES_BASE2 and value 0 if Context switch logging is disabled or in the range 3 to 12 if context switch has to be enabled.
<syntaxhighlight lang="C">
<syntaxhighlight lang="C">
     #define NUMBER_OF_DATAQS 2
     #define CS_LOG_DEF_ENTRIES_BASE2  3
...
     /*
     /*
     * Create the application configuration structure
     * Create the application configuration structure
     */
     */
     struct application_configuration          app_config = {0};
     struct application_configuration          app_config = {0};
     app_config.number_of_data_queues        = NUMBER_OF_DATAQS;
     app_config.CS_log_entries_base2          = CS_LOG_DEF_ENTRIES_BASE2;
</syntaxhighlight>
</syntaxhighlight>
</blockquote>
</blockquote>
<blockquote>
User must add extra space to log data area to accommodate context switch logging. Please read more [[OCEOS/oceos_logging#Logging_Configuration|HERE]].
Defined parameter LOG_DATA_ARRAY_SIZE_U32S must be big enough to hold context switch logging data.
<syntaxhighlight lang="C">
#define LOG_DATA_ARRAY_SIZE_U32S                0x100 // Log Area plus Context switch Area, if context switch is enabled
U32_t log_data[LOG_DATA_ARRAY_SIZE_U32S];
...
/*
* Create the application configuration structure
*/
struct application_configuration          app_config = {0};
app_config.log_address                  = (adrs_t)log_data;
</syntaxhighlight>
</blockquote>
===== <span style="color:#0000ff">ARM Context Logging Configuration</span> =====
<blockquote>
For ARM Cortex-M microcontrollers user must include in each implemented IRQ Handler OCEOS at the start and at the end
<syntaxhighlight lang="C">


</syntaxhighlight>
</blockquote>
==<span style="color:#0000ff">DMON Commands</span>==
==<span style="color:#0000ff">DMON Commands</span>==
===<span style="color:#1b7ac2">oceos profile <status|enable|disable></span>===
===<span style="color:#1b7ac2">oceos profile <status|enable|disable></span>===

Revision as of 09:27, 30 March 2022

OCEOS Profiling

Introduction

Each time a context switch or interrupt occurs, four 32-bit words are added to the context switch log if enabled:

1. The first of these describes the type of switch and also gives the current window pointer (CWP) and the low 8 bits of the high 32 bits of the 64-bit system time when the switch occurred.

Switch information:
8 bits high time bits (31 to 24)
5 bits CWP (23 to 19)
1 bit (18) switch type, 0=> starting, 1 => interrupt or ending
1 bit (17) ‘from’ ID type, 0=> from task, 1 => from interrupt
1 bit (16) ‘to’ ID type, 0 => to task, 1 => to interrupt
8 bits (15 to 8) ID of task/interrupt from which switching
8 bits (7 to 0) ID of task/interrupt to which switching
TASK_ID_INVALID (0xff) is used to indicate switching to or from the scheduler itself. The interrupt ID 0 is not expected to occur, used as TO when CPU put to sleep Initialised by oceos_start() to 0x0000ffff (invalid as scheduler 
doesn’t switch to itself).

2. The second gives the 32-bit system time in microseconds at which the switch occurred.

Context switch time word

3. The third gives the start delay if a task is being started, otherwise a signed int giving the remaining time until the deadline or INT_MAX if the task has no deadline, a negative value gives by how much the deadline has been missed.

Low 32 bits of the time at which switch happened. The next 8 bits of the 64-bit system time are given in the switch information word, giving an overall 40-bit time value. Initialised to 0.
Start wait time / deadline time margin word.
When first starting a task, the delay between the start request and execution beginning. Otherwise a signed int giving remaining time until deadline or 0x7fffffff if no deadline. Initialised to 0.

4 The fourth gives the current system stack pointer.

System stack pointer when switch was made. Initialized to 0.

The user specifies the number of entries in the context switch log in the application configuration. This size is given as a number in the range 3 to 12, resulting in from 2^3 to 2^12 entries. If a size outside this range is specified no context switch log is present (no header and no entries).

If valid, the size is stored in sysMetaPtr->CS_log_entries_base2. If invalid this holds 0, CS logging is off.

Stored in log area immediately after last system log entry and before END_SENTINEL for log area.

Space needed for CS log is included in log area size recorded at the start of the log area.

Number of CS log entries is 2^size unless size is invalid, in which case no storage is used.

If sysMetaPtr->CS_log_entries_base2 is outside the allowed range (typically 0) no context switch logging is done. The CS header is not present, END_SENTINEL is at that position instead.

Configuration

User must define CS_LOG_DEF_ENTRIES_BASE2 and value 0 if Context switch logging is disabled or in the range 3 to 12 if context switch has to be enabled.

    #define CS_LOG_DEF_ENTRIES_BASE2  3
...
    /*
     * Create the application configuration structure
     */
    struct application_configuration           app_config = {0};
    app_config.CS_log_entries_base2          = CS_LOG_DEF_ENTRIES_BASE2;

User must add extra space to log data area to accommodate context switch logging. Please read more HERE. Defined parameter LOG_DATA_ARRAY_SIZE_U32S must be big enough to hold context switch logging data.

#define LOG_DATA_ARRAY_SIZE_U32S                0x100 // Log Area plus Context switch Area, if context switch is enabled
U32_t log_data[LOG_DATA_ARRAY_SIZE_U32S];
...
/*
 * Create the application configuration structure
 */
struct application_configuration           app_config = {0};
app_config.log_address                   = (adrs_t)log_data;
ARM Context Logging Configuration

For ARM Cortex-M microcontrollers user must include in each implemented IRQ Handler OCEOS at the start and at the end

DMON Commands

oceos profile <status|enable|disable>

oceos profile displays context switch logging information. This functionality can be enabled/disabled or show current status of the command. Context switch logging should be enabled in OCEOS before this command can be used. More information about context switch logging can be found here.

This command can be used only when DMON starts with -gui switch and executable with OCEOS loaded to the target. This view can be displayed in separate window.

CPU Profile View ZOOM


The table below shows all the entries read from the target (system log messages, user log messages, context switching from context to context). DMON reads log area and context switch log area and presents in readable form. Available information for each log entry depends on log type. Log types:

  • System log entry
Displays log error type and extra log information
  • User log entry
Displays user defined value and extra log information
  • Switch from task to task
    • Starting new task
    Displays delay between request to start the task and actual time when task was started
    • Ending task
Displays remaining time until deadline if was specified by user, when task was created
  • Switch from task to scheduler
  • Switch from task to sleep
Also DMON displays stack pointer at the time of context switch, CWP(current window pointer) and system state variable.

The table allows browsing through the list of log entries, moving from one context to another. Double click on any entry in the table sets the marker on the time line. Zoom in and out can be used only then to have a closer look at selected time frame. Time Line and Stack view are synchronized to match the currently selected entry.

Table view ZOOM

The Stack Graph below displays stack for the last minute. Stack displays between MIN and MAX values if specified by user in app_config.c

Stack view ZOOM

The Time Line view below displays system interaction by context over time. Each row presents the context. Tasks are ordered by its priorities, from higher to lower. The first row presents the overall context switch activities. The real time update of Time Line is possible only at 10ms scale by moving the scroll bar to the max on the right.

Task run time is shown as rectangle filled with task specific color.

Context switches marked with vertical lines.

Grey rectangle before task indicates the time from start request to actual task start.

DMON can detect buffer overrun. The message is printed to the console and red vertical line displayed on the Time Line View. If this happened, context switch log buffer size has to be increased.

Time Line view ZOOM

Setting the marker by double clicking on the entry in the table

Time Line view at 10ms ZOOM

Zoom in to 1 micro second

Time Line view at 1 micro second ZOOM

Time Line view has some basic controls:

  • Status (running/paused)
  • Button to enable/disable command
  • Save button (please see below)
  • Slider to change time scale. It is disabled and defaults to 10ms while updating in real time.

Limitations:

  • If Context switch buffer is too big it puts constrains on the link to the target. This can happen if the rate, at which the tasks are started, is very frequent. If this is the case then this feature cannot be used and cpuload command is the only choice, as it does not depend on buffer size.

oceos profile save <fileName>

oceos profile save saves context switch logging to the csv file. This command activates saving to the file. After all content is saved, it continues appending to the file. This command cannot be disabled. Every time when new image is loaded to the target, new csv file is created.

If fileName parameter is not specified, the file is created in DMON User directory: c:\Users\UserName\DMON\UserData

Sample of saved Context switch logging to csv file