2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
47 char *command
= "unspecified";
51 parse_int_args(int argc
, char *argv
[], uint64_t ints
[], int len
)
57 for (i
= 0; i
< len
; ++i
)
58 ints
[i
] = (i
< argc
) ? strtoul(argv
[i
], NULL
, 0) : 0;
62 read_file(int dest_fid
)
68 // Touch all buffer pages to ensure they are mapped in the
69 // page table. This is required in the case of X86_FS, where
70 // Linux does demand paging.
71 memset(buf
, 0, sizeof(buf
));
73 while ((len
= m5_readfile(buf
, sizeof(buf
), offset
)) > 0) {
74 write(dest_fid
, buf
, len
);
80 do_exit(int argc
, char *argv
[])
85 m5_exit((argc
> 0) ? strtoul(argv
[0], NULL
, 0) : 0);
89 do_reset_stats(int argc
, char *argv
[])
92 parse_int_args(argc
, argv
, ints
, 2);
93 m5_reset_stats(ints
[0], ints
[1]);
97 do_dump_stats(int argc
, char *argv
[])
100 parse_int_args(argc
, argv
, ints
, 2);
101 m5_dump_stats(ints
[0], ints
[1]);
105 do_dump_reset_stats(int argc
, char *argv
[])
108 parse_int_args(argc
, argv
, ints
, 2);
109 m5_dumpreset_stats(ints
[0], ints
[1]);
113 do_read_file(int argc
, char *argv
[])
118 read_file(STDOUT_FILENO
);
122 do_exec_file(int argc
, char *argv
[])
127 const char *destname
= "/tmp/execfile";
129 int fid
= open(destname
, O_WRONLY
, 0777);
130 int len
= read_file(fid
);
133 execl(destname
, "execfile", NULL
);
134 err(1, "execl failed!");
139 do_checkpoint(int argc
, char *argv
[])
142 parse_int_args(argc
, argv
, ints
, 2);
143 m5_checkpoint(ints
[0], ints
[1]);
147 do_load_symbol(int argc
, char *argv
[])
152 uint64_t addr
= strtoul(argv
[0], NULL
, 0);
153 char *symbol
= argv
[1];
154 m5_loadsymbol(addr
, symbol
);
158 do_initparam(int argc
, char *argv
[])
164 printf("%ld", m5_initparam());
168 do_sw99param(int argc
, char *argv
[])
173 uint64_t param
= m5_initparam();
175 // run-time, rampup-time, rampdown-time, warmup-time, connections
176 printf("%d %d %d %d %d", (param
>> 48) & 0xfff,
177 (param
>> 36) & 0xfff, (param
>> 24) & 0xfff,
178 (param
>> 12) & 0xfff, (param
>> 0) & 0xfff);
183 do_pin(int argc
, char *argv
[])
191 const char *sep
= ",";
192 char *target
= strtok(argv
[0], sep
);
194 CPU_SET(atoi(target
), &mask
);
195 target
= strtok(NULL
, sep
);
198 if (sched_setaffinity(0, sizeof(cpu_set_t
), &mask
) < 0)
199 err(1, "setaffinity");
201 execvp(argv
[1], &argv
[1]);
202 err(1, "execvp failed!");
209 void (*func
)(int argc
, char *argv
[]);
213 struct MainFunc mainfuncs
[] = {
214 { "exit", do_exit
, "[delay]" },
215 { "resetstats", do_reset_stats
, "[delay [period]]" },
216 { "dumpstats", do_dump_stats
, "[delay [period]]" },
217 { "dumpresetstats", do_dump_reset_stats
, "[delay [period]]" },
218 { "readfile", do_read_file
, "[filename]" },
219 { "execfile", do_exec_file
, "<filename>" },
220 { "checkpoint", do_checkpoint
, "[delay [period]]" },
221 { "loadsymbol", do_load_symbol
, "<address> <symbol>" },
222 { "initparam", do_initparam
, "" },
223 { "sw99param", do_sw99param
, "" },
225 { "pin", do_pin
, "<cpu> <program> [args ...]" }
228 int numfuncs
= sizeof(mainfuncs
) / sizeof(mainfuncs
[0]);
235 for (i
= 0; i
< numfuncs
; ++i
) {
236 char *header
= i
? "" : "usage:";
237 fprintf(stderr
, "%-6s %s %s %s\n",
238 header
, progname
, mainfuncs
[i
].name
, mainfuncs
[i
].usage
);
240 fprintf(stderr
, "\n");
241 fprintf(stderr
, "All times in nanoseconds!\n");
247 main(int argc
, char *argv
[])
259 for (i
= 0; i
< numfuncs
; ++i
) {
260 if (strcmp(command
, mainfuncs
[i
].name
) != 0)
263 mainfuncs
[i
].func(argc
, argv
);