From 24b615cba1ba1c3ec55032878e4889431ceeb9ea Mon Sep 17 00:00:00 2001 From: Andras Tantos Date: Fri, 2 Oct 2020 02:05:40 +0000 Subject: [PATCH] Finally fixed the cc hang for good. The problem was that two consequtive reads of the RTC in quick succession within the compiler was used to validate the results in the buffer filled by the mtimes syscall. This syscall buffer is potentially filled by another processor or by the same one, so the programmers decided to use two techniques to decide if the results are reliable: 1. Read the buffer twice and compare 2. Make sure that the two reads happened within 200 clock-cycles from one another. Since our RTC is based on the host clock, the actual time passed between those two instructions depends on the host speed. This fix allows for a - programmable - interval within which if two RTC queries are made, we return an artificially low delta time. This makes cc happy, while doesn't interfere with normal OS operation and scheduling. The setting (RealTimeClockChunkLimit, which defaults to 5000) might need to be adjusted for slow machines, such as the RaspberryPi4 or similar. --- simulator/sim_lib/cray_mainframe.cpp | 16 +++++++++++----- simulator/sim_lib/cray_mainframe.h | 4 +++- simulator/sim_lib/sys_task_req.cpp | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/simulator/sim_lib/cray_mainframe.cpp b/simulator/sim_lib/cray_mainframe.cpp index ae4084b..34a4852 100644 --- a/simulator/sim_lib/cray_mainframe.cpp +++ b/simulator/sim_lib/cray_mainframe.cpp @@ -140,13 +140,15 @@ Mainframe_c::Mainframe_c(const Configuration_c &aConfig, CLogger_c &aLogger, boo mLogger(aConfig), mOsType(OsTypes_e::None), mUseHostRealTimeClock(aConfig.get("UseHostRealTimeClock", true)), + mRealTimeClockIncrement(aConfig.get("RealTimeClockIncrement", 10)), + mRealTimeClockChunkLimit(aConfig.get("RealTimeClockChunkLimit", 5000)), + mDeltaClockIncrement(aConfig.get("DeltaClockIncrement", 1)), mDisableAutoTerminal(aDisableAutoTerminal) { mLogger.SetParent(aLogger); mChannels.resize(aConfig.get("ChannelCount", 8)); mOwnedChannels.resize(mChannels.size()); try { - mRealTimeClockIncrement = aConfig.get("RealTimeClockIncrement", 10); std::string MachineType = aConfig.get("MachineType", "J90"); if (MachineType == "J90") { mMachineType = MachineTypes_e::J90; @@ -768,11 +770,15 @@ CInt_t Mainframe_c::GetRealTimeClock() const { if (mUseHostRealTimeClock) { boost::timer::nanosecond_type DeltaTime = mRealTimeTimer.elapsed().wall - mRealTimeStart; CInt_t DeltaClocks = CInt_t(double(DeltaTime) / mSystemClockPeriod); - if (DeltaClocks == mLastRealTimeReading) { - DeltaClocks += 1; + CInt_t NewRTC = mRealTimeClock + DeltaClocks; + if (NewRTC > mLastRealTimeReading + mRealTimeClockChunkLimit) { + mLastRealTimeReading = NewRTC; + return NewRTC; + } else { + NewRTC = mLastRealTimeReading + mRealTimeClockIncrement; + mLastRealTimeReading = NewRTC; + return NewRTC; } - mLastRealTimeReading = DeltaClocks; - return mRealTimeClock + DeltaClocks; } else { return mRealTimeClock; } diff --git a/simulator/sim_lib/cray_mainframe.h b/simulator/sim_lib/cray_mainframe.h index 10d490e..899833d 100644 --- a/simulator/sim_lib/cray_mainframe.h +++ b/simulator/sim_lib/cray_mainframe.h @@ -341,7 +341,7 @@ public: void Dump(size_t aIdent=0) const; void DumpMemories() const; void DumpHistory(); - CLogger_c &GetLogger() { return mLogger; } + CLogger_c &GetLogger() const { return mLogger; } virtual uint64_t GetTimeStamp() const override { return mEnableTimeStamp ? mTickCnt : 0ULL; } virtual uint64_t GetResolution() const override { return 105000000ULL; } // TODO: make this configurable @@ -367,6 +367,7 @@ protected: bool mMultiThreaded; bool mDisableAutoTerminal; mutable CInt_t mLastRealTimeReading; + CInt_t mDeltaClockIncrement; class MainFrameEventDispatcher_c: public DebugEventDispatcher_c { public: @@ -409,6 +410,7 @@ protected: double mSystemClockPeriod; CInt_t mRealTimeClock; CInt_t mRealTimeClockIncrement; + CInt_t mRealTimeClockChunkLimit; bool mUseHostRealTimeClock; struct WatchPoint_c { diff --git a/simulator/sim_lib/sys_task_req.cpp b/simulator/sim_lib/sys_task_req.cpp index 1a3c819..8f18145 100644 --- a/simulator/sim_lib/sys_task_req.cpp +++ b/simulator/sim_lib/sys_task_req.cpp @@ -206,12 +206,15 @@ void PrintIntArg(std::ostream &aLogger, size_t aArg, const ExchangePacket_c &aEx void ParseUnicosExchangePacket(const ExchangePacket_c &aCurrentEP, const ExchangePacket_c &aNewEP, std::ostream &aLogger, const Cpu_c &aCpu) { static size_t LastSysCall = SIZE_MAX; const Mainframe_c &Mainframe = aCpu.GetMainframe(); + if (aCurrentEP.GetMode().IsMonitorMode()) { CInt_t S[8]; for (size_t Idx = 0; Idx