Go to the documentation of this file.
42 #include <sys/types.h>
54 #include "debug/AddrRanges.hh"
55 #include "debug/Checkpoint.hh"
65 #if defined(__APPLE__) || defined(__FreeBSD__)
67 #define MAP_NORESERVE 0
73 bool mmap_using_noreserve,
74 const std::string& shared_backstore) :
75 _name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve),
76 sharedBackstore(shared_backstore)
78 if (mmap_using_noreserve)
79 warn(
"Not reserving swap space. May cause SIGSEGV on actual usage\n");
83 for (
const auto&
m : _memories) {
85 if (
m->isInAddrMap()) {
94 "Memory address range for %s is overlapping\n",
101 "Skipping memory %s that is not in global address map\n",
105 fatal_if(
m->getAddrRange().interleaved(),
106 "Memory %s that is not in the global address map cannot "
107 "be interleaved\n",
m->name());
114 m->isConfReported(),
m->isInAddrMap(),
127 if (!
r.second->isNull()) {
129 if (
r.first.interleaved()) {
133 if (!intlv_ranges.empty() &&
134 !intlv_ranges.back().mergesWith(
r.first)) {
138 for (
const auto&
c : curr_memories)
139 if (
f->isConfReported() !=
c->isConfReported() ||
140 f->isInAddrMap() !=
c->isInAddrMap() ||
141 f->isKvmMap() !=
c->isKvmMap())
142 fatal(
"Inconsistent flags in an interleaved "
146 f->isConfReported(),
f->isInAddrMap(),
149 intlv_ranges.clear();
150 curr_memories.clear();
152 intlv_ranges.push_back(
r.first);
153 curr_memories.push_back(
r.second);
157 r.second->isConfReported(),
158 r.second->isInAddrMap(),
159 r.second->isKvmMap());
166 if (!intlv_ranges.empty()) {
170 for (
const auto&
c : curr_memories)
171 if (
f->isConfReported() !=
c->isConfReported() ||
172 f->isInAddrMap() !=
c->isInAddrMap() ||
173 f->isKvmMap() !=
c->isKvmMap())
174 fatal(
"Inconsistent flags in an interleaved "
178 f->isConfReported(),
f->isInAddrMap(),
186 bool conf_table_reported,
bool in_addr_map,
bool kvm_map)
189 "Cannot create backing store for interleaved range %s\n",
193 DPRINTF(AddrRanges,
"Creating backing store for range %s with size %d\n",
201 map_flags = MAP_ANON | MAP_PRIVATE;
203 DPRINTF(AddrRanges,
"Sharing backing store as %s\n",
207 panic(
"Shared memory failed");
208 if (ftruncate(shm_fd, range.
size()))
209 panic(
"Setting size of shared memory failed");
210 map_flags = MAP_SHARED;
216 map_flags |= MAP_NORESERVE;
219 uint8_t* pmem = (uint8_t*) mmap(NULL, range.
size(),
220 PROT_READ | PROT_WRITE,
221 map_flags, shm_fd, 0);
223 if (pmem == (uint8_t*) MAP_FAILED) {
225 fatal(
"Could not mmap %d bytes for range %s!\n", range.
size(),
232 conf_table_reported, in_addr_map, kvm_map);
235 for (
const auto&
m : _memories) {
236 DPRINTF(AddrRanges,
"Mapping memory %s to backing store\n",
238 m->setBackingStore(pmem);
246 munmap((
char*)
s.pmem,
s.range.size());
263 if (
r.second->isConfReported()) {
265 if (
r.first.interleaved()) {
269 if (!intlv_ranges.empty() &&
270 !intlv_ranges.back().mergesWith(
r.first)) {
271 ranges.push_back(
AddrRange(intlv_ranges));
272 intlv_ranges.clear();
274 intlv_ranges.push_back(
r.first);
277 ranges.push_back(
r.first);
284 if (!intlv_ranges.empty()) {
285 ranges.push_back(
AddrRange(intlv_ranges));
297 m->second->access(pkt);
306 m->second->functionalAccess(pkt);
319 lal_addr.push_back(
l.addr);
320 lal_cid.push_back(
l.contextId);
331 unsigned int store_id = 0;
345 std::string filename =
347 long range_size = range.
size();
349 DPRINTF(Checkpoint,
"Serializing physical memory %s with size %d\n",
350 filename, range_size);
358 gzFile compressed_mem = gzopen(filepath.c_str(),
"wb");
359 if (compressed_mem == NULL)
360 fatal(
"Can't open physical memory checkpoint file '%s'\n",
363 uint64_t pass_size = 0;
366 for (uint64_t written = 0; written < range.
size();
367 written += pass_size) {
368 pass_size = (uint64_t)INT_MAX < (range.
size() - written) ?
369 (uint64_t)INT_MAX : (range.
size() - written);
371 if (gzwrite(compressed_mem, pmem + written,
372 (
unsigned int) pass_size) != (
int) pass_size) {
373 fatal(
"Write failed on physical memory checkpoint file '%s'\n",
380 if (gzclose(compressed_mem))
381 fatal(
"Close failed on physical memory checkpoint file '%s'\n",
395 for (
size_t i = 0;
i < lal_addr.size(); ++
i) {
397 m->second->addLockedAddr(
LockedAddr(lal_addr[
i], lal_cid[
i]));
401 unsigned int nbr_of_stores;
404 for (
unsigned int i = 0;
i < nbr_of_stores; ++
i) {
414 const uint32_t chunk_size = 16384;
416 unsigned int store_id;
419 std::string filename;
421 std::string filepath =
cp.getCptDir() +
"/" + filename;
424 gzFile compressed_mem = gzopen(filepath.c_str(),
"rb");
425 if (compressed_mem == NULL)
426 fatal(
"Can't open physical memory checkpoint file '%s'", filename);
435 DPRINTF(Checkpoint,
"Unserializing physical memory %s with size %d\n",
436 filename, range_size);
438 if (range_size != range.
size())
439 fatal(
"Memory range size has changed! Saw %lld, expected %lld\n",
440 range_size, range.
size());
442 uint64_t curr_size = 0;
443 long* temp_page =
new long[chunk_size];
446 while (curr_size < range.
size()) {
447 bytes_read = gzread(compressed_mem, temp_page, chunk_size);
451 assert(bytes_read %
sizeof(
long) == 0);
453 for (uint32_t
x = 0;
x < bytes_read /
sizeof(long);
x++) {
456 if (*(temp_page +
x) != 0) {
457 pmem_current = (
long*)(pmem + curr_size +
x *
sizeof(
long));
458 *pmem_current = *(temp_page +
x);
461 curr_size += bytes_read;
466 if (gzclose(compressed_mem))
467 fatal(
"Close failed on physical memory checkpoint file '%s'\n",
#define fatal(...)
This implements a cprintf based fatal() function.
AddrRange getAddrRange() const
Get address range to which this packet belongs.
#define UNSERIALIZE_SCALAR(scalar)
iterator insert(const AddrRange &r, const V &d)
#define UNSERIALIZE_CONTAINER(member)
bool interleaved() const
Determine if the range is interleaved or not.
const_iterator end() const
Locked address class that represents a physical address and a context id.
const std::string to_string(sc_enc enc)
void unserializeStore(CheckpointIn &cp)
Unserialize a specific backing store, identified by a section.
const std::string sharedBackstore
std::unordered_map< int, std::stack< Addr > > locked_addrs
PhysicalMemory(const PhysicalMemory &)
An abstract memory represents a contiguous block of physical memory, with an associated address range...
const std::string name() const
Return the name for debugging and for creation of sections for checkpointing.
void createBackingStore(AddrRange range, const std::vector< AbstractMemory * > &_memories, bool conf_table_reported, bool in_addr_map, bool kvm_map)
Create the memory region providing the backing store for a given address range that corresponds to a ...
void serializeStore(CheckpointOut &cp, unsigned int store_id, AddrRange range, uint8_t *pmem) const
Serialize a specific store.
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
std::vector< BackingStoreEntry > backingStore
const bool mmapUsingNoReserve
void functionalAccess(PacketPtr pkt)
Perform an untimed memory read or write without changing anything but the memory itself.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define SERIALIZE_SCALAR(scalar)
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
std::vector< AbstractMemory * > memories
bool isMemAddr(Addr addr) const
Check if a physical address is within a range of a memory that is part of the global address map.
std::string to_string() const
Get a string representation of the range.
AddrRangeMap< AbstractMemory *, 1 > addrMap
#define SERIALIZE_CONTAINER(member)
const_iterator contains(const AddrRange &r) const
Find entry that contains the given address range.
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
void serialize(CheckpointOut &cp) const override
Serialize all the memories in the system.
std::ostream CheckpointOut
void access(PacketPtr pkt)
Perform an untimed memory access and update all the state (e.g.
AddrRangeList getConfAddrRanges() const
Get the memory ranges for all memories that are to be reported to the configuration table.
static std::string dir()
Get the current checkout directory name.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Addr size() const
Get the size of the address range.
void unserialize(CheckpointIn &cp) override
Unserialize the memories in the system.
~PhysicalMemory()
Unmap all the backing store we have used.
std::string csprintf(const char *format, const Args &...args)
#define panic(...)
This implements a cprintf based panic() function.
Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17