summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2012-01-16 04:27:10 -0800
committerGabe Black <gblack@eecs.umich.edu>2012-01-16 04:27:10 -0800
commitda2a4acc26ba264c3c4a12495776fd6a1c4fb133 (patch)
treef142100388b9d1403492c97b0d323728ce18ef8a /src/base
parent241cc0c8402f1b9f2ec20d1cc152d96930959b2a (diff)
parenta7394ad6807bd5e85f680184bf308673ca00534a (diff)
downloadgem5-da2a4acc26ba264c3c4a12495776fd6a1c4fb133.tar.xz
Merge yet again with the main repository.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/hostinfo.cc32
-rw-r--r--src/base/hostinfo.hh8
-rw-r--r--src/base/random.cc11
-rw-r--r--src/base/statistics.hh5
-rw-r--r--src/base/stats/info.hh1
-rw-r--r--src/base/stats/text.cc15
6 files changed, 66 insertions, 6 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__
diff --git a/src/base/random.cc b/src/base/random.cc
index 457b0c98b..cffeddec9 100644
--- a/src/base/random.cc
+++ b/src/base/random.cc
@@ -29,6 +29,7 @@
* Ali Saidi
*/
+#include <limits>
#include "base/fenv.hh"
#include "base/intmath.hh"
#include "base/misc.hh"
@@ -67,7 +68,10 @@ Random::genrand(uint32_t max)
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint32_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint32_t) * 8 - log);
uint32_t random;
@@ -83,7 +87,10 @@ Random::genrand(uint64_t max)
{
if (max == 0)
return 0;
- int log = ceilLog2(max) + 1;
+ if (max == std::numeric_limits<uint64_t>::max())
+ return genrand();
+
+ int log = ceilLog2(max + 1);
int shift = (sizeof(uint64_t) * 8 - log);
uint64_t random;
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index d98c79414..1f8a59326 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -1477,6 +1477,8 @@ class HistStor
/** The current sum. */
Counter sum;
+ /** The sum of logarithm of each sample, used to compute geometric mean. */
+ Counter logs;
/** The sum of squares. */
Counter squares;
/** The number of samples. */
@@ -1528,6 +1530,7 @@ class HistStor
sum += val * number;
squares += val * val * number;
+ logs += log(val) * number;
samples += number;
}
@@ -1567,6 +1570,7 @@ class HistStor
data.cvec[i] = cvec[i];
data.sum = sum;
+ data.logs = logs;
data.squares = squares;
data.samples = samples;
}
@@ -1589,6 +1593,7 @@ class HistStor
sum = Counter();
squares = Counter();
samples = Counter();
+ logs = Counter();
}
};
diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh
index 2c5b44a38..98e811747 100644
--- a/src/base/stats/info.hh
+++ b/src/base/stats/info.hh
@@ -183,6 +183,7 @@ struct DistData
VCounter cvec;
Counter sum;
Counter squares;
+ Counter logs;
Counter samples;
};
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index 683ba7fe4..8fb49dc59 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -367,6 +367,12 @@ DistPrint::operator()(ostream &stream) const
print.value = data.samples ? data.sum / data.samples : NAN;
print(stream);
+ if (data.type == Hist) {
+ print.name = base + "gmean";
+ print.value = data.samples ? exp(data.logs / data.samples) : NAN;
+ print(stream);
+ }
+
Result stdev = NAN;
if (data.samples)
stdev = sqrt((data.samples * data.squares - data.sum * data.sum) /
@@ -507,7 +513,14 @@ Text::visit(const Vector2dInfo &info)
bool havesub = false;
VectorPrint print;
- print.subnames = info.y_subnames;
+ if (!info.y_subnames.empty()) {
+ for (off_type i = 0; i < info.y; ++i) {
+ if (!info.y_subnames[i].empty()) {
+ print.subnames = info.y_subnames;
+ }
+ break;
+ }
+ }
print.flags = info.flags;
print.separatorString = info.separatorString;
print.descriptions = descriptions;