Vcore mapping and idle core management
[akaros.git] / kern / src / env.c
index b063137..4ad9677 100644 (file)
@@ -91,6 +91,12 @@ env_init(void)
        int i;
 
        schedule_init();
+       // core 0 is not idle, all others are (for now)
+       spin_lock(&idle_lock);
+       num_idlecores = num_cpus - 1;
+       for (i = 0; i < num_idlecores; i++)
+               idlecoremap[i] = i + 1;
+       spin_unlock(&idle_lock);
        atomic_init(&num_envs, 0);
        TAILQ_INIT(&proc_freelist);
        assert(envs != NULL);
@@ -164,7 +170,8 @@ WRITES(e->env_pgdir, e->env_cr3, e->env_procinfo, e->env_procdata)
        for(int i=0; i<PROCINFO_NUM_PAGES; i++) {
                if(page_alloc(&pginfo[i]) < 0)
                        goto env_setup_vm_error;
-               if(page_insert(e->env_pgdir, pginfo[i], (void*SNT)(UINFO + i*PGSIZE), PTE_USER_RO) < 0)
+               if(page_insert(e->env_pgdir, pginfo[i], (void*SNT)(UINFO + i*PGSIZE),
+                              PTE_USER_RO) < 0)
                        goto env_setup_vm_error;
        }
 
@@ -175,7 +182,8 @@ WRITES(e->env_pgdir, e->env_cr3, e->env_procinfo, e->env_procdata)
        for(int i=0; i<PROCDATA_NUM_PAGES; i++) {
                if(page_alloc(&pgdata[i]) < 0)
                        goto env_setup_vm_error;
-               if(page_insert(e->env_pgdir, pgdata[i], (void*SNT)(UDATA + i*PGSIZE), PTE_USER_RW) < 0)
+               if(page_insert(e->env_pgdir, pgdata[i], (void*SNT)(UDATA + i*PGSIZE),
+                              PTE_USER_RW) < 0)
                        goto env_setup_vm_error;
        }
 
@@ -270,15 +278,17 @@ env_alloc(env_t **newenv_store, envid_t parent_id)
        e->env_runs = 0;
        e->env_refcnt = 1;
        e->env_flags = 0;
-
+       e->env_entry = 0; // cheating.  this really gets set in load_icode
 #ifdef __SHARC__
        /* init SharC state */
        sharC_env_init(&e->sharC_env);
 #endif
+       e->num_vcores = 0;
+       memset(&e->vcoremap, 0, sizeof(e->vcoremap));
 
        memset(&e->env_ancillary_state, 0, sizeof(e->env_ancillary_state));
        memset(&e->env_tf, 0, sizeof(e->env_tf));
-       env_init_trapframe(e);
+       proc_init_trapframe(&e->env_tf);
 
        /*
         * Initialize the contents of the e->env_procinfo structure
@@ -410,7 +420,8 @@ load_icode(env_t *SAFE e, uint8_t *COUNT(size) binary, size_t size)
                memset((void*)phdr.p_va + phdr.p_filesz, 0, phdr.p_memsz - phdr.p_filesz);
        }}
 
-       env_set_program_counter(e, elfhdr.e_entry);
+       proc_set_program_counter(&e->env_tf, elfhdr.e_entry);
+       e->env_entry = elfhdr.e_entry;
 
        // Now map one page for the program's initial stack
        // at virtual address USTACKTOP - PGSIZE.