physical.cc (6820:2980bd04e6df) | physical.cc (7730:982b4c6c1470) |
---|---|
1/* 2 * Copyright (c) 2001-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; --- 17 unchanged lines hidden (view full) --- 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ron Dreslinski 29 * Ali Saidi 30 */ 31 32#include <sys/types.h> 33#include <sys/mman.h> | 1/* 2 * Copyright (c) 2001-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; --- 17 unchanged lines hidden (view full) --- 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Ron Dreslinski 29 * Ali Saidi 30 */ 31 32#include <sys/types.h> 33#include <sys/mman.h> |
34#include <sys/user.h> |
|
34#include <errno.h> 35#include <fcntl.h> 36#include <unistd.h> 37#include <zlib.h> 38 39#include <cstdio> 40#include <iostream> 41#include <string> 42 43#include "arch/registers.hh" | 35#include <errno.h> 36#include <fcntl.h> 37#include <unistd.h> 38#include <zlib.h> 39 40#include <cstdio> 41#include <iostream> 42#include <string> 43 44#include "arch/registers.hh" |
45#include "base/intmath.hh" |
|
44#include "base/misc.hh" 45#include "base/random.hh" 46#include "base/types.hh" 47#include "config/full_system.hh" 48#include "config/the_isa.hh" 49#include "mem/packet_access.hh" 50#include "mem/physical.hh" 51#include "sim/eventq.hh" 52 53using namespace std; 54using namespace TheISA; 55 56PhysicalMemory::PhysicalMemory(const Params *p) 57 : MemObject(p), pmemAddr(NULL), pagePtr(0), 58 lat(p->latency), lat_var(p->latency_var), | 46#include "base/misc.hh" 47#include "base/random.hh" 48#include "base/types.hh" 49#include "config/full_system.hh" 50#include "config/the_isa.hh" 51#include "mem/packet_access.hh" 52#include "mem/physical.hh" 53#include "sim/eventq.hh" 54 55using namespace std; 56using namespace TheISA; 57 58PhysicalMemory::PhysicalMemory(const Params *p) 59 : MemObject(p), pmemAddr(NULL), pagePtr(0), 60 lat(p->latency), lat_var(p->latency_var), |
59 cachedSize(params()->range.size()), cachedStart(params()->range.start) | 61 _size(params()->range.size()), _start(params()->range.start) |
60{ | 62{ |
61 if (params()->range.size() % TheISA::PageBytes != 0) | 63 if (size() % TheISA::PageBytes != 0) |
62 panic("Memory Size not divisible by page size\n"); 63 64 if (params()->null) 65 return; 66 | 64 panic("Memory Size not divisible by page size\n"); 65 66 if (params()->null) 67 return; 68 |
67 int map_flags = MAP_ANON | MAP_PRIVATE; 68 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(), 69 PROT_READ | PROT_WRITE, map_flags, -1, 0); | |
70 | 69 |
70 if (params()->file == "") { 71 int map_flags = MAP_ANON | MAP_PRIVATE; 72 pmemAddr = (uint8_t *)mmap(NULL, size(), 73 PROT_READ | PROT_WRITE, map_flags, -1, 0); 74 } else { 75 int map_flags = MAP_PRIVATE; 76 int fd = open(params()->file.c_str(), O_RDONLY); 77 _size = lseek(fd, 0, SEEK_END); 78 lseek(fd, 0, SEEK_SET); 79 pmemAddr = (uint8_t *)mmap(NULL, roundUp(size(), PAGE_SIZE), 80 PROT_READ | PROT_WRITE, map_flags, fd, 0); 81 } 82 |
|
71 if (pmemAddr == (void *)MAP_FAILED) { 72 perror("mmap"); | 83 if (pmemAddr == (void *)MAP_FAILED) { 84 perror("mmap"); |
73 fatal("Could not mmap!\n"); | 85 if (params()->file == "") 86 fatal("Could not mmap!\n"); 87 else 88 fatal("Could not find file: %s\n", params()->file); |
74 } 75 76 //If requested, initialize all the memory to 0 77 if (p->zero) | 89 } 90 91 //If requested, initialize all the memory to 0 92 if (p->zero) |
78 memset(pmemAddr, 0, p->range.size()); | 93 memset(pmemAddr, 0, size()); |
79} 80 81void 82PhysicalMemory::init() 83{ 84 if (ports.size() == 0) { 85 fatal("PhysicalMemory object %s is unconnected!", name()); 86 } 87 88 for (PortIterator pi = ports.begin(); pi != ports.end(); ++pi) { 89 if (*pi) 90 (*pi)->sendStatusChange(Port::RangeChange); 91 } 92} 93 94PhysicalMemory::~PhysicalMemory() 95{ 96 if (pmemAddr) | 94} 95 96void 97PhysicalMemory::init() 98{ 99 if (ports.size() == 0) { 100 fatal("PhysicalMemory object %s is unconnected!", name()); 101 } 102 103 for (PortIterator pi = ports.begin(); pi != ports.end(); ++pi) { 104 if (*pi) 105 (*pi)->sendStatusChange(Port::RangeChange); 106 } 107} 108 109PhysicalMemory::~PhysicalMemory() 110{ 111 if (pmemAddr) |
97 munmap((char*)pmemAddr, params()->range.size()); 98 //Remove memPorts? | 112 munmap((char*)pmemAddr, size()); |
99} 100 101Addr 102PhysicalMemory::new_page() 103{ 104 Addr return_addr = pagePtr << LogVMPageSize; 105 return_addr += start(); 106 --- 296 unchanged lines hidden (view full) --- 403 memory->getAddressRanges(resp, snoop); 404} 405 406void 407PhysicalMemory::getAddressRanges(AddrRangeList &resp, bool &snoop) 408{ 409 snoop = false; 410 resp.clear(); | 113} 114 115Addr 116PhysicalMemory::new_page() 117{ 118 Addr return_addr = pagePtr << LogVMPageSize; 119 return_addr += start(); 120 --- 296 unchanged lines hidden (view full) --- 417 memory->getAddressRanges(resp, snoop); 418} 419 420void 421PhysicalMemory::getAddressRanges(AddrRangeList &resp, bool &snoop) 422{ 423 snoop = false; 424 resp.clear(); |
411 resp.push_back(RangeSize(start(), params()->range.size())); | 425 resp.push_back(RangeSize(start(), size())); |
412} 413 414unsigned 415PhysicalMemory::MemoryPort::deviceBlockSize() const 416{ 417 return memory->deviceBlockSize(); 418} 419 --- 38 unchanged lines hidden (view full) --- 458{ 459 if (!pmemAddr) 460 return; 461 462 gzFile compressedMem; 463 string filename = name() + ".physmem"; 464 465 SERIALIZE_SCALAR(filename); | 426} 427 428unsigned 429PhysicalMemory::MemoryPort::deviceBlockSize() const 430{ 431 return memory->deviceBlockSize(); 432} 433 --- 38 unchanged lines hidden (view full) --- 472{ 473 if (!pmemAddr) 474 return; 475 476 gzFile compressedMem; 477 string filename = name() + ".physmem"; 478 479 SERIALIZE_SCALAR(filename); |
480 SERIALIZE_SCALAR(_size); |
|
466 467 // write memory file 468 string thefile = Checkpoint::dir() + "/" + filename.c_str(); 469 int fd = creat(thefile.c_str(), 0664); 470 if (fd < 0) { 471 perror("creat"); 472 fatal("Can't open physical memory checkpoint file '%s'\n", filename); 473 } 474 475 compressedMem = gzdopen(fd, "wb"); 476 if (compressedMem == NULL) 477 fatal("Insufficient memory to allocate compression state for %s\n", 478 filename); 479 | 481 482 // write memory file 483 string thefile = Checkpoint::dir() + "/" + filename.c_str(); 484 int fd = creat(thefile.c_str(), 0664); 485 if (fd < 0) { 486 perror("creat"); 487 fatal("Can't open physical memory checkpoint file '%s'\n", filename); 488 } 489 490 compressedMem = gzdopen(fd, "wb"); 491 if (compressedMem == NULL) 492 fatal("Insufficient memory to allocate compression state for %s\n", 493 filename); 494 |
480 if (gzwrite(compressedMem, pmemAddr, params()->range.size()) != 481 (int)params()->range.size()) { | 495 if (gzwrite(compressedMem, pmemAddr, size()) != (int)size()) { |
482 fatal("Write failed on physical memory checkpoint file '%s'\n", 483 filename); 484 } 485 486 if (gzclose(compressedMem)) 487 fatal("Close failed on physical memory checkpoint file '%s'\n", 488 filename); 489} --- 27 unchanged lines hidden (view full) --- 517 compressedMem = gzdopen(fd, "rb"); 518 if (compressedMem == NULL) 519 fatal("Insufficient memory to allocate compression state for %s\n", 520 filename); 521 522 // unmap file that was mmaped in the constructor 523 // This is done here to make sure that gzip and open don't muck with our 524 // nice large space of memory before we reallocate it | 496 fatal("Write failed on physical memory checkpoint file '%s'\n", 497 filename); 498 } 499 500 if (gzclose(compressedMem)) 501 fatal("Close failed on physical memory checkpoint file '%s'\n", 502 filename); 503} --- 27 unchanged lines hidden (view full) --- 531 compressedMem = gzdopen(fd, "rb"); 532 if (compressedMem == NULL) 533 fatal("Insufficient memory to allocate compression state for %s\n", 534 filename); 535 536 // unmap file that was mmaped in the constructor 537 // This is done here to make sure that gzip and open don't muck with our 538 // nice large space of memory before we reallocate it |
525 munmap((char*)pmemAddr, params()->range.size()); | 539 munmap((char*)pmemAddr, size()); |
526 | 540 |
527 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(), | 541 UNSERIALIZE_SCALAR(_size); 542 if (size() > params()->range.size()) 543 fatal("Memory size has changed!\n"); 544 545 pmemAddr = (uint8_t *)mmap(NULL, size(), |
528 PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); 529 530 if (pmemAddr == (void *)MAP_FAILED) { 531 perror("mmap"); 532 fatal("Could not mmap physical memory!\n"); 533 } 534 535 curSize = 0; 536 tempPage = (long*)malloc(chunkSize); 537 if (tempPage == NULL) 538 fatal("Unable to malloc memory to read file %s\n", filename); 539 540 /* Only copy bytes that are non-zero, so we don't give the VM system hell */ | 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 */ |
541 while (curSize < params()->range.size()) { | 559 while (curSize < size()) { |
542 bytesRead = gzread(compressedMem, tempPage, chunkSize); 543 if (bytesRead == 0) 544 break; 545 546 assert(bytesRead % sizeof(long) == 0); 547 548 for (uint32_t x = 0; x < bytesRead / sizeof(long); x++) 549 { --- 21 unchanged lines hidden --- | 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 { --- 21 unchanged lines hidden --- |