abstract_mem.cc (9236:c38988024f1f) | abstract_mem.cc (9293:df7c3f99ebca) |
---|---|
1/* 2 * Copyright (c) 2010-2012 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 28 unchanged lines hidden (view full) --- 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Ron Dreslinski 41 * Ali Saidi 42 * Andreas Hansson 43 */ 44 | 1/* 2 * Copyright (c) 2010-2012 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software --- 28 unchanged lines hidden (view full) --- 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Ron Dreslinski 41 * Ali Saidi 42 * Andreas Hansson 43 */ 44 |
45#include <sys/mman.h> 46#include <sys/types.h> 47#include <sys/user.h> 48#include <fcntl.h> 49#include <unistd.h> 50#include <zlib.h> 51 52#include <cerrno> 53#include <cstdio> 54#include <climits> 55#include <iostream> 56#include <string> 57 | |
58#include "arch/registers.hh" 59#include "config/the_isa.hh" 60#include "debug/LLSC.hh" 61#include "debug/MemoryAccess.hh" 62#include "mem/abstract_mem.hh" 63#include "mem/packet_access.hh" 64#include "sim/system.hh" 65 66using namespace std; 67 68AbstractMemory::AbstractMemory(const Params *p) : 69 MemObject(p), range(params()->range), pmemAddr(NULL), 70 confTableReported(p->conf_table_reported), inAddrMap(p->in_addr_map), 71 _system(NULL) 72{ 73 if (size() % TheISA::PageBytes != 0) 74 panic("Memory Size not divisible by page size\n"); | 45#include "arch/registers.hh" 46#include "config/the_isa.hh" 47#include "debug/LLSC.hh" 48#include "debug/MemoryAccess.hh" 49#include "mem/abstract_mem.hh" 50#include "mem/packet_access.hh" 51#include "sim/system.hh" 52 53using namespace std; 54 55AbstractMemory::AbstractMemory(const Params *p) : 56 MemObject(p), range(params()->range), pmemAddr(NULL), 57 confTableReported(p->conf_table_reported), inAddrMap(p->in_addr_map), 58 _system(NULL) 59{ 60 if (size() % TheISA::PageBytes != 0) 61 panic("Memory Size not divisible by page size\n"); |
75 76 if (params()->null) 77 return; 78 79 int map_flags = MAP_ANON | MAP_PRIVATE; 80 pmemAddr = (uint8_t *)mmap(NULL, size(), 81 PROT_READ | PROT_WRITE, map_flags, -1, 0); 82 83 if (pmemAddr == (void *)MAP_FAILED) { 84 perror("mmap"); 85 fatal("Could not mmap!\n"); 86 } 87 88 //If requested, initialize all the memory to 0 89 if (p->zero) 90 memset(pmemAddr, 0, size()); | |
91} 92 | 62} 63 |
93 94AbstractMemory::~AbstractMemory() | 64void 65AbstractMemory::setBackingStore(uint8_t* pmem_addr) |
95{ | 66{ |
96 if (pmemAddr) 97 munmap((char*)pmemAddr, size()); | 67 pmemAddr = pmem_addr; |
98} 99 100void 101AbstractMemory::regStats() 102{ 103 using namespace Stats; 104 105 assert(system()); --- 332 unchanged lines hidden (view full) --- 438 prs->printLabels(); 439 // Right now we just print the single byte at the specified address. 440 ccprintf(prs->os, "%s%#x\n", prs->curPrefix(), *hostAddr); 441 } else { 442 panic("AbstractMemory: unimplemented functional command %s", 443 pkt->cmdString()); 444 } 445} | 68} 69 70void 71AbstractMemory::regStats() 72{ 73 using namespace Stats; 74 75 assert(system()); --- 332 unchanged lines hidden (view full) --- 408 prs->printLabels(); 409 // Right now we just print the single byte at the specified address. 410 ccprintf(prs->os, "%s%#x\n", prs->curPrefix(), *hostAddr); 411 } else { 412 panic("AbstractMemory: unimplemented functional command %s", 413 pkt->cmdString()); 414 } 415} |
446 447void 448AbstractMemory::serialize(ostream &os) 449{ 450 if (!pmemAddr) 451 return; 452 453 gzFile compressedMem; 454 string filename = name() + ".physmem"; 455 long _size = range.size(); 456 457 SERIALIZE_SCALAR(filename); 458 SERIALIZE_SCALAR(_size); 459 460 // write memory file 461 string thefile = Checkpoint::dir() + "/" + filename.c_str(); 462 int fd = creat(thefile.c_str(), 0664); 463 if (fd < 0) { 464 perror("creat"); 465 fatal("Can't open physical memory checkpoint file '%s'\n", filename); 466 } 467 468 compressedMem = gzdopen(fd, "wb"); 469 if (compressedMem == NULL) 470 fatal("Insufficient memory to allocate compression state for %s\n", 471 filename); 472 473 uint64_t pass_size = 0; 474 // gzwrite fails if (int)len < 0 (gzwrite returns int) 475 for (uint64_t written = 0; written < size(); written += pass_size) { 476 pass_size = (uint64_t)INT_MAX < (size() - written) ? 477 (uint64_t)INT_MAX : (size() - written); 478 479 if (gzwrite(compressedMem, pmemAddr + written, 480 (unsigned int) pass_size) != (int)pass_size) { 481 fatal("Write failed on physical memory checkpoint file '%s'\n", 482 filename); 483 } 484 } 485 486 if (gzclose(compressedMem)) 487 fatal("Close failed on physical memory checkpoint file '%s'\n", 488 filename); 489 490 list<LockedAddr>::iterator i = lockedAddrList.begin(); 491 492 vector<Addr> lal_addr; 493 vector<int> lal_cid; 494 while (i != lockedAddrList.end()) { 495 lal_addr.push_back(i->addr); 496 lal_cid.push_back(i->contextId); 497 i++; 498 } 499 arrayParamOut(os, "lal_addr", lal_addr); 500 arrayParamOut(os, "lal_cid", lal_cid); 501} 502 503void 504AbstractMemory::unserialize(Checkpoint *cp, const string §ion) 505{ 506 if (!pmemAddr) 507 return; 508 509 gzFile compressedMem; 510 long *tempPage; 511 long *pmem_current; 512 uint64_t curSize; 513 uint32_t bytesRead; 514 const uint32_t chunkSize = 16384; 515 516 string filename; 517 518 UNSERIALIZE_SCALAR(filename); 519 520 filename = cp->cptDir + "/" + filename; 521 522 // mmap memoryfile 523 int fd = open(filename.c_str(), O_RDONLY); 524 if (fd < 0) { 525 perror("open"); 526 fatal("Can't open physical memory checkpoint file '%s'", filename); 527 } 528 529 compressedMem = gzdopen(fd, "rb"); 530 if (compressedMem == NULL) 531 fatal("Insufficient memory to allocate compression state for %s\n", 532 filename); 533 534 // unmap file that was mmapped in the constructor 535 // This is done here to make sure that gzip and open don't muck with our 536 // nice large space of memory before we reallocate it 537 munmap((char*)pmemAddr, size()); 538 539 long _size; 540 UNSERIALIZE_SCALAR(_size); 541 if (_size > params()->range.size()) 542 fatal("Memory size has changed! size %lld, param size %lld\n", 543 _size, params()->range.size()); 544 545 pmemAddr = (uint8_t *)mmap(NULL, size(), 546 PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); 547 548 if (pmemAddr == (void *)MAP_FAILED) { 549 perror("mmap"); 550 fatal("Could not mmap physical memory!\n"); 551 } 552 553 curSize = 0; 554 tempPage = (long*)malloc(chunkSize); 555 if (tempPage == NULL) 556 fatal("Unable to malloc memory to read file %s\n", filename); 557 558 /* Only copy bytes that are non-zero, so we don't give the VM system hell */ 559 while (curSize < size()) { 560 bytesRead = gzread(compressedMem, tempPage, chunkSize); 561 if (bytesRead == 0) 562 break; 563 564 assert(bytesRead % sizeof(long) == 0); 565 566 for (uint32_t x = 0; x < bytesRead / sizeof(long); x++) 567 { 568 if (*(tempPage+x) != 0) { 569 pmem_current = (long*)(pmemAddr + curSize + x * sizeof(long)); 570 *pmem_current = *(tempPage+x); 571 } 572 } 573 curSize += bytesRead; 574 } 575 576 free(tempPage); 577 578 if (gzclose(compressedMem)) 579 fatal("Close failed on physical memory checkpoint file '%s'\n", 580 filename); 581 582 vector<Addr> lal_addr; 583 vector<int> lal_cid; 584 arrayParamIn(cp, section, "lal_addr", lal_addr); 585 arrayParamIn(cp, section, "lal_cid", lal_cid); 586 for(int i = 0; i < lal_addr.size(); i++) 587 lockedAddrList.push_front(LockedAddr(lal_addr[i], lal_cid[i])); 588} | |