diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2012-01-09 18:08:20 -0600 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2012-01-09 18:08:20 -0600 |
commit | c2dbfc1d6ca677f9b6fb8eaa60e4003a903e26bd (patch) | |
tree | 1835c4773d4f647f337fa40cecb8cbff48a0fb9e /src/base | |
parent | 4b772782871f265cf7372c984ad750803396938c (diff) | |
download | gem5-c2dbfc1d6ca677f9b6fb8eaa60e4003a903e26bd.tar.xz |
MAC: Make gem5 compile and run on MacOSX 10.7.2
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.
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/hostinfo.cc | 32 | ||||
-rw-r--r-- | src/base/hostinfo.hh | 8 |
2 files changed, 37 insertions, 3 deletions
diff --git a/src/base/hostinfo.cc b/src/base/hostinfo.cc index 5ff34e603..857ccfa7f 100644 --- a/src/base/hostinfo.cc +++ b/src/base/hostinfo.cc @@ -30,6 +30,12 @@ #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 +} diff --git a/src/base/hostinfo.hh b/src/base/hostinfo.hh index ac7d40f13..d9a30481a 100644 --- a/src/base/hostinfo.hh +++ b/src/base/hostinfo.hh @@ -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__ |