Deleted Added
sdiff udiff text old ( 6820:2980bd04e6df ) new ( 7730:982b4c6c1470 )
full compact
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 <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"
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),
59 cachedSize(params()->range.size()), cachedStart(params()->range.start)
60{
61 if (params()->range.size() % TheISA::PageBytes != 0)
62 panic("Memory Size not divisible by page size\n");
63
64 if (params()->null)
65 return;
66
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
71 if (pmemAddr == (void *)MAP_FAILED) {
72 perror("mmap");
73 fatal("Could not mmap!\n");
74 }
75
76 //If requested, initialize all the memory to 0
77 if (p->zero)
78 memset(pmemAddr, 0, p->range.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)
97 munmap((char*)pmemAddr, params()->range.size());
98 //Remove memPorts?
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();
411 resp.push_back(RangeSize(start(), params()->range.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);
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
480 if (gzwrite(compressedMem, pmemAddr, params()->range.size()) !=
481 (int)params()->range.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
525 munmap((char*)pmemAddr, params()->range.size());
526
527 pmemAddr = (uint8_t *)mmap(NULL, params()->range.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 */
541 while (curSize < params()->range.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 ---