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), pagePtr(0), 56 lat(p->latency), lat_var(p->latency_var), 57 cachedSize(params()->range.size()), cachedStart(params()->range.start) |
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 |
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()); |
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 } |
290 if (pmemAddr) 291 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize()); |
292 TRACE_PACKET("Read"); 293 } else if (pkt->isWrite()) { 294 if (writeOK(pkt)) { |
295 if (pmemAddr) 296 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize()); |
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()) { |
325 if (pmemAddr) 326 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize()); |
327 TRACE_PACKET("Read"); 328 pkt->makeAtomicResponse(); 329 } else if (pkt->isWrite()) { |
330 if (pmemAddr) 331 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize()); |
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 |
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 §ion) 489{ |
490 if (!pmemAddr) 491 return; 492 |
493 gzFile compressedMem; 494 long *tempPage; 495 long *pmem_current; 496 uint64_t curSize; 497 uint32_t bytesRead; 498 const int chunkSize = 16384; 499 |
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 --- |