kth: Remove irq_state from sem_.*irqsave's interface
[akaros.git] / kern / src / monitor.c
index 3465872..3f26125 100644 (file)
@@ -2,7 +2,6 @@
 // controlling the kernel and exploring the system interactively.
 
 #include <arch/arch.h>
-#include <stab.h>
 #include <smp.h>
 #include <arch/console.h>
 
@@ -24,6 +23,7 @@
 #include <trap.h>
 #include <time.h>
 #include <percpu.h>
+#include <kprof.h>
 
 #include <ros/memlayout.h>
 #include <ros/event.h>
@@ -74,6 +74,7 @@ static command_t commands[] = {
        { "hd", "Hexdump PID's memory (0 for kernel)", mon_hexdump},
        { "pahexdump", "Hexdump physical memory", mon_pahexdump},
        { "phd", "Hexdump physical memory", mon_pahexdump},
+       { "dmesg", "Dump the dmesg buffer", mon_dmesg},
 };
 #define NCOMMANDS (sizeof(commands)/sizeof(commands[0]))
 
@@ -120,8 +121,10 @@ static int __backtrace(int argc, char **argv, struct hw_trapframe *hw_tf)
        }
        pc = strtol(argv[1], 0, 16);
        fp = strtol(argv[2], 0, 16);
+       print_lock();
        printk("Backtrace from instruction %p, with frame pointer %p\n", pc, fp);
        backtrace_frame(pc, fp);
+       print_unlock();
        return 0;
 }
 
@@ -187,13 +190,11 @@ int mon_sm(int argc, char **argv, struct hw_trapframe *hw_tf)
        return __showmapping(argc, argv, hw_tf);
 }
 
-static spinlock_t print_info_lock = SPINLOCK_INITIALIZER_IRQSAVE;
-
 static void print_info_handler(struct hw_trapframe *hw_tf, void *data)
 {
        uint64_t tsc = read_tsc();
 
-       spin_lock_irqsave(&print_info_lock);
+       print_lock();
        cprintf("----------------------------\n");
        cprintf("This is Core %d\n", core_id());
        cprintf("Timestamp = %lld\n", tsc);
@@ -218,7 +219,7 @@ static void print_info_handler(struct hw_trapframe *hw_tf, void *data)
                read_msr(0x20e), read_msr(0x20f));
 #endif // CONFIG_X86
        cprintf("----------------------------\n");
-       spin_unlock_irqsave(&print_info_lock);
+       print_unlock();
 }
 
 static bool print_all_info(void)
@@ -254,6 +255,7 @@ int mon_nanwan(int argc, char **argv, struct hw_trapframe *hw_tf)
        /* Borrowed with love from http://www.geocities.com/SoHo/7373/zoo.htm
         * (http://www.ascii-art.com/).  Slightly modified to make it 25 lines tall.
         */
+       print_lock();
        printk("\n");
        printk("             .-.  .-.\n");
        printk("             |  \\/  |\n");
@@ -278,6 +280,7 @@ int mon_nanwan(int argc, char **argv, struct hw_trapframe *hw_tf)
        printk("                                \\'   .\\#\n");
        printk("                             jgs \\   ::\\#\n");
        printk("                                  \\      \n");
+       print_unlock();
        return 0;
 }
 
@@ -680,22 +683,21 @@ static DEFINE_PERCPU(bool, mon_nmi_trace);
 
 static void emit_hwtf_backtrace(struct hw_trapframe *hw_tf)
 {
-       char *fn_name;
-
        if (mon_verbose_trace) {
+               printk("\n");
                print_trapframe(hw_tf);
                backtrace_hwtf(hw_tf);
        }
-       fn_name = get_fn_name(get_hwtf_pc(hw_tf));
        printk("Core %d is at %p (%s)\n", core_id(), get_hwtf_pc(hw_tf),
-              fn_name);
-       kfree(fn_name);
+              get_fn_name(get_hwtf_pc(hw_tf)));
 }
 
 static void emit_vmtf_backtrace(struct vm_trapframe *vm_tf)
 {
-       if (mon_verbose_trace)
+       if (mon_verbose_trace) {
+               printk("\n");
                print_vmtrapframe(vm_tf);
+       }
        printk("Core %d is at %p\n", core_id(), get_vmtf_pc(vm_tf));
 }
 
@@ -704,22 +706,18 @@ static void emit_vmtf_backtrace(struct vm_trapframe *vm_tf)
  * doesn't deal in contexts (yet) */
 void emit_monitor_backtrace(int type, void *tf)
 {
-       struct per_cpu_info *pcpui = &per_cpu_info[core_id()];
-
        if (!PERCPU_VAR(mon_nmi_trace))
                return;
        /* To prevent a spew of output during a lot of perf NMIs, we'll turn off the
         * monitor output as soon as any NMI hits our core. */
        PERCPU_VAR(mon_nmi_trace) = FALSE;
-       /* Temporarily disable deadlock detection when we print.  We could
-        * deadlock if we were printing when we NMIed. */
-       pcpui->__lock_checking_enabled--;
+       print_lock();
        if (type == ROS_HW_CTX)
                emit_hwtf_backtrace((struct hw_trapframe*)tf);
        else
                emit_vmtf_backtrace((struct vm_trapframe*)tf);
        print_kmsgs(core_id());
-       pcpui->__lock_checking_enabled++;
+       print_unlock();
 }
 
 
@@ -1007,14 +1005,14 @@ int mon_db(int argc, char **argv, struct hw_trapframe *hw_tf)
 
        if (argc < 2) {
                printk("Usage: db OPTION\n");
-               printk("\tsem [PID]: print all semaphore info\n");
+               printk("\tblk [PID]: print all blocked kthreads\n");
                printk("\taddr PID 0xADDR: for PID lookup ADDR's file/vmr info\n");
                return 1;
        }
-       if (!strcmp(argv[1], "sem")) {
+       if (!strcmp(argv[1], "blk") || !strcmp(argv[1], "sem")) {
                if (argc > 2)
                        pid = strtol(argv[2], 0, 0);
-               print_all_sem_info(pid);
+               print_db_blk_info(pid);
        } else if (!strcmp(argv[1], "addr")) {
                if (argc < 4) {
                        printk("Usage: db addr PID 0xADDR\n");
@@ -1214,3 +1212,9 @@ int mon_pahexdump(int argc, char **argv, struct hw_trapframe *hw_tf)
        pahexdump(start, len);
        return 0;
 }
+
+int mon_dmesg(int argc, char **argv, struct hw_trapframe *hw_tf)
+{
+       kprof_dump_data();
+       return 0;
+}