Can choose between mmap (default) and malloc
This commit is contained in:
@@ -49,6 +49,7 @@
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <stdlib.h>
|
||||
#include "../common/DebugManager.h"
|
||||
#include "../common/dramExtension.h"
|
||||
#include "../controller/Controller.h"
|
||||
@@ -59,6 +60,8 @@
|
||||
#include "../common/third_party/DRAMPower/src/libdrampower/LibDRAMPower.h"
|
||||
#include "../error/errormodel.h"
|
||||
|
||||
//#define USE_MALLOC
|
||||
|
||||
using namespace std;
|
||||
using namespace tlm;
|
||||
using namespace Data;
|
||||
@@ -95,9 +98,15 @@ struct Dram : sc_module {
|
||||
dramController = NULL;
|
||||
|
||||
std::uint64_t memorySize = Configuration::getInstance().getSimMemSizeInBytes();
|
||||
#ifdef USE_MALLOC
|
||||
memory = (unsigned char *)malloc(memorySize);
|
||||
if (!memory) {
|
||||
SC_REPORT_FATAL(this->name(), "Memory allocation failed");
|
||||
}
|
||||
#else
|
||||
// allocate and model storage of one DRAM channel using memory map
|
||||
memory = (unsigned char *)mmap(NULL, memorySize, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
|
||||
memory = (unsigned char *)mmap(NULL, memorySize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
|
||||
#endif
|
||||
|
||||
tSocket.register_nb_transport_fw(this, &Dram::nb_transport_fw);
|
||||
tSocket.register_transport_dbg(this, &Dram::transport_dbg);
|
||||
@@ -299,6 +308,10 @@ struct Dram : sc_module {
|
||||
for (auto e : ememory) {
|
||||
delete e;
|
||||
}
|
||||
|
||||
#ifdef USE_MALLOC
|
||||
free(memory);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual tlm::tlm_sync_enum nb_transport_fw(tlm::tlm_generic_payload &payload,
|
||||
|
||||
Reference in New Issue
Block a user