1/* 2 * Copyright (c) 2003-2006 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; 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. 15 * 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. 27 * 28 * Authors: Nathan Binkert 29 */ 30 31#include <errno.h> 32#include <fcntl.h> 33#include <unistd.h> 34 35#include <fstream> 36#include <string> 37 38#include "arch/vtophys.hh" 39#include "base/annotate.hh" 40#include "cpu/base.hh" 41#include "cpu/thread_context.hh" 42#include "cpu/quiesce_event.hh" 43#include "arch/kernel_stats.hh" 44#include "sim/pseudo_inst.hh" 45#include "sim/serialize.hh" 46#include "sim/sim_exit.hh" 47#include "sim/stat_control.hh" 48#include "sim/stats.hh" 49#include "sim/system.hh" 50#include "sim/debug.hh" 51#include "sim/vptr.hh" 52 53using namespace std; 54 55using namespace Stats; 56using namespace TheISA; 57 58namespace PseudoInst 59{ 60 void 61 arm(ThreadContext *tc) 62 { 63 if (tc->getKernelStats()) 64 tc->getKernelStats()->arm(); 65 } 66 67 void 68 quiesce(ThreadContext *tc) 69 { 70 if (!tc->getCpuPtr()->params->do_quiesce) 71 return; 72 73 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name()); 74 75 tc->suspend(); 76 if (tc->getKernelStats()) 77 tc->getKernelStats()->quiesce(); 78 } 79 80 void 81 quiesceNs(ThreadContext *tc, uint64_t ns) 82 { 83 if (!tc->getCpuPtr()->params->do_quiesce || ns == 0) 84 return; 85 86 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 87 88 Tick resume = curTick + Clock::Int::ns * ns; 89
| 1/* 2 * Copyright (c) 2003-2006 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; 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. 15 * 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. 27 * 28 * Authors: Nathan Binkert 29 */ 30 31#include <errno.h> 32#include <fcntl.h> 33#include <unistd.h> 34 35#include <fstream> 36#include <string> 37 38#include "arch/vtophys.hh" 39#include "base/annotate.hh" 40#include "cpu/base.hh" 41#include "cpu/thread_context.hh" 42#include "cpu/quiesce_event.hh" 43#include "arch/kernel_stats.hh" 44#include "sim/pseudo_inst.hh" 45#include "sim/serialize.hh" 46#include "sim/sim_exit.hh" 47#include "sim/stat_control.hh" 48#include "sim/stats.hh" 49#include "sim/system.hh" 50#include "sim/debug.hh" 51#include "sim/vptr.hh" 52 53using namespace std; 54 55using namespace Stats; 56using namespace TheISA; 57 58namespace PseudoInst 59{ 60 void 61 arm(ThreadContext *tc) 62 { 63 if (tc->getKernelStats()) 64 tc->getKernelStats()->arm(); 65 } 66 67 void 68 quiesce(ThreadContext *tc) 69 { 70 if (!tc->getCpuPtr()->params->do_quiesce) 71 return; 72 73 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name()); 74 75 tc->suspend(); 76 if (tc->getKernelStats()) 77 tc->getKernelStats()->quiesce(); 78 } 79 80 void 81 quiesceNs(ThreadContext *tc, uint64_t ns) 82 { 83 if (!tc->getCpuPtr()->params->do_quiesce || ns == 0) 84 return; 85 86 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent(); 87 88 Tick resume = curTick + Clock::Int::ns * ns; 89
|
117 118 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n", 119 tc->getCpuPtr()->name(), cycles, resume); 120 121 tc->suspend(); 122 if (tc->getKernelStats()) 123 tc->getKernelStats()->quiesce(); 124 } 125 126 uint64_t 127 quiesceTime(ThreadContext *tc) 128 { 129 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns; 130 } 131 132 void 133 m5exit_old(ThreadContext *tc) 134 { 135 exitSimLoop("m5_exit_old instruction encountered"); 136 } 137 138 void 139 m5exit(ThreadContext *tc, Tick delay) 140 { 141 Tick when = curTick + delay * Clock::Int::ns; 142 schedExitSimLoop("m5_exit instruction encountered", when); 143 } 144 145 void 146 loadsymbol(ThreadContext *tc) 147 { 148 const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 149 if (filename.empty()) { 150 return; 151 } 152 153 std::string buffer; 154 ifstream file(filename.c_str()); 155 156 if (!file) 157 fatal("file error: Can't open symbol table file %s\n", filename); 158 159 while (!file.eof()) { 160 getline(file, buffer); 161 162 if (buffer.empty()) 163 continue; 164 165 int idx = buffer.find(' '); 166 if (idx == string::npos) 167 continue; 168 169 string address = "0x" + buffer.substr(0, idx); 170 eat_white(address); 171 if (address.empty()) 172 continue; 173 174 // Skip over letter and space 175 string symbol = buffer.substr(idx + 3); 176 eat_white(symbol); 177 if (symbol.empty()) 178 continue; 179 180 Addr addr; 181 if (!to_number(address, addr)) 182 continue; 183 184 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 185 continue; 186 187 188 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 189 } 190 file.close(); 191 } 192 193 void 194 resetstats(ThreadContext *tc, Tick delay, Tick period) 195 { 196 if (!tc->getCpuPtr()->params->do_statistics_insts) 197 return; 198 199 200 Tick when = curTick + delay * Clock::Int::ns; 201 Tick repeat = period * Clock::Int::ns; 202 203 Stats::StatEvent(false, true, when, repeat); 204 } 205 206 void 207 dumpstats(ThreadContext *tc, Tick delay, Tick period) 208 { 209 if (!tc->getCpuPtr()->params->do_statistics_insts) 210 return; 211 212 213 Tick when = curTick + delay * Clock::Int::ns; 214 Tick repeat = period * Clock::Int::ns; 215 216 Stats::StatEvent(true, false, when, repeat); 217 } 218 219 void 220 addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 221 { 222 char symb[100]; 223 CopyStringOut(tc, symb, symbolAddr, 100); 224 std::string symbol(symb); 225 226 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 227 228 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 229 } 230 231 void 232 anBegin(ThreadContext *tc, uint64_t cur) 233 { 234 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 235 0xFFFFFFFF, 0,0); 236 } 237 238 void 239 anWait(ThreadContext *tc, uint64_t cur, uint64_t wait) 240 { 241 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 242 0xFFFFFFFF, wait >> 32, wait & 0xFFFFFFFF); 243 } 244 245 246 void 247 dumpresetstats(ThreadContext *tc, Tick delay, Tick period) 248 { 249 if (!tc->getCpuPtr()->params->do_statistics_insts) 250 return; 251 252 253 Tick when = curTick + delay * Clock::Int::ns; 254 Tick repeat = period * Clock::Int::ns; 255 256 Stats::StatEvent(true, true, when, repeat); 257 } 258 259 void 260 m5checkpoint(ThreadContext *tc, Tick delay, Tick period) 261 { 262 if (!tc->getCpuPtr()->params->do_checkpoint_insts) 263 return; 264 265 Tick when = curTick + delay * Clock::Int::ns; 266 Tick repeat = period * Clock::Int::ns; 267 268 schedExitSimLoop("checkpoint", when, repeat); 269 } 270 271 uint64_t 272 readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 273 { 274 const string &file = tc->getSystemPtr()->params()->readfile; 275 if (file.empty()) { 276 return ULL(0); 277 } 278 279 uint64_t result = 0; 280 281 int fd = ::open(file.c_str(), O_RDONLY, 0); 282 if (fd < 0) 283 panic("could not open file %s\n", file); 284 285 if (::lseek(fd, offset, SEEK_SET) < 0) 286 panic("could not seek: %s", strerror(errno)); 287 288 char *buf = new char[len]; 289 char *p = buf; 290 while (len > 0) { 291 int bytes = ::read(fd, p, len); 292 if (bytes <= 0) 293 break; 294 295 p += bytes; 296 result += bytes; 297 len -= bytes; 298 } 299 300 close(fd); 301 CopyIn(tc, vaddr, buf, result); 302 delete [] buf; 303 return result; 304 } 305 306 void debugbreak(ThreadContext *tc) 307 { 308 debug_break(); 309 } 310 311 void switchcpu(ThreadContext *tc) 312 { 313 exitSimLoop("switchcpu"); 314 } 315}
| 111 112 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n", 113 tc->getCpuPtr()->name(), cycles, resume); 114 115 tc->suspend(); 116 if (tc->getKernelStats()) 117 tc->getKernelStats()->quiesce(); 118 } 119 120 uint64_t 121 quiesceTime(ThreadContext *tc) 122 { 123 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns; 124 } 125 126 void 127 m5exit_old(ThreadContext *tc) 128 { 129 exitSimLoop("m5_exit_old instruction encountered"); 130 } 131 132 void 133 m5exit(ThreadContext *tc, Tick delay) 134 { 135 Tick when = curTick + delay * Clock::Int::ns; 136 schedExitSimLoop("m5_exit instruction encountered", when); 137 } 138 139 void 140 loadsymbol(ThreadContext *tc) 141 { 142 const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 143 if (filename.empty()) { 144 return; 145 } 146 147 std::string buffer; 148 ifstream file(filename.c_str()); 149 150 if (!file) 151 fatal("file error: Can't open symbol table file %s\n", filename); 152 153 while (!file.eof()) { 154 getline(file, buffer); 155 156 if (buffer.empty()) 157 continue; 158 159 int idx = buffer.find(' '); 160 if (idx == string::npos) 161 continue; 162 163 string address = "0x" + buffer.substr(0, idx); 164 eat_white(address); 165 if (address.empty()) 166 continue; 167 168 // Skip over letter and space 169 string symbol = buffer.substr(idx + 3); 170 eat_white(symbol); 171 if (symbol.empty()) 172 continue; 173 174 Addr addr; 175 if (!to_number(address, addr)) 176 continue; 177 178 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 179 continue; 180 181 182 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 183 } 184 file.close(); 185 } 186 187 void 188 resetstats(ThreadContext *tc, Tick delay, Tick period) 189 { 190 if (!tc->getCpuPtr()->params->do_statistics_insts) 191 return; 192 193 194 Tick when = curTick + delay * Clock::Int::ns; 195 Tick repeat = period * Clock::Int::ns; 196 197 Stats::StatEvent(false, true, when, repeat); 198 } 199 200 void 201 dumpstats(ThreadContext *tc, Tick delay, Tick period) 202 { 203 if (!tc->getCpuPtr()->params->do_statistics_insts) 204 return; 205 206 207 Tick when = curTick + delay * Clock::Int::ns; 208 Tick repeat = period * Clock::Int::ns; 209 210 Stats::StatEvent(true, false, when, repeat); 211 } 212 213 void 214 addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 215 { 216 char symb[100]; 217 CopyStringOut(tc, symb, symbolAddr, 100); 218 std::string symbol(symb); 219 220 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 221 222 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 223 } 224 225 void 226 anBegin(ThreadContext *tc, uint64_t cur) 227 { 228 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 229 0xFFFFFFFF, 0,0); 230 } 231 232 void 233 anWait(ThreadContext *tc, uint64_t cur, uint64_t wait) 234 { 235 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur & 236 0xFFFFFFFF, wait >> 32, wait & 0xFFFFFFFF); 237 } 238 239 240 void 241 dumpresetstats(ThreadContext *tc, Tick delay, Tick period) 242 { 243 if (!tc->getCpuPtr()->params->do_statistics_insts) 244 return; 245 246 247 Tick when = curTick + delay * Clock::Int::ns; 248 Tick repeat = period * Clock::Int::ns; 249 250 Stats::StatEvent(true, true, when, repeat); 251 } 252 253 void 254 m5checkpoint(ThreadContext *tc, Tick delay, Tick period) 255 { 256 if (!tc->getCpuPtr()->params->do_checkpoint_insts) 257 return; 258 259 Tick when = curTick + delay * Clock::Int::ns; 260 Tick repeat = period * Clock::Int::ns; 261 262 schedExitSimLoop("checkpoint", when, repeat); 263 } 264 265 uint64_t 266 readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 267 { 268 const string &file = tc->getSystemPtr()->params()->readfile; 269 if (file.empty()) { 270 return ULL(0); 271 } 272 273 uint64_t result = 0; 274 275 int fd = ::open(file.c_str(), O_RDONLY, 0); 276 if (fd < 0) 277 panic("could not open file %s\n", file); 278 279 if (::lseek(fd, offset, SEEK_SET) < 0) 280 panic("could not seek: %s", strerror(errno)); 281 282 char *buf = new char[len]; 283 char *p = buf; 284 while (len > 0) { 285 int bytes = ::read(fd, p, len); 286 if (bytes <= 0) 287 break; 288 289 p += bytes; 290 result += bytes; 291 len -= bytes; 292 } 293 294 close(fd); 295 CopyIn(tc, vaddr, buf, result); 296 delete [] buf; 297 return result; 298 } 299 300 void debugbreak(ThreadContext *tc) 301 { 302 debug_break(); 303 } 304 305 void switchcpu(ThreadContext *tc) 306 { 307 exitSimLoop("switchcpu"); 308 } 309}
|