physical.cc (5399:e951ca2d56e2) physical.cc (5477:dc04d655315a)
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;

--- 38 unchanged lines hidden (view full) ---

47#include "mem/physical.hh"
48#include "sim/eventq.hh"
49#include "sim/host.hh"
50
51using namespace std;
52using namespace TheISA;
53
54PhysicalMemory::PhysicalMemory(const Params *p)
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;

--- 38 unchanged lines hidden (view full) ---

47#include "mem/physical.hh"
48#include "sim/eventq.hh"
49#include "sim/host.hh"
50
51using namespace std;
52using namespace TheISA;
53
54PhysicalMemory::PhysicalMemory(const Params *p)
55 : MemObject(p), pmemAddr(NULL), lat(p->latency),
56 lat_var(p->latency_var)
55 : MemObject(p), pmemAddr(NULL), pagePtr(0),
56 lat(p->latency), lat_var(p->latency_var),
57 cachedSize(params()->range.size()), cachedStart(params()->range.start)
57{
58 if (params()->range.size() % TheISA::PageBytes != 0)
59 panic("Memory Size not divisible by page size\n");
60
58{
59 if (params()->range.size() % TheISA::PageBytes != 0)
60 panic("Memory Size not divisible by page size\n");
61
62 if (params()->null)
63 return;
64
61 int map_flags = MAP_ANON | MAP_PRIVATE;
62 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(),
63 PROT_READ | PROT_WRITE, map_flags, -1, 0);
64
65 if (pmemAddr == (void *)MAP_FAILED) {
66 perror("mmap");
67 fatal("Could not mmap!\n");
68 }
69
70 //If requested, initialize all the memory to 0
71 if (p->zero)
72 memset(pmemAddr, 0, p->range.size());
65 int map_flags = MAP_ANON | MAP_PRIVATE;
66 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(),
67 PROT_READ | PROT_WRITE, map_flags, -1, 0);
68
69 if (pmemAddr == (void *)MAP_FAILED) {
70 perror("mmap");
71 fatal("Could not mmap!\n");
72 }
73
74 //If requested, initialize all the memory to 0
75 if (p->zero)
76 memset(pmemAddr, 0, p->range.size());
73
74 pagePtr = 0;
75
76 cachedSize = params()->range.size();
77 cachedStart = params()->range.start;
78
79}
80
81void
82PhysicalMemory::init()
83{
84 if (ports.size() == 0) {
85 fatal("PhysicalMemory object %s is unconnected!", name());
86 }

--- 165 unchanged lines hidden (view full) ---

252 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
253
254 if (pkt->cmd == MemCmd::SwapReq) {
255 IntReg overwrite_val;
256 bool overwrite_mem;
257 uint64_t condition_val64;
258 uint32_t condition_val32;
259
77}
78
79void
80PhysicalMemory::init()
81{
82 if (ports.size() == 0) {
83 fatal("PhysicalMemory object %s is unconnected!", name());
84 }

--- 165 unchanged lines hidden (view full) ---

250 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
251
252 if (pkt->cmd == MemCmd::SwapReq) {
253 IntReg overwrite_val;
254 bool overwrite_mem;
255 uint64_t condition_val64;
256 uint32_t condition_val32;
257
258 if (!pmemAddr)
259 panic("Swap only works if there is real memory (i.e. null=False)");
260 assert(sizeof(IntReg) >= pkt->getSize());
261
262 overwrite_mem = true;
263 // keep a copy of our possible write value, and copy what is at the
264 // memory address into the packet
265 std::memcpy(&overwrite_val, pkt->getPtr<uint8_t>(), pkt->getSize());
266 std::memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
267

--- 14 unchanged lines hidden (view full) ---

282 std::memcpy(hostAddr, &overwrite_val, pkt->getSize());
283
284 TRACE_PACKET("Read/Write");
285 } else if (pkt->isRead()) {
286 assert(!pkt->isWrite());
287 if (pkt->isLocked()) {
288 trackLoadLocked(pkt);
289 }
260 assert(sizeof(IntReg) >= pkt->getSize());
261
262 overwrite_mem = true;
263 // keep a copy of our possible write value, and copy what is at the
264 // memory address into the packet
265 std::memcpy(&overwrite_val, pkt->getPtr<uint8_t>(), pkt->getSize());
266 std::memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
267

--- 14 unchanged lines hidden (view full) ---

282 std::memcpy(hostAddr, &overwrite_val, pkt->getSize());
283
284 TRACE_PACKET("Read/Write");
285 } else if (pkt->isRead()) {
286 assert(!pkt->isWrite());
287 if (pkt->isLocked()) {
288 trackLoadLocked(pkt);
289 }
290 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
290 if (pmemAddr)
291 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
291 TRACE_PACKET("Read");
292 } else if (pkt->isWrite()) {
293 if (writeOK(pkt)) {
292 TRACE_PACKET("Read");
293 } else if (pkt->isWrite()) {
294 if (writeOK(pkt)) {
294 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
295 if (pmemAddr)
296 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
295 TRACE_PACKET("Write");
296 }
297 } else if (pkt->isInvalidate()) {
298 //upgrade or invalidate
299 if (pkt->needsResponse()) {
300 pkt->makeAtomicResponse();
301 }
302 } else {

--- 12 unchanged lines hidden (view full) ---

315{
316 assert(pkt->getAddr() >= start() &&
317 pkt->getAddr() + pkt->getSize() <= start() + size());
318
319
320 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
321
322 if (pkt->isRead()) {
297 TRACE_PACKET("Write");
298 }
299 } else if (pkt->isInvalidate()) {
300 //upgrade or invalidate
301 if (pkt->needsResponse()) {
302 pkt->makeAtomicResponse();
303 }
304 } else {

--- 12 unchanged lines hidden (view full) ---

317{
318 assert(pkt->getAddr() >= start() &&
319 pkt->getAddr() + pkt->getSize() <= start() + size());
320
321
322 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
323
324 if (pkt->isRead()) {
323 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
325 if (pmemAddr)
326 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
324 TRACE_PACKET("Read");
325 pkt->makeAtomicResponse();
326 } else if (pkt->isWrite()) {
327 TRACE_PACKET("Read");
328 pkt->makeAtomicResponse();
329 } else if (pkt->isWrite()) {
327 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
330 if (pmemAddr)
331 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
328 TRACE_PACKET("Write");
329 pkt->makeAtomicResponse();
330 } else if (pkt->isPrint()) {
331 Packet::PrintReqState *prs =
332 dynamic_cast<Packet::PrintReqState*>(pkt->senderState);
333 // Need to call printLabels() explicitly since we're not going
334 // through printObj().
335 prs->printLabels();

--- 107 unchanged lines hidden (view full) ---

443 else
444 changeState(Drained);
445 return count;
446}
447
448void
449PhysicalMemory::serialize(ostream &os)
450{
332 TRACE_PACKET("Write");
333 pkt->makeAtomicResponse();
334 } else if (pkt->isPrint()) {
335 Packet::PrintReqState *prs =
336 dynamic_cast<Packet::PrintReqState*>(pkt->senderState);
337 // Need to call printLabels() explicitly since we're not going
338 // through printObj().
339 prs->printLabels();

--- 107 unchanged lines hidden (view full) ---

447 else
448 changeState(Drained);
449 return count;
450}
451
452void
453PhysicalMemory::serialize(ostream &os)
454{
455 if (!pmemAddr)
456 return;
457
451 gzFile compressedMem;
452 string filename = name() + ".physmem";
453
454 SERIALIZE_SCALAR(filename);
455
456 // write memory file
457 string thefile = Checkpoint::dir() + "/" + filename.c_str();
458 int fd = creat(thefile.c_str(), 0664);

--- 16 unchanged lines hidden (view full) ---

475 if (gzclose(compressedMem))
476 fatal("Close failed on physical memory checkpoint file '%s'\n",
477 filename);
478}
479
480void
481PhysicalMemory::unserialize(Checkpoint *cp, const string &section)
482{
458 gzFile compressedMem;
459 string filename = name() + ".physmem";
460
461 SERIALIZE_SCALAR(filename);
462
463 // write memory file
464 string thefile = Checkpoint::dir() + "/" + filename.c_str();
465 int fd = creat(thefile.c_str(), 0664);

--- 16 unchanged lines hidden (view full) ---

482 if (gzclose(compressedMem))
483 fatal("Close failed on physical memory checkpoint file '%s'\n",
484 filename);
485}
486
487void
488PhysicalMemory::unserialize(Checkpoint *cp, const string &section)
489{
490 if (!pmemAddr)
491 return;
492
483 gzFile compressedMem;
484 long *tempPage;
485 long *pmem_current;
486 uint64_t curSize;
487 uint32_t bytesRead;
488 const int chunkSize = 16384;
489
493 gzFile compressedMem;
494 long *tempPage;
495 long *pmem_current;
496 uint64_t curSize;
497 uint32_t bytesRead;
498 const int chunkSize = 16384;
499
490
491 string filename;
492
493 UNSERIALIZE_SCALAR(filename);
494
495 filename = cp->cptDir + "/" + filename;
496
497 // mmap memoryfile
498 int fd = open(filename.c_str(), O_RDONLY);

--- 63 unchanged lines hidden ---
500 string filename;
501
502 UNSERIALIZE_SCALAR(filename);
503
504 filename = cp->cptDir + "/" + filename;
505
506 // mmap memoryfile
507 int fd = open(filename.c_str(), O_RDONLY);

--- 63 unchanged lines hidden ---