MAC: Make gem5 compile and run on MacOSX 10.7.2
authorAndreas Hansson <andreas.hansson@arm.com>
Tue, 10 Jan 2012 00:08:20 +0000 (18:08 -0600)
committerAndreas Hansson <andreas.hansson@arm.com>
Tue, 10 Jan 2012 00:08:20 +0000 (18:08 -0600)
Adaptations to make gem5 compile and run on OSX 10.7.2, with a stock
gcc 4.2.1 and the remaining dependencies from macports, i.e. python
2.7,.2 swig 2.0.4, mercurial 2.0. The changes include an adaptation of
the SConstruct to handle non-library linker flags, and Darwin-specific
code to find the memory usage of gem5. A number of Ruby files relied
on ambigious uint (without the 32 suffix) which caused compilation
errors.

SConstruct
ext/libelf/SConscript
src/base/hostinfo.cc
src/base/hostinfo.hh
src/cpu/testers/directedtest/DirectedGenerator.hh
src/cpu/testers/directedtest/InvalidateGenerator.cc
src/cpu/testers/directedtest/InvalidateGenerator.hh
src/cpu/testers/directedtest/RubyDirectedTester.hh
src/cpu/testers/directedtest/SeriesRequestGenerator.cc
src/cpu/testers/directedtest/SeriesRequestGenerator.hh

index 89761a4f19bc1f2da608172655a78ec02bc07170..0630cbd79bc78fadd11f9b0c37872f578766b3f9 100755 (executable)
@@ -663,10 +663,14 @@ if not py_getvar('Py_ENABLE_SHARED'):
 
 py_libs = []
 for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
-    assert lib.startswith('-l')
-    lib = lib[2:]   
-    if lib not in py_libs:
-        py_libs.append(lib)
+    if not lib.startswith('-l'):
+        # Python requires some special flags to link (e.g. -framework
+        # common on OS X systems), assume appending preserves order
+        main.Append(LINKFLAGS=[lib])
+    else:
+        lib = lib[2:]
+        if lib not in py_libs:
+            py_libs.append(lib)
 py_libs.append(py_version)
 
 main.Append(CPPPATH=py_includes)
index 1e7fbb465d477966f629d39ab0540249aa4a047b..7f33990d8ed7f3e7091ffd41e6bf2ee10090bb0c 100644 (file)
@@ -91,7 +91,7 @@ ElfFile('libelf_msize.c')
 
 m4env = main.Clone()
 if m4env['GCC']:
-    major,minor,dot = [ int(x) for x in m4env['CXXVERSION'].split('.')]
+    major,minor,dot = [int(x) for x in m4env['GCC_VERSION'].split('.')]
     if major >= 4:
         m4env.Append(CCFLAGS=['-Wno-pointer-sign'])
 m4env.Append(CCFLAGS=['-Wno-implicit'])
index 5ff34e6036ffc43b7157afd9644dc76fcd07cdb8..857ccfa7fbcfba991a8e6b32a76b256c7398cca0 100644 (file)
 
 #include <unistd.h>
 
+#ifdef __APPLE__
+#include <mach/mach_init.h>
+#include <mach/shared_region.h>
+#include <mach/task.h>
+#endif
+
 #include <cctype>
 #include <cerrno>
 #include <cmath>
@@ -82,7 +88,31 @@ procInfo(const char *filename, const char *target)
     }
 
     if (fp)
-      fclose(fp);
+        fclose(fp);
 
     return 0;
 }
+
+uint64_t
+memUsage()
+{
+// For the Mach-based Darwin kernel, use the task_info of the self task
+#ifdef __APPLE__
+    struct task_basic_info t_info;
+    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
+
+    if (KERN_SUCCESS != task_info(mach_task_self(),
+                                  TASK_BASIC_INFO, (task_info_t)&t_info,
+                                  &t_info_count)) {
+        return 0;
+    }
+
+    // Mimic Darwin's implementation of top and subtract
+    // SHARED_REGION_SIZE from the tasks virtual size to account for the
+    // shared memory submap that is incorporated into every process.
+    return (t_info.virtual_size - SHARED_REGION_SIZE) / 1024;
+#else
+    // Linux implementation
+    return procInfo("/proc/self/status", "VmSize:");
+#endif
+}
index ac7d40f13eddaa10ff9e69551d734bdb98bf3ff3..d9a30481a478e6943956869278a365484a1575e1 100644 (file)
@@ -39,7 +39,11 @@ std::string &hostname();
 
 uint64_t procInfo(const char *filename, const char *target);
 
-inline uint64_t memUsage()
-{ return procInfo("/proc/self/status", "VmSize:"); }
+/**
+ * Determine the simulator process' total virtual memory usage.
+ *
+ * @return virtual memory usage in kilobytes
+ */
+uint64_t memUsage();
 
 #endif // __HOSTINFO_HH__
index 904dcf399e11a1b13ecd4f80c6996d143ced593b..c156efff062f0efb72fcd402c6aac0aad7aee0bd 100644 (file)
@@ -43,7 +43,7 @@ class DirectedGenerator : public SimObject
     virtual ~DirectedGenerator() {}
     
     virtual bool initiate() = 0;
-    virtual void performCallback(uint proc, Addr address) = 0;
+    virtual void performCallback(uint32_t proc, Addr address) = 0;
     
     void setDirectedTester(RubyDirectedTester* directed_tester);
     
index 902c6cc15980d93c0c7099360b1091db0a26d113..4d8271a05e4971c6950ac3f16624538420f27365 100644 (file)
@@ -103,7 +103,7 @@ InvalidateGenerator::initiate()
 }
 
 void 
-InvalidateGenerator::performCallback(uint proc, Addr address)
+InvalidateGenerator::performCallback(uint32_t proc, Addr address)
 {
     assert(m_address == address);  
 
index 14c47b70bce9084f5ee1a3222d29f4377c26e7c7..50db180e3c901b8f284b5ce51d7e9cb2449ee47e 100644 (file)
@@ -49,14 +49,14 @@ class InvalidateGenerator : public DirectedGenerator
     ~InvalidateGenerator();
     
     bool initiate();
-    void performCallback(uint proc, Addr address);
+    void performCallback(uint32_t proc, Addr address);
     
   private:
     InvalidateGeneratorStatus m_status;
     Addr m_address;
-    uint m_active_read_node;
-    uint m_active_inv_node;
-    uint m_addr_increment_size;
+    uint32_t m_active_read_node;
+    uint32_t m_active_inv_node;
+    uint32_t m_addr_increment_size;
 };
 
 #endif //__CPU_DIRECTEDTEST_INVALIDATEGENERATOR_HH__
index 163c206d808c209e1eee98399bb29cfd22a64b71..53c3896928bdb1aa1ea86c24a4aa7e374226440d 100644 (file)
@@ -53,11 +53,11 @@ class RubyDirectedTester : public MemObject
         RubyDirectedTester *tester;
 
       public:
-        CpuPort(const std::string &_name, RubyDirectedTester *_tester, uint _idx)
+        CpuPort(const std::string &_name, RubyDirectedTester *_tester, uint32_t _idx)
             : SimpleTimingPort(_name, _tester), tester(_tester), idx(_idx)
         {}
 
-        uint idx;
+        uint32_t idx;
 
       protected:
         virtual bool recvTiming(PacketPtr pkt);
index 43e140178ccb859783ccd819b44da8ef123075b7..4cf9aed1ca6e839a619a143fe81f4f6f4768bf72 100644 (file)
@@ -89,7 +89,7 @@ SeriesRequestGenerator::initiate()
 }
 
 void 
-SeriesRequestGenerator::performCallback(uint proc, Addr address)
+SeriesRequestGenerator::performCallback(uint32_t proc, Addr address)
 {
     assert(m_active_node == proc);
     assert(m_address == address);  
index 97b632a12c576fb395e2533095f89a92ee2324b9..9b1c3e8bad4d4ec28a08df1eeee6e86699c2108c 100644 (file)
@@ -49,13 +49,13 @@ class SeriesRequestGenerator : public DirectedGenerator
     ~SeriesRequestGenerator();
     
     bool initiate();
-    void performCallback(uint proc, Addr address);
+    void performCallback(uint32_t proc, Addr address);
     
   private:
     SeriesRequestGeneratorStatus m_status;
     Addr m_address;
-    uint m_active_node;
-    uint m_addr_increment_size;
+    uint32_t m_active_node;
+    uint32_t m_addr_increment_size;
     bool m_issue_writes;
 };