feat: add general SPT lock for operations across threads
This commit is contained in:
@@ -736,6 +736,10 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->recent_cpu = recent_cpu;
|
||||
t->priority = t->base_priority;
|
||||
|
||||
#ifdef VM
|
||||
lock_init (&t->spt_lock);
|
||||
#endif
|
||||
|
||||
old_level = intr_disable ();
|
||||
list_push_back (&all_list, &t->allelem);
|
||||
intr_set_level (old_level);
|
||||
|
||||
@@ -149,6 +149,8 @@ struct thread
|
||||
struct hash open_files; /* Hash Table of FD -> Struct File. */
|
||||
#endif
|
||||
|
||||
struct lock spt_lock;
|
||||
|
||||
void *curr_esp;
|
||||
|
||||
/* Owned by thread.c. */
|
||||
|
||||
@@ -133,7 +133,8 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
||||
enum page_type type)
|
||||
{
|
||||
/* If page exists, just update it. */
|
||||
struct page_entry *existing = page_get (thread_current (), upage);
|
||||
struct thread *t = thread_current ();
|
||||
struct page_entry *existing = page_get (t, upage);
|
||||
if (existing != NULL)
|
||||
{
|
||||
ASSERT (existing->read_bytes == read_bytes);
|
||||
@@ -164,11 +165,13 @@ page_insert_file (struct file *file, off_t ofs, void *upage,
|
||||
struct page_entry *
|
||||
page_get (struct thread *thread, void *upage)
|
||||
{
|
||||
lock_acquire (&thread->spt_lock);
|
||||
struct page_entry fake_page_entry;
|
||||
fake_page_entry.upage = upage;
|
||||
|
||||
struct hash_elem *e
|
||||
= hash_find (&thread->pages, &fake_page_entry.elem);
|
||||
lock_release (&thread->spt_lock);
|
||||
if (e == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -290,6 +293,7 @@ page_load_file (struct page_entry *page)
|
||||
void
|
||||
page_cleanup (struct hash_elem *e, void *aux UNUSED)
|
||||
{
|
||||
lock_acquire (&thread_current ()->spt_lock);
|
||||
struct page_entry *page = hash_entry (e, struct page_entry, elem);
|
||||
if (page->type == PAGE_SHARED)
|
||||
{
|
||||
@@ -312,6 +316,7 @@ page_cleanup (struct hash_elem *e, void *aux UNUSED)
|
||||
lock_release (&shared_file_pages_lock);
|
||||
}
|
||||
free (page);
|
||||
lock_release (&thread_current ()->spt_lock);
|
||||
}
|
||||
|
||||
/* Flags the provided page table entry as representing a swapped out page. */
|
||||
@@ -343,7 +348,9 @@ page_set_swap (struct thread *owner, uint32_t *pte, size_t swap_slot)
|
||||
bool
|
||||
page_in_swap (struct thread *owner, void *upage)
|
||||
{
|
||||
lock_acquire (&owner->spt_lock);
|
||||
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
||||
lock_release (&owner->spt_lock);
|
||||
return page_in_swap_pte (pte);
|
||||
}
|
||||
|
||||
@@ -360,6 +367,7 @@ page_in_swap_pte (uint32_t *pte)
|
||||
size_t
|
||||
page_get_swap (struct thread *owner, void *upage)
|
||||
{
|
||||
lock_acquire (&owner->spt_lock);
|
||||
uint32_t *pte = lookup_page (owner->pagedir, upage, false);
|
||||
|
||||
ASSERT (pte != NULL);
|
||||
@@ -367,6 +375,7 @@ page_get_swap (struct thread *owner, void *upage)
|
||||
|
||||
/* Masks the address bits and returns truncated value. */
|
||||
page_flag_swap (pte, false);
|
||||
lock_release (&owner->spt_lock);
|
||||
return ((*pte & PTE_ADDR) >> ADDR_START_BIT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user