m5.c (4098:9b57d3d6af2a) | m5.c (5754:b50a557f93df) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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; --- 15 unchanged lines hidden (view full) --- 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. 27 * 28 * Authors: Nathan Binkert 29 */ 30 31#include <inttypes.h> | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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; --- 15 unchanged lines hidden (view full) --- 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. 27 * 28 * Authors: Nathan Binkert 29 */ 30 31#include <inttypes.h> |
32#include <err.h> 33#include <fcntl.h> |
|
32#include <stdio.h> 33#include <stdlib.h> 34#include <string.h> 35#include <unistd.h> 36 37#include "m5op.h" 38 39char *progname; | 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> 37#include <unistd.h> 38 39#include "m5op.h" 40 41char *progname; |
42char *command = "unspecified"; 43void usage(); |
|
40 41void | 44 45void |
42usage() | 46parse_int_args(int argc, char *argv[], uint64_t ints[], int len) |
43{ | 47{ |
44 printf("usage: m5 initparam\n" 45 " m5 sw99param\n" 46 " m5 exit [delay]\n" 47 " m5 resetstats [delay [period]]\n" 48 " m5 dumpstats [delay [period]]\n" 49 " m5 dumpresetstats [delay [period]]\n" 50 " m5 checkpoint [delay [period]]\n" 51 " m5 readfile\n" 52 "\n" 53 "All times in nanoseconds!\n"); 54 exit(1); | 48 if (argc > len) 49 usage(); 50 51 int i; 52 for (i = 0; i < len; ++i) 53 ints[i] = (i < argc) ? strtoul(argv[i], NULL, 0) : 0; |
55} 56 | 54} 55 |
57#define COMPARE(X) (strcmp(X, command) == 0) 58 | |
59int | 56int |
60main(int argc, char *argv[]) | 57read_file(int dest_fid) |
61{ | 58{ |
62 char *command; 63 uint64_t param; 64 uint64_t arg1 = 0; 65 uint64_t arg2 = 0; | 59 char buf[256*1024]; 60 int offset = 0; 61 int len; |
66 | 62 |
67 progname = argv[0]; 68 if (argc < 2) | 63 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { 64 write(dest_fid, buf, len); 65 offset += len; 66 } 67} 68 69void 70do_exit(int argc, char *argv[]) 71{ 72 if (argc > 1) |
69 usage(); 70 | 73 usage(); 74 |
71 command = argv[1]; | 75 m5_exit((argc > 0) ? strtoul(argv[0], NULL, 0) : 0); 76} |
72 | 77 |
73 if (COMPARE("initparam")) { 74 if (argc != 2) 75 usage(); | 78void 79do_reset_stats(int argc, char *argv[]) 80{ 81 uint64_t ints[2]; 82 parse_int_args(argc, argv, ints, 2); 83 m5_reset_stats(ints[0], ints[1]); 84} |
76 | 85 |
77 printf("%ld", m5_initparam()); 78 return 0; 79 } | 86void 87do_dump_stats(int argc, char *argv[]) 88{ 89 uint64_t ints[2]; 90 parse_int_args(argc, argv, ints, 2); 91 m5_dump_stats(ints[0], ints[1]); 92} |
80 | 93 |
81 if (COMPARE("sw99param")) { 82 if (argc != 2) 83 usage(); | 94void 95do_dump_reset_stats(int argc, char *argv[]) 96{ 97 uint64_t ints[2]; 98 parse_int_args(argc, argv, ints, 2); 99 m5_dumpreset_stats(ints[0], ints[1]); 100} |
84 | 101 |
85 param = m5_initparam(); 86 // run-time, rampup-time, rampdown-time, warmup-time, connections 87 printf("%d %d %d %d %d", (param >> 48) & 0xfff, 88 (param >> 36) & 0xfff, (param >> 24) & 0xfff, 89 (param >> 12) & 0xfff, (param >> 0) & 0xfff); | 102void 103do_read_file(int argc, char *argv[]) 104{ 105 if (argc > 0) 106 usage(); |
90 | 107 |
91 return 0; 92 } | 108 read_file(STDOUT_FILENO); 109} |
93 | 110 |
94 if (COMPARE("exit")) { 95 switch (argc) { 96 case 3: 97 arg1 = strtoul(argv[2], NULL, 0); 98 case 2: 99 m5_exit(arg1); 100 return 0; | 111void 112do_exec_file(int argc, char *argv[]) 113{ 114 if (argc > 0) 115 usage(); |
101 | 116 |
102 default: 103 usage(); 104 } | 117 const char *destname = "/tmp/execfile"; 118 119 int fid = open(destname, O_WRONLY, 0777); 120 int len = read_file(fid); 121 close(fid); 122 if (len > 0) { 123 execl(destname, "execfile", NULL); 124 err(1, "execl failed!"); |
105 } | 125 } |
126} |
|
106 | 127 |
107 if (COMPARE("resetstats")) { 108 switch (argc) { 109 case 4: 110 arg2 = strtoul(argv[3], NULL, 0); 111 case 3: 112 arg1 = strtoul(argv[2], NULL, 0); 113 case 2: 114 m5_reset_stats(arg1, arg2); 115 return 0; | 128void 129do_checkpoint(int argc, char *argv[]) 130{ 131 uint64_t ints[2]; 132 parse_int_args(argc, argv, ints, 2); 133 m5_checkpoint(ints[0], ints[1]); 134} |
116 | 135 |
117 default: 118 usage(); 119 } 120 } | 136void 137do_load_symbol(int argc, char *argv[]) 138{ 139 if (argc != 2) 140 usage(); |
121 | 141 |
122 if (COMPARE("dumpstats")) { 123 switch (argc) { 124 case 4: 125 arg2 = strtoul(argv[3], NULL, 0); 126 case 3: 127 arg1 = strtoul(argv[2], NULL, 0); 128 case 2: 129 m5_dump_stats(arg1, arg2); 130 return 0; | 142 uint64_t addr = strtoul(argv[0], NULL, 0); 143 char *symbol = argv[1]; 144 m5_loadsymbol(addr, symbol); 145} |
131 | 146 |
132 default: 133 usage(); 134 } 135 } | 147void 148do_initparam(int argc, char *argv[]) 149{ 150 if (argc != 0) 151 usage(); |
136 | 152 |
137 if (COMPARE("dumpresetstats")) { 138 switch (argc) { 139 case 4: 140 arg2 = strtoul(argv[3], NULL, 0); 141 case 3: 142 arg1 = strtoul(argv[2], NULL, 0); 143 case 2: 144 m5_dumpreset_stats(arg1, arg2); 145 return 0; | 153 154 printf("%ld", m5_initparam()); 155} |
146 | 156 |
147 default: 148 usage(); 149 } 150 } | 157void 158do_sw99param(int argc, char *argv[]) 159{ 160 if (argc != 0) 161 usage(); |
151 | 162 |
152 if (COMPARE("readfile")) { 153 char buf[256*1024]; 154 int offset = 0; 155 int len; | 163 uint64_t param = m5_initparam(); |
156 | 164 |
157 if (argc != 2) 158 usage(); | 165 // run-time, rampup-time, rampdown-time, warmup-time, connections 166 printf("%d %d %d %d %d", (param >> 48) & 0xfff, 167 (param >> 36) & 0xfff, (param >> 24) & 0xfff, 168 (param >> 12) & 0xfff, (param >> 0) & 0xfff); 169} |
159 | 170 |
160 while ((len = m5_readfile(buf, sizeof(buf), offset)) > 0) { 161 write(STDOUT_FILENO, buf, len); 162 offset += len; 163 } | 171struct MainFunc 172{ 173 char *name; 174 void (*func)(int argc, char *argv[]); 175 char *usage; 176}; |
164 | 177 |
165 return 0; | 178struct MainFunc mainfuncs[] = { 179 { "exit", do_exit, "[delay]" }, 180 { "resetstats", do_reset_stats, "[delay [period]]" }, 181 { "dumpstats", do_dump_stats, "[delay [period]]" }, 182 { "dumpresetstats", do_dump_reset_stats, "[delay [period]]" }, 183 { "readfile", do_read_file, "[filename]" }, 184 { "execfile", do_exec_file, "<filename>" }, 185 { "checkpoint", do_checkpoint, "[delay [period]]" }, 186 { "loadsymbol", do_load_symbol, "<address> <symbol>" }, 187 { "initparam", do_initparam, "" }, 188 { "sw99param", do_sw99param, "" }, 189}; 190int numfuncs = sizeof(mainfuncs) / sizeof(mainfuncs[0]); 191 192void 193usage() 194{ 195 int i; 196 197 for (i = 0; i < numfuncs; ++i) { 198 char *header = i ? "" : "usage:"; 199 fprintf(stderr, "%-6s %s %s %s\n", 200 header, progname, mainfuncs[i].name, mainfuncs[i].usage); |
166 } | 201 } |
202 fprintf(stderr, "\n"); 203 fprintf(stderr, "All times in nanoseconds!\n"); |
|
167 | 204 |
168 if (COMPARE("checkpoint")) { 169 switch (argc) { 170 case 4: 171 arg2 = strtoul(argv[3], NULL, 0); 172 case 3: 173 arg1 = strtoul(argv[2], NULL, 0); 174 case 2: 175 m5_checkpoint(arg1, arg2); 176 return 0; | 205 exit(1); 206} |
177 | 207 |
178 default: 179 usage(); 180 } | 208int 209main(int argc, char *argv[]) 210{ 211 progname = argv[0]; 212 if (argc < 2) 213 usage(1); |
181 | 214 |
182 return 0; 183 } | 215 command = argv[1]; |
184 | 216 |
185 if (COMPARE("loadsymbol")) { 186 m5_loadsymbol(arg1); 187 return 0; | 217 argv += 2; 218 argc -= 2; 219 220 int i; 221 for (i = 0; i < numfuncs; ++i) { 222 if (strcmp(command, mainfuncs[i].name) != 0) 223 continue; 224 225 mainfuncs[i].func(argc, argv); 226 exit(0); |
188 } | 227 } |
189 usage(); | 228 229 usage(1); |
190} | 230} |