kernel/arch: enhance the "ready thread" cache
The way the ready thread cache was implemented caused it to not always be "hot", i.e. there could be some misses, which happened when the cached thread was taken out of the ready queue. When that happened, it was not replaced immediately, since doing so could mean that the replacement might not run because the flow could be interrupted and another thread could take its place. This was the more conservative approach that insured that moving a thread to the cache would never be wasted. However, this caused two problems: 1. The cache could not be refilled until another thread context-switched in, since there was no thread in the cache to compare priorities against. 2. Interrupt exit code would always have to call into C to find what thread to run when the current thread was not coop and did not have the scheduler locked. Furthermore, it was possible for this code path to encounter a cold cache and then it had to find out what thread to run the long way. To fix this, filling the cache is now more aggressive, i.e. the next thread to put in the cache is found even in the case the current cached thread is context-switched out. This ensures the interrupt exit code is much faster on the slow path. In addition, since finding the next thread to run is now always "get it from the cache", which is a simple fetch from memory (_kernel.ready_q.cache), there is no need to call the more complex C code. On the ARM FRDM K64F board, this improvement is seen: Before: 1- Measure time to switch from ISR back to interrupted task switching time is 215 tcs = 1791 nsec 2- Measure time from ISR to executing a different task (rescheduled) switch time is 315 tcs = 2625 nsec After: 1- Measure time to switch from ISR back to interrupted task switching time is 130 tcs = 1083 nsec 2- Measure time from ISR to executing a different task (rescheduled) switch time is 225 tcs = 1875 nsec These are the most dramatic improvements, but most of the numbers generated by the latency_measure test are improved. Fixes ZEP-1401. Change-Id: I2eaac147048b1ec71a93bd0a285e743a39533973 Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
parent
e6ebe3a8b4
commit
88b3691415
17 changed files with 85 additions and 180 deletions
|
@ -25,7 +25,6 @@ GTEXT(_thread_entry_wrapper)
|
|||
|
||||
/* imports */
|
||||
GTEXT(_sys_k_event_logger_context_switch)
|
||||
GTEXT(_get_next_ready_thread)
|
||||
GTEXT(_k_neg_eagain)
|
||||
|
||||
/* unsigned int _Swap(unsigned int key)
|
||||
|
@ -78,16 +77,17 @@ SECTION_FUNC(exception.other, _Swap)
|
|||
ori r10, r10, %lo(_kernel)
|
||||
#endif /* CONFIG_KERNEL_EVENT_LOGGER_CONTEXT_SWITCH */
|
||||
|
||||
/* Assign to _kernel.current the return value of
|
||||
* _get_next_ready_thread()
|
||||
*/
|
||||
call _get_next_ready_thread
|
||||
movhi r10, %hi(_kernel)
|
||||
ori r10, r10, %lo(_kernel)
|
||||
stw r2, _kernel_offset_to_current(r10)
|
||||
|
||||
/* get cached thread to run */
|
||||
ldw r2, _kernel_offset_to_ready_q_cache(r10)
|
||||
|
||||
/* At this point r2 points to the next thread to be swapped in */
|
||||
|
||||
/* the thread to be swapped in is now the current thread */
|
||||
stw r2, _kernel_offset_to_current(r10)
|
||||
|
||||
/* Restore callee-saved registers and switch to the incoming
|
||||
* thread's stack
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue