changeset 582b379f6d4f in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=582b379f6d4f
description:
mem: Resolve TrafficGen trace relative to the config
The traffic generator currently resolves relative trace paths relative
to gem5's current working directory. This can lead to surprising
results for relative paths where the expectation would normally be
that they are resolved relative to the configuration file. This
changeset implements config-relative trace file lookups. The old
behavior is kept as a fallback for configs that expect that behavior.
Change-Id: I1bda4e16725842666ffc37dcb6838c23a6ff138c
Signed-off-by: Andreas Sandberg <[email protected]>
Reviewed-by: Curtis Dunham <[email protected]>
diffstat:
src/cpu/testers/traffic_gen/traffic_gen.cc | 27 ++++++++++++++++++++++++++-
src/cpu/testers/traffic_gen/traffic_gen.hh | 15 +++++++++++++++
tests/quick/se/70.tgen/tgen-simple-mem.cfg | 2 +-
3 files changed, 42 insertions(+), 2 deletions(-)
diffs (93 lines):
diff -r de57dbf319d0 -r 582b379f6d4f src/cpu/testers/traffic_gen/traffic_gen.cc
--- a/src/cpu/testers/traffic_gen/traffic_gen.cc Mon Jun 20 14:39:49
2016 +0100
+++ b/src/cpu/testers/traffic_gen/traffic_gen.cc Mon Jun 20 14:49:37
2016 +0100
@@ -38,12 +38,15 @@
* Andreas Hansson
* Sascha Bischoff
*/
+#include "cpu/testers/traffic_gen/traffic_gen.hh"
+
+#include <libgen.h>
+#include <unistd.h>
#include <sstream>
#include "base/intmath.hh"
#include "base/random.hh"
-#include "cpu/testers/traffic_gen/traffic_gen.hh"
#include "debug/Checkpoint.hh"
#include "debug/TrafficGen.hh"
#include "sim/stats.hh"
@@ -229,6 +232,27 @@
}
}
+std::string
+TrafficGen::resolveFile(const std::string &name)
+{
+ // Do nothing for empty and absolute file names
+ if (name.empty() || name[0] == '/')
+ return name;
+
+ char *config_path = strdup(configFile.c_str());
+ char *config_dir = dirname(config_path);
+ const std::string config_rel = csprintf("%s/%s", config_dir, name);
+ free(config_path);
+
+ // Check the path relative to the config file first
+ if (access(config_rel.c_str(), R_OK) == 0)
+ return config_rel;
+
+ // Fall back to the old behavior and search relative to the
+ // current working directory.
+ return name;
+}
+
void
TrafficGen::parseConfig()
{
@@ -273,6 +297,7 @@
Addr addrOffset;
is >> traceFile >> addrOffset;
+ traceFile = resolveFile(traceFile);
states[id] = new TraceGen(name(), masterID, duration,
traceFile, addrOffset);
diff -r de57dbf319d0 -r 582b379f6d4f src/cpu/testers/traffic_gen/traffic_gen.hh
--- a/src/cpu/testers/traffic_gen/traffic_gen.hh Mon Jun 20 14:39:49
2016 +0100
+++ b/src/cpu/testers/traffic_gen/traffic_gen.hh Mon Jun 20 14:49:37
2016 +0100
@@ -76,6 +76,21 @@
void enterState(uint32_t newState);
/**
+ * Resolve a file path in the configuration file.
+ *
+ * This method resolves a relative path to a file that has been
+ * referenced in the configuration file. It first tries to resolve
+ * the file relative to the configuration file's path. If that
+ * fails, it falls back to constructing a path relative to the
+ * current working directory.
+ *
+ * Absolute paths are returned unmodified.
+ *
+ * @param name Path to resolve
+ */
+ std::string resolveFile(const std::string &name);
+
+ /**
* Parse the config file and build the state map and
* transition matrix.
*/
diff -r de57dbf319d0 -r 582b379f6d4f tests/quick/se/70.tgen/tgen-simple-mem.cfg
--- a/tests/quick/se/70.tgen/tgen-simple-mem.cfg Mon Jun 20 14:39:49
2016 +0100
+++ b/tests/quick/se/70.tgen/tgen-simple-mem.cfg Mon Jun 20 14:49:37
2016 +0100
@@ -19,7 +19,7 @@
# and random state is from a uniform random distribution over the
# interval. If a specific value is desired, then the min and max can
# be set to the same value.
-STATE 0 1000000 TRACE tests/quick/se/70.tgen/tgen-simple-mem.trc 100
+STATE 0 1000000 TRACE tgen-simple-mem.trc 100
STATE 1 100000000 RANDOM 0 0 134217728 64 30000 30000 0
STATE 2 1000000000 IDLE
STATE 3 100000000 LINEAR 0 0 134217728 64 30000 30000 0
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev