sys_getvcoreid uses the proc calls
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 13 Mar 2010 05:29:44 +0000 (21:29 -0800)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:39 +0000 (17:35 -0700)
Not a big deal, esp since we might get rid of sys_getvcoreid once all
userspaces cache their vcoreid in TLS right after startup.

kern/include/process.h
kern/src/process.c
kern/src/syscall.c

index 64c69a3..3643772 100644 (file)
@@ -82,6 +82,8 @@ void proc_startcore(struct proc *SAFE p, trapframe_t *SAFE tf)
      __attribute__((noreturn));
 void proc_destroy(struct proc *SAFE p);
 void proc_yield(struct proc *SAFE p);
+/* Exposed for sys_getvcoreid(), til it's unnecessary */
+uint32_t proc_get_vcoreid(struct proc *SAFE p, uint32_t pcoreid);
 
 /* Process core management.  Only call these if you are RUNNING_M or RUNNABLE_M.
  * These all adjust the vcoremap and take appropriate actions (like __startcore
index ea43a40..185ad06 100644 (file)
@@ -605,7 +605,8 @@ void proc_destroy(struct proc *p)
                                             (void *SNT)0);
                        break;
                default:
-                       panic("Weird state(0x%08x) in proc_destroy", p->state);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
        }
        __proc_set_state(p, PROC_DYING);
        /* this decref is for the process in general */
@@ -716,7 +717,8 @@ void proc_yield(struct proc *SAFE p)
                        break;
                default:
                        // there are races that can lead to this (async death, preempt, etc)
-                       panic("Weird state(0x%08x) in proc_yield", p->state);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
        }
        spin_unlock_irqsave(&p->proc_lock);
        proc_decref(p, 1);
@@ -725,6 +727,28 @@ void proc_yield(struct proc *SAFE p)
        abandon_core();
 }
 
+/* Global version of the helper, for sys_get_vcoreid (might phase that syscall
+ * out). */
+uint32_t proc_get_vcoreid(struct proc *SAFE p, uint32_t pcoreid)
+{
+       uint32_t vcoreid;
+       // TODO: the code currently doesn't track the vcoreid properly for _S
+       spin_lock_irqsave(&p->proc_lock);
+       switch (p->state) {
+               case PROC_RUNNING_S:
+                       spin_unlock_irqsave(&p->proc_lock);
+                       return 0; // TODO: here's the ugly part
+               case PROC_RUNNING_M:
+                       vcoreid = get_vcoreid(p, pcoreid);
+                       spin_unlock_irqsave(&p->proc_lock);
+                       return vcoreid;
+               default:
+                       spin_unlock_irqsave(&p->proc_lock);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
+       }
+}
+
 /* Gives process p the additional num cores listed in pcorelist.  You must be
  * RUNNABLE_M or RUNNING_M before calling this.  If you're RUNNING_M, this will
  * startup your new cores at the entry point with their virtual IDs.  If you're
@@ -800,7 +824,8 @@ bool __proc_give_cores(struct proc *SAFE p, uint32_t *pcorelist, size_t num)
                        }
                        break;
                default:
-                       panic("Weird proc state %d in proc_give_cores()!\n", p->state);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
        }
        return self_ipi_pending;
 }
@@ -842,7 +867,8 @@ bool __proc_take_cores(struct proc *SAFE p, uint32_t *pcorelist,
                        assert(message);
                        break;
                default:
-                       panic("Weird state %d in proc_take_cores()!\n", p->state);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
        }
        spin_lock(&idle_lock);
        assert((num <= p->procinfo->num_vcores) &&
@@ -886,7 +912,8 @@ bool __proc_take_allcores(struct proc *SAFE p, amr_t message,
                        assert(message);
                        break;
                default:
-                       panic("Weird state %d in proc_take_allcores()!\n", p->state);
+                       panic("Weird state(%s) in %s()", procstate2str(p->state),
+                             __FUNCTION__);
        }
        spin_lock(&idle_lock);
        assert(num_idlecores + p->procinfo->num_vcores <= num_cpus); // sanity
index ac1010c..c6e48e9 100644 (file)
@@ -160,18 +160,11 @@ static uint32_t sys_getcpuid(void)
        return core_id();
 }
 
-// TODO: Temporary hack until thread-local storage is implemented on i386
-static size_t sys_getvcoreid(env_t* e)
+// TODO: Temporary hack until thread-local storage is implemented on i386 and
+// this is removed from the user interface
+static size_t sys_getvcoreid(struct proc *p)
 {
-       if(e->state == PROC_RUNNING_S)
-               return 0;
-
-       size_t i;
-       for(i = 0; i < e->procinfo->num_vcores; i++)
-               if(core_id() == e->procinfo->vcoremap[i].pcoreid)
-                       return i;
-
-       panic("virtual core id not found in sys_getvcoreid()!");
+       return proc_get_vcoreid(p, core_id());
 }
 
 /************** Process management syscalls **************/