Difference between revisions of "OCEOS/oceos profiling"
Okhoruzhyy (talk | contribs) |
Okhoruzhyy (talk | contribs) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=<span style="color:#0000ff">'''OCEOS Profiling'''</span>= | =<span style="color:#0000ff">'''OCEOS Profiling'''</span>= | ||
==<span style="color:#0000ff">Introduction</span>== | ==<span style="color:#0000ff">Introduction</span>== | ||
Each time a context switch or interrupt occurs, four 32-bit words are added to the context switch log if enabled:<br> | |||
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 Initialized 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. Initialized 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. Initialized 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. | |||
==<span style="color:#0000ff">Configuration</span>== | |||
<blockquote> | |||
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"> | |||
#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; | |||
</syntaxhighlight> | |||
</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 at the start and at the end of the handler OCEOS code to do Context switch logging. | |||
<blockquote style="background-color: #c6e2f7; border-left-style: solid; border-left-width: 3px; border-left-color: blue; "> '''Note'''<br> | |||
Should be removed in production | |||
</blockquote> | |||
This adds the information to the Context Switch Logging when IRQ was triggered. If user does not require some IRQs reflected in Context Switch Logging, this can be omitted.<br> | |||
OCEOS code is defined in ''oceos_arm_trap_handler.h'' header file that user must include. | |||
<syntaxhighlight lang="C"> | |||
#incude oceos_arm_trap_handler.h | |||
void user_device_irq_handler() { | |||
OCEOS_ISR_CS_LOG_START | |||
// User Code to handle IRQ | |||
OCEOS_ISR_CS_LOG_END | |||
} // End | |||
</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>=== | ||
:'''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 [[ | :'''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 [[OCEOS/oceos_profiling#Introduction|'''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. | 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. | ||
[[File:cpu_profile_main.png|600px|CPU Profile View]] | [[File:cpu_profile_main.png|600px|CPU Profile View]] | ||
[[Media:cpu_profile_main.png|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: | 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: | ||
Line 30: | Line 114: | ||
[[File:cpu_profile_table.png|600px|Table view]] | [[File:cpu_profile_table.png|600px|Table view]] | ||
[[Media:cpu_profile_table.png|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 | 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 | ||
[[File:cpu_profile_stack.png|600px|Stack view]] | [[File:cpu_profile_stack.png|600px|Stack view]] | ||
[[Media:cpu_profile_stack.png|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. | 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. | ||
Line 46: | Line 132: | ||
[[File:cpu_profile_timeline.png|600px|Time Line view]] | [[File:cpu_profile_timeline.png|600px|Time Line view]] | ||
[[Media:cpu_profile_timeline.png|ZOOM]] | |||
Setting the marker by double clicking on the entry in the table | Setting the marker by double clicking on the entry in the table | ||
[[File:cpu_profile_10ms.png|600px|Time Line view at 10ms]] | [[File:cpu_profile_10ms.png|600px|Time Line view at 10ms]] | ||
[[Media:cpu_profile_10ms.png|ZOOM]] | |||
Zoom in to 1 micro second | Zoom in to 1 micro second | ||
[[File:cpu_profile_1.png|600px|Time Line view at 1 micro second]] | [[File:cpu_profile_1.png|600px|Time Line view at 1 micro second]] | ||
[[Media:cpu_profile_1.png|ZOOM]] | |||
Time Line view has some basic controls: | Time Line view has some basic controls: | ||
Line 60: | Line 149: | ||
*Save button (please see below) | *Save button (please see below) | ||
*Slider to change time scale. It is disabled and defaults to 10ms while updating in real time. | *Slider to change time scale. It is disabled and defaults to 10ms while updating in real time. | ||
<blockquote style="background-color: #c6e2f7; border-left-style: solid; border-left-width: 3px; border-left-color: blue; "> '''Note'''<br> | |||
'''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 [[OCEOS/oceos debugging#oceos_cpuload_.3Cstatus.7Cenable.7Cdisable.3E|oceos cpuload]] command is the only choice, as it does not depend on buffer size. | |||
</blockquote> | |||
---- | |||
=== <span style="color:#1b7ac2">oceos profile save <fileName> </span>=== | |||
:'''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 | |||
[[File:Cpu_profile_save.png|Sample of saved Context switch logging to csv file]] | |||
---- | ---- | ||
[[Category:backup]] |
Latest revision as of 16:57, 31 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 Initialized 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. Initialized 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. Initialized 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 at the start and at the end of the handler OCEOS code to do Context switch logging.
Note
Should be removed in production
This adds the information to the Context Switch Logging when IRQ was triggered. If user does not require some IRQs reflected in Context Switch Logging, this can be omitted.
OCEOS code is defined in oceos_arm_trap_handler.h header file that user must include.
#incude oceos_arm_trap_handler.h void user_device_irq_handler() { OCEOS_ISR_CS_LOG_START // User Code to handle IRQ OCEOS_ISR_CS_LOG_END } // 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.
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.
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
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.
Setting the marker by double clicking on the entry in the table
Zoom in to 1 micro second
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.
Note
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 oceos 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