Debug code to see remote kmsgs
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 May 2012 21:55:04 +0000 (14:55 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 5 Sep 2012 21:43:58 +0000 (14:43 -0700)
Mostly useful for resolving deadlocks - you can see what kmsgs are on
remote cores.  It won't deal with races (though I can build that in if
we want).

The easiest way to use it on x86 is to "trace coretf coreid", since I
built it in the NMI handler.  Or you can kfunc print_kmsgs 0xcoreid
(remember, kfunc deals with hex!).

kern/arch/i686/trap.c
kern/arch/riscv/trap.c
kern/arch/sparc/trap.c
kern/include/trap.h

index 2f330e2..1672534 100644 (file)
@@ -252,6 +252,7 @@ static void trap_dispatch(struct trapframe *tf)
                        char *fn_name = get_fn_name(tf->tf_eip);
                        printk("Core %d is at %08p (%s)\n", core_id(), tf->tf_eip, fn_name);
                        kfree(fn_name);
+                       print_kmsgs(core_id());
                        break;
                case T_BRKPT:
                        enable_irq();
@@ -703,3 +704,23 @@ void process_routine_kmsg(struct trapframe *tf)
                msg_cp.pc(tf, msg_cp.srcid, msg_cp.arg0, msg_cp.arg1, msg_cp.arg2);
        }
 }
+
+/* extremely dangerous and racy: prints out the immed and routine kmsgs for a
+ * specific core (so possibly remotely) */
+void print_kmsgs(uint32_t coreid)
+{
+       struct per_cpu_info *pcpui = &per_cpu_info[coreid];
+       void __print_kmsgs(struct kernel_msg_list *list, char *type)
+       {
+               char *fn_name;
+               struct kernel_message *kmsg_i;
+               STAILQ_FOREACH(kmsg_i, list, link) {
+                       fn_name = get_fn_name((long)kmsg_i->pc);
+                       printk("%s KMSG on %d from %d to run %08p(%s)\n", type,
+                              kmsg_i->dstid, kmsg_i->srcid, kmsg_i->pc, fn_name); 
+                       kfree(fn_name);
+               }
+       }
+       __print_kmsgs(&pcpui->immed_amsgs, "Immedte");
+       __print_kmsgs(&pcpui->routine_amsgs, "Routine");
+}
index b5e600d..364cf19 100644 (file)
@@ -260,6 +260,26 @@ process_routine_kmsg(struct trapframe *tf)
        }
 }
 
+/* extremely dangerous and racy: prints out the immed and routine kmsgs for a
+ * specific core (so possibly remotely).  Same as x86. */
+void print_kmsgs(uint32_t coreid)
+{
+       struct per_cpu_info *pcpui = &per_cpu_info[coreid];
+       void __print_kmsgs(struct kernel_msg_list *list, char *type)
+       {
+               char *fn_name;
+               struct kernel_message *kmsg_i;
+               STAILQ_FOREACH(kmsg_i, list, link) {
+                       fn_name = get_fn_name((long)kmsg_i->pc);
+                       printk("%s KMSG on %d from %d to run %08p(%s)\n", type,
+                              kmsg_i->dstid, kmsg_i->srcid, kmsg_i->pc, fn_name); 
+                       kfree(fn_name);
+               }
+       }
+       __print_kmsgs(&pcpui->immed_amsgs, "Immedte");
+       __print_kmsgs(&pcpui->routine_amsgs, "Routine");
+}
+
 static void
 unhandled_trap(trapframe_t* state, const char* name)
 {
index c14dbde..9a1f0e8 100644 (file)
@@ -312,6 +312,26 @@ void process_routine_kmsg(struct trapframe *tf)
        }
 }
 
+/* extremely dangerous and racy: prints out the immed and routine kmsgs for a
+ * specific core (so possibly remotely).  Same as x86. */
+void print_kmsgs(uint32_t coreid)
+{
+       struct per_cpu_info *pcpui = &per_cpu_info[coreid];
+       void __print_kmsgs(struct kernel_msg_list *list, char *type)
+       {
+               char *fn_name;
+               struct kernel_message *kmsg_i;
+               STAILQ_FOREACH(kmsg_i, list, link) {
+                       fn_name = get_fn_name((long)kmsg_i->pc);
+                       printk("%s KMSG on %d from %d to run %08p(%s)\n", type,
+                              kmsg_i->dstid, kmsg_i->srcid, kmsg_i->pc, fn_name); 
+                       kfree(fn_name);
+               }
+       }
+       __print_kmsgs(&pcpui->immed_amsgs, "Immedte");
+       __print_kmsgs(&pcpui->routine_amsgs, "Routine");
+}
+
 void
 unhandled_trap(trapframe_t* state)
 {
index ad02681..0caac34 100644 (file)
@@ -97,5 +97,6 @@ typedef struct kernel_message kernel_message_t;
 uint32_t send_kernel_message(uint32_t dst, amr_t pc, long arg0, long arg1,
                              long arg2, int type);
 void process_routine_kmsg(struct trapframe *tf);
+void print_kmsgs(uint32_t coreid);
 
 #endif /* ROS_KERN_TRAP_H */