Monitor enhancements
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 1 May 2010 06:15:50 +0000 (23:15 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:46 +0000 (17:35 -0700)
Allows for reading the procinfo (unlocked!) of a process, which would
deadlock the system if the lock was already held.  Also allows for the
unlocking of arbitrary locks (you provide the address).

This will help with killing the EXPER_TRADPROCs, which don't want to die
anymore.  Just unlock them, and they will go away.  Yikes.

kern/src/monitor.c
kern/src/process.c

index 130415d..d0a9ef8 100644 (file)
@@ -309,7 +309,7 @@ int mon_procinfo(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf)
                printk("\trunnable: show proc_runnablelist\n");
                printk("\tresources: show resources wanted/granted for all procs\n");
                printk("\tpid NUM: show a lot of info for proc NUM\n");
-               printk("\tunlock NUM: unlock the lock for proc NUM (OMG!!!)\n");
+               printk("\tunlock: unlock the lock for the ADDR (OMG!!!)\n");
                printk("\tkill NUM: destroy proc NUM\n");
                return 1;
        }
@@ -329,16 +329,15 @@ int mon_procinfo(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf)
                print_proc_info(strtol(argv[2], 0, 0));
        } else if (!strcmp(argv[1], "unlock")) {
                if (argc != 3) {
-                       printk("Give me a pid number.\n");
+                       printk("Gimme lock address!  Me want lock address!.\n");
                        return 1;
                }
-               struct proc *p = pid2proc(strtol(argv[2], 0, 0));
-               if (!p) {
-                       printk("No such proc\n");
+               spinlock_t *lock = (spinlock_t*)strtol(argv[2], 0, 16);
+               if (!lock) {
+                       printk("Null address...\n");
                        return 1;
                }
-               spin_unlock(&p->proc_lock);
-               proc_decref(p, 1);
+               spin_unlock(lock);
        } else if (!strcmp(argv[1], "kill")) {
                if (argc != 3) {
                        printk("Give me a pid number.\n");
index 97fbd66..c89d49e 100644 (file)
@@ -1691,14 +1691,18 @@ void print_allpids(void)
 void print_proc_info(pid_t pid)
 {
        int j = 0;
-       struct proc *p = pid2proc(pid);
+       /* Doing this without the incref! careful! (avoiding deadlocks) TODO (REF)*/
+       //struct proc *p = pid2proc(pid);
+       spin_lock(&pid_hash_lock);
+       struct proc *p = hashtable_search(pid_hash, (void*)pid);
+       spin_unlock(&pid_hash_lock);
        // not concerned with a race on the state...
        if (!p) {
                printk("Bad PID.\n");
                return;
        }
        spinlock_debug(&p->proc_lock);
-       spin_lock(&p->proc_lock);
+       //spin_lock(&p->proc_lock); // No locking!!
        printk("struct proc: %p\n", p);
        printk("PID: %d\n", p->pid);
        printk("PPID: %d\n", p->ppid);
@@ -1720,6 +1724,7 @@ void print_proc_info(pid_t pid)
        /* No one cares, and it clutters the terminal */
        //printk("Vcore 0's Last Trapframe:\n");
        //print_trapframe(&p->env_tf);
-       spin_unlock(&p->proc_lock);
-       proc_decref(p, 1); /* decref for the pid2proc reference */
+       /* no locking / unlocking or refcnting */
+       // spin_unlock(&p->proc_lock);
+       // proc_decref(p, 1); /* decref for the pid2proc reference */
 }