Allow filtering by PID for "db sem"
[akaros.git] / kern / src / kthread.c
index 518f37a..908a40f 100644 (file)
@@ -154,7 +154,13 @@ void restart_kthread(struct kthread *kthread)
                        proc_decref(kthread->proc);
                        kthread->proc = 0;
                } else {
-                       /* Load our page tables before potentially decreffing cur_proc */
+                       /* Load our page tables before potentially decreffing cur_proc.
+                        *
+                        * We don't need to do an EPT flush here.  The EPT is flushed and
+                        * managed in sync with the VMCS.  We won't run a different VM (and
+                        * thus *need* a different EPT) without first removing the old GPC,
+                        * which ultimately will result in a flushed EPT (on x86, this
+                        * actually happens when we clear_owning_proc()). */
                        lcr3(kthread->proc->env_cr3);
                        /* Might have to clear out an existing current.  If they need to be
                         * set later (like in restartcore), it'll be done on demand. */
@@ -587,11 +593,34 @@ static void debug_upped_sem(struct semaphore *sem)
 
 #endif /* CONFIG_SEMAPHORE_DEBUG */
 
-void print_sem_info(struct semaphore *sem)
+static bool __sem_has_pid(struct semaphore *sem, pid_t pid)
 {
        struct kthread *kth_i;
+
+       if (pid == -1)
+               return TRUE;
+       TAILQ_FOREACH(kth_i, &sem->waiters, link) {
+               if (kth_i->proc) {
+                       if (kth_i->proc->pid == pid)
+                               return TRUE;
+               } else {
+                       if (pid == 0)
+                               return TRUE;
+               }
+       }
+       return FALSE;
+}
+
+static void print_sem_info(struct semaphore *sem, pid_t pid)
+{
+       struct kthread *kth_i;
+
        /* Always safe to irqsave */
        spin_lock_irqsave(&sem->lock);
+       if (!__sem_has_pid(sem, pid)) {
+               spin_unlock_irqsave(&sem->lock);
+               return;
+       }
        printk("Semaphore %p has %d signals (neg = waiters)\n", sem,
               sem->nr_signals);
        TAILQ_FOREACH(kth_i, &sem->waiters, link)
@@ -603,14 +632,14 @@ void print_sem_info(struct semaphore *sem)
        spin_unlock_irqsave(&sem->lock);
 }
 
-void print_all_sem_info(void)
+void print_all_sem_info(pid_t pid)
 {
 #ifdef CONFIG_SEMAPHORE_DEBUG
        struct semaphore *sem_i;
        printk("All sems with waiters:\n");
        spin_lock_irqsave(&sems_with_waiters_lock);
        TAILQ_FOREACH(sem_i, &sems_with_waiters, link)
-               print_sem_info(sem_i);
+               print_sem_info(sem_i, pid);
        spin_unlock_irqsave(&sems_with_waiters_lock);
 #else
        printk("Failed to print all sems: build with CONFIG_SEMAPHORE_DEBUG\n");