Deleted Added
sdiff udiff text old ( 4762:c94e103c83ad ) new ( 4870:fcc39d001154 )
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;

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

39#include <iostream>
40#include <string>
41
42#include "arch/isa_traits.hh"
43#include "base/misc.hh"
44#include "config/full_system.hh"
45#include "mem/packet_access.hh"
46#include "mem/physical.hh"
47#include "sim/eventq.hh"
48#include "sim/host.hh"
49
50using namespace std;
51using namespace TheISA;
52
53PhysicalMemory::PhysicalMemory(const Params *p)
54 : MemObject(p), pmemAddr(NULL), lat(p->latency)
55{
56 if (params()->range.size() % TheISA::PageBytes != 0)
57 panic("Memory Size not divisible by page size\n");
58
59 int map_flags = MAP_ANON | MAP_PRIVATE;
60 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(), PROT_READ | PROT_WRITE,
61 map_flags, -1, 0);
62
63 if (pmemAddr == (void *)MAP_FAILED) {
64 perror("mmap");
65 fatal("Could not mmap!\n");
66 }
67
68 //If requested, initialize all the memory to 0
69 if (p->zero)
70 memset(pmemAddr, 0, p->range.size());
71
72 pagePtr = 0;
73}
74
75void
76PhysicalMemory::init()
77{
78 if (ports.size() == 0) {

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

83 if (*pi)
84 (*pi)->sendStatusChange(Port::RangeChange);
85 }
86}
87
88PhysicalMemory::~PhysicalMemory()
89{
90 if (pmemAddr)
91 munmap((char*)pmemAddr, params()->range.size());
92 //Remove memPorts?
93}
94
95Addr
96PhysicalMemory::new_page()
97{
98 Addr return_addr = pagePtr << LogVMPageSize;
99 return_addr += start();

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

115 return lat;
116}
117
118
119
120// Add load-locked to tracking list. Should only be called if the
121// operation is a load and the LOCKED flag is set.
122void
123PhysicalMemory::trackLoadLocked(Request *req)
124{
125 Addr paddr = LockedAddr::mask(req->getPaddr());
126
127 // first we check if we already have a locked addr for this
128 // xc. Since each xc only gets one, we just update the
129 // existing record with the new address.
130 list<LockedAddr>::iterator i;
131
132 for (i = lockedAddrList.begin(); i != lockedAddrList.end(); ++i) {

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

145}
146
147
148// Called on *writes* only... both regular stores and
149// store-conditional operations. Check for conventional stores which
150// conflict with locked addresses, and for success/failure of store
151// conditionals.
152bool
153PhysicalMemory::checkLockedAddrList(Request *req)
154{
155 Addr paddr = LockedAddr::mask(req->getPaddr());
156 bool isLocked = req->isLocked();
157
158 // Initialize return value. Non-conditional stores always
159 // succeed. Assume conditional stores will fail until proven
160 // otherwise.
161 bool success = !isLocked;
162
163 // Iterate over list. Note that there could be multiple matching
164 // records, as more than one context could have done a load locked

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

192
193 if (isLocked) {
194 req->setExtraData(success ? 1 : 0);
195 }
196
197 return success;
198}
199
200void
201PhysicalMemory::doFunctionalAccess(PacketPtr pkt)
202{
203 assert(pkt->getAddr() >= start() &&
204 pkt->getAddr() + pkt->getSize() <= start() + size());
205
206 if (pkt->isRead()) {
207 if (pkt->req->isLocked()) {
208 trackLoadLocked(pkt->req);
209 }
210 memcpy(pkt->getPtr<uint8_t>(), pmemAddr + pkt->getAddr() - start(),
211 pkt->getSize());
212#if TRACING_ON
213 switch (pkt->getSize()) {
214 case sizeof(uint64_t):
215 DPRINTF(MemoryAccess, "Read of size %i on address 0x%x data 0x%x\n",
216 pkt->getSize(), pkt->getAddr(),pkt->get<uint64_t>());
217 break;
218 case sizeof(uint32_t):
219 DPRINTF(MemoryAccess, "Read of size %i on address 0x%x data 0x%x\n",
220 pkt->getSize(), pkt->getAddr(),pkt->get<uint32_t>());
221 break;
222 case sizeof(uint16_t):
223 DPRINTF(MemoryAccess, "Read of size %i on address 0x%x data 0x%x\n",
224 pkt->getSize(), pkt->getAddr(),pkt->get<uint16_t>());
225 break;
226 case sizeof(uint8_t):
227 DPRINTF(MemoryAccess, "Read of size %i on address 0x%x data 0x%x\n",
228 pkt->getSize(), pkt->getAddr(),pkt->get<uint8_t>());
229 break;
230 default:
231 DPRINTF(MemoryAccess, "Read of size %i on address 0x%x\n",
232 pkt->getSize(), pkt->getAddr());
233 }
234#endif
235 }
236 else if (pkt->isWrite()) {
237 if (writeOK(pkt->req)) {
238 memcpy(pmemAddr + pkt->getAddr() - start(), pkt->getPtr<uint8_t>(),
239 pkt->getSize());
240#if TRACING_ON
241 switch (pkt->getSize()) {
242 case sizeof(uint64_t):
243 DPRINTF(MemoryAccess, "Write of size %i on address 0x%x data 0x%x\n",
244 pkt->getSize(), pkt->getAddr(),pkt->get<uint64_t>());
245 break;
246 case sizeof(uint32_t):
247 DPRINTF(MemoryAccess, "Write of size %i on address 0x%x data 0x%x\n",
248 pkt->getSize(), pkt->getAddr(),pkt->get<uint32_t>());
249 break;
250 case sizeof(uint16_t):
251 DPRINTF(MemoryAccess, "Write of size %i on address 0x%x data 0x%x\n",
252 pkt->getSize(), pkt->getAddr(),pkt->get<uint16_t>());
253 break;
254 case sizeof(uint8_t):
255 DPRINTF(MemoryAccess, "Write of size %i on address 0x%x data 0x%x\n",
256 pkt->getSize(), pkt->getAddr(),pkt->get<uint8_t>());
257 break;
258 default:
259 DPRINTF(MemoryAccess, "Write of size %i on address 0x%x\n",
260 pkt->getSize(), pkt->getAddr());
261 }
262#endif
263 }
264 } else if (pkt->isInvalidate()) {
265 //upgrade or invalidate
266 pkt->flags |= SATISFIED;
267 } else if (pkt->isReadWrite()) {
268 IntReg overwrite_val;
269 bool overwrite_mem;
270 uint64_t condition_val64;
271 uint32_t condition_val32;
272
273 assert(sizeof(IntReg) >= pkt->getSize());
274
275 overwrite_mem = true;
276 // keep a copy of our possible write value, and copy what is at the
277 // memory address into the packet
278 std::memcpy(&overwrite_val, pkt->getPtr<uint8_t>(), pkt->getSize());
279 std::memcpy(pkt->getPtr<uint8_t>(), pmemAddr + pkt->getAddr() - start(),
280 pkt->getSize());
281
282 if (pkt->req->isCondSwap()) {
283 if (pkt->getSize() == sizeof(uint64_t)) {
284 condition_val64 = pkt->req->getExtraData();
285 overwrite_mem = !std::memcmp(&condition_val64, pmemAddr +
286 pkt->getAddr() - start(), sizeof(uint64_t));
287 } else if (pkt->getSize() == sizeof(uint32_t)) {
288 condition_val32 = (uint32_t)pkt->req->getExtraData();
289 overwrite_mem = !std::memcmp(&condition_val32, pmemAddr +
290 pkt->getAddr() - start(), sizeof(uint32_t));
291 } else
292 panic("Invalid size for conditional read/write\n");
293 }
294
295 if (overwrite_mem)
296 std::memcpy(pmemAddr + pkt->getAddr() - start(),
297 &overwrite_val, pkt->getSize());
298
299#if TRACING_ON
300 switch (pkt->getSize()) {
301 case sizeof(uint64_t):
302 DPRINTF(MemoryAccess, "Read/Write of size %i on address 0x%x old data 0x%x\n",
303 pkt->getSize(), pkt->getAddr(),pkt->get<uint64_t>());
304 DPRINTF(MemoryAccess, "New Data 0x%x %s conditional (0x%x) and %s \n",
305 overwrite_mem, pkt->req->isCondSwap() ? "was" : "wasn't",
306 condition_val64, overwrite_mem ? "happened" : "didn't happen");
307 break;
308 case sizeof(uint32_t):
309 DPRINTF(MemoryAccess, "Read/Write of size %i on address 0x%x old data 0x%x\n",
310 pkt->getSize(), pkt->getAddr(),pkt->get<uint32_t>());
311 DPRINTF(MemoryAccess, "New Data 0x%x %s conditional (0x%x) and %s \n",
312 overwrite_mem, pkt->req->isCondSwap() ? "was" : "wasn't",
313 condition_val32, overwrite_mem ? "happened" : "didn't happen");
314 break;
315 case sizeof(uint16_t):
316 DPRINTF(MemoryAccess, "Read/Write of size %i on address 0x%x old data 0x%x\n",
317 pkt->getSize(), pkt->getAddr(),pkt->get<uint16_t>());
318 DPRINTF(MemoryAccess, "New Data 0x%x wasn't conditional and happned\n",
319 overwrite_mem);
320 break;
321 case sizeof(uint8_t):
322 DPRINTF(MemoryAccess, "Read/Write of size %i on address 0x%x old data 0x%x\n",
323 pkt->getSize(), pkt->getAddr(),pkt->get<uint8_t>());
324 DPRINTF(MemoryAccess, "New Data 0x%x wasn't conditional and happned\n",
325 overwrite_mem);
326 break;
327 default:
328 DPRINTF(MemoryAccess, "Read/Write of size %i on address 0x%x\n",
329 pkt->getSize(), pkt->getAddr());
330 }
331#endif
332 } else {
333 panic("unimplemented");
334 }
335
336 pkt->result = Packet::Success;
337}
338
339Port *
340PhysicalMemory::getPort(const std::string &if_name, int idx)
341{
342 // Accept request for "functional" port for backwards compatibility
343 // with places where this function is called from C++. I'd prefer
344 // to move all these into Python someday.
345 if (if_name == "functional") {
346 return new MemoryPort(csprintf("%s-functional", name()), this);

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

389 memory->getAddressRanges(resp, snoop);
390}
391
392void
393PhysicalMemory::getAddressRanges(AddrRangeList &resp, bool &snoop)
394{
395 snoop = false;
396 resp.clear();
397 resp.push_back(RangeSize(start(), params()->range.size()));
398}
399
400int
401PhysicalMemory::MemoryPort::deviceBlockSize()
402{
403 return memory->deviceBlockSize();
404}
405
406Tick
407PhysicalMemory::MemoryPort::recvAtomic(PacketPtr pkt)
408{
409 memory->doFunctionalAccess(pkt);
410 return memory->calculateLatency(pkt);
411}
412
413void
414PhysicalMemory::MemoryPort::recvFunctional(PacketPtr pkt)
415{
416 checkFunctional(pkt);
417
418 // Default implementation of SimpleTimingPort::recvFunctional()

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

452 fatal("Can't open physical memory checkpoint file '%s'\n", filename);
453 }
454
455 compressedMem = gzdopen(fd, "wb");
456 if (compressedMem == NULL)
457 fatal("Insufficient memory to allocate compression state for %s\n",
458 filename);
459
460 if (gzwrite(compressedMem, pmemAddr, params()->range.size()) !=
461 params()->range.size()) {
462 fatal("Write failed on physical memory checkpoint file '%s'\n",
463 filename);
464 }
465
466 if (gzclose(compressedMem))
467 fatal("Close failed on physical memory checkpoint file '%s'\n",
468 filename);
469}

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

495 compressedMem = gzdopen(fd, "rb");
496 if (compressedMem == NULL)
497 fatal("Insufficient memory to allocate compression state for %s\n",
498 filename);
499
500 // unmap file that was mmaped in the constructor
501 // This is done here to make sure that gzip and open don't muck with our
502 // nice large space of memory before we reallocate it
503 munmap((char*)pmemAddr, params()->range.size());
504
505 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(),
506 PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
507
508 if (pmemAddr == (void *)MAP_FAILED) {
509 perror("mmap");
510 fatal("Could not mmap physical memory!\n");
511 }
512
513 curSize = 0;
514 tempPage = (long*)malloc(chunkSize);
515 if (tempPage == NULL)
516 fatal("Unable to malloc memory to read file %s\n", filename);
517
518 /* Only copy bytes that are non-zero, so we don't give the VM system hell */
519 while (curSize < params()->range.size()) {
520 bytesRead = gzread(compressedMem, tempPage, chunkSize);
521 if (bytesRead != chunkSize &&
522 bytesRead != params()->range.size() - curSize)
523 fatal("Read failed on physical memory checkpoint file '%s'"
524 " got %d bytes, expected %d or %d bytes\n",
525 filename, bytesRead, chunkSize,
526 params()->range.size() - curSize);
527
528 assert(bytesRead % sizeof(long) == 0);
529
530 for (int x = 0; x < bytesRead/sizeof(long); x++)
531 {
532 if (*(tempPage+x) != 0) {
533 pmem_current = (long*)(pmemAddr + curSize + x * sizeof(long));
534 *pmem_current = *(tempPage+x);

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

540 free(tempPage);
541
542 if (gzclose(compressedMem))
543 fatal("Close failed on physical memory checkpoint file '%s'\n",
544 filename);
545
546}
547
548PhysicalMemory *
549PhysicalMemoryParams::create()
550{
551 return new PhysicalMemory(this);
552}