tracing: swap: bug fix and enhancement for ARC

* Move switched_in into the arch context switch assembly code,
  which will correctly record the switched_in information.

* Add switched_in/switched_out for context switch in irq exit.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
This commit is contained in:
Watson Zeng 2020-09-03 15:15:42 +08:00 committed by Carles Cufí
commit 1dddbecb35
5 changed files with 48 additions and 2 deletions

View file

@ -273,6 +273,13 @@ _firq_switch_from_coop:
pop_s r0 /* status32 into r0 */ pop_s r0 /* status32 into r0 */
sr r0, [_ARC_V2_STATUS32_P0] sr r0, [_ARC_V2_STATUS32_P0]
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif
rtie rtie
.balign 4 .balign 4
@ -287,5 +294,12 @@ _firq_switch_from_firq:
sr ilink, [_ARC_V2_STATUS32_P0] sr ilink, [_ARC_V2_STATUS32_P0]
ld ilink, [sp, -8] /* pc into ilink */ ld ilink, [sp, -8] /* pc into ilink */
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif
/* LP registers are already restored, just switch back to bank 0 */ /* LP registers are already restored, just switch back to bank 0 */
rtie rtie

View file

@ -309,6 +309,13 @@ _rirq_switch_from_coop:
*/ */
st_s r13, [sp, ___isf_t_r13_OFFSET] st_s r13, [sp, ___isf_t_r13_OFFSET]
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif
/* stack now has the IRQ stack frame layout, pointing to sp */ /* stack now has the IRQ stack frame layout, pointing to sp */
/* rtie will pop the rest from the stack */ /* rtie will pop the rest from the stack */
rtie rtie
@ -319,5 +326,12 @@ _rirq_switch_from_rirq:
_set_misc_regs_irq_switch_from_irq _set_misc_regs_irq_switch_from_irq
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif
_rirq_no_switch: _rirq_no_switch:
rtie rtie

View file

@ -132,6 +132,13 @@ _switch_return_from_coop:
pop_s blink pop_s blink
#endif /* CONFIG_EXECUTION_BENCHMARKING */ #endif /* CONFIG_EXECUTION_BENCHMARKING */
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif
j_s [blink] j_s [blink]
@ -160,5 +167,12 @@ _switch_return_from_firq:
sjli SJLI_CALL_ARC_SECURE sjli SJLI_CALL_ARC_SECURE
#else #else
sr r3, [_ARC_V2_AUX_IRQ_ACT] sr r3, [_ARC_V2_AUX_IRQ_ACT]
#endif
#ifdef CONFIG_TRACING
push_s blink
bl sys_trace_thread_switched_in
pop_s blink
#endif #endif
rtie rtie

View file

@ -117,7 +117,7 @@ static ALWAYS_INLINE unsigned int do_swap(unsigned int key,
wait_for_switch(new_thread); wait_for_switch(new_thread);
arch_switch(new_thread->switch_handle, arch_switch(new_thread->switch_handle,
&old_thread->switch_handle); &old_thread->switch_handle);
sys_trace_thread_switched_in();
} }
if (is_spinlock) { if (is_spinlock) {

View file

@ -829,6 +829,7 @@ struct k_thread *z_get_next_ready_thread(void)
/* Just a wrapper around _current = xxx with tracing */ /* Just a wrapper around _current = xxx with tracing */
static inline void set_current(struct k_thread *new_thread) static inline void set_current(struct k_thread *new_thread)
{ {
sys_trace_thread_switched_out();
_current_cpu->current = new_thread; _current_cpu->current = new_thread;
} }
@ -862,7 +863,10 @@ void *z_get_next_switch_handle(void *interrupted)
} }
} }
#else #else
set_current(z_get_next_ready_thread()); struct k_thread *thread = z_get_next_ready_thread();
if (_current != thread) {
set_current(thread);
}
#endif #endif
wait_for_switch(_current); wait_for_switch(_current);