From 61cd47be3f8269e87caf185f102bf0ab8baf8478 Mon Sep 17 00:00:00 2001 From: Graeme Bragg Date: Mon, 18 Oct 2021 13:44:29 +0100 Subject: [PATCH 1/5] Softswitch tweak for idle --- Source/Softswitch/src/softswitch_main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Softswitch/src/softswitch_main.cpp b/Source/Softswitch/src/softswitch_main.cpp index dfbb5d63..ca46574f 100644 --- a/Source/Softswitch/src/softswitch_main.cpp +++ b/Source/Softswitch/src/softswitch_main.cpp @@ -14,6 +14,11 @@ void softswitch_main() { // The thread context will reside at the base of the DRAM memory area. PThreadContext* ThreadContext = static_cast(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]; From 0c36c6077f750c4ede42d0d56cf8bf8d65f77d31 Mon Sep 17 00:00:00 2001 From: Graeme Bragg Date: Mon, 25 Oct 2021 12:26:44 +0100 Subject: [PATCH 2/5] Fix makefile to generate dummy binaries --- Source/Softswitch/Makefile | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Source/Softswitch/Makefile b/Source/Softswitch/Makefile index 169a3a3d..fc737d10 100644 --- a/Source/Softswitch/Makefile +++ b/Source/Softswitch/Makefile @@ -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)) @@ -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 $< $@ @@ -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 @@ -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 From 0dbe44eb2f1911a0e8a2e862c336b009ef4e0363 Mon Sep 17 00:00:00 2001 From: Graeme Bragg Date: Mon, 25 Oct 2021 16:47:13 +0100 Subject: [PATCH 3/5] Make composer store dummy binaries --- Source/OrchBase/Composer.cpp | 36 ++++++++++++++++++++++++++++++++++++ Source/OrchBase/Composer.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/Source/OrchBase/Composer.cpp b/Source/OrchBase/Composer.cpp index db75e0ea..665c0958 100644 --- a/Source/OrchBase/Composer.cpp +++ b/Source/OrchBase/Composer.cpp @@ -126,6 +126,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(devTStrsMap.size())); @@ -1211,6 +1216,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) { diff --git a/Source/OrchBase/Composer.h b/Source/OrchBase/Composer.h index 33b9809e..f7293064 100644 --- a/Source/OrchBase/Composer.h +++ b/Source/OrchBase/Composer.h @@ -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&); From e9c983a6bdba2d661bbdd0ca593d7f7bc68ea497 Mon Sep 17 00:00:00 2001 From: Graeme Bragg Date: Mon, 25 Oct 2021 18:17:10 +0100 Subject: [PATCH 4/5] add logic to get dummy binaries --- Source/OrchBase/Composer.cpp | 34 +++++++++++++++++++++++++++++ Source/OrchBase/Composer.h | 2 ++ Source/OrchBase/Handlers/CmDepl.cpp | 6 ++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Source/OrchBase/Composer.cpp b/Source/OrchBase/Composer.cpp index 665c0958..901a0f84 100644 --- a/Source/OrchBase/Composer.cpp +++ b/Source/OrchBase/Composer.cpp @@ -38,6 +38,9 @@ ComposerGraphI_t::ComposerGraphI_t() compilationFlags = ""; provenanceCache = ""; + + idleInstructionBinary = ""; + idleDataBinary = ""; } ComposerGraphI_t::ComposerGraphI_t(GraphI_t* graphIIn, std::string& outputPath) @@ -59,6 +62,9 @@ ComposerGraphI_t::ComposerGraphI_t(GraphI_t* graphIIn, std::string& outputPath) compilationFlags = ""; provenanceCache = ""; + + idleInstructionBinary = ""; + idleDataBinary = ""; } ComposerGraphI_t::~ComposerGraphI_t() @@ -1017,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 *****************************************************************************/ diff --git a/Source/OrchBase/Composer.h b/Source/OrchBase/Composer.h index f7293064..69c62aba 100644 --- a/Source/OrchBase/Composer.h +++ b/Source/OrchBase/Composer.h @@ -143,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); diff --git a/Source/OrchBase/Handlers/CmDepl.cpp b/Source/OrchBase/Handlers/CmDepl.cpp index 9f0cb1eb..688d8742 100644 --- a/Source/OrchBase/Handlers/CmDepl.cpp +++ b/Source/OrchBase/Handlers/CmDepl.cpp @@ -376,11 +376,11 @@ int CmDepl::DeployGraph(GraphI_t* gi) bool soloApp = dynamic_cast(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); From 9668721d53b3e54035e7bacd571d48f53cec840e Mon Sep 17 00:00:00 2001 From: Graeme Bragg Date: Mon, 25 Oct 2021 18:19:36 +0100 Subject: [PATCH 5/5] add missing Softswitch files --- Source/Softswitch/inc/softswitch_vars.h | 23 ++++++ Source/Softswitch/src/dummy.cpp | 9 +++ Source/Softswitch/src/softswitch_vars.cpp | 20 ++++++ .../Softswitch/src/threadCtxInitGenerator.cpp | 70 +++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 Source/Softswitch/inc/softswitch_vars.h create mode 100644 Source/Softswitch/src/dummy.cpp create mode 100644 Source/Softswitch/src/softswitch_vars.cpp create mode 100644 Source/Softswitch/src/threadCtxInitGenerator.cpp diff --git a/Source/Softswitch/inc/softswitch_vars.h b/Source/Softswitch/inc/softswitch_vars.h new file mode 100644 index 00000000..80653985 --- /dev/null +++ b/Source/Softswitch/inc/softswitch_vars.h @@ -0,0 +1,23 @@ +#ifndef _VARS_H_ +#define _VARS_H_ +#include +#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_*/ \ No newline at end of file diff --git a/Source/Softswitch/src/dummy.cpp b/Source/Softswitch/src/dummy.cpp new file mode 100644 index 00000000..47bd6fbe --- /dev/null +++ b/Source/Softswitch/src/dummy.cpp @@ -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; +} diff --git a/Source/Softswitch/src/softswitch_vars.cpp b/Source/Softswitch/src/softswitch_vars.cpp new file mode 100644 index 00000000..347b5f65 --- /dev/null +++ b/Source/Softswitch/src/softswitch_vars.cpp @@ -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}; \ No newline at end of file diff --git a/Source/Softswitch/src/threadCtxInitGenerator.cpp b/Source/Softswitch/src/threadCtxInitGenerator.cpp new file mode 100644 index 00000000..77e34685 --- /dev/null +++ b/Source/Softswitch/src/threadCtxInitGenerator.cpp @@ -0,0 +1,70 @@ +#include "config.h" + +#include +#include +#include +#include +#include +#include + + +// Number of bytes per thread partition 2^21 = 2,097,152 +uint32_t BytesPerDRAMPartition=1<