2006-02-03 20:54:37 +01:00
|
|
|
/*
|
2014-10-16 11:50:01 +02:00
|
|
|
* Copyright (c) 2012, 2014 ARM Limited
|
2010-11-08 20:58:25 +01:00
|
|
|
* All rights reserved
|
|
|
|
*
|
|
|
|
* The license below extends only to copyright in the software and shall
|
|
|
|
* not be construed as granting a license to any other intellectual
|
|
|
|
* property including but not limited to intellectual property relating
|
|
|
|
* to a hardware implementation of the functionality of the software
|
|
|
|
* licensed hereunder. You may use the software subject to the license
|
|
|
|
* terms below provided that you ensure that this notice is replicated
|
|
|
|
* unmodified and in its entirety in all distributions of the software,
|
|
|
|
* modified or unmodified, in source code or in binary form.
|
|
|
|
*
|
2006-02-03 20:54:37 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
2012-04-06 19:46:31 +02:00
|
|
|
* Authors: Andreas Hansson
|
2006-02-03 20:54:37 +01:00
|
|
|
*/
|
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
#include <cerrno>
|
|
|
|
#include <climits>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2012-11-16 17:27:47 +01:00
|
|
|
#include "base/trace.hh"
|
2014-09-20 23:18:32 +02:00
|
|
|
#include "debug/AddrRanges.hh"
|
2012-10-15 14:12:32 +02:00
|
|
|
#include "debug/Checkpoint.hh"
|
|
|
|
#include "mem/abstract_mem.hh"
|
2006-02-15 20:21:09 +01:00
|
|
|
#include "mem/physical.hh"
|
|
|
|
|
2015-02-16 09:33:47 +01:00
|
|
|
/**
|
|
|
|
* On Linux, MAP_NORESERVE allow us to simulate a very large memory
|
|
|
|
* without committing to actually providing the swap space on the
|
|
|
|
* host. On OSX the MAP_NORESERVE flag does not exist, so simply make
|
|
|
|
* it 0.
|
|
|
|
*/
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#ifndef MAP_NORESERVE
|
|
|
|
#define MAP_NORESERVE 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-02-03 20:54:37 +01:00
|
|
|
using namespace std;
|
2012-01-25 18:18:25 +01:00
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
PhysicalMemory::PhysicalMemory(const string& _name,
|
2015-02-16 09:33:47 +01:00
|
|
|
const vector<AbstractMemory*>& _memories,
|
|
|
|
bool mmap_using_noreserve) :
|
|
|
|
_name(_name), rangeCache(addrMap.end()), size(0),
|
|
|
|
mmapUsingNoReserve(mmap_using_noreserve)
|
2006-10-08 19:53:24 +02:00
|
|
|
{
|
2015-02-16 09:33:47 +01:00
|
|
|
if (mmap_using_noreserve)
|
|
|
|
warn("Not reserving swap space. May cause SIGSEGV on actual usage\n");
|
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
// add the memories from the system to the address map as
|
|
|
|
// appropriate
|
2014-10-16 11:50:01 +02:00
|
|
|
for (const auto& m : _memories) {
|
2012-04-06 19:46:31 +02:00
|
|
|
// only add the memory if it is part of the global address map
|
2014-10-16 11:50:01 +02:00
|
|
|
if (m->isInAddrMap()) {
|
|
|
|
memories.push_back(m);
|
2006-10-08 19:53:24 +02:00
|
|
|
|
2012-04-06 19:46:31 +02:00
|
|
|
// calculate the total size once and for all
|
2014-10-16 11:50:01 +02:00
|
|
|
size += m->size();
|
2006-10-08 19:53:24 +02:00
|
|
|
|
2012-04-06 19:46:31 +02:00
|
|
|
// add the range to our interval tree and make sure it does not
|
|
|
|
// intersect an existing range
|
2014-10-16 11:50:01 +02:00
|
|
|
fatal_if(addrMap.insert(m->getAddrRange(), m) == addrMap.end(),
|
|
|
|
"Memory address range for %s is overlapping\n",
|
|
|
|
m->name());
|
2012-10-15 14:12:32 +02:00
|
|
|
} else {
|
|
|
|
// this type of memory is used e.g. as reference memory by
|
|
|
|
// Ruby, and they also needs a backing store, but should
|
|
|
|
// not be part of the global address map
|
2014-10-16 11:50:01 +02:00
|
|
|
DPRINTF(AddrRanges,
|
|
|
|
"Skipping memory %s that is not in global address map\n",
|
|
|
|
m->name());
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
fatal_if(m->getAddrRange().interleaved(),
|
|
|
|
"Memory %s that is not in the global address map cannot "
|
|
|
|
"be interleaved\n", m->name());
|
2012-10-15 14:12:32 +02:00
|
|
|
|
|
|
|
// simply do it independently, also note that this kind of
|
|
|
|
// memories are allowed to overlap in the logic address
|
|
|
|
// map
|
2014-10-16 11:50:01 +02:00
|
|
|
vector<AbstractMemory*> unmapped_mems{m};
|
|
|
|
createBackingStore(m->getAddrRange(), unmapped_mems);
|
2006-10-08 19:53:24 +02:00
|
|
|
}
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:51:01 +01:00
|
|
|
// iterate over the increasing addresses and chunks of contiguous
|
|
|
|
// space to be mapped to backing store, create it and inform the
|
|
|
|
// memories
|
2013-03-01 19:20:21 +01:00
|
|
|
vector<AddrRange> intlv_ranges;
|
2012-10-15 14:12:32 +02:00
|
|
|
vector<AbstractMemory*> curr_memories;
|
2014-10-16 11:50:01 +02:00
|
|
|
for (const auto& r : addrMap) {
|
2012-10-15 14:12:32 +02:00
|
|
|
// simply skip past all memories that are null and hence do
|
|
|
|
// not need any backing store
|
2014-10-16 11:50:01 +02:00
|
|
|
if (!r.second->isNull()) {
|
2013-03-01 19:20:21 +01:00
|
|
|
// if the range is interleaved then save it for now
|
2014-10-16 11:50:01 +02:00
|
|
|
if (r.first.interleaved()) {
|
2013-03-01 19:20:21 +01:00
|
|
|
// if we already got interleaved ranges that are not
|
|
|
|
// part of the same range, then first do a merge
|
|
|
|
// before we add the new one
|
|
|
|
if (!intlv_ranges.empty() &&
|
2014-10-16 11:50:01 +02:00
|
|
|
!intlv_ranges.back().mergesWith(r.first)) {
|
2013-03-01 19:20:21 +01:00
|
|
|
AddrRange merged_range(intlv_ranges);
|
|
|
|
createBackingStore(merged_range, curr_memories);
|
|
|
|
intlv_ranges.clear();
|
|
|
|
curr_memories.clear();
|
|
|
|
}
|
2014-10-16 11:50:01 +02:00
|
|
|
intlv_ranges.push_back(r.first);
|
|
|
|
curr_memories.push_back(r.second);
|
2013-03-01 19:20:21 +01:00
|
|
|
} else {
|
2014-10-16 11:50:01 +02:00
|
|
|
vector<AbstractMemory*> single_memory{r.second};
|
|
|
|
createBackingStore(r.first, single_memory);
|
2013-03-01 19:20:21 +01:00
|
|
|
}
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 19:20:21 +01:00
|
|
|
|
|
|
|
// if there is still interleaved ranges waiting to be merged, go
|
|
|
|
// ahead and do it
|
|
|
|
if (!intlv_ranges.empty()) {
|
|
|
|
AddrRange merged_range(intlv_ranges);
|
|
|
|
createBackingStore(merged_range, curr_memories);
|
|
|
|
}
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PhysicalMemory::createBackingStore(AddrRange range,
|
|
|
|
const vector<AbstractMemory*>& _memories)
|
|
|
|
{
|
2014-10-16 11:50:01 +02:00
|
|
|
panic_if(range.interleaved(),
|
|
|
|
"Cannot create backing store for interleaved range %s\n",
|
2013-01-07 19:05:38 +01:00
|
|
|
range.to_string());
|
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
// perform the actual mmap
|
2014-09-20 23:18:32 +02:00
|
|
|
DPRINTF(AddrRanges, "Creating backing store for range %s with size %d\n",
|
2013-01-07 19:05:38 +01:00
|
|
|
range.to_string(), range.size());
|
2012-10-15 14:12:32 +02:00
|
|
|
int map_flags = MAP_ANON | MAP_PRIVATE;
|
2015-02-16 09:33:47 +01:00
|
|
|
|
|
|
|
// to be able to simulate very large memories, the user can opt to
|
|
|
|
// pass noreserve to mmap
|
|
|
|
if (mmapUsingNoReserve) {
|
|
|
|
map_flags |= MAP_NORESERVE;
|
|
|
|
}
|
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
uint8_t* pmem = (uint8_t*) mmap(NULL, range.size(),
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
map_flags, -1, 0);
|
|
|
|
|
|
|
|
if (pmem == (uint8_t*) MAP_FAILED) {
|
|
|
|
perror("mmap");
|
2013-01-07 19:05:38 +01:00
|
|
|
fatal("Could not mmap %d bytes for range %s!\n", range.size(),
|
|
|
|
range.to_string());
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// remember this backing store so we can checkpoint it and unmap
|
|
|
|
// it appropriately
|
|
|
|
backingStore.push_back(make_pair(range, pmem));
|
|
|
|
|
2014-02-18 11:51:01 +01:00
|
|
|
// point the memories to their backing store
|
2014-10-16 11:50:01 +02:00
|
|
|
for (const auto& m : _memories) {
|
2014-09-20 23:18:32 +02:00
|
|
|
DPRINTF(AddrRanges, "Mapping memory %s to backing store\n",
|
2014-10-16 11:50:01 +02:00
|
|
|
m->name());
|
|
|
|
m->setBackingStore(pmem);
|
2006-10-08 19:53:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 14:12:32 +02:00
|
|
|
PhysicalMemory::~PhysicalMemory()
|
|
|
|
{
|
|
|
|
// unmap the backing store
|
2014-10-16 11:50:01 +02:00
|
|
|
for (auto& s : backingStore)
|
|
|
|
munmap((char*)s.second, s.first.size());
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
|
2006-10-08 19:53:24 +02:00
|
|
|
bool
|
2012-04-06 19:46:31 +02:00
|
|
|
PhysicalMemory::isMemAddr(Addr addr) const
|
|
|
|
{
|
|
|
|
// see if the address is within the last matched range
|
2015-02-16 09:33:37 +01:00
|
|
|
if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2012-04-06 19:46:31 +02:00
|
|
|
// lookup in the interval tree
|
2014-10-16 11:50:01 +02:00
|
|
|
const auto& r = addrMap.find(addr);
|
2012-04-06 19:46:31 +02:00
|
|
|
if (r == addrMap.end()) {
|
|
|
|
// not in the cache, and not in the tree
|
|
|
|
return false;
|
2006-10-08 19:53:24 +02:00
|
|
|
}
|
2012-04-06 19:46:31 +02:00
|
|
|
// the range is in the tree, update the cache
|
2015-02-16 09:33:37 +01:00
|
|
|
rangeCache = r;
|
|
|
|
return true;
|
2006-10-08 19:53:24 +02:00
|
|
|
}
|
2006-03-26 00:31:20 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:09 +01:00
|
|
|
AddrRangeList
|
2012-04-06 19:46:31 +02:00
|
|
|
PhysicalMemory::getConfAddrRanges() const
|
2006-03-26 00:31:20 +01:00
|
|
|
{
|
2012-04-06 19:46:31 +02:00
|
|
|
// this could be done once in the constructor, but since it is unlikely to
|
|
|
|
// be called more than once the iteration should not be a problem
|
2012-01-17 19:55:09 +01:00
|
|
|
AddrRangeList ranges;
|
2013-01-07 19:05:38 +01:00
|
|
|
vector<AddrRange> intlv_ranges;
|
2014-10-16 11:50:01 +02:00
|
|
|
for (const auto& r : addrMap) {
|
|
|
|
if (r.second->isConfReported()) {
|
2013-01-07 19:05:38 +01:00
|
|
|
// if the range is interleaved then save it for now
|
2014-10-16 11:50:01 +02:00
|
|
|
if (r.first.interleaved()) {
|
2013-01-07 19:05:38 +01:00
|
|
|
// if we already got interleaved ranges that are not
|
|
|
|
// part of the same range, then first do a merge
|
|
|
|
// before we add the new one
|
|
|
|
if (!intlv_ranges.empty() &&
|
2014-10-16 11:50:01 +02:00
|
|
|
!intlv_ranges.back().mergesWith(r.first)) {
|
2013-01-07 19:05:38 +01:00
|
|
|
ranges.push_back(AddrRange(intlv_ranges));
|
|
|
|
intlv_ranges.clear();
|
|
|
|
}
|
2014-10-16 11:50:01 +02:00
|
|
|
intlv_ranges.push_back(r.first);
|
2013-01-07 19:05:38 +01:00
|
|
|
} else {
|
|
|
|
// keep the current range
|
2014-10-16 11:50:01 +02:00
|
|
|
ranges.push_back(r.first);
|
2013-01-07 19:05:38 +01:00
|
|
|
}
|
2012-04-06 19:46:31 +02:00
|
|
|
}
|
2007-05-19 06:24:34 +02:00
|
|
|
}
|
|
|
|
|
2013-01-07 19:05:38 +01:00
|
|
|
// if there is still interleaved ranges waiting to be merged,
|
|
|
|
// go ahead and do it
|
|
|
|
if (!intlv_ranges.empty()) {
|
|
|
|
ranges.push_back(AddrRange(intlv_ranges));
|
|
|
|
}
|
|
|
|
|
2012-04-06 19:46:31 +02:00
|
|
|
return ranges;
|
2006-07-21 01:03:47 +02:00
|
|
|
}
|
2006-02-22 23:29:04 +01:00
|
|
|
|
2006-02-03 20:54:37 +01:00
|
|
|
void
|
2012-04-06 19:46:31 +02:00
|
|
|
PhysicalMemory::access(PacketPtr pkt)
|
2006-02-03 20:54:37 +01:00
|
|
|
{
|
2012-04-06 19:46:31 +02:00
|
|
|
assert(pkt->isRequest());
|
|
|
|
Addr addr = pkt->getAddr();
|
2015-02-16 09:33:37 +01:00
|
|
|
if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
|
|
|
|
rangeCache->second->access(pkt);
|
|
|
|
} else {
|
|
|
|
// do not update the cache here, as we typically call
|
|
|
|
// isMemAddr before calling access
|
|
|
|
const auto& m = addrMap.find(addr);
|
|
|
|
assert(m != addrMap.end());
|
|
|
|
m->second->access(pkt);
|
|
|
|
}
|
2006-02-03 20:54:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-06 19:46:31 +02:00
|
|
|
PhysicalMemory::functionalAccess(PacketPtr pkt)
|
2006-02-03 20:54:37 +01:00
|
|
|
{
|
2012-04-06 19:46:31 +02:00
|
|
|
assert(pkt->isRequest());
|
|
|
|
Addr addr = pkt->getAddr();
|
2015-02-16 09:33:37 +01:00
|
|
|
if (rangeCache != addrMap.end() && rangeCache->first.contains(addr)) {
|
|
|
|
rangeCache->second->functionalAccess(pkt);
|
|
|
|
} else {
|
|
|
|
// do not update the cache here, as we typically call
|
|
|
|
// isMemAddr before calling functionalAccess
|
|
|
|
const auto& m = addrMap.find(addr);
|
|
|
|
assert(m != addrMap.end());
|
|
|
|
m->second->functionalAccess(pkt);
|
|
|
|
}
|
2006-02-03 20:54:37 +01:00
|
|
|
}
|
2012-10-15 14:12:32 +02:00
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
PhysicalMemory::serialize(CheckpointOut &cp) const
|
2012-10-15 14:12:32 +02:00
|
|
|
{
|
|
|
|
// serialize all the locked addresses and their context ids
|
|
|
|
vector<Addr> lal_addr;
|
2015-08-07 10:59:13 +02:00
|
|
|
vector<ContextID> lal_cid;
|
2012-10-15 14:12:32 +02:00
|
|
|
|
2014-10-16 11:50:01 +02:00
|
|
|
for (auto& m : memories) {
|
|
|
|
const list<LockedAddr>& locked_addrs = m->getLockedAddrList();
|
|
|
|
for (const auto& l : locked_addrs) {
|
|
|
|
lal_addr.push_back(l.addr);
|
|
|
|
lal_cid.push_back(l.contextId);
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 10:51:03 +02:00
|
|
|
SERIALIZE_CONTAINER(lal_addr);
|
|
|
|
SERIALIZE_CONTAINER(lal_cid);
|
2012-10-15 14:12:32 +02:00
|
|
|
|
|
|
|
// serialize the backing stores
|
|
|
|
unsigned int nbr_of_stores = backingStore.size();
|
|
|
|
SERIALIZE_SCALAR(nbr_of_stores);
|
|
|
|
|
|
|
|
unsigned int store_id = 0;
|
|
|
|
// store each backing store memory segment in a file
|
2014-10-16 11:50:01 +02:00
|
|
|
for (auto& s : backingStore) {
|
2015-07-07 10:51:03 +02:00
|
|
|
ScopedCheckpointSection sec(cp, csprintf("store%d", store_id));
|
|
|
|
serializeStore(cp, store_id++, s.first, s.second);
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
PhysicalMemory::serializeStore(CheckpointOut &cp, unsigned int store_id,
|
|
|
|
AddrRange range, uint8_t* pmem) const
|
2012-10-15 14:12:32 +02:00
|
|
|
{
|
|
|
|
// we cannot use the address range for the name as the
|
|
|
|
// memories that are not part of the address map can overlap
|
2013-01-07 19:05:35 +01:00
|
|
|
string filename = name() + ".store" + to_string(store_id) + ".pmem";
|
2012-10-15 14:12:32 +02:00
|
|
|
long range_size = range.size();
|
|
|
|
|
|
|
|
DPRINTF(Checkpoint, "Serializing physical memory %s with size %d\n",
|
|
|
|
filename, range_size);
|
|
|
|
|
|
|
|
SERIALIZE_SCALAR(store_id);
|
|
|
|
SERIALIZE_SCALAR(filename);
|
|
|
|
SERIALIZE_SCALAR(range_size);
|
|
|
|
|
|
|
|
// write memory file
|
2015-07-07 10:51:03 +02:00
|
|
|
string filepath = CheckpointIn::dir() + "/" + filename.c_str();
|
2014-09-27 15:08:29 +02:00
|
|
|
gzFile compressed_mem = gzopen(filepath.c_str(), "wb");
|
2012-10-15 14:12:32 +02:00
|
|
|
if (compressed_mem == NULL)
|
2014-09-27 15:08:29 +02:00
|
|
|
fatal("Can't open physical memory checkpoint file '%s'\n",
|
2012-10-15 14:12:32 +02:00
|
|
|
filename);
|
|
|
|
|
|
|
|
uint64_t pass_size = 0;
|
|
|
|
|
|
|
|
// gzwrite fails if (int)len < 0 (gzwrite returns int)
|
|
|
|
for (uint64_t written = 0; written < range.size();
|
|
|
|
written += pass_size) {
|
|
|
|
pass_size = (uint64_t)INT_MAX < (range.size() - written) ?
|
|
|
|
(uint64_t)INT_MAX : (range.size() - written);
|
|
|
|
|
|
|
|
if (gzwrite(compressed_mem, pmem + written,
|
|
|
|
(unsigned int) pass_size) != (int) pass_size) {
|
|
|
|
fatal("Write failed on physical memory checkpoint file '%s'\n",
|
|
|
|
filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// close the compressed stream and check that the exit status
|
|
|
|
// is zero
|
|
|
|
if (gzclose(compressed_mem))
|
|
|
|
fatal("Close failed on physical memory checkpoint file '%s'\n",
|
|
|
|
filename);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
PhysicalMemory::unserialize(CheckpointIn &cp)
|
2012-10-15 14:12:32 +02:00
|
|
|
{
|
|
|
|
// unserialize the locked addresses and map them to the
|
|
|
|
// appropriate memory controller
|
|
|
|
vector<Addr> lal_addr;
|
2015-08-07 10:59:13 +02:00
|
|
|
vector<ContextID> lal_cid;
|
2015-07-07 10:51:03 +02:00
|
|
|
UNSERIALIZE_CONTAINER(lal_addr);
|
|
|
|
UNSERIALIZE_CONTAINER(lal_cid);
|
2012-10-15 14:12:32 +02:00
|
|
|
for(size_t i = 0; i < lal_addr.size(); ++i) {
|
2014-10-16 11:50:01 +02:00
|
|
|
const auto& m = addrMap.find(lal_addr[i]);
|
2012-10-15 14:12:32 +02:00
|
|
|
m->second->addLockedAddr(LockedAddr(lal_addr[i], lal_cid[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// unserialize the backing stores
|
|
|
|
unsigned int nbr_of_stores;
|
|
|
|
UNSERIALIZE_SCALAR(nbr_of_stores);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < nbr_of_stores; ++i) {
|
2015-07-07 10:51:03 +02:00
|
|
|
ScopedCheckpointSection sec(cp, csprintf("store%d", i));
|
|
|
|
unserializeStore(cp);
|
2012-10-15 14:12:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-07 10:51:03 +02:00
|
|
|
PhysicalMemory::unserializeStore(CheckpointIn &cp)
|
2012-10-15 14:12:32 +02:00
|
|
|
{
|
|
|
|
const uint32_t chunk_size = 16384;
|
|
|
|
|
|
|
|
unsigned int store_id;
|
|
|
|
UNSERIALIZE_SCALAR(store_id);
|
|
|
|
|
|
|
|
string filename;
|
|
|
|
UNSERIALIZE_SCALAR(filename);
|
2015-07-07 10:51:03 +02:00
|
|
|
string filepath = cp.cptDir + "/" + filename;
|
2012-10-15 14:12:32 +02:00
|
|
|
|
|
|
|
// mmap memoryfile
|
2014-09-27 15:08:29 +02:00
|
|
|
gzFile compressed_mem = gzopen(filepath.c_str(), "rb");
|
2012-10-15 14:12:32 +02:00
|
|
|
if (compressed_mem == NULL)
|
2014-09-27 15:08:29 +02:00
|
|
|
fatal("Can't open physical memory checkpoint file '%s'", filename);
|
2012-10-15 14:12:32 +02:00
|
|
|
|
2014-02-18 11:51:01 +01:00
|
|
|
// we've already got the actual backing store mapped
|
2012-10-15 14:12:32 +02:00
|
|
|
uint8_t* pmem = backingStore[store_id].second;
|
|
|
|
AddrRange range = backingStore[store_id].first;
|
|
|
|
|
|
|
|
long range_size;
|
|
|
|
UNSERIALIZE_SCALAR(range_size);
|
|
|
|
|
|
|
|
DPRINTF(Checkpoint, "Unserializing physical memory %s with size %d\n",
|
|
|
|
filename, range_size);
|
|
|
|
|
|
|
|
if (range_size != range.size())
|
|
|
|
fatal("Memory range size has changed! Saw %lld, expected %lld\n",
|
|
|
|
range_size, range.size());
|
|
|
|
|
|
|
|
uint64_t curr_size = 0;
|
|
|
|
long* temp_page = new long[chunk_size];
|
|
|
|
long* pmem_current;
|
|
|
|
uint32_t bytes_read;
|
|
|
|
while (curr_size < range.size()) {
|
|
|
|
bytes_read = gzread(compressed_mem, temp_page, chunk_size);
|
|
|
|
if (bytes_read == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
assert(bytes_read % sizeof(long) == 0);
|
|
|
|
|
|
|
|
for (uint32_t x = 0; x < bytes_read / sizeof(long); x++) {
|
|
|
|
// Only copy bytes that are non-zero, so we don't give
|
|
|
|
// the VM system hell
|
|
|
|
if (*(temp_page + x) != 0) {
|
|
|
|
pmem_current = (long*)(pmem + curr_size + x * sizeof(long));
|
|
|
|
*pmem_current = *(temp_page + x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr_size += bytes_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] temp_page;
|
|
|
|
|
|
|
|
if (gzclose(compressed_mem))
|
|
|
|
fatal("Close failed on physical memory checkpoint file '%s'\n",
|
|
|
|
filename);
|
|
|
|
}
|