atomic.cc revision 5336
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282760Sbinkertn@umich.edu * Authors: Steve Reinhardt 292760Sbinkertn@umich.edu */ 302665Ssaidi@eecs.umich.edu 312SN/A#include "arch/locked_mem.hh" 322SN/A#include "arch/mmaped_ipr.hh" 332SN/A#include "arch/utility.hh" 342SN/A#include "base/bigint.hh" 352SN/A#include "cpu/exetrace.hh" 362SN/A#include "cpu/simple/atomic.hh" 372SN/A#include "mem/packet.hh" 382SN/A#include "mem/packet_access.hh" 392SN/A#include "params/AtomicSimpleCPU.hh" 402SN/A#include "sim/system.hh" 412SN/A 424841Ssaidi@eecs.umich.eduusing namespace std; 432SN/Ausing namespace TheISA; 44217SN/A 452SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c) 4656SN/A : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) 472SN/A{ 482738Sstever@eecs.umich.edu} 49395SN/A 50237SN/A 514000Ssaidi@eecs.umich.eduvoid 522SN/AAtomicSimpleCPU::TickEvent::process() 53217SN/A{ 54502SN/A cpu->tick(); 55217SN/A} 56217SN/A 57237SN/Aconst char * 58502SN/AAtomicSimpleCPU::TickEvent::description() const 59217SN/A{ 60217SN/A return "AtomicSimpleCPU tick"; 61217SN/A} 62217SN/A 63217SN/APort * 64217SN/AAtomicSimpleCPU::getPort(const std::string &if_name, int idx) 654841Ssaidi@eecs.umich.edu{ 664841Ssaidi@eecs.umich.edu if (if_name == "dcache_port") 674841Ssaidi@eecs.umich.edu return &dcachePort; 684841Ssaidi@eecs.umich.edu else if (if_name == "icache_port") 69237SN/A return &icachePort; 70217SN/A else if (if_name == "physmem_port") { 71217SN/A hasPhysMemPort = true; 724841Ssaidi@eecs.umich.edu return &physmemPort; 734841Ssaidi@eecs.umich.edu } 744841Ssaidi@eecs.umich.edu else 754841Ssaidi@eecs.umich.edu panic("No Such Port\n"); 76237SN/A} 77237SN/A 784000Ssaidi@eecs.umich.eduvoid 79237SN/AAtomicSimpleCPU::init() 80237SN/A{ 81217SN/A BaseCPU::init(); 82217SN/A cpuId = tc->readCpuId(); 83217SN/A#if FULL_SYSTEM 84237SN/A for (int i = 0; i < threadContexts.size(); ++i) { 85222SN/A ThreadContext *tc = threadContexts[i]; 86217SN/A 87237SN/A // initialize CPU, including PC 88217SN/A TheISA::initCPU(tc, cpuId); 89223SN/A } 90223SN/A#endif 91223SN/A if (hasPhysMemPort) { 92223SN/A bool snoop = false; 93223SN/A AddrRangeList pmAddrList; 94223SN/A physmemPort.getPeerAddressRanges(pmAddrList, snoop); 95237SN/A physMemAddr = *pmAddrList.begin(); 96223SN/A } 97223SN/A ifetch_req.setThreadContext(cpuId, 0); // Add thread ID if we add MT 98223SN/A data_read_req.setThreadContext(cpuId, 0); // Add thread ID here too 99217SN/A data_write_req.setThreadContext(cpuId, 0); // Add thread ID here too 100217SN/A} 101217SN/A 102217SN/Abool 103237SN/AAtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt) 104237SN/A{ 105237SN/A panic("AtomicSimpleCPU doesn't expect recvTiming callback!"); 106237SN/A return true; 107237SN/A} 108237SN/A 1094000Ssaidi@eecs.umich.eduTick 110237SN/AAtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt) 111237SN/A{ 112237SN/A //Snooping a coherence request, just return 113217SN/A return 0; 1142SN/A} 1152SN/A 1162SN/Avoid 117395SN/AAtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt) 1182SN/A{ 1192SN/A //No internal storage to update, just return 120510SN/A return; 121510SN/A} 1222SN/A 1232SN/Avoid 124395SN/AAtomicSimpleCPU::CpuPort::recvStatusChange(Status status) 125395SN/A{ 1262SN/A if (status == RangeChange) { 127265SN/A if (!snoopRangeSent) { 128512SN/A snoopRangeSent = true; 1292SN/A sendStatusChange(Port::RangeChange); 130510SN/A } 131237SN/A return; 132237SN/A } 133395SN/A 134237SN/A panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!"); 1352SN/A} 1362287SN/A 1372287SN/Avoid 1382287SN/AAtomicSimpleCPU::CpuPort::recvRetry() 1392868Sktlim@umich.edu{ 1402868Sktlim@umich.edu panic("AtomicSimpleCPU doesn't expect recvRetry callback!"); 141395SN/A} 1422SN/A 1432SN/Avoid 1442SN/AAtomicSimpleCPU::DcachePort::setPeer(Port *port) 145395SN/A{ 146395SN/A Port::setPeer(port); 1472SN/A 1482SN/A#if FULL_SYSTEM 1492SN/A // Update the ThreadContext's memory ports (Functional/Virtual 150395SN/A // Ports) 1512SN/A cpu->tcBase()->connectMemPorts(); 152395SN/A#endif 1532SN/A} 1542SN/A 155395SN/AAtomicSimpleCPU::AtomicSimpleCPU(Params *p) 1562SN/A : BaseSimpleCPU(p), tickEvent(this), 157395SN/A width(p->width), simulate_stalls(p->simulate_stalls), 1582SN/A icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this), 1592SN/A physmemPort(name() + "-iport", this), hasPhysMemPort(false) 1602SN/A{ 161395SN/A _status = Idle; 1622SN/A 163395SN/A icachePort.snoopRangeSent = false; 1642SN/A dcachePort.snoopRangeSent = false; 165395SN/A 1662SN/A} 1672SN/A 168395SN/A 169395SN/AAtomicSimpleCPU::~AtomicSimpleCPU() 1702SN/A{ 1712SN/A} 1722SN/A 173395SN/Avoid 174395SN/AAtomicSimpleCPU::serialize(ostream &os) 1752SN/A{ 1762SN/A SimObject::State so_state = SimObject::getState(); 1772SN/A SERIALIZE_ENUM(so_state); 1782SN/A Status _status = status(); 1792SN/A SERIALIZE_ENUM(_status); 1802SN/A BaseSimpleCPU::serialize(os); 181395SN/A nameOut(os, csprintf("%s.tickEvent", name())); 1822SN/A tickEvent.serialize(os); 1832SN/A} 1842SN/A 1852SN/Avoid 1862SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1872SN/A{ 1882SN/A SimObject::State so_state; 1892SN/A UNSERIALIZE_ENUM(so_state); 190395SN/A UNSERIALIZE_ENUM(_status); 191395SN/A BaseSimpleCPU::unserialize(cp, section); 1922738Sstever@eecs.umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 1932SN/A} 1942SN/A 1952SN/Avoid 1962SN/AAtomicSimpleCPU::resume() 1972SN/A{ 198395SN/A if (_status == Idle || _status == SwitchedOut) 199395SN/A return; 2002SN/A 201395SN/A DPRINTF(SimpleCPU, "Resume\n"); 2022SN/A assert(system->getMemoryMode() == Enums::atomic); 203395SN/A 2042SN/A changeState(SimObject::Running); 205395SN/A if (thread->status() == ThreadContext::Active) { 2062738Sstever@eecs.umich.edu if (!tickEvent.scheduled()) { 2072SN/A tickEvent.schedule(nextCycle()); 2082SN/A } 2092SN/A } 2102SN/A} 211395SN/A 2122SN/Avoid 2132SN/AAtomicSimpleCPU::switchOut() 214237SN/A{ 215395SN/A assert(status() == Running || status() == Idle); 216237SN/A _status = SwitchedOut; 2172SN/A 2182797Sktlim@umich.edu tickEvent.squash(); 2192868Sktlim@umich.edu} 2202797Sktlim@umich.edu 221237SN/A 222237SN/Avoid 223237SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 224237SN/A{ 225237SN/A BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort); 226237SN/A 227395SN/A assert(!tickEvent.scheduled()); 228237SN/A 229237SN/A // if any of this CPU's ThreadContexts are active, mark the CPU as 2302738Sstever@eecs.umich.edu // running and schedule its tick event. 231237SN/A for (int i = 0; i < threadContexts.size(); ++i) { 232937SN/A ThreadContext *tc = threadContexts[i]; 233937SN/A if (tc->status() == ThreadContext::Active && _status != Running) { 234237SN/A _status = Running; 235237SN/A tickEvent.schedule(nextCycle()); 236237SN/A break; 237237SN/A } 2384000Ssaidi@eecs.umich.edu } 239304SN/A if (_status != Running) { 240304SN/A _status = Idle; 241449SN/A } 242449SN/A assert(threadContexts.size() == 1); 243449SN/A cpuId = tc->readCpuId(); 244449SN/A ifetch_req.setThreadContext(cpuId, 0); // Add thread ID if we add MT 245449SN/A data_read_req.setThreadContext(cpuId, 0); // Add thread ID here too 246449SN/A data_write_req.setThreadContext(cpuId, 0); // Add thread ID here too 247449SN/A} 248449SN/A 249449SN/A 250449SN/Avoid 251449SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay) 252449SN/A{ 253449SN/A DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 254237SN/A 2552SN/A assert(thread_num == 0); 2562SN/A assert(thread); 257 258 assert(_status == Idle); 259 assert(!tickEvent.scheduled()); 260 261 notIdleFraction++; 262 numCycles += tickToCycles(thread->lastActivate - thread->lastSuspend); 263 264 //Make sure ticks are still on multiples of cycles 265 tickEvent.schedule(nextCycle(curTick + ticks(delay))); 266 _status = Running; 267} 268 269 270void 271AtomicSimpleCPU::suspendContext(int thread_num) 272{ 273 DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 274 275 assert(thread_num == 0); 276 assert(thread); 277 278 assert(_status == Running); 279 280 // tick event may not be scheduled if this gets called from inside 281 // an instruction's execution, e.g. "quiesce" 282 if (tickEvent.scheduled()) 283 tickEvent.deschedule(); 284 285 notIdleFraction--; 286 _status = Idle; 287} 288 289 290template <class T> 291Fault 292AtomicSimpleCPU::read(Addr addr, T &data, unsigned flags) 293{ 294 // use the CPU's statically allocated read request and packet objects 295 Request *req = &data_read_req; 296 297 if (traceData) { 298 traceData->setAddr(addr); 299 } 300 301 //The block size of our peer. 302 int blockSize = dcachePort.peerBlockSize(); 303 //The size of the data we're trying to read. 304 int dataSize = sizeof(T); 305 306 uint8_t * dataPtr = (uint8_t *)&data; 307 308 //The address of the second part of this access if it needs to be split 309 //across a cache line boundary. 310 Addr secondAddr = roundDown(addr + dataSize - 1, blockSize); 311 312 if(secondAddr > addr) 313 dataSize = secondAddr - addr; 314 315 dcache_latency = 0; 316 317 while(1) { 318 req->setVirt(0, addr, dataSize, flags, thread->readPC()); 319 320 // translate to physical address 321 Fault fault = thread->translateDataReadReq(req); 322 323 // Now do the access. 324 if (fault == NoFault) { 325 Packet pkt = Packet(req, 326 req->isLocked() ? MemCmd::LoadLockedReq : MemCmd::ReadReq, 327 Packet::Broadcast); 328 pkt.dataStatic(dataPtr); 329 330 if (req->isMmapedIpr()) 331 dcache_latency += TheISA::handleIprRead(thread->getTC(), &pkt); 332 else { 333 if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 334 dcache_latency += physmemPort.sendAtomic(&pkt); 335 else 336 dcache_latency += dcachePort.sendAtomic(&pkt); 337 } 338 dcache_access = true; 339 340 assert(!pkt.isError()); 341 342 if (req->isLocked()) { 343 TheISA::handleLockedRead(thread, req); 344 } 345 } 346 347 // This will need a new way to tell if it has a dcache attached. 348 if (req->isUncacheable()) 349 recordEvent("Uncached Read"); 350 351 //If there's a fault, return it 352 if (fault != NoFault) 353 return fault; 354 //If we don't need to access a second cache line, stop now. 355 if (secondAddr <= addr) 356 { 357 data = gtoh(data); 358 return fault; 359 } 360 361 /* 362 * Set up for accessing the second cache line. 363 */ 364 365 //Move the pointer we're reading into to the correct location. 366 dataPtr += dataSize; 367 //Adjust the size to get the remaining bytes. 368 dataSize = addr + sizeof(T) - secondAddr; 369 //And access the right address. 370 addr = secondAddr; 371 } 372} 373 374Fault 375AtomicSimpleCPU::translateDataReadAddr(Addr vaddr, Addr & paddr, 376 int size, unsigned flags) 377{ 378 // use the CPU's statically allocated read request and packet objects 379 Request *req = &data_read_req; 380 381 if (traceData) { 382 traceData->setAddr(vaddr); 383 } 384 385 //The block size of our peer. 386 int blockSize = dcachePort.peerBlockSize(); 387 //The size of the data we're trying to read. 388 int dataSize = size; 389 390 bool firstTimeThrough = true; 391 392 //The address of the second part of this access if it needs to be split 393 //across a cache line boundary. 394 Addr secondAddr = roundDown(vaddr + dataSize - 1, blockSize); 395 396 if(secondAddr > vaddr) 397 dataSize = secondAddr - vaddr; 398 399 while(1) { 400 req->setVirt(0, vaddr, dataSize, flags, thread->readPC()); 401 402 // translate to physical address 403 Fault fault = thread->translateDataReadReq(req); 404 405 //If there's a fault, return it 406 if (fault != NoFault) 407 return fault; 408 409 if (firstTimeThrough) { 410 paddr = req->getPaddr(); 411 firstTimeThrough = false; 412 } 413 414 //If we don't need to access a second cache line, stop now. 415 if (secondAddr <= vaddr) 416 return fault; 417 418 /* 419 * Set up for accessing the second cache line. 420 */ 421 422 //Adjust the size to get the remaining bytes. 423 dataSize = vaddr + size - secondAddr; 424 //And access the right address. 425 vaddr = secondAddr; 426 } 427} 428 429#ifndef DOXYGEN_SHOULD_SKIP_THIS 430 431template 432Fault 433AtomicSimpleCPU::read(Addr addr, Twin32_t &data, unsigned flags); 434 435template 436Fault 437AtomicSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags); 438 439template 440Fault 441AtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags); 442 443template 444Fault 445AtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags); 446 447template 448Fault 449AtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags); 450 451template 452Fault 453AtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags); 454 455#endif //DOXYGEN_SHOULD_SKIP_THIS 456 457template<> 458Fault 459AtomicSimpleCPU::read(Addr addr, double &data, unsigned flags) 460{ 461 return read(addr, *(uint64_t*)&data, flags); 462} 463 464template<> 465Fault 466AtomicSimpleCPU::read(Addr addr, float &data, unsigned flags) 467{ 468 return read(addr, *(uint32_t*)&data, flags); 469} 470 471 472template<> 473Fault 474AtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags) 475{ 476 return read(addr, (uint32_t&)data, flags); 477} 478 479 480template <class T> 481Fault 482AtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res) 483{ 484 // use the CPU's statically allocated write request and packet objects 485 Request *req = &data_write_req; 486 487 if (traceData) { 488 traceData->setAddr(addr); 489 } 490 491 //The block size of our peer. 492 int blockSize = dcachePort.peerBlockSize(); 493 //The size of the data we're trying to read. 494 int dataSize = sizeof(T); 495 496 uint8_t * dataPtr = (uint8_t *)&data; 497 498 //The address of the second part of this access if it needs to be split 499 //across a cache line boundary. 500 Addr secondAddr = roundDown(addr + dataSize - 1, blockSize); 501 502 if(secondAddr > addr) 503 dataSize = secondAddr - addr; 504 505 dcache_latency = 0; 506 507 while(1) { 508 req->setVirt(0, addr, dataSize, flags, thread->readPC()); 509 510 // translate to physical address 511 Fault fault = thread->translateDataWriteReq(req); 512 513 // Now do the access. 514 if (fault == NoFault) { 515 MemCmd cmd = MemCmd::WriteReq; // default 516 bool do_access = true; // flag to suppress cache access 517 518 if (req->isLocked()) { 519 cmd = MemCmd::StoreCondReq; 520 do_access = TheISA::handleLockedWrite(thread, req); 521 } else if (req->isSwap()) { 522 cmd = MemCmd::SwapReq; 523 if (req->isCondSwap()) { 524 assert(res); 525 req->setExtraData(*res); 526 } 527 } 528 529 if (do_access) { 530 Packet pkt = Packet(req, cmd, Packet::Broadcast); 531 pkt.dataStatic(dataPtr); 532 533 if (req->isMmapedIpr()) { 534 dcache_latency += 535 TheISA::handleIprWrite(thread->getTC(), &pkt); 536 } else { 537 //XXX This needs to be outside of the loop in order to 538 //work properly for cache line boundary crossing 539 //accesses in transendian simulations. 540 data = htog(data); 541 if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 542 dcache_latency += physmemPort.sendAtomic(&pkt); 543 else 544 dcache_latency += dcachePort.sendAtomic(&pkt); 545 } 546 dcache_access = true; 547 assert(!pkt.isError()); 548 549 if (req->isSwap()) { 550 assert(res); 551 *res = pkt.get<T>(); 552 } 553 } 554 555 if (res && !req->isSwap()) { 556 *res = req->getExtraData(); 557 } 558 } 559 560 // This will need a new way to tell if it's hooked up to a cache or not. 561 if (req->isUncacheable()) 562 recordEvent("Uncached Write"); 563 564 //If there's a fault or we don't need to access a second cache line, 565 //stop now. 566 if (fault != NoFault || secondAddr <= addr) 567 { 568 // If the write needs to have a fault on the access, consider 569 // calling changeStatus() and changing it to "bad addr write" 570 // or something. 571 return fault; 572 } 573 574 /* 575 * Set up for accessing the second cache line. 576 */ 577 578 //Move the pointer we're reading into to the correct location. 579 dataPtr += dataSize; 580 //Adjust the size to get the remaining bytes. 581 dataSize = addr + sizeof(T) - secondAddr; 582 //And access the right address. 583 addr = secondAddr; 584 } 585} 586 587Fault 588AtomicSimpleCPU::translateDataWriteAddr(Addr vaddr, Addr &paddr, 589 int size, unsigned flags) 590{ 591 // use the CPU's statically allocated write request and packet objects 592 Request *req = &data_write_req; 593 594 if (traceData) { 595 traceData->setAddr(vaddr); 596 } 597 598 //The block size of our peer. 599 int blockSize = dcachePort.peerBlockSize(); 600 601 //The address of the second part of this access if it needs to be split 602 //across a cache line boundary. 603 Addr secondAddr = roundDown(vaddr + size - 1, blockSize); 604 605 //The size of the data we're trying to read. 606 int dataSize = size; 607 608 bool firstTimeThrough = true; 609 610 if(secondAddr > vaddr) 611 dataSize = secondAddr - vaddr; 612 613 dcache_latency = 0; 614 615 while(1) { 616 req->setVirt(0, vaddr, dataSize, flags, thread->readPC()); 617 618 // translate to physical address 619 Fault fault = thread->translateDataWriteReq(req); 620 621 //If there's a fault or we don't need to access a second cache line, 622 //stop now. 623 if (fault != NoFault) 624 return fault; 625 626 if (firstTimeThrough) { 627 paddr = req->getPaddr(); 628 firstTimeThrough = false; 629 } 630 631 if (secondAddr <= vaddr) 632 return fault; 633 634 /* 635 * Set up for accessing the second cache line. 636 */ 637 638 //Adjust the size to get the remaining bytes. 639 dataSize = vaddr + size - secondAddr; 640 //And access the right address. 641 vaddr = secondAddr; 642 } 643} 644 645 646#ifndef DOXYGEN_SHOULD_SKIP_THIS 647 648template 649Fault 650AtomicSimpleCPU::write(Twin32_t data, Addr addr, 651 unsigned flags, uint64_t *res); 652 653template 654Fault 655AtomicSimpleCPU::write(Twin64_t data, Addr addr, 656 unsigned flags, uint64_t *res); 657 658template 659Fault 660AtomicSimpleCPU::write(uint64_t data, Addr addr, 661 unsigned flags, uint64_t *res); 662 663template 664Fault 665AtomicSimpleCPU::write(uint32_t data, Addr addr, 666 unsigned flags, uint64_t *res); 667 668template 669Fault 670AtomicSimpleCPU::write(uint16_t data, Addr addr, 671 unsigned flags, uint64_t *res); 672 673template 674Fault 675AtomicSimpleCPU::write(uint8_t data, Addr addr, 676 unsigned flags, uint64_t *res); 677 678#endif //DOXYGEN_SHOULD_SKIP_THIS 679 680template<> 681Fault 682AtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res) 683{ 684 return write(*(uint64_t*)&data, addr, flags, res); 685} 686 687template<> 688Fault 689AtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res) 690{ 691 return write(*(uint32_t*)&data, addr, flags, res); 692} 693 694 695template<> 696Fault 697AtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res) 698{ 699 return write((uint32_t)data, addr, flags, res); 700} 701 702 703void 704AtomicSimpleCPU::tick() 705{ 706 DPRINTF(SimpleCPU, "Tick\n"); 707 708 Tick latency = ticks(1); // instruction takes one cycle by default 709 710 for (int i = 0; i < width; ++i) { 711 numCycles++; 712 713 if (!curStaticInst || !curStaticInst->isDelayedCommit()) 714 checkForInterrupts(); 715 716 Fault fault = setupFetchRequest(&ifetch_req); 717 718 if (fault == NoFault) { 719 Tick icache_latency = 0; 720 bool icache_access = false; 721 dcache_access = false; // assume no dcache access 722 723 //Fetch more instruction memory if necessary 724 //if(predecoder.needMoreBytes()) 725 //{ 726 icache_access = true; 727 Packet ifetch_pkt = Packet(&ifetch_req, MemCmd::ReadReq, 728 Packet::Broadcast); 729 ifetch_pkt.dataStatic(&inst); 730 731 if (hasPhysMemPort && ifetch_pkt.getAddr() == physMemAddr) 732 icache_latency = physmemPort.sendAtomic(&ifetch_pkt); 733 else 734 icache_latency = icachePort.sendAtomic(&ifetch_pkt); 735 736 assert(!ifetch_pkt.isError()); 737 738 // ifetch_req is initialized to read the instruction directly 739 // into the CPU object's inst field. 740 //} 741 742 preExecute(); 743 744 if (curStaticInst) { 745 fault = curStaticInst->execute(this, traceData); 746 747 // keep an instruction count 748 if (fault == NoFault) 749 countInst(); 750 else if (traceData) { 751 // If there was a fault, we should trace this instruction. 752 delete traceData; 753 traceData = NULL; 754 } 755 756 postExecute(); 757 } 758 759 // @todo remove me after debugging with legion done 760 if (curStaticInst && (!curStaticInst->isMicroop() || 761 curStaticInst->isFirstMicroop())) 762 instCnt++; 763 764 if (simulate_stalls) { 765 Tick icache_stall = 766 icache_access ? icache_latency - ticks(1) : 0; 767 Tick dcache_stall = 768 dcache_access ? dcache_latency - ticks(1) : 0; 769 Tick stall_cycles = (icache_stall + dcache_stall) / ticks(1); 770 if (ticks(stall_cycles) < (icache_stall + dcache_stall)) 771 latency += ticks(stall_cycles+1); 772 else 773 latency += ticks(stall_cycles); 774 } 775 776 } 777 if(fault != NoFault || !stayAtPC) 778 advancePC(fault); 779 } 780 781 if (_status != Idle) 782 tickEvent.schedule(curTick + latency); 783} 784 785 786void 787AtomicSimpleCPU::printAddr(Addr a) 788{ 789 dcachePort.printAddr(a); 790} 791 792 793//////////////////////////////////////////////////////////////////////// 794// 795// AtomicSimpleCPU Simulation Object 796// 797AtomicSimpleCPU * 798AtomicSimpleCPUParams::create() 799{ 800 AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params(); 801 params->name = name; 802 params->numberOfThreads = 1; 803 params->max_insts_any_thread = max_insts_any_thread; 804 params->max_insts_all_threads = max_insts_all_threads; 805 params->max_loads_any_thread = max_loads_any_thread; 806 params->max_loads_all_threads = max_loads_all_threads; 807 params->progress_interval = progress_interval; 808 params->deferRegistration = defer_registration; 809 params->phase = phase; 810 params->clock = clock; 811 params->functionTrace = function_trace; 812 params->functionTraceStart = function_trace_start; 813 params->width = width; 814 params->simulate_stalls = simulate_stalls; 815 params->system = system; 816 params->cpu_id = cpu_id; 817 params->tracer = tracer; 818 819 params->itb = itb; 820 params->dtb = dtb; 821#if FULL_SYSTEM 822 params->profile = profile; 823 params->do_quiesce = do_quiesce; 824 params->do_checkpoint_insts = do_checkpoint_insts; 825 params->do_statistics_insts = do_statistics_insts; 826#else 827 if (workload.size() != 1) 828 panic("only one workload allowed"); 829 params->process = workload[0]; 830#endif 831 832 AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params); 833 return cpu; 834} 835