changeset 55014a40512c in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=55014a40512c
description:
        kern, arm: Dump dmesg on kernel panic/oops

        Add helper functions to dump the guest kernel's dmesg buffer to a text
        file in m5out. This functionality is split into two parts. First, a
        dmesg dump function that can be used in other places:

        void Linux::dumpDmesg(ThreadContext *, std::ostream &)

        This function is used to implement two PCEvents: DmesgDumpEvent and
        KernelPanic event. The only difference between the two is that the
        latter produces a gem5 panic instead of a warning in addition to
        dumping the kernel log.

        Change-Id: I6d2af1d666ace57124089648ea906f6c787ac63c
        Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
        Reviewed-by: Nikos Nikoleris <nikos.nikole...@arm.com>
        Reviewed-by: Gabor Dozsa <gabor.do...@arm.com>

diffstat:

 src/arch/arm/ArmSystem.py    |    8 ++
 src/arch/arm/linux/system.cc |   24 +++++-
 src/arch/arm/linux/system.hh |    6 +
 src/kern/SConscript          |    1 +
 src/kern/linux/events.cc     |   33 +++++++++-
 src/kern/linux/events.hh     |   52 +++++++++++++++
 src/kern/linux/helpers.cc    |  148 +++++++++++++++++++++++++++++++++++++++++++
 src/kern/linux/helpers.hh    |   59 +++++++++++++++++
 8 files changed, 324 insertions(+), 7 deletions(-)

diffs (truncated from 444 to 300 lines):

diff -r 93e2bd032c3b -r 55014a40512c src/arch/arm/ArmSystem.py
--- a/src/arch/arm/ArmSystem.py Mon Jun 20 14:39:48 2016 +0100
+++ b/src/arch/arm/ArmSystem.py Mon Jun 20 14:39:49 2016 +0100
@@ -98,6 +98,14 @@
     type = 'LinuxArmSystem'
     cxx_header = "arch/arm/linux/system.hh"
 
+    @classmethod
+    def export_method_cxx_predecls(cls, code):
+        code('#include "arch/arm/linux/system.hh"')
+
+    @classmethod
+    def export_methods(cls, code):
+        code('''void dumpDmesg();''')
+
 class FreebsdArmSystem(GenericArmSystem):
     type = 'FreebsdArmSystem'
     cxx_header = "arch/arm/freebsd/system.hh"
diff -r 93e2bd032c3b -r 55014a40512c src/arch/arm/linux/system.cc
--- a/src/arch/arm/linux/system.cc      Mon Jun 20 14:39:48 2016 +0100
+++ b/src/arch/arm/linux/system.cc      Mon Jun 20 14:39:49 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2013 ARM Limited
+ * Copyright (c) 2010-2013, 2016 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -53,6 +53,7 @@
 #include "cpu/thread_context.hh"
 #include "debug/Loader.hh"
 #include "kern/linux/events.hh"
+#include "kern/linux/helpers.hh"
 #include "mem/fs_translating_port_proxy.hh"
 #include "mem/physical.hh"
 #include "sim/stat_control.hh"
@@ -65,14 +66,21 @@
       enableContextSwitchStatsDump(p->enable_context_switch_stats_dump),
       taskFile(nullptr), kernelPanicEvent(nullptr), kernelOopsEvent(nullptr)
 {
+    const std::string dmesg_output = name() + ".dmesg";
     if (p->panic_on_panic) {
-        kernelPanicEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
-            "panic", "Kernel panic in simulated kernel");
+        kernelPanicEvent = addKernelFuncEventOrPanic<Linux::KernelPanicEvent>(
+            "panic", "Kernel panic in simulated kernel", dmesg_output);
+    } else {
+        kernelPanicEvent = addKernelFuncEventOrPanic<Linux::DmesgDumpEvent>(
+            "panic", "Kernel panic in simulated kernel", dmesg_output);
     }
 
     if (p->panic_on_oops) {
-        kernelOopsEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
-            "oops_exit", "Kernel oops in guest");
+        kernelOopsEvent = addKernelFuncEventOrPanic<Linux::KernelPanicEvent>(
+            "oops_exit", "Kernel oops in guest", dmesg_output);
+    } else {
+        kernelOopsEvent = addKernelFuncEventOrPanic<Linux::DmesgDumpEvent>(
+            "oops_exit", "Kernel oops in guest", dmesg_output);
     }
 
     // With ARM udelay() is #defined to __udelay
@@ -261,6 +269,12 @@
     }
 }
 
+void
+LinuxArmSystem::dumpDmesg()
+{
+    Linux::dumpDmesg(getThreadContext(0), std::cout);
+}
+
 /** This function is called whenever the the kernel function
  *  "__switch_to" is called to change running tasks.
  *
diff -r 93e2bd032c3b -r 55014a40512c src/arch/arm/linux/system.hh
--- a/src/arch/arm/linux/system.hh      Mon Jun 20 14:39:48 2016 +0100
+++ b/src/arch/arm/linux/system.hh      Mon Jun 20 14:39:49 2016 +0100
@@ -95,6 +95,12 @@
      * @param tc thread context that is currentyl executing  */
     void mapPid(ThreadContext* tc, uint32_t pid);
 
+  public: // Exported Python methods
+    /**
+     * Dump the kernel's dmesg buffer to stdout
+     */
+    void dumpDmesg();
+
   private:
     /** Event to halt the simulator if the kernel calls panic()  */
     PCEvent *kernelPanicEvent;
diff -r 93e2bd032c3b -r 55014a40512c src/kern/SConscript
--- a/src/kern/SConscript       Mon Jun 20 14:39:48 2016 +0100
+++ b/src/kern/SConscript       Mon Jun 20 14:39:49 2016 +0100
@@ -36,6 +36,7 @@
 Source('kernel_stats.cc')
 Source('linux/events.cc')
 Source('linux/linux.cc')
+Source('linux/helpers.cc')
 Source('linux/printk.cc')
 Source('freebsd/events.cc')
 Source('operatingsystem.cc')
diff -r 93e2bd032c3b -r 55014a40512c src/kern/linux/events.cc
--- a/src/kern/linux/events.cc  Mon Jun 20 14:39:48 2016 +0100
+++ b/src/kern/linux/events.cc  Mon Jun 20 14:39:49 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 ARM Limited
+ * Copyright (c) 2011, 2016 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -41,13 +41,17 @@
  *          Ali Saidi
  */
 
+#include "kern/linux/events.hh"
+
 #include <sstream>
 
 #include "arch/utility.hh"
+#include "base/output.hh"
 #include "base/trace.hh"
+#include "cpu/base.hh"
 #include "cpu/thread_context.hh"
 #include "debug/DebugPrintf.hh"
-#include "kern/linux/events.hh"
+#include "kern/linux/helpers.hh"
 #include "kern/linux/printk.hh"
 #include "kern/system_events.hh"
 #include "sim/arguments.hh"
@@ -94,5 +98,30 @@
     }
 }
 
+void
+DmesgDumpEvent::process(ThreadContext *tc)
+{
+    StringWrap name(tc->getCpuPtr()->name() + ".dmesg_dump_event");
+
+    inform("Dumping kernel dmesg buffer to %s...\n", fname);
+    OutputStream *os = simout.create(fname);
+    dumpDmesg(tc, *os->stream());
+    simout.close(os);
+
+    warn(descr());
+}
+
+void
+KernelPanicEvent::process(ThreadContext *tc)
+{
+    StringWrap name(tc->getCpuPtr()->name() + ".dmesg_dump_event");
+
+    inform("Dumping kernel dmesg buffer to %s...\n", fname);
+    OutputStream *os = simout.create(fname);
+    dumpDmesg(tc, *os->stream());
+    simout.close(os);
+
+    panic(descr());
+}
 
 } // namespace linux
diff -r 93e2bd032c3b -r 55014a40512c src/kern/linux/events.hh
--- a/src/kern/linux/events.hh  Mon Jun 20 14:39:48 2016 +0100
+++ b/src/kern/linux/events.hh  Mon Jun 20 14:39:49 2016 +0100
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2016 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2004-2006 The Regents of The University of Michigan
  * All rights reserved.
  *
@@ -44,6 +56,46 @@
     virtual void process(ThreadContext *xc);
 };
 
+/**
+ * Dump the guest kernel's dmesg buffer to a file in gem5's output
+ * directory and print a warning.
+ *
+ * @warn This event uses Linux::dumpDmesg() and comes with the same
+ * limitations. Most importantly, the kernel's address mappings must
+ * be available to the translating proxy.
+ */
+class DmesgDumpEvent : public PCEvent
+{
+  protected:
+    std::string fname;
+
+  public:
+    DmesgDumpEvent(PCEventQueue *q, const std::string &desc, Addr addr,
+                   const std::string &_fname)
+        : PCEvent(q, desc, addr), fname(_fname) {}
+    virtual void process(ThreadContext *xc);
+};
+
+/**
+ * Dump the guest kernel's dmesg buffer to a file in gem5's output
+ * directory and panic.
+ *
+ * @warn This event uses Linux::dumpDmesg() and comes with the same
+ * limitations. Most importantly, the kernel's address mappings must
+ * be available to the translating proxy.
+ */
+class KernelPanicEvent : public PCEvent
+{
+  protected:
+    std::string fname;
+
+  public:
+    KernelPanicEvent(PCEventQueue *q, const std::string &desc, Addr addr,
+               const std::string &_fname)
+        : PCEvent(q, desc, addr), fname(_fname) {}
+    virtual void process(ThreadContext *xc);
+};
+
 /** A class to skip udelay() and related calls in the kernel.
  * This class has two additional parameters that take the argument to udelay 
and
  * manipulated it to come up with ns and eventually ticks to quiesce for.
diff -r 93e2bd032c3b -r 55014a40512c src/kern/linux/helpers.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kern/linux/helpers.cc Mon Jun 20 14:39:49 2016 +0100
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2016 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include "kern/linux/helpers.hh"
+
+#include "arch/isa_traits.hh"
+#include "config/the_isa.hh"
+#include "cpu/thread_context.hh"
+#include "mem/fs_translating_port_proxy.hh"
+#include "sim/system.hh"
+
+struct DmesgEntry {
+    uint64_t ts_nsec;
+    uint16_t len;
+    uint16_t text_len;
+    uint16_t dict_len;
+    uint8_t facility;
+    uint8_t flags;
+} M5_ATTR_PACKED;
+
+static int
+dumpDmesgEntry(const uint8_t *base, const uint8_t *end, std::ostream &os)
+{
+    const size_t max_length = end - base;
+    DmesgEntry de;
+
+    if (max_length < sizeof(de)) {
+        warn("Malformed dmesg entry\n");
+        return -1;
+    }
+
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to