amt_wanted_min added to resource requests
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 6 Nov 2009 01:15:12 +0000 (17:15 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 9 Nov 2009 22:20:49 +0000 (14:20 -0800)
Allows userspace to say the minimum amount of resources that must be
present for it to run.  Note that this doesn't actually do anything with
the info, it simply tracks it in the resources array in the struct proc.

kern/include/resource.h
kern/include/ros/resource.h
kern/src/resource.c
kern/src/syscall.c
user/apps/roslib/mhello.c
user/apps/roslib/mproctests.c
user/roslib/inc/lib.h
user/roslib/src/syscall.c

index 543eaa7..3e5315b 100644 (file)
@@ -16,7 +16,8 @@
 #include <process.h>
 
 ssize_t core_request(struct proc *p);
 #include <process.h>
 
 ssize_t core_request(struct proc *p);
-error_t resource_req(struct proc *p, int type, size_t amount, uint32_t flags);
+error_t resource_req(struct proc *p, int type, size_t amt_wanted,
+                     size_t amt_wanted_min, uint32_t flags);
 
 void print_resources(struct proc *p);
 void print_all_resources(void);
 
 void print_resources(struct proc *p);
 void print_all_resources(void);
index 9f9b880..bd8e080 100644 (file)
@@ -25,6 +25,8 @@
  * pain too.  The batch one is nice, since it amortizes the overhead of the syscall,
  * but it doesn't really matter that much, esp when there are only a few resources.
  *
  * pain too.  The batch one is nice, since it amortizes the overhead of the syscall,
  * but it doesn't really matter that much, esp when there are only a few resources.
  *
+ * amt_wanted_min is the least amount you are will to run with.
+ *
  * A few caveats for cores:
  * - when someone yields (esp if the wish > grant): yielding means take one
  *   away, and set wished = current.  don't yield if you want another core still
  * A few caveats for cores:
  * - when someone yields (esp if the wish > grant): yielding means take one
  *   away, and set wished = current.  don't yield if you want another core still
@@ -46,6 +48,7 @@
 struct resource {
        int type;
        size_t amt_wanted;
 struct resource {
        int type;
        size_t amt_wanted;
+       size_t amt_wanted_min;
        size_t amt_granted;
        uint32_t flags;
 };
        size_t amt_granted;
        uint32_t flags;
 };
index de53a4f..80d5a99 100644 (file)
@@ -136,11 +136,12 @@ ssize_t core_request(struct proc *p)
        return num_granted;
 }
 
        return num_granted;
 }
 
-error_t resource_req(struct proc *p, int type, size_t amount, uint32_t flags)
+error_t resource_req(struct proc *p, int type, size_t amt_wanted,
+                     size_t amt_wanted_min, uint32_t flags)
 {
        error_t retval;
 {
        error_t retval;
-       printk("Received request for type: %d, amount: %d, flag: %d\n",
-              type, amount, flags);
+       printk("Received request for type: %d, amt_wanted: %d, amt_wanted_min: %d, "
+              "flag: %d\n", type, amt_wanted, amt_wanted_min, flags);
        if (flags & REQ_ASYNC)
                // We have no sense of time yet, or of half-filling requests
                printk("[kernel] Async requests treated synchronously for now.\n");
        if (flags & REQ_ASYNC)
                // We have no sense of time yet, or of half-filling requests
                printk("[kernel] Async requests treated synchronously for now.\n");
@@ -148,12 +149,13 @@ error_t resource_req(struct proc *p, int type, size_t amount, uint32_t flags)
        /* set the desired resource amount in the process's resource list. */
        spin_lock_irqsave(&p->proc_lock);
        size_t old_amount = p->resources[type].amt_wanted;
        /* set the desired resource amount in the process's resource list. */
        spin_lock_irqsave(&p->proc_lock);
        size_t old_amount = p->resources[type].amt_wanted;
-       p->resources[type].amt_wanted = amount;
+       p->resources[type].amt_wanted = amt_wanted;
+       p->resources[type].amt_wanted_min = MIN(amt_wanted_min, amt_wanted);
        p->resources[type].flags = flags;
        spin_unlock_irqsave(&p->proc_lock);
 
        // no change in the amt_wanted
        p->resources[type].flags = flags;
        spin_unlock_irqsave(&p->proc_lock);
 
        // no change in the amt_wanted
-       if (old_amount == amount)
+       if (old_amount == amt_wanted)
                return 0;
 
        switch (type) {
                return 0;
 
        switch (type) {
index 789f385..fcdea21 100644 (file)
@@ -481,7 +481,7 @@ intreg_t syscall(struct proc *p, uintreg_t syscallno, uintreg_t a1,
                        printk("brk not implemented yet\n");
                        return -EINVAL;
                case SYS_resource_req:
                        printk("brk not implemented yet\n");
                        return -EINVAL;
                case SYS_resource_req:
-                       return resource_req(p, a1, a2, a3);
+                       return resource_req(p, a1, a2, a3, a4);
 
        #ifdef __i386__
                case SYS_serial_write:
 
        #ifdef __i386__
                case SYS_serial_write:
index 1afae72..287231d 100644 (file)
@@ -32,7 +32,7 @@ int main(int argc, char** argv)
        } else { // core 0
                cprintf("Hello from vcore 0\n");
                cprintf("Multi-Goodbye, world, from PID: %d!\n", sys_getpid());
        } else { // core 0
                cprintf("Hello from vcore 0\n");
                cprintf("Multi-Goodbye, world, from PID: %d!\n", sys_getpid());
-               retval = sys_resource_req(RES_CORES, 7, 0);
+               retval = sys_resource_req(RES_CORES, 7, 1, 0);
        }
        cprintf("Vcore %d Done!\n", vcoreid);
        while (1);
        }
        cprintf("Vcore %d Done!\n", vcoreid);
        while (1);
index 8a0936d..1b70abb 100644 (file)
@@ -66,19 +66,19 @@ int main(int argc, char** argv)
                                cprintf("Should not see me!!!!!!!!!!!!!!!!!!\n");
                                while(1);
                        case TEST_ONE_CORE:
                                cprintf("Should not see me!!!!!!!!!!!!!!!!!!\n");
                                while(1);
                        case TEST_ONE_CORE:
-                               retval = sys_resource_req(RES_CORES, 1, 0);
+                               retval = sys_resource_req(RES_CORES, 1, 1, 0);
                                cprintf("One core test's core0's retval: %d\n", retval);
                                cprintf("Check to see it's on a worker core.\n");
                                while(1);
                        case TEST_ASK_FOR_TOO_MANY_CORES:
                                cprintf("One core test's core0's retval: %d\n", retval);
                                cprintf("Check to see it's on a worker core.\n");
                                while(1);
                        case TEST_ASK_FOR_TOO_MANY_CORES:
-                               retval = sys_resource_req(RES_CORES, 12, 0);
+                               retval = sys_resource_req(RES_CORES, 12, 1, 0);
                                cprintf("Asked for too many, retval: %d\n", retval);
                                return 0;
                        case TEST_INCREMENTAL_CHANGES:
                                cprintf("Asked for too many, retval: %d\n", retval);
                                return 0;
                        case TEST_INCREMENTAL_CHANGES:
-                               retval = sys_resource_req(RES_CORES, 4, 0);
+                               retval = sys_resource_req(RES_CORES, 4, 1, 0);
                                break;
                        default:
                                break;
                        default:
-                               retval = sys_resource_req(RES_CORES, 7, 0);
+                               retval = sys_resource_req(RES_CORES, 7, 1, 0);
                }
                cprintf("Should see me if you want to relocate core0's context "
                        "when moving from RUNNING_S\n");
                }
                cprintf("Should see me if you want to relocate core0's context "
                        "when moving from RUNNING_S\n");
@@ -89,7 +89,7 @@ int main(int argc, char** argv)
                case TEST_YIELD_OUT_OF_ORDER:
                        udelay(10000000, 1995014570);
                        cprintf("Core 2 should have yielded, asking for another\n");
                case TEST_YIELD_OUT_OF_ORDER:
                        udelay(10000000, 1995014570);
                        cprintf("Core 2 should have yielded, asking for another\n");
-                       retval = sys_resource_req(RES_CORES, 7, 0);
+                       retval = sys_resource_req(RES_CORES, 7, 1, 0);
                        break;
                case TEST_YIELD_0_OUT_OF_ORDER:
                        udelay(5000000, 1995014570);
                        break;
                case TEST_YIELD_0_OUT_OF_ORDER:
                        udelay(5000000, 1995014570);
@@ -120,12 +120,12 @@ void hart_entry(void)
                                // Testing asking for less than we already have
                                udelay(1000000, 1995014570); // KVM's freq.  Whatever.
                                cprintf("Asking for too few:\n");
                                // Testing asking for less than we already have
                                udelay(1000000, 1995014570); // KVM's freq.  Whatever.
                                cprintf("Asking for too few:\n");
-                               retval = sys_resource_req(RES_CORES, 2, 0);
+                               retval = sys_resource_req(RES_CORES, 2, 1, 0);
                                cprintf("Should be -EINVAL(7): %d\n", retval);
                                // Testing getting more while running
                                cprintf("Asking for more while running:\n");
                                udelay(1000000, 1995014570);
                                cprintf("Should be -EINVAL(7): %d\n", retval);
                                // Testing getting more while running
                                cprintf("Asking for more while running:\n");
                                udelay(1000000, 1995014570);
-                               retval = sys_resource_req(RES_CORES, 7, 0);
+                               retval = sys_resource_req(RES_CORES, 7, 1, 0);
                                cprintf("core2's retval: %d\n", retval);
                                break;
                        case TEST_YIELD_OUT_OF_ORDER:
                                cprintf("core2's retval: %d\n", retval);
                                break;
                        case TEST_YIELD_OUT_OF_ORDER:
@@ -135,7 +135,7 @@ void hart_entry(void)
                        case TEST_YIELD_0_OUT_OF_ORDER:
                                udelay(7500000, 1995014570);
                                cprintf("Core 0 should have yielded, asking for another\n");
                        case TEST_YIELD_0_OUT_OF_ORDER:
                                udelay(7500000, 1995014570);
                                cprintf("Core 0 should have yielded, asking for another\n");
-                               retval = sys_resource_req(RES_CORES, 7, 0);
+                               retval = sys_resource_req(RES_CORES, 7, 1, 0);
                }
        }
        global_tests(vcoreid);
                }
        }
        global_tests(vcoreid);
@@ -154,7 +154,7 @@ static void global_tests(uint32_t vcoreid)
                case TEST_SWITCH_TO_RUNNABLE_S:
                        if (vcoreid == 2) {
                                cprintf("Core %d trying to request 0/ switch to _S\n", vcoreid);
                case TEST_SWITCH_TO_RUNNABLE_S:
                        if (vcoreid == 2) {
                                cprintf("Core %d trying to request 0/ switch to _S\n", vcoreid);
-                               retval = sys_resource_req(RES_CORES, 0, 0);
+                               retval = sys_resource_req(RES_CORES, 0, 0, 0);
                                // will only see this if we are scheduled()
                                cprintf("Core %d back up! (retval:%d)\n", vcoreid, retval);
                                cprintf("And exiting\n");
                                // will only see this if we are scheduled()
                                cprintf("Core %d back up! (retval:%d)\n", vcoreid, retval);
                                cprintf("And exiting\n");
@@ -163,7 +163,7 @@ static void global_tests(uint32_t vcoreid)
                        while(1);
                case TEST_CRAZY_YIELDS:
                        udelay(300000*vcoreid, 1995014570);
                        while(1);
                case TEST_CRAZY_YIELDS:
                        udelay(300000*vcoreid, 1995014570);
-                       sys_resource_req(RES_CORES, 7, 0);
+                       sys_resource_req(RES_CORES, 7, 1, 0);
                        yield();
                        cprintf("should  never see me, unless you slip into *_S\n");
                        break;
                        yield();
                        cprintf("should  never see me, unless you slip into *_S\n");
                        break;
index 3cc2d3f..e483e48 100644 (file)
@@ -69,7 +69,8 @@ error_t     sys_proc_run(int pid);
 void *COUNT(length) sys_mmap(void *SNT addr, size_t length, int prot, int flags,
                              int fd, size_t offset);
 /* Resource Requests */
 void *COUNT(length) sys_mmap(void *SNT addr, size_t length, int prot, int flags,
                              int fd, size_t offset);
 /* Resource Requests */
-ssize_t sys_resource_req(int type, size_t amount, uint32_t flags);
+ssize_t sys_resource_req(int type, size_t amt_wanted, size_t amt_wanted_min,
+                         uint32_t flags);
 
 /* Generic Async Call */
 error_t     waiton_syscall(syscall_desc_t* desc, syscall_rsp_t*COUNT(1) rsp);
 
 /* Generic Async Call */
 error_t     waiton_syscall(syscall_desc_t* desc, syscall_rsp_t*COUNT(1) rsp);
index f6076ae..6a89cc6 100644 (file)
@@ -159,7 +159,8 @@ sys_mmap(void *SNT addr, size_t length, int prot, int flags, int fd,
 }
 
 /* Request resources from the kernel.  Flags in ros/resource.h. */
 }
 
 /* Request resources from the kernel.  Flags in ros/resource.h. */
-ssize_t sys_resource_req(int type, size_t amount, uint32_t flags)
+ssize_t sys_resource_req(int type, size_t amt_wanted, size_t amt_wanted_min,
+                         uint32_t flags)
 {
 {
-       return syscall(SYS_resource_req, type, amount, flags, 0, 0);
+       return syscall(SYS_resource_req, type, amt_wanted, amt_wanted_min, flags, 0);
 }
 }