Skip to content

Commit

Permalink
Merge branch 'FEATURE-0242-HardwareIdle-Mothership' of github.com:POE…
Browse files Browse the repository at this point in the history
…TSII/Orchestrator into FEATURE-0242-HardwareIdle-Mothership
  • Loading branch information
mvousden committed Oct 27, 2021
2 parents 7fb7f9e + 7c7dd68 commit 2e85f79
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 8 deletions.
70 changes: 70 additions & 0 deletions Source/OrchBase/Composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ ComposerGraphI_t::ComposerGraphI_t()

compilationFlags = "";
provenanceCache = "";

idleInstructionBinary = "";
idleDataBinary = "";
}

ComposerGraphI_t::ComposerGraphI_t(GraphI_t* graphIIn, std::string& outputPath)
Expand All @@ -59,6 +62,9 @@ ComposerGraphI_t::ComposerGraphI_t(GraphI_t* graphIIn, std::string& outputPath)

compilationFlags = "";
provenanceCache = "";

idleInstructionBinary = "";
idleDataBinary = "";
}

ComposerGraphI_t::~ComposerGraphI_t()
Expand Down Expand Up @@ -126,6 +132,11 @@ void ComposerGraphI_t::Dump(unsigned off,FILE* file)
default: fprintf(file, "**INVALID**\n");
}


fprintf(file, " Hardware Idle Instructions: %s\n",
idleInstructionBinary.c_str());
fprintf(file, " Hardware Idle Data: %s\n",idleDataBinary.c_str());

fprintf(file, "\nNitty gritty details:\n");
fprintf(file, " Device type strs map size: %lu \n",
static_cast<unsigned long>(devTStrsMap.size()));
Expand Down Expand Up @@ -1012,6 +1023,34 @@ bool Composer::isCompiled(GraphI_t* graphI)
return builderGraphI->compiled;
}

/******************************************************************************
* Public method to get the paths for the HW Idle binaries
*****************************************************************************/
bool Composer::getDummyPaths(GraphI_t* graphI, std::string& instrBin,
std::string& dataBin)
{
ComposerGraphI_t* builderGraphI;

ComposerGraphIMap_t::iterator srch = graphIMap.find(graphI);
if (srch == graphIMap.end())
{ // The Graph Instance has not been seen before, so not compiled.
return false;

} else {
builderGraphI = srch->second;
}

if(builderGraphI->idleInstructionBinary == "" ||
builderGraphI->idleDataBinary == "")
{ // We are missing a binary path, return false.
return false;
}

instrBin = builderGraphI->idleInstructionBinary;
dataBin = builderGraphI->idleDataBinary;
return true;
}

/******************************************************************************
* Invoke a clean and then a degenerate
*****************************************************************************/
Expand Down Expand Up @@ -1211,6 +1250,37 @@ int Composer::checkBinaries(ComposerGraphI_t* builderGraphI)
std::string taskDir(builderGraphI->outputDir);
std::string elfPath(taskDir + "/bin");


// Check that the "dummy" binaries for HW idle were generated.
FILE* dummyBinary;

// Check Dummy Instruction binary and add to GraphI
std::string dummyPath = elfPath + "/dummy_code.v";
dummyBinary = fopen(dummyPath.c_str(), "r");
if(dummyBinary == PNULL)
{ // Failed to open binary
fprintf(fd,"\tFailed to open dummy instruction binary %s after compilation\n",
dummyPath.c_str());
return -1;
}
fclose(dummyBinary);
builderGraphI->idleInstructionBinary = dummyPath;


// Check Dummy Data binary and add to GraphI
dummyPath = elfPath + "/threadCtxInit_data.v";
dummyBinary = fopen(dummyPath.c_str(), "r");
if(dummyBinary == PNULL)
{ // Failed to open binary
fprintf(fd,"\tFailed to open dummy data binary %s after compilation\n",
dummyPath.c_str());
return -1;
}
fclose(dummyBinary);
builderGraphI->idleDataBinary = dummyPath;



// Check that the core binaries were made and link to each core.
WALKSET(P_core*,(*(builderGraphI->cores)),coreNode)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/OrchBase/Composer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ typedef struct ComposerGraphI_t
ssLoopMode_t softswitchLoopMode;
bool softswitchRequestIdle;

std::string idleInstructionBinary; // Dummy instruction binary for HW Idle
std::string idleDataBinary; // Dummy data binary for HW Idle

// Constructors/Destructors
ComposerGraphI_t();
ComposerGraphI_t(GraphI_t*, std::string&);
Expand Down Expand Up @@ -140,6 +143,8 @@ int addFlags(GraphI_t*, std::string&);
bool isGenerated(GraphI_t*);
bool isCompiled(GraphI_t*);

bool getDummyPaths(GraphI_t*, std::string&, std::string&); // Get the hardware idle binary names

void Show(FILE * = stdout);
void Dump(unsigned = 0,FILE * = stdout);

Expand Down
6 changes: 3 additions & 3 deletions Source/OrchBase/Handlers/CmDepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ int CmDepl::DeployGraph(GraphI_t* gi)
bool soloApp = dynamic_cast<Root *>(par)->pOC->SingleApp();
if (soloApp)
{
/* TODO: GMB to plonk binary paths here (or at least some way to
* grab them). <!> */
#warning GMB to define these paths somewhere.
std::string codePath;
std::string dataPath;

// Get the dummy binary paths
par->pComposer->getDummyPaths(gi, codePath, dataPath);

emptMessage.Put(0, &codePath);
emptMessage.Put(1, &dataPath);
Expand Down
35 changes: 30 additions & 5 deletions Source/Softswitch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ VDTARGETS := $(patsubst $(GENINC)/vars_%.h,$(BINDIR)/softswitch_data_%.v,$(wildc
# targets for thread-local variables
THREADVARS := $(patsubst $(GENSRC)/%.cpp,%.o,$(wildcard $(GENSRC)/vars_*_*.cpp))

.PHONY: all clean printvars supervisor
all : $(TARGETS) $(VCTARGETS) $(VDTARGETS) supervisor
.PHONY: all clean printvars supervisor dummy
all : $(TARGETS) $(VCTARGETS) $(VDTARGETS) supervisor dummy

# This line can be given a target/prerequisite (tgt : $(TARGETS)) if needed
# $(foreach TARGET,$<,cp $(TARGET) $(BINDIR)/$(TARGET))
Expand All @@ -155,9 +155,11 @@ SupervisorData.o : supervisor.bin
ld -r -b binary -o $@ supervisor.bin
rm supervisor.bin

# Supervisor shared object.
$(BINDIR)/libSupervisor.so: Supervisor.cpp Supervisor.h supervisor_generated.cpp supervisor_generated.h SupervisorApi.h SupervisorApiEntrypoints.h SupervisorData.o
$(MPICXX) $(MPICFLAGS) $(MPILDFLAGS) -O3 -Wl,-soname,libSupervisor.so -o $@ $< SupervisorData.o
$(MPICXX) $(MPICFLAGS) -pipe $(MPILDFLAGS) -O3 -Wl,-soname,libSupervisor.so -o $@ $< SupervisorData.o

# Split out the code and data from the elf.
$(BINDIR)/softswitch_code_%.v: $(BINDIR)/softswitch_%.elf
$(TINSELBIN)/checkelf.sh $<
$(RV_OBJCOPY) -O verilog --only-section=.text $< $@
Expand All @@ -176,7 +178,7 @@ io.o : io.c io.h tinsel.h $(TINSELINC)/config.h

## the pattern substitution should find all vars_x_y.o created from vars_x_y.cpp
.SECONDEXPANSION:
$(BINDIR)/softswitch_%.elf : softswitch_main.o softswitch_common.o softswitch.o vars_%.o $$(patsubst $$(SECEXPCPPS),$$(SECEXPOS),$$(wildcard $(GENSRC)/vars_$$*_*.cpp)) handlers_%.o io.o link_%.ld entry.o libc.a libgcc.a
$(BINDIR)/softswitch_%.elf : softswitch_main.o softswitch_common.o softswitch.o softswitch_vars.o vars_%.o $$(patsubst $$(SECEXPCPPS),$$(SECEXPOS),$$(wildcard $(GENSRC)/vars_$$*_*.cpp)) handlers_%.o io.o link_%.ld entry.o libc.a libgcc.a
$(RV_LD) $(LDFLAGS) -T link_$(notdir $*).ld -o $@ $(filter-out link_$(notdir $*).ld, $^)

# this convoluted rule (we hope) will establish as a prerequisite for any file
Expand Down Expand Up @@ -205,5 +207,28 @@ link_%.ld : genld.sh
$(HL)/%.o :
make -C $(TINSELHL)


# Rules to build the dummy binaries for Hardware Idle detection.
dummy: $(BINDIR)/threadCtxInit_data.v $(BINDIR)/dummy_code.v

threadCtxInitGenerator : threadCtxInitGenerator.cpp
$(MPICXX) -I$(TINSELINC) -std=c++14 -o $@ $<

dummy.o : dummy.cpp
$(RV_CPPC) $(CFLAGS) -Wall -c -o $@ $<

$(BINDIR)/dummy.elf : dummy.o link_0.ld entry.o libc.a libgcc.a
$(RV_LD) $(LDFLAGS) -T link_0.ld -o $@ $(filter-out link_0.ld, $^)

$(BINDIR)/dummy_code.v : $(BINDIR)/dummy.elf
$(TINSELBIN)/checkelf.sh $<
$(RV_OBJCOPY) -O verilog --only-section=.text $< $@

$(BINDIR)/threadCtxInit_data.v : threadCtxInitGenerator
./$<
mv threadCtxInit_data.v $@


# Cleanup on aisle 3
clean :
rm -f *.o *.elf link.ld $(BINDIR)/*.elf $(BINDIR)/*.v $(BINDIR)/libSupervisor.so
rm -f *.o *.elf link.ld link_*.ld $(BINDIR)/*.elf $(BINDIR)/*.v $(BINDIR)/libSupervisor.so threadCtxInitGenerator
23 changes: 23 additions & 0 deletions Source/Softswitch/inc/softswitch_vars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _VARS_H_
#define _VARS_H_
#include <cstdint>
#include "softswitch_common.h"

extern ThreadCtxt_t Thread_0_Context;
extern ThreadCtxt_t Thread_1_Context;
extern ThreadCtxt_t Thread_2_Context;
extern ThreadCtxt_t Thread_3_Context;
extern ThreadCtxt_t Thread_4_Context;
extern ThreadCtxt_t Thread_5_Context;
extern ThreadCtxt_t Thread_6_Context;
extern ThreadCtxt_t Thread_7_Context;
extern ThreadCtxt_t Thread_8_Context;
extern ThreadCtxt_t Thread_9_Context;
extern ThreadCtxt_t Thread_10_Context;
extern ThreadCtxt_t Thread_11_Context;
extern ThreadCtxt_t Thread_12_Context;
extern ThreadCtxt_t Thread_13_Context;
extern ThreadCtxt_t Thread_14_Context;
extern ThreadCtxt_t Thread_15_Context;

#endif /*_VARS_H_*/
9 changes: 9 additions & 0 deletions Source/Softswitch/src/dummy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "tinsel.h"

int main(int argc, char** argv)
{
// Block on tinselIdle to facilitate hardware idle.
while(true) tinselIdle(1);

return 0;
}
5 changes: 5 additions & 0 deletions Source/Softswitch/src/softswitch_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ void softswitch_main()
{
// The thread context will reside at the base of the DRAM memory area.
PThreadContext* ThreadContext = static_cast<PThreadContext*>(tinselHeapBase());

if(ThreadContext->numDevInsts == 0)
{ // We have no devices loaded, so should do nothing.
while(true) tinselIdle(1);
}

// Configure rtsBuf
outPin_t* rtsBuf[ThreadContext->rtsBuffSize+1];
Expand Down
20 changes: 20 additions & 0 deletions Source/Softswitch/src/softswitch_vars.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#include "softswitch_common.h"
#include "softswitch_vars.h"

ThreadCtxt_t Thread_0_Context __attribute__((weak, section (".thr0_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_1_Context __attribute__((weak, section (".thr1_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_2_Context __attribute__((weak, section (".thr2_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_3_Context __attribute__((weak, section (".thr3_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_4_Context __attribute__((weak, section (".thr4_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_5_Context __attribute__((weak, section (".thr5_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_6_Context __attribute__((weak, section (".thr6_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_7_Context __attribute__((weak, section (".thr7_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_8_Context __attribute__((weak, section (".thr8_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_9_Context __attribute__((weak, section (".thr9_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_10_Context __attribute__((weak, section (".thr10_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_11_Context __attribute__((weak, section (".thr11_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_12_Context __attribute__((weak, section (".thr12_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_13_Context __attribute__((weak, section (".thr13_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_14_Context __attribute__((weak, section (".thr14_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ThreadCtxt_t Thread_15_Context __attribute__((weak, section (".thr15_base"))) = {0,PNULL,0,PNULL,PNULL,0,PNULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
70 changes: 70 additions & 0 deletions Source/Softswitch/src/threadCtxInitGenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "config.h"

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>


// Number of bytes per thread partition 2^21 = 2,097,152
uint32_t BytesPerDRAMPartition=1<<TinselLogBytesPerDRAMPartition;

// The number of cores that share a DRAM 2^(2+3) = 32
uint32_t CoresPerDRAM=1<<(TinselLogCoresPerDCache+TinselLogDCachesPerDRAM);

// The number of threads per DRAM 32*16 = 512
uint32_t ThreadsPerDRAM=CoresPerDRAM*TinselThreadsPerCore;

uint32_t InterleavedPartitionOffset=0x80000000;

int main(void)
{
// The output binary
std::ofstream dataBin;

dataBin.open("threadCtxInit_data.v");
if(dataBin.fail()) // Check that the file opened
{ // if it didn't, barf
std::cout << "***ERROR*** FAILED TO OPEN DATA BINARY\n" << std::endl;
return -1;
}

// Populate the bin
uint32_t i = 0;
for(int coreNum = 0; coreNum<CoresPerDRAM; coreNum++)
{
for(int threadNum = 1; threadNum<=TinselThreadsPerCore; threadNum++)
{
uint32_t threadAddr, threadOffset;

threadOffset = ((coreNum << TinselLogThreadsPerCore) + threadNum);
threadOffset *= BytesPerDRAMPartition;

threadAddr = TinselBytesPerDRAM - threadOffset;

threadAddr |= InterleavedPartitionOffset;

// Write the address
dataBin << std::hex << std::uppercase << "@" << threadAddr << "\n";

// Write out the initialiser
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n";
dataBin << "00 00 00 00 00 00 00 00 " << std::endl;

i++;
}
}

// And we are done
dataBin.close();

return 0;
}

0 comments on commit 2e85f79

Please sign in to comment.