Add context switch profile point.
Add the context switch profile point for x86 and ARM arquitectures. Change-Id: Ib7205059104ed47b96ba75b8cfefec3ff35f6813 Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
This commit is contained in:
parent
efd8e246cc
commit
520542bef2
|
@ -16,6 +16,7 @@ CONFIG_XIP=y
|
|||
# CONFIG_EVENT_LOGGER is not set
|
||||
# CONFIG_KERNEL_PROFILER is not set
|
||||
# CONFIG_PROFILER_BUFFER_SIZE is not set
|
||||
# CONFIG_PROFILER_CONTEXT_SWITCH is not set
|
||||
|
||||
#
|
||||
# Nanokernel Options
|
||||
|
|
|
@ -73,6 +73,13 @@ SECTION_FUNC(TEXT, __pendsv)
|
|||
|
||||
_GDB_STUB_EXC_ENTRY
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
/* Register the context switch */
|
||||
push {lr}
|
||||
bl _sys_profiler_context_switch
|
||||
pop {lr}
|
||||
#endif
|
||||
|
||||
/* load _Nanokernel into r1 and current tCCS into r2 */
|
||||
ldr r1, =_nanokernel
|
||||
ldr r2, [r1, #__tNANO_current_OFFSET]
|
||||
|
|
|
@ -17,6 +17,7 @@ CONFIG_XIP=y
|
|||
# CONFIG_EVENT_LOGGER is not set
|
||||
# CONFIG_KERNEL_PROFILER is not set
|
||||
# CONFIG_PROFILER_BUFFER_SIZE is not set
|
||||
# CONFIG_PROFILER_CONTEXT_SWITCH is not set
|
||||
|
||||
#
|
||||
# Nanokernel Options
|
||||
|
|
|
@ -136,6 +136,14 @@ SECTION_FUNC(TEXT, _Swap)
|
|||
movl __tNANO_current_OFFSET (%eax), %ecx
|
||||
movl %esp, __tCCS_coopReg_OFFSET + __tCoopReg_esp_OFFSET (%ecx)
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
/* save %eax since it used as the return value for _Swap */
|
||||
pushl %eax
|
||||
/* Register the context switch */
|
||||
call _sys_profiler_context_switch
|
||||
/* restore _Swap's %eax */
|
||||
popl %eax
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Determine what FIBER or TASK context needs to be swapped in.
|
||||
|
|
|
@ -19,6 +19,7 @@ CONFIG_ENHANCED_SECURITY=y
|
|||
# CONFIG_EVENT_LOGGER is not set
|
||||
# CONFIG_KERNEL_PROFILER is not set
|
||||
# CONFIG_PROFILER_BUFFER_SIZE is not set
|
||||
# CONFIG_PROFILER_CONTEXT_SWITCH is not set
|
||||
|
||||
#
|
||||
# Security Options
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
|
||||
#ifdef CONFIG_KERNEL_PROFILER
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
#define PROFILER_CONTEXT_SWITCH_EVENT_ID 0x0001
|
||||
#endif /* CONFIG_PROFILER_CONTEXT_SWITCH */
|
||||
|
||||
/**
|
||||
* Global variable of the ring buffer that allows user to implement
|
||||
* their own reading routine.
|
||||
|
@ -142,6 +146,23 @@ void sys_profiler_put_timed(uint16_t event_id);
|
|||
buffer_size, timeout)
|
||||
#endif /* CONFIG_NANO_TIMEOUTS */
|
||||
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
|
||||
/**
|
||||
* @brief Register the fiber that calls the function as collector
|
||||
*
|
||||
* @details Initialize internal profiling data. This avoid registering the
|
||||
* context switch of the collector fiber when CONFIG_PROFILE_CONTEXT_SWITCH
|
||||
* is enable.
|
||||
*
|
||||
* @return No return value.
|
||||
*/
|
||||
void sys_profiler_register_as_collector(void);
|
||||
#else /* !CONFIG_PROFILER_CONTEXT_SWITCH */
|
||||
static inline void sys_profiler_register_as_collector(void) {};
|
||||
#endif /* CONFIG_PROFILER_CONTEXT_SWITCH */
|
||||
|
||||
#else /* !CONFIG_KERNEL_PROFILER */
|
||||
|
||||
static inline void sys_profiler_put(uint16_t event_id, uint32_t *event_data,
|
||||
|
|
|
@ -130,6 +130,18 @@ config PROFILER_BUFFER_SIZE
|
|||
help
|
||||
Buffer size in 32-bit words.
|
||||
|
||||
menu "Profiler points"
|
||||
depends on KERNEL_PROFILER
|
||||
|
||||
config PROFILER_CONTEXT_SWITCH
|
||||
bool
|
||||
prompt "Context switch profiler point"
|
||||
default n
|
||||
depends on KERNEL_PROFILER
|
||||
help
|
||||
Enable the context switch event messages.
|
||||
endmenu
|
||||
|
||||
menu "Security Options"
|
||||
depends on ENHANCED_SECURITY
|
||||
|
||||
|
|
|
@ -37,9 +37,14 @@
|
|||
#include <misc/profiler.h>
|
||||
#include <misc/util.h>
|
||||
#include <init.h>
|
||||
#include <nano_private.h>
|
||||
|
||||
uint32_t _sys_profiler_buffer[CONFIG_PROFILER_BUFFER_SIZE];
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
void *_collector_context=NULL;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the profiler system.
|
||||
*
|
||||
|
@ -69,3 +74,49 @@ void sys_profiler_put_timed(uint16_t event_id)
|
|||
sys_event_logger_put(&sys_profiler_logger, event_id, data,
|
||||
ARRAY_SIZE(data));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PROFILER_CONTEXT_SWITCH
|
||||
void _sys_profiler_context_switch(void)
|
||||
{
|
||||
extern tNANO _nanokernel;
|
||||
uint32_t data[2];
|
||||
extern void _sys_event_logger_put_non_preemptible(
|
||||
struct event_logger *logger, uint16_t event_id, uint32_t *event_data,
|
||||
uint8_t data_size);
|
||||
|
||||
/* if the profiler has not been initialized, we do nothing */
|
||||
if (sys_profiler_logger.buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_collector_context != _nanokernel.current) {
|
||||
data[0] = nano_tick_get_32();
|
||||
data[1] = (uint32_t)_nanokernel.current;
|
||||
|
||||
/*
|
||||
* The mechanism we use to log the profile events uses a sync semaphore
|
||||
* to inform that there are available events to be collected. The
|
||||
* context switch event can be triggered from a task context. When we
|
||||
* signal a semaphore from a task context and a fiber is waiting for
|
||||
* that semaphore, a context switch is generated immediately. Due to
|
||||
* the fact that we register the context switch event while the context
|
||||
* switch is being processed, a new context switch can be generated
|
||||
* before the kernel finishes processing the current context switch. We
|
||||
* need to prevent this because the kernel is not able to handle it.
|
||||
* The _sem_give_non_preemptible function does not trigger a context
|
||||
* switch when we signal the semaphore from any type of context. Using
|
||||
* _sys_event_logger_put_non_preemptible function, that internally uses
|
||||
* _sem_give_non_preemptible function for signaling the sync semaphore,
|
||||
* allow us registering the context switch event without triggering any
|
||||
* new context switch during the process.
|
||||
*/
|
||||
_sys_event_logger_put_non_preemptible(&sys_profiler_logger,
|
||||
PROFILER_CONTEXT_SWITCH_EVENT_ID, data, ARRAY_SIZE(data));
|
||||
}
|
||||
}
|
||||
|
||||
void sys_profiler_register_as_collector(void)
|
||||
{
|
||||
_collector_context = _nanokernel.current;
|
||||
}
|
||||
#endif /* CONFIG_PROFILER_CONTEXT_SWITCH */
|
||||
|
|
Loading…
Reference in a new issue