2020-09-01 22:12:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Lexmark International, Inc.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <tracing_user.h>
|
|
|
|
#include <kernel_internal.h>
|
2022-05-06 17:12:04 +08:00
|
|
|
#include <zephyr/kernel_structs.h>
|
2020-09-01 22:12:09 +08:00
|
|
|
#include <ksched.h>
|
|
|
|
|
2022-01-13 10:55:15 +08:00
|
|
|
static int nested_interrupts[CONFIG_MP_NUM_CPUS];
|
2020-09-01 22:12:09 +08:00
|
|
|
|
|
|
|
void __weak sys_trace_thread_switched_in_user(struct k_thread *thread) {}
|
|
|
|
void __weak sys_trace_thread_switched_out_user(struct k_thread *thread) {}
|
2022-01-13 10:55:15 +08:00
|
|
|
void __weak sys_trace_isr_enter_user(int nested_interrupts) {}
|
|
|
|
void __weak sys_trace_isr_exit_user(int nested_interrupts) {}
|
2020-09-01 22:12:09 +08:00
|
|
|
void __weak sys_trace_idle_user(void) {}
|
|
|
|
|
|
|
|
void sys_trace_k_thread_switched_in(void)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
|
|
|
|
2022-01-13 10:55:15 +08:00
|
|
|
__ASSERT_NO_MSG(nested_interrupts[_current_cpu->id] == 0);
|
2022-04-23 04:12:20 +08:00
|
|
|
/* Can't use k_current_get as thread base and z_tls_current might be incorrect */
|
|
|
|
sys_trace_thread_switched_in_user(z_current_get());
|
2020-09-01 22:12:09 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_trace_k_thread_switched_out(void)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
|
|
|
|
2022-01-13 10:55:15 +08:00
|
|
|
__ASSERT_NO_MSG(nested_interrupts[_current_cpu->id] == 0);
|
2022-04-23 04:12:20 +08:00
|
|
|
/* Can't use k_current_get as thread base and z_tls_current might be incorrect */
|
|
|
|
sys_trace_thread_switched_out_user(z_current_get());
|
2020-09-01 22:12:09 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_trace_isr_enter(void)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
2022-01-13 10:55:15 +08:00
|
|
|
_cpu_t *curr_cpu = _current_cpu;
|
|
|
|
|
|
|
|
sys_trace_isr_enter_user(nested_interrupts[curr_cpu->id]);
|
|
|
|
nested_interrupts[curr_cpu->id]++;
|
2020-09-01 22:12:09 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_trace_isr_exit(void)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
2022-01-13 10:55:15 +08:00
|
|
|
_cpu_t *curr_cpu = _current_cpu;
|
|
|
|
|
|
|
|
nested_interrupts[curr_cpu->id]--;
|
|
|
|
sys_trace_isr_exit_user(nested_interrupts[curr_cpu->id]);
|
2020-09-01 22:12:09 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_trace_idle(void)
|
|
|
|
{
|
|
|
|
sys_trace_idle_user();
|
|
|
|
}
|