summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-12-03 04:57:54 -0800
committerNathan Binkert <nate@binkert.org>2008-12-03 04:57:54 -0800
commit47e2b0889359877cb9a86c02c4bdf862fbd87338 (patch)
tree96804612ef449238a5bf3b611c17557d56163001 /util
parentab593c69b6745c49913bd1b18c7a6fa9a3aeb0a4 (diff)
downloadgem5-47e2b0889359877cb9a86c02c4bdf862fbd87338.tar.xz
util/m5: Add a new function called pin to bind a program to a set of cores.
This is not m5 specific and this currently only works in linux.
Diffstat (limited to 'util')
-rw-r--r--util/m5/m5.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/m5/m5.c b/util/m5/m5.c
index 5eb69ea36..7747fc0bc 100644
--- a/util/m5/m5.c
+++ b/util/m5/m5.c
@@ -28,6 +28,11 @@
* Authors: Nathan Binkert
*/
+#ifdef linux
+#define _GNU_SOURCE
+#include <sched.h>
+#endif
+
#include <inttypes.h>
#include <err.h>
#include <fcntl.h>
@@ -168,6 +173,31 @@ do_sw99param(int argc, char *argv[])
(param >> 12) & 0xfff, (param >> 0) & 0xfff);
}
+#ifdef linux
+void
+do_pin(int argc, char *argv[])
+{
+ if (argc < 2)
+ usage();
+
+ cpu_set_t mask;
+ CPU_ZERO(&mask);
+
+ const char *sep = ",";
+ char *target = strtok(argv[0], sep);
+ while (target) {
+ CPU_SET(atoi(target), &mask);
+ target = strtok(NULL, sep);
+ }
+
+ if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) < 0)
+ err(1, "setaffinity");
+
+ execvp(argv[1], &argv[1]);
+ err(1, "execvp failed!");
+}
+#endif
+
struct MainFunc
{
char *name;
@@ -186,6 +216,9 @@ struct MainFunc mainfuncs[] = {
{ "loadsymbol", do_load_symbol, "<address> <symbol>" },
{ "initparam", do_initparam, "" },
{ "sw99param", do_sw99param, "" },
+#ifdef linux
+ { "pin", do_pin, "<cpu> <program> [args ...]" }
+#endif
};
int numfuncs = sizeof(mainfuncs) / sizeof(mainfuncs[0]);