mirror of
https://github.com/drasko/codezero.git
synced 2026-01-20 23:03:16 +01:00
New UTCB implementation almost working.
- KIP's pointer to UTCB seems to work with existing l4lib ipc functions. - Works up to clone() - In clone we mmap() the same UTCB on each new thread - excessive. - Generally during page fault handling, cloned threads may fault on the same page multiple times even though a single handling would be enough for all of them. Need to detect and handle this.
This commit is contained in:
@@ -255,12 +255,12 @@ static inline void context_switch(struct ktcb *next)
|
||||
|
||||
// printk("(%d) to (%d)\n", cur->tid, next->tid);
|
||||
|
||||
/* Update KIP UTCB pointer for new thread to run */
|
||||
kip.utcb = next->utcb_address;
|
||||
|
||||
/* Flush caches and everything */
|
||||
arch_hardware_flush(next->pgd);
|
||||
|
||||
/* Update utcb region for next task */
|
||||
task_update_utcb(cur, next);
|
||||
|
||||
/* Switch context */
|
||||
arch_switch(cur, next);
|
||||
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
#include <l4/generic/scheduler.h>
|
||||
#include <l4/generic/preempt.h>
|
||||
#include <l4/lib/idpool.h>
|
||||
#include <l4/api/kip.h>
|
||||
#include INC_ARCH(exception.h)
|
||||
#include INC_SUBARCH(mm.h)
|
||||
#include INC_GLUE(memory.h)
|
||||
|
||||
/* ID pools for threads and spaces. */
|
||||
struct id_pool *thread_id_pool;
|
||||
@@ -22,3 +25,36 @@ struct list_head global_task_list;
|
||||
unsigned int need_resched_offset = offsetof(struct ktcb, ts_need_resched);
|
||||
unsigned int syscall_regs_offset = offsetof(struct ktcb, syscall_regs);
|
||||
|
||||
/*
|
||||
* Every thread has a unique utcb region that is mapped to its address
|
||||
* space as its context is loaded. The utcb region is a function of
|
||||
* this mapping and its offset that is reached via the KIP UTCB pointer
|
||||
*/
|
||||
void task_update_utcb(struct ktcb *cur, struct ktcb *next)
|
||||
{
|
||||
/* Update the KIP pointer */
|
||||
kip.utcb = next->utcb_address;
|
||||
|
||||
/* We stick with KIP update and no private tls mapping for now */
|
||||
#if 0
|
||||
/*
|
||||
* Unless current and next are in the same address
|
||||
* space and sharing the same physical utcb page, we
|
||||
* update the mapping
|
||||
*/
|
||||
if (cur->utcb_phys != next->utcb_phys)
|
||||
add_mapping(page_align(next->utcb_phys),
|
||||
page_align(next->utcb_virt),
|
||||
page_align_up(UTCB_SIZE),
|
||||
MAP_USR_RW_FLAGS);
|
||||
/*
|
||||
* If same physical utcb but different pgd, it means two
|
||||
* address spaces share the same utcb. We treat this as a
|
||||
* bug for now.
|
||||
*/
|
||||
else
|
||||
BUG_ON(cur->pgd != next->pgd);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user