Skip to content

Commit

Permalink
Merge Pull Request #2331 from mjleven/sst-elements/checkpoint
Browse files Browse the repository at this point in the history
Automatically Merged using SST Pull Request AutoTester
PR Title: b'Checkpoint Vanadis'
PR Author: mjleven
  • Loading branch information
sst-autotester authored Mar 8, 2024
2 parents 58f2391 + c3d5ea2 commit e8f1db4
Show file tree
Hide file tree
Showing 26 changed files with 1,364 additions and 33 deletions.
89 changes: 88 additions & 1 deletion src/sst/elements/memHierarchy/membackend/backing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Backing {

virtual uint8_t get( Addr addr) = 0;
virtual void get( Addr addr, size_t size, std::vector<uint8_t>& data) = 0;
virtual void dump( FILE* ) {};
};

class BackingMMAP : public Backing {
Expand Down Expand Up @@ -100,7 +101,49 @@ class BackingMalloc : public Backing {
m_shift = log2Of(m_allocUnit);
}

BackingMalloc( FILE* fp ) {
int num;
char str[80];
fscanf(fp,"Number-of-pages: %d\n", &num );
fscanf(fp,"m_allocUnit: %d\n", &m_allocUnit );
fscanf(fp,"m_init: %d\n", &m_init );
fscanf(fp,"m_shift: %d\n", &m_shift );
printf("Number-of-pages: %d\n",num);
printf("m_allocUnit: %d\n",m_allocUnit);
printf("m_init: %d\n",m_init);
printf("m_shift: %d\n",m_shift);
Addr addr;
while ( 1 == fscanf(fp,"addr: %" PRIx64 "\n",&addr) ) {
Addr bAddr = addr >> m_shift;

assert( m_buffer.find( bAddr ) == m_buffer.end() );

auto buf = (uint8_t*) malloc( m_allocUnit );
m_buffer[ bAddr ] = buf;
//printf("%s() %#lx %#lx %p\n",__func__, addr, bAddr, buf );
auto ptr = (uint64_t*) m_buffer[bAddr];
//printf("addr: %#x %p\n",addr,ptr);
auto length = ( sizeof(uint8_t) * m_allocUnit ) / sizeof(uint64_t);

for ( auto i = 0; i < length ; i++ ) {
#if 0
if ( i % 8 == 0 ) {
printf("\n%#lx ",addr + i*8);
}
#endif
uint64_t data;
assert( 1 == fscanf(fp,"%" PRIx64 " ",&data) );
//printf("%#" PRIx64 " ",data);
ptr[i] = data;
}
//printf("\n");
}
}

void set( Addr addr, uint8_t value ) {
#if 0
printf("%s addr=%#lx\n",__func__,addr);
#endif
Addr bAddr = addr >> m_shift;
Addr offset = addr - (bAddr << m_shift);
allocIfNeeded(bAddr);
Expand All @@ -115,8 +158,14 @@ class BackingMalloc : public Backing {

allocIfNeeded(bAddr);

#if 0
printf("%s() addr=%#lx size=%zu ",__func__,addr,size);
#endif
while (dataOffset != size) {
m_buffer[bAddr][offset] = data[dataOffset];
#if 0
printf("%#x ",data[dataOffset]);
#endif
offset++;
dataOffset++;

Expand All @@ -126,17 +175,27 @@ class BackingMalloc : public Backing {
allocIfNeeded(bAddr);
}
}
#if 0
printf("\n");
#endif
}

void get (Addr addr, size_t size, std::vector<uint8_t> &data) {
#if 0
printf("%s() addr=%#lx size=%zu ",__func__,addr,size);
#endif
Addr bAddr = addr >> m_shift;
Addr offset = addr - (bAddr << m_shift);
size_t dataOffset = 0;

allocIfNeeded(bAddr);
assert( data.size() == size );

assert( m_buffer.find(bAddr) != m_buffer.end() );
auto buf = m_buffer[bAddr];
while (dataOffset != size) {
data[dataOffset] = m_buffer[bAddr][offset];

data[dataOffset] = buf[offset];
offset++;
dataOffset++;
if (offset == m_allocUnit) {
Expand All @@ -145,6 +204,12 @@ class BackingMalloc : public Backing {
allocIfNeeded(bAddr);
}
}
#if 0
for ( auto i = 0; i < size; i++ ) {
printf("%x ",data[i]);
}
printf("\n");
#endif
}

uint8_t get( Addr addr ) {
Expand All @@ -154,6 +219,28 @@ class BackingMalloc : public Backing {
return m_buffer[bAddr][offset];
}


void dump( FILE* fp ) {
fprintf(fp,"Number-of-pages: %d\n",m_buffer.size());
fprintf(fp,"m_allocUnit: %d\n",m_allocUnit);
fprintf(fp,"m_init: %d\n",m_init);
fprintf(fp,"m_shift: %d\n",m_shift);

for ( auto const& x : m_buffer ) {
fprintf(fp,"addr: %#lx\n",x.first << m_shift);
auto length = sizeof(uint8_t)*m_allocUnit;
length /= sizeof(uint64_t);
auto ptr = (uint64_t*) x.second;
for ( auto i = 0; i < length ; i++ ) {
fprintf(fp,"%#" PRIx64 "",ptr[i]);
if ( i + 1 < length ) {
fprintf(fp," ");
}
}
fprintf(fp,"\n");
}
}

private:
void allocIfNeeded(Addr bAddr) {
if (m_buffer.find(bAddr) == m_buffer.end()) {
Expand Down
35 changes: 34 additions & 1 deletion src/sst/elements/memHierarchy/memoryController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ MemController::MemController(ComponentId_t id, Params &params) : Component(id),
// Output for debug
dbg.init("", dlevel, 0, (Output::output_location_t)params.find<int>("debug", 0));

checkpointDir_ = params.find<std::string>("checkpointDir", "");
auto tmp = params.find<std::string>("checkpoint", "");
if ( ! tmp.empty() ) {
assert( ! checkpointDir_.empty() );
if ( 0 == tmp.compare("load") ) {
checkpoint_ = CHECKPOINT_LOAD;
} else if ( 0 == tmp.compare("save") ) {
checkpoint_ = CHECKPOINT_SAVE;
} else {
assert(0);
}
} else {
checkpoint_ = NO_CHECKPOINT;
}

bool initBacking = params.find<bool>("initBacking", false);

// Debug address
Expand Down Expand Up @@ -310,7 +325,16 @@ MemController::MemController(ComponentId_t id, Params &params) : Component(id),
out.fatal(CALL_INFO, -1, "%s, Error - unable to create backing store. Exception thrown is %d.\n", getName().c_str(), e);
}
} else if (backingType == "malloc") {
backing_ = new Backend::BackingMalloc(sizeBytes,initBacking);
if ( CHECKPOINT_LOAD == checkpoint_ ) {
stringstream filename;
filename << checkpointDir_ << "/" << getName();
//printf("%s\n",filename.str().c_str());
auto fp = fopen(filename.str().c_str(),"r");
assert(fp);
backing_ = new Backend::BackingMalloc(fp);
} else {
backing_ = new Backend::BackingMalloc(sizeBytes,initBacking);
}
}

/* Custom command handler */
Expand Down Expand Up @@ -579,6 +603,15 @@ void MemController::finish(void) {
cycle--;
memBackendConvertor_->finish(cycle);
link_->finish();
if ( CHECKPOINT_SAVE == checkpoint_ ) {
stringstream filename;
filename << checkpointDir_ << "/" << getName();
auto fp = fopen(filename.str().c_str(),"w+");
assert(fp);
printf("Checkpoint component `%s` %s\n",getName().c_str(), filename.str().c_str());
backing_->dump( fp );
fclose( fp );
}
}

void MemController::writeData(MemEvent* event) {
Expand Down
3 changes: 3 additions & 0 deletions src/sst/elements/memHierarchy/memoryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ class MemController : public SST::Component {
void writeData( MemEvent* );
void readData( MemEvent* );

std::string checkpointDir_;
enum { NO_CHECKPOINT, CHECKPOINT_LOAD, CHECKPOINT_SAVE } checkpoint_;

size_t memSize_;

bool clockOn_;
Expand Down
2 changes: 2 additions & 0 deletions src/sst/elements/mmu/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class MMU : public SubComponent {

MMU(SST::ComponentId_t id, SST::Params& params);
virtual ~MMU() {}
virtual void checkpoint( std::string ) = 0;
virtual void checkpointLoad( std::string ) = 0;

virtual void init(unsigned int phase);
void registerPermissionsCallback( Callback& callback ) { m_permissionsCallback = callback; }
Expand Down
62 changes: 62 additions & 0 deletions src/sst/elements/mmu/simpleMMU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,65 @@ int SimpleMMU::getPerms( unsigned pid, uint32_t vpn ) {
return pte->perms;
}

void SimpleMMU::checkpoint( std::string dir ) {

std::stringstream filename;
filename << dir << "/" << getName();
auto fp = fopen(filename.str().c_str(),"w+");

m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"Checkpoint component `%s` %s\n",getName().c_str(), filename.str().c_str());

fprintf(fp,"m_pageTableMap.size() %zu\n",m_pageTableMap.size());
for ( auto & x : m_pageTableMap ) {
auto pageTable = x.second;
fprintf(fp,"pid: %i\n",x.first);
pageTable->checkpoint( fp );
}

fprintf(fp,"m_coreToPid.size() %zu\n", m_coreToPid.size());
for ( auto core = 0; core < m_coreToPid.size(); core++ ) {
auto& x = m_coreToPid[core];
fprintf(fp,"core: %d, numPids: %d\n",core,x.size());
for ( auto j = 0; j < x.size(); j++ ) {
fprintf(fp,"%d ",x[j]);
}
fprintf(fp,"\n");
}
}

void SimpleMMU::checkpointLoad( std::string dir ) {
std::stringstream filename;
filename << dir << "/" << getName();
auto fp = fopen(filename.str().c_str(),"r");
assert(fp);

m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"Checkpoint load component `%s` %s\n",getName().c_str(), filename.str().c_str());

int size;
assert( 1 == fscanf( fp, "m_pageTableMap.size() %d\n",&size) );
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"m_pageTableMap.size() %d\n",size);
for ( auto i = 0; i < size; i++ ) {
int pid;
assert( 1 == fscanf( fp, "pid: %d\n",&pid) );
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"pid: %d\n",pid);
m_pageTableMap[pid] = new PageTable( &m_dbg, fp );
}

assert( 1 == fscanf( fp, "m_coreToPid.size() %d\n", &size) );
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"m_coreToPid.size() %d\n",size );

m_coreToPid.resize( size );
for ( auto core = 0; core < m_coreToPid.size(); core++ ) {
int x, numPids;
assert( 2 == fscanf( fp, "core: %d, numPids: %d\n", &x, &numPids) );
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT, "core: %d, numPids: %d\n", x, numPids);
m_coreToPid[core].resize( numPids );
for ( auto i = 0; i < numPids; i++ ) {
int pid;
assert( 1 == fscanf(fp,"%d ",&pid) );
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"%d ",pid);
m_coreToPid[core][i] = pid;
}
m_dbg.debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"\n");
}
}
25 changes: 25 additions & 0 deletions src/sst/elements/mmu/simpleMMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace SST {

#define MMU_DBG_CHECKPOINT (1<<0)
namespace MMU_Lib {

class SimpleMMU : public MMU {
Expand All @@ -43,6 +44,8 @@ class SimpleMMU : public MMU {
)

SimpleMMU(SST::ComponentId_t id, SST::Params& params);
void checkpoint( std::string );
void checkpointLoad( std::string );

virtual void removeWrite( unsigned pid );
virtual void map( unsigned pid, uint32_t vpn, std::vector<uint32_t>& ppns, int pageSize, uint64_t flags );
Expand Down Expand Up @@ -100,6 +103,22 @@ class SimpleMMU : public MMU {

class PageTable {
public:
PageTable() {}
PageTable( SST::Output* output, FILE* fp ) {
int size;

assert( 1 == fscanf( fp, "pteMap.size() %d\n", &size ) );
output->debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"pteMap.size() %d\n",size);
for ( auto i = 0; i < size; i++ ) {
uint32_t vpn;
uint32_t ppn;
uint32_t perms;
assert( 3 == fscanf( fp, "vpn: %d, ppn: %d, perms: %x\n", &vpn, &ppn, &perms ) );
output->debug(CALL_INFO_LONG,1,MMU_DBG_CHECKPOINT,"vpn: %d, ppn: %d, perms: %x\n", vpn, ppn, perms );
pteMap[vpn] = PTE( ppn, perms );
}
}

void add( uint32_t vpn, PTE pte ) {
pteMap[vpn] = pte;
}
Expand All @@ -123,6 +142,12 @@ class SimpleMMU : public MMU {
printf("PageTabl::%s() %s vpn=%d ppn=%d perm=%#x\n",__func__,str.c_str(),kv.first,kv.second.ppn,kv.second.perms);
}
}
void checkpoint( FILE* fp ) {
fprintf(fp,"pteMap.size() %zu\n",pteMap.size());
for ( auto & x : pteMap ) {
fprintf(fp,"vpn: %d, ppn: %d, perms: %#lx \n", x.first,x.second.ppn,x.second.perms );
}
}
private:
std::map<uint32_t,PTE> pteMap;
};
Expand Down
3 changes: 3 additions & 0 deletions src/sst/elements/vanadis/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ vinsbundle.h \
vinsloader.h \
\
os/vappruntimememory.h \
os/vcheckpointreq.h \
os/vcpuos.h \
os/vcpuos2.h \
os/vdumpregsreq.h \
Expand Down Expand Up @@ -158,6 +159,7 @@ os/include/virtMemMap.h \
os/callev/voscallaccessev.h \
os/callev/voscallall.h \
os/callev/voscallbrk.h \
os/callev/voscallcheckpoint.h \
os/callev/voscallclone.h \
os/callev/voscallclose.h \
os/callev/voscallexitgrp.h \
Expand Down Expand Up @@ -196,6 +198,7 @@ os/callev/voscallwritev.h \
\
os/syscall/access.h \
os/syscall/brk.h \
os/syscall/checkpoint.h \
os/syscall/clone.cc \
os/syscall/clone.h \
os/syscall/close.h \
Expand Down
1 change: 1 addition & 0 deletions src/sst/elements/vanadis/os/callev/voscallall.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "os/callev/voscallaccessev.h"
#include "os/callev/voscallgetaffinity.h"
#include "os/callev/voscallcheckpoint.h"
#include "os/callev/voscallbrk.h"
#include "os/callev/voscallclose.h"
#include "os/callev/voscallexit.h"
Expand Down
Loading

0 comments on commit e8f1db4

Please sign in to comment.