Fixed up manager macros and fork()'s test
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 23 Jul 2010 23:33:28 +0000 (16:33 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:49 +0000 (17:35 -0700)
kern/src/manager.c
kern/src/syscall.c
tests/fork.c

index 92b600b..b224db2 100644 (file)
@@ -53,24 +53,33 @@ void manager(void)
        MANAGER_FUNC(DEVELOPER_NAME)();
 }
 
-/* Helper macro for quickly running something out of KFS.  Pass it a string and
- * a proc pointer. */
-#define quick_proc_run(x, p)                                                     \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+/* Helper macro for quickly running a process.  Pass it a string, *file, and a
+ * *proc. */
+#define quick_proc_run(x, p, f)                                                  \
+       (f) = path_to_file((x));                                                     \
+       assert((f));                                                                 \
+       (p) = proc_create(f, 0, 0);                                                  \
+       atomic_dec(&(f)->f_refcnt);                                                  \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);                                                \
        proc_run((p));                                                               \
        proc_decref((p), 1);
 
-#define quick_proc_create(x, p)                                                  \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+#define quick_proc_create(x, p, f)                                               \
+       (f) = path_to_file((x));                                                     \
+       assert((f));                                                                 \
+       (p) = proc_create(f, 0, 0);                                                  \
+       atomic_dec(&(f)->f_refcnt);                                                  \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);
 
-#define quick_proc_color_run(x, p, c)                                            \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+#define quick_proc_color_run(x, p, c, f)                                         \
+       (f) = path_to_file((x));                                                     \
+       assert((f));                                                                 \
+       (p) = proc_create(f, 0, 0);                                                  \
+       atomic_dec(&(f)->f_refcnt);                                                  \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);                                                \
@@ -80,8 +89,11 @@ void manager(void)
        proc_run((p));                                                               \
        proc_decref((p), 1);
 
-#define quick_proc_color_create(x, p, c)                                         \
-       (p) = kfs_proc_create(kfs_lookup_path((x)));                                 \
+#define quick_proc_color_create(x, p, c, f)                                      \
+       (f) = path_to_file((x));                                                     \
+       assert((f));                                                                 \
+       (p) = proc_create(f, 0, 0);                                                  \
+       atomic_dec(&(f)->f_refcnt);                                                  \
        spin_lock(&(p)->proc_lock);                                                  \
        __proc_set_state((p), PROC_RUNNABLE_S);                                      \
        spin_unlock(&(p)->proc_lock);                                                \
@@ -93,6 +105,7 @@ void manager_brho(void)
 {
        static uint8_t RACY progress = 0;
        static struct proc *p;
+       struct file *temp_f;
 
        // for testing taking cores, check in case 1 for usage
        uint32_t corelist[MAX_NUM_CPUS];
@@ -100,11 +113,10 @@ void manager_brho(void)
 
        switch (progress++) {
                case 0:
-                       monitor(0);
                        /* 124 is half of the available boxboro colors (with the kernel
                         * getting 8) */
-                       //quick_proc_color_run("msr_dumb_while", p, 124);
-                       //quick_proc_run("mhello", p);
+                       //quick_proc_color_run("msr_dumb_while", p, 124, temp_f);
+                       quick_proc_run("/bin/hello", p, temp_f);
                        #if 0
                        // this is how you can transition to a parallel process manually
                        // make sure you don't proc run first
index c59d8b8..b25b8d8 100644 (file)
@@ -207,7 +207,7 @@ static int sys_proc_create(struct proc *p, const char *DANGEROUS path)
        user_mem_strlcpy(p, t_path, path, MAX_PATH_LEN, PTE_USER_RO);
        program = path_to_file(t_path);
        if (!program)
-               return -1;
+               return -1;                      /* presumably, errno is already set */
        new_p = proc_create(program, 0, 0);
        pid = new_p->pid;
        proc_decref(new_p, 1);  /* give up the reference created in proc_create() */
@@ -352,6 +352,8 @@ static ssize_t sys_fork(env_t* e)
 
        // don't decref the new process.
        // that will happen when the parent waits for it.
+       // TODO: if the parent doesn't wait, we need to change the child's parent
+       // when the parent dies, or at least decref it
 
        printd("[PID %d] fork PID %d\n",e->pid,env->pid);
 
index b1bd6d8..11ea1c7 100644 (file)
@@ -1,14 +1,19 @@
 #include <stdlib.h>
 #include <rstdio.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 int main(int argc, char** argv)
 {
+       int status;
        pid_t pid = 0;
        pid = fork();
-       if (pid)
+       if (pid) {
                printf("Hello world from parent!!\n");
-       else 
+               waitpid(pid, &status, 0);
+       } else {
                printf("Hello world from child!!\n");
+       }
        return 0;
 }