Skip to content

Commit 9d367ee

Browse files
Andy RossAnas Nashif
authored andcommitted
xtensa, kernel/sched: Move next switch_handle selection to the scheduler
The xtensa asm2 layer had a function to select the next switch handle to return into following an exception. There is no arch-specific code there, it's just scheduler logic. Move it to the scheduler where it belongs. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
1 parent e825789 commit 9d367ee

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

arch/xtensa/core/xtensa-asm2.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,6 @@ static void dump_stack(int *stack)
137137
printk(" ** SAR %p\n", (void *)bsa[BSA_SAR_OFF/4]);
138138
}
139139

140-
#if CONFIG_XTENSA_ASM2
141-
static inline void *restore_stack(void *interrupted_stack)
142-
{
143-
if (!_is_preempt(_current) &&
144-
!(_current->base.thread_state & _THREAD_DEAD)) {
145-
return interrupted_stack;
146-
}
147-
148-
int key = irq_lock();
149-
150-
_current->switch_handle = interrupted_stack;
151-
_current = _get_next_ready_thread();
152-
153-
void *ret = _current->switch_handle;
154-
155-
irq_unlock(key);
156-
157-
_check_stack_sentinel();
158-
159-
return ret;
160-
}
161-
#endif
162-
163140
/* The wrapper code lives here instead of in the python script that
164141
* generates _xtensa_handle_one_int*(). Seems cleaner, still kind of
165142
* ugly.
@@ -174,7 +151,7 @@ void *xtensa_int##l##_c(void *interrupted_stack) \
174151
irqs ^= m; \
175152
__asm__ volatile("wsr.intclear %0" : : "r"(m)); \
176153
} \
177-
return restore_stack(interrupted_stack); \
154+
return _get_next_switch_handle(interrupted_stack); \
178155
}
179156

180157
DEF_INT_C_HANDLER(2)
@@ -235,6 +212,6 @@ void *xtensa_excint1_c(int *interrupted_stack)
235212
_NanoFatalErrorHandler(_NANO_ERR_HW_EXCEPTION, &_default_esf);
236213
}
237214

238-
return restore_stack(interrupted_stack);
215+
return _get_next_switch_handle(interrupted_stack);
239216
}
240217

kernel/include/ksched.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,10 @@ static inline int _is_thread_user(void)
541541
#endif
542542
}
543543
#endif /* CONFIG_USERSPACE */
544+
545+
/**
546+
* Returns the switch_handle of the next thread to run following an interrupt.
547+
*/
548+
void *_get_next_switch_handle(void *interrupted);
549+
544550
#endif /* _ksched__h_ */

kernel/sched.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,26 @@ struct k_thread *_get_next_ready_thread(void)
538538
return NULL;
539539
}
540540
#endif
541+
542+
#ifdef CONFIG_USE_SWITCH
543+
void *_get_next_switch_handle(void *interrupted)
544+
{
545+
if (!_is_preempt(_current) &&
546+
!(_current->base.thread_state & _THREAD_DEAD)) {
547+
return interrupted;
548+
}
549+
550+
int key = irq_lock();
551+
552+
_current->switch_handle = interrupted;
553+
_current = _get_next_ready_thread();
554+
555+
void *ret = _current->switch_handle;
556+
557+
irq_unlock(key);
558+
559+
_check_stack_sentinel();
560+
561+
return ret;
562+
}
563+
#endif

0 commit comments

Comments
 (0)