Moves resource requests to procdata (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 29 Feb 2012 00:39:09 +0000 (16:39 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 29 Feb 2012 22:53:02 +0000 (14:53 -0800)
Userspace doesn't use it yet, but resource requests are via procdata
instead of a syscall.  Resource grants are in procinfo.

Reinstall your kernel headers / rebuild parlib apps.

kern/include/env.h
kern/include/ros/procdata.h
kern/include/ros/procinfo.h
kern/include/ros/resource.h
kern/src/process.c
kern/src/resource.c

index 7ba6376..c047ce4 100644 (file)
@@ -47,9 +47,6 @@ struct proc {
        uint8_t* cache_colors_map;
        size_t next_cache_color;
 
-       /* Info about this process's resources (granted, desired) for each type. */
-       struct resource resources[MAX_NUM_RESOURCES];
-
        /* Keeps track of this process's current memory allocation 
      * (i.e. its heap pointer) */
        void* heap_top;
index 80a1ae5..c5bb115 100644 (file)
@@ -25,6 +25,7 @@ typedef struct procdata {
 #endif
        /* glibc relies on stuff above this point.  if you change it, you need to
         * rebuild glibc. */
+       struct resource_req             res_req[MAX_NUM_RESOURCES];
        struct event_queue              *kernel_evts[MAX_NR_EVENT];
        /* Long range, would like these to be mapped in lazily, as the vcores are
         * requested.  Sharing MAX_NUM_CPUS is a bit weird too. */
index b2c2080..676fea0 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <ros/memlayout.h>
 #include <ros/common.h>
+#include <ros/resource.h>
 #include <ros/atomic.h>
 #include <ros/arch/arch.h>
 
@@ -48,6 +49,7 @@ typedef struct procinfo {
        /* glibc relies on stuff above this point.  if you change it, you need to
         * rebuild glibc. */
        bool is_mcp;                    /* is in multi mode */
+       unsigned long           res_grant[MAX_NUM_RESOURCES];
        struct vcore            vcoremap[MAX_NUM_CPUS];
        uint32_t                        num_vcores;
        struct pcore            pcoremap[MAX_NUM_CPUS];
index bd8e080..fa5f412 100644 (file)
 #define REQ_ASYNC                      0x01 // Sync by default (?)
 #define REQ_SOFT                       0x02 // just making something up
 
-struct resource {
-       int type;
-       size_t amt_wanted;
-       size_t amt_wanted_min;
-       size_t amt_granted;
-       uint32_t flags;
+struct resource_req {
+       unsigned long                           amt_wanted;
+       unsigned long                           amt_wanted_min;
+       int                                                     flags;
 };
 
 #endif // !ROS_INCLUDE_RESOURCE_H
index 8f46307..c71ebd1 100644 (file)
@@ -192,6 +192,7 @@ static void proc_init_procinfo(struct proc* p)
        /* 0'ing the arguments.  Some higher function will need to set them */
        memset(p->procinfo->argp, 0, sizeof(p->procinfo->argp));
        memset(p->procinfo->argbuf, 0, sizeof(p->procinfo->argbuf));
+       memset(p->procinfo->res_grant, 0, sizeof(p->procinfo->res_grant));
        /* 0'ing the vcore/pcore map.  Will link the vcores later. */
        memset(&p->procinfo->vcoremap, 0, sizeof(p->procinfo->vcoremap));
        memset(&p->procinfo->pcoremap, 0, sizeof(p->procinfo->pcoremap));
@@ -248,7 +249,6 @@ error_t proc_alloc(struct proc **pp, struct proc *parent)
        p->env_flags = 0;
        p->env_entry = 0; // cheating.  this really gets set later
        p->heap_top = (void*)UTEXT;     /* heap_bottom set in proc_init_procinfo */
-       memset(&p->resources, 0, sizeof(p->resources));
        memset(&p->env_ancillary_state, 0, sizeof(p->env_ancillary_state));
        memset(&p->env_tf, 0, sizeof(p->env_tf));
        spinlock_init(&p->mm_lock);
@@ -932,8 +932,8 @@ void proc_yield(struct proc *SAFE p, bool being_nice)
        /* Next time the vcore starts, it starts fresh */
        vcpd->notif_disabled = FALSE;
        __unmap_vcore(p, vcoreid);
-       /* Adjust implied resource desires */
-       p->resources[RES_CORES].amt_granted = --(p->procinfo->num_vcores);
+       p->procinfo->num_vcores--;
+       p->procinfo->res_grant[RES_CORES] = p->procinfo->num_vcores;
        __seq_end_write(&p->procinfo->coremap_seqctr);
        /* Hand the now-idle core to the ksched */
        put_idle_core(pcoreid);
@@ -996,8 +996,8 @@ void __proc_wakeup(struct proc *p)
        if (__proc_is_mcp(p)) {
                /* Need to make sure they want at least 1 vcore, so the ksched gives
                 * them something.  Might do this via short handler later. */
-               if (!p->resources[RES_CORES].amt_wanted)
-                       p->resources[RES_CORES].amt_wanted = 1;
+               if (!p->procdata->res_req[RES_CORES].amt_wanted)
+                       p->procdata->res_req[RES_CORES].amt_wanted = 1;
                __proc_set_state(p, PROC_RUNNABLE_M);
        } else {
                printk("[kernel] FYI, waking up an _S proc\n");
@@ -1282,7 +1282,8 @@ void __proc_give_cores(struct proc *p, uint32_t *pc_arr, uint32_t num)
                        panic("Weird state(%s) in %s()", procstate2str(p->state),
                              __FUNCTION__);
        }
-       p->resources[RES_CORES].amt_granted += num;
+       /* TODO: move me to the ksched */
+       p->procinfo->res_grant[RES_CORES] += num;
 }
 
 /********** Core revocation (bulk and single) ***********/
@@ -1354,7 +1355,7 @@ void __proc_take_corelist(struct proc *p, uint32_t *pc_arr, uint32_t num,
        }
        p->procinfo->num_vcores -= num;
        __seq_end_write(&p->procinfo->coremap_seqctr);
-       p->resources[RES_CORES].amt_granted -= num;
+       p->procinfo->res_grant[RES_CORES] -= num;
 }
 
 /* Takes all cores from a process (revoke via kmsg or unmap), putting them on
@@ -1393,7 +1394,7 @@ uint32_t __proc_take_allcores(struct proc *p, uint32_t *pc_arr, bool preempt)
        assert(num == p->procinfo->num_vcores);
        p->procinfo->num_vcores = 0;
        __seq_end_write(&p->procinfo->coremap_seqctr);
-       p->resources[RES_CORES].amt_granted = 0;
+       p->procinfo->res_grant[RES_CORES] = 0;
        return num;
 }
 
@@ -1874,7 +1875,7 @@ void print_proc_info(pid_t pid)
        printk("Resources:\n------------------------\n");
        for (int i = 0; i < MAX_NUM_RESOURCES; i++)
                printk("\tRes type: %02d, amt wanted: %08d, amt granted: %08d\n", i,
-                      p->resources[i].amt_wanted, p->resources[i].amt_granted);
+                      p->procdata->res_req[i].amt_wanted, p->procinfo->res_grant[i]);
        printk("Open Files:\n");
        struct files_struct *files = &p->open_files;
        spin_lock(&files->lock);
index fec001d..a83e304 100644 (file)
@@ -41,17 +41,17 @@ bool core_request(struct proc *p)
         * esp with moving amt_wanted to procdata (TODO).  Will probably want to
         * copy-in amt_wanted too. */
        spin_lock(&p->proc_lock);
-       amt_wanted = p->resources[RES_CORES].amt_wanted;
-       amt_granted = p->resources[RES_CORES].amt_granted;      /* aka, num_vcores */
+       amt_wanted = p->procdata->res_req[RES_CORES].amt_wanted;
+       amt_granted = p->procinfo->res_grant[RES_CORES];
 
        /* Help them out - if they ask for something impossible, give them 1 so they
-        * can make some progress. */
+        * can make some progress. (these two are racy). */
        if (amt_wanted > p->procinfo->max_vcores) {
-               p->resources[RES_CORES].amt_wanted = 1;
+               p->procdata->res_req[RES_CORES].amt_wanted = 1;
        }
        /* TODO: sort how this works with WAITING. */
        if (!amt_wanted) {
-               p->resources[RES_CORES].amt_wanted = 1;
+               p->procdata->res_req[RES_CORES].amt_wanted = 1;
        }
        /* if they are satisfied, we're done.  There's a slight chance they have
         * cores, but they aren't running (sched gave them cores while they were
@@ -103,10 +103,9 @@ error_t resource_req(struct proc *p, int type, size_t amt_wanted,
 
        /* set the desired resource amount in the process's resource list. */
        spin_lock(&p->proc_lock);
-       size_t old_amount = p->resources[type].amt_wanted;
-       p->resources[type].amt_wanted = amt_wanted;
-       p->resources[type].amt_wanted_min = MIN(amt_wanted_min, amt_wanted);
-       p->resources[type].flags = flags;
+       p->procdata->res_req[type].amt_wanted = amt_wanted;
+       p->procdata->res_req[type].amt_wanted_min = MIN(amt_wanted_min, amt_wanted);
+       p->procdata->res_req[type].flags = flags;
        spin_unlock(&p->proc_lock);
 
        switch (type) {
@@ -146,7 +145,7 @@ void print_resources(struct proc *p)
        printk("--------------------\n");
        for (int i = 0; i < MAX_NUM_RESOURCES; i++)
                printk("Res type: %02d, amt wanted: %08d, amt granted: %08d\n", i,
-                      p->resources[i].amt_wanted, p->resources[i].amt_granted);
+                      p->procdata->res_req[i].amt_wanted, p->procinfo->res_grant[i]);
 }
 
 void print_all_resources(void)