From 7c32974f7b60f729c6b1f90013c50b2a796e120f Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Mon, 24 Mar 2025 08:24:06 -0400 Subject: [PATCH 01/51] update readme --- README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9b85140..430d0ce 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,25 @@ -# MannaChip +# RISC-V Bluespec Classic ## Introduction: -Manna was the miraculous food provided by God requiring no effort on behalf of the Israelites. In a similar vein, the POWER3.0 compliant MannaChip -processor delivers groundbreaking performance, necessitating minimal intervention on the developer's or user's part. -Just as "man does not live by bread alone, but by every word that proceeds from the mouth of God," this chip thrives on every instruction word you provide. It's not just about raw computational power, but the synergy between user input and hardware optimization. - -``TOPMODULE=mkTop make v_compile`` to generate verilog. The generated verilog can -be found in the ``verilog_RTL/`` folder. +The beginnings of an implementation of a Linux capable RISCV processor in Bluespec +Haskell. Here, we plan to take full advantage of the Haskell type system embedded +in Bluespec Haskell. Given that the Bluespec semantics are inspired by TLA+ which +is different from traditional Haskell semantics, we're doing functional design +exploration first in [Haskell](https://git.joyofhardware.com/Yehowshua/RiscV-Formal) +and iteratively transforming it into Bluespec. Most of the Haskell code is valid +Bluespec, we merely need to partition the functional Haskell definition of a CPU into +atomic actions/transactions that can be resolved and scheduled across time. # Status -Admittedly, not very far. Perhaps one could say we've got the beginnings -of what would make for LED and UART controllers. + * Basic peripheral working on FPGA such as UART and + BRAM(work on this is out of tree - need to merge) + * Much of the grunt-work for a functional definition of RV64i already + [exists](https://git.joyofhardware.com/Yehowshua/RiscV-Formal/src/branch/main/hs) + and some porting work has been done offline + * I've begun the implementation of an asynchronous bus that supports tagged + transactions using a Free List based stack. + # Dependencies ## Linux @@ -65,4 +73,4 @@ TOPMODULE=mkTop make v_compile - [ ] try to optimize decoder # Notable Reference Files -``/Users/yehowshuaimmanuel/git/bsc/testsuite/bsc.bsv_examples/cpu/FiveStageCPUQ3sol.bsv`` \ No newline at end of file +``/Users/yehowshuaimmanuel/git/bsc/testsuite/bsc.bsv_examples/cpu/FiveStageCPUQ3sol.bsv`` From 6247ae3b70aabd78402b0a28dfe3f27925e5f13d Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 25 Mar 2025 08:48:43 -0400 Subject: [PATCH 02/51] clean unused experiments --- bs/Top.bs | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/bs/Top.bs b/bs/Top.bs index 373589c..f4f1cda 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -21,44 +21,6 @@ interface ITop = { ;ftdi_txd :: Bit 1 -> Action {-# always_ready , always_enabled #-} }; -interface BusClient = - request :: Bit 1 - response :: Bit 1 -> Action - -mkBusClient :: Module BusClient -mkBusClient = module - reqReg :: Reg (Bit 1) <- mkReg 0 - return $ - interface BusClient - request = reqReg - response resp = do - reqReg := 0 -- Reset request after receiving response - -interface Bus = - request :: Bit 1 -> Action - response :: Bit 1 - -mkBus :: Module Bus -mkBus = module - respReg :: Reg (Bit 1) <- mkReg 0 - return $ - interface Bus - request req = do - respReg := req -- Simple pass-through for this example - response = respReg - --- -- Function to connect Bus to BusClient -connectBusToClient :: Bus -> BusClient -> Rules -connectBusToClient bus client = - rules - "busConnection": when True ==> do - bus.request client.request - client.response bus.response - --- need to implement mkBus - --- need function that can connect Bus to BusClient - mkTop :: Module ITop mkTop = do fileHandle :: Handle <- openFile "compile.log" WriteMode @@ -66,15 +28,9 @@ mkTop = do serializer :: ISerializer FCLK BAUD <- mkSerialize fileHandle core :: Core FCLK <- mkCore - bus :: Bus <- mkBus - busClient :: BusClient <- mkBusClient - persistLed :: Reg (Bit 8) <- mkReg 0 messageM $ "Hallo!!" + (realToString 5) - -- need to instantiate a Bus and BusClient - addRules $ connectBusToClient bus busClient - addRules $ rules -- need new rule that always connects Bus to BusClient From d436209f545e2d5ee576ec226eb4f0abde3fd9f7 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 2 Apr 2025 02:09:41 -0400 Subject: [PATCH 03/51] seemingly reasonable stopping point --- bs/TagEngine.bs | 119 ++++++++++++++---------------------- bs/Tests/TagEngineTester.bs | 1 + 2 files changed, 48 insertions(+), 72 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index edca9fa..91c5fdf 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -5,40 +5,41 @@ package TagEngine( import Vector import Util +import FIFO +import FIFOF #define UIntLog2N(n) (UInt (TLog n)) interface (TagEngine :: # -> *) numTags = - requestTag :: ActionValue (Maybe UIntLog2N(numTags)) - retireTag :: UIntLog2N(numTags) -> ActionValue BasicResult + requestTag :: ActionValue UIntLog2N(numTags) + retireTag :: UIntLog2N(numTags) -> Action -- The tag engine returns a tag that is unique for the duration of -- the lifetime of the tag. Useful when you need to tag transactions -- on a bus for example. --- This implementation is stack based. +-- This implementation is FIFO based. mkTagEngine :: Module (TagEngine numTags) mkTagEngine = do - let reifiedNumTags = fromInteger |> valueOf numTags - freeStackVec :: Vector numTags (Reg UIntLog2N(numTags)) - freeStackVec <- mapM (\i -> mkReg |> fromInteger i) genVector - inUseVec :: Vector numTags (Reg Bool) inUseVec <- replicateM |> mkReg False - stackPtr :: (Reg (Maybe(UIntLog2N(numTags)))) - stackPtr <- mkReg |> Just |> reifiedNumTags - 1 + -- Since Bluespec doesn't allow us to initialize FIFOs with values at + -- reset, we can pretend as if the buffer within our tagFIFO is populated + -- with sequentially incrementing values(starting from 0) on reset + -- by having our tag engine effectively return the value of a decrementing + -- counter initialized to (numTags - 1) for the first n tag requests made + -- to TagEngine where `n := numTags`. + resetTagCounter :: (Reg (Maybe UIntLog2N(numTags))) + resetTagCounter <- mkReg |> Just |> reifiedNumTags - 1 - methodRequestTagCalled :: PulseWire - methodRequestTagCalled <- mkPulseWire + retireQueue :: FIFOF UIntLog2N(numTags) + retireQueue <- mkSizedFIFOF reifiedNumTags - methodRetireTagCalledValid :: RWire UIntLog2N(numTags) - methodRetireTagCalledValid <- mkUnsafeRWire - - -- computedTagResult :: BypassWire (Maybe UIntLog2N(numTags)) - -- methodRetireTagCalledValid <- mkBypassWire + freeQueue :: FIFOF UIntLog2N(numTags) + freeQueue <- mkSizedFIFOF reifiedNumTags debugOnce <- mkReg True @@ -46,71 +47,46 @@ mkTagEngine = rules "display": when (debugOnce == True) ==> do - $display "freeStackVec : " (fshow |> readVReg freeStackVec) $display "inUseVec : " (fshow |> readVReg inUseVec) - $display "stackPtr : " (fshow stackPtr) debugOnce := False - - "update stack pointer": when True ==> + + -- The "retire_tags" rule can't fire when the `requestTag` method is called. + -- In practice, this is Ok since: + -- 1. the `requestTag` method should take priority over the "retire_tags" rule + -- 2. the `requestTag` method handles the case where there are some tags to retire. + "retire_tags": when True ==> do - stackPtr := - case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of - (True, Just _) -> stackPtr - (True, Nothing) -> - case stackPtr of - Just 0 -> Nothing - Just sampledStackPtr -> Just |> sampledStackPtr - 1 - Nothing -> Nothing - (False, Just _) -> - case stackPtr of - Just sampledStackPtr -> Just |> sampledStackPtr + 1 - Nothing -> Nothing - (False, Nothing) -> stackPtr - - "update free stack": when True ==> - do - case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of - (True, Just _) -> do action {} - (True, Nothing) -> do action {} - (False, Just tag) -> do - case stackPtr of - Just sampledStackPtr -> do - (select freeStackVec (sampledStackPtr + 1)) := tag - Nothing -> do - (select freeStackVec 0) := tag - (False, Nothing) -> do action {} - - "update in use": when True ==> - do - case (methodRequestTagCalled, methodRetireTagCalledValid.wget) of - (True, Just _) -> do action {} - (True, Nothing) -> - case stackPtr of - Just sampledStackPtr -> do - (select inUseVec sampledStackPtr) := True - Nothing -> do action {} - (False, Just tag) -> do - (select inUseVec tag) := False - (False, Nothing) -> do action {} + let tag = retireQueue.first + $display "firing retire_tags" (fshow tag) + retireQueue.deq + freeQueue.enq tag + (select inUseVec tag) := False return $ interface TagEngine - requestTag :: ActionValue (Maybe UIntLog2N(numTags)) + requestTag :: ActionValue UIntLog2N(numTags) requestTag = do - methodRequestTagCalled.send - case methodRetireTagCalledValid.wget of + case resetTagCounter of + Just 0 -> do + resetTagCounter := Nothing + (select inUseVec 0) := True + return 0 Just tag -> do - return |> Just tag + resetTagCounter := Just |> tag - 1 + (select inUseVec tag) := True + return tag Nothing -> do - return |> - case stackPtr of - Just sampledStackPtr -> - Just |> readReg (select freeStackVec sampledStackPtr) - Nothing -> Nothing + let tag = freeQueue.first + freeQueue.deq + return tag - retireTag :: UIntLog2N(numTags) -> ActionValue BasicResult + -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) + -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. + -- Internally, the tagEngine will keep a correct and consistent state since TagEngine + -- validates tags before attempting to retire them. + retireTag :: UIntLog2N(numTags) -> Action retireTag tag = do let @@ -118,7 +94,6 @@ mkTagEngine = tagInUse = readReg (select inUseVec tag) if (tagValid && tagInUse) then do - methodRetireTagCalledValid.wset tag - return Success + retireQueue.enq tag else do - return Failure + action {} diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 334b8d2..e4bf3c4 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -44,6 +44,7 @@ mkTagEngineTester = do |> do requestTagAction |> do retireTagAction 1 |> do requestTagAction + |> do $finish addRules $ rules From e055b1bbdfa2d871425c0196e1be713f7dee827d Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 2 Apr 2025 02:59:49 -0400 Subject: [PATCH 04/51] reduced latency --- bs/TagEngine.bs | 27 +++++++++++++++------------ bs/Tests/TagEngineTester.bs | 35 +++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 91c5fdf..e54eff4 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -23,8 +23,10 @@ mkTagEngine = do let reifiedNumTags = fromInteger |> valueOf numTags + -- we really only use inUseVec after emptying out our `resetTagCounter` buffer + -- perhaps rename this variable to better communicate that inUseVec :: Vector numTags (Reg Bool) - inUseVec <- replicateM |> mkReg False + inUseVec <- replicateM |> mkReg True -- Since Bluespec doesn't allow us to initialize FIFOs with values at -- reset, we can pretend as if the buffer within our tagFIFO is populated @@ -32,11 +34,12 @@ mkTagEngine = -- by having our tag engine effectively return the value of a decrementing -- counter initialized to (numTags - 1) for the first n tag requests made -- to TagEngine where `n := numTags`. + -- Maybe resetTagCounter isn't the greatest name? resetTagCounter :: (Reg (Maybe UIntLog2N(numTags))) resetTagCounter <- mkReg |> Just |> reifiedNumTags - 1 - retireQueue :: FIFOF UIntLog2N(numTags) - retireQueue <- mkSizedFIFOF reifiedNumTags + retireTag :: Wire UIntLog2N(numTags) + retireTag <- mkWire freeQueue :: FIFOF UIntLog2N(numTags) freeQueue <- mkSizedFIFOF reifiedNumTags @@ -56,11 +59,9 @@ mkTagEngine = -- 2. the `requestTag` method handles the case where there are some tags to retire. "retire_tags": when True ==> do - let tag = retireQueue.first - $display "firing retire_tags" (fshow tag) - retireQueue.deq - freeQueue.enq tag - (select inUseVec tag) := False + $display "firing retire_tags" (fshow retireTag) + freeQueue.enq retireTag + (select inUseVec retireTag) := False return $ interface TagEngine @@ -71,11 +72,9 @@ mkTagEngine = case resetTagCounter of Just 0 -> do resetTagCounter := Nothing - (select inUseVec 0) := True return 0 Just tag -> do resetTagCounter := Just |> tag - 1 - (select inUseVec tag) := True return tag Nothing -> do let tag = freeQueue.first @@ -86,14 +85,18 @@ mkTagEngine = -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- validates tags before attempting to retire them. + -- Also worth noting the TagEngin will ignore attempts to retire a tag you just + -- requested in the same cycle. This is enforce with `tag > tagCounter` below. retireTag :: UIntLog2N(numTags) -> Action retireTag tag = do let tagValid = tag < reifiedNumTags - tagInUse = readReg (select inUseVec tag) + tagInUse = case resetTagCounter of + Just tagCounter -> tag > tagCounter + Nothing -> readReg (select inUseVec tag) if (tagValid && tagInUse) then do - retireQueue.enq tag + retireTag := tag else do action {} diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index e4bf3c4..6c140c3 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -6,7 +6,7 @@ import ActionSeq mkTagEngineTester :: Module Empty mkTagEngineTester = do tagEngine :: TagEngine 5 <- mkTagEngine - count :: Reg (UInt 4) <- mkReg 0; + count :: Reg (UInt 32) <- mkReg 0; runOnce :: Reg Bool <- mkReg False s :: ActionSeq @@ -30,24 +30,35 @@ mkTagEngineTester = do do requestTagAction |> do requestTagAction |> do requestTagAction - |> do retireTagAction 3 - |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + |> do requestTagAction + |> do requestTagAction + |> do retireTagAction 2 + -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" |> do retireTagAction 4 requestTagAction - |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" - |> do requestTagAction - |> do retireTagAction 4 - |> do retireTagAction 4 - |> do retireTagAction 0 - |> do requestTagAction - |> do requestTagAction - |> do retireTagAction 1 - |> do requestTagAction + -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" + -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + |> do + retireTagAction 4 + requestTagAction + -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" |> do $finish + -- |> do retireTagAction 4 + -- |> do retireTagAction 4 + -- |> do retireTagAction 0 + -- |> do requestTagAction + -- |> do requestTagAction + -- |> do retireTagAction 1 + -- |> do requestTagAction + -- |> do $finish addRules $ rules + "counter": when True ==> + do + count := count + 1 + $display "count : " (fshow count) "testIncrement": when (runOnce == False) ==> do s.start From d1e335819710f785d86ef496b069a57d0f22f372 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 2 Apr 2025 03:03:39 -0400 Subject: [PATCH 05/51] now using wire instead of FIFO --- bs/TagEngine.bs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index e54eff4..b5f04b1 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -26,7 +26,7 @@ mkTagEngine = -- we really only use inUseVec after emptying out our `resetTagCounter` buffer -- perhaps rename this variable to better communicate that inUseVec :: Vector numTags (Reg Bool) - inUseVec <- replicateM |> mkReg True + inUseVec <- replicateM |> mkReg False -- Since Bluespec doesn't allow us to initialize FIFOs with values at -- reset, we can pretend as if the buffer within our tagFIFO is populated @@ -72,9 +72,11 @@ mkTagEngine = case resetTagCounter of Just 0 -> do resetTagCounter := Nothing + (select inUseVec 0) := True return 0 Just tag -> do resetTagCounter := Just |> tag - 1 + (select inUseVec tag) := True return tag Nothing -> do let tag = freeQueue.first @@ -85,16 +87,12 @@ mkTagEngine = -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- validates tags before attempting to retire them. - -- Also worth noting the TagEngin will ignore attempts to retire a tag you just - -- requested in the same cycle. This is enforce with `tag > tagCounter` below. retireTag :: UIntLog2N(numTags) -> Action retireTag tag = do let tagValid = tag < reifiedNumTags - tagInUse = case resetTagCounter of - Just tagCounter -> tag > tagCounter - Nothing -> readReg (select inUseVec tag) + tagInUse = readReg (select inUseVec tag) if (tagValid && tagInUse) then do retireTag := tag From 271148e53840b2fd5fdc33e742e9831b50a7b857 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 3 Apr 2025 09:15:53 -0400 Subject: [PATCH 06/51] better names in TagEngine --- bs/TagEngine.bs | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index b5f04b1..d8e0736 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -23,10 +23,10 @@ mkTagEngine = do let reifiedNumTags = fromInteger |> valueOf numTags - -- we really only use inUseVec after emptying out our `resetTagCounter` buffer - -- perhaps rename this variable to better communicate that - inUseVec :: Vector numTags (Reg Bool) - inUseVec <- replicateM |> mkReg False + -- we really only use tagUsageTracker after emptying out our + -- `initialTagDistributor` buffer + tagUsageTracker :: Vector numTags (Reg Bool) + tagUsageTracker <- replicateM |> mkReg False -- Since Bluespec doesn't allow us to initialize FIFOs with values at -- reset, we can pretend as if the buffer within our tagFIFO is populated @@ -34,15 +34,14 @@ mkTagEngine = -- by having our tag engine effectively return the value of a decrementing -- counter initialized to (numTags - 1) for the first n tag requests made -- to TagEngine where `n := numTags`. - -- Maybe resetTagCounter isn't the greatest name? - resetTagCounter :: (Reg (Maybe UIntLog2N(numTags))) - resetTagCounter <- mkReg |> Just |> reifiedNumTags - 1 + initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags))) + initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1 retireTag :: Wire UIntLog2N(numTags) retireTag <- mkWire - freeQueue :: FIFOF UIntLog2N(numTags) - freeQueue <- mkSizedFIFOF reifiedNumTags + tagFIFO :: FIFOF UIntLog2N(numTags) + tagFIFO <- mkSizedFIFOF reifiedNumTags debugOnce <- mkReg True @@ -50,18 +49,14 @@ mkTagEngine = rules "display": when (debugOnce == True) ==> do - $display "inUseVec : " (fshow |> readVReg inUseVec) + $display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker) debugOnce := False - -- The "retire_tags" rule can't fire when the `requestTag` method is called. - -- In practice, this is Ok since: - -- 1. the `requestTag` method should take priority over the "retire_tags" rule - -- 2. the `requestTag` method handles the case where there are some tags to retire. "retire_tags": when True ==> do $display "firing retire_tags" (fshow retireTag) - freeQueue.enq retireTag - (select inUseVec retireTag) := False + tagFIFO.enq retireTag + (select tagUsageTracker retireTag) := False return $ interface TagEngine @@ -69,18 +64,18 @@ mkTagEngine = requestTag :: ActionValue UIntLog2N(numTags) requestTag = do - case resetTagCounter of + case initialTagDistributor of Just 0 -> do - resetTagCounter := Nothing - (select inUseVec 0) := True + initialTagDistributor := Nothing + (select tagUsageTracker 0) := True return 0 Just tag -> do - resetTagCounter := Just |> tag - 1 - (select inUseVec tag) := True + initialTagDistributor := Just |> tag - 1 + (select tagUsageTracker tag) := True return tag Nothing -> do - let tag = freeQueue.first - freeQueue.deq + let tag = tagFIFO.first + tagFIFO.deq return tag -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) @@ -92,7 +87,7 @@ mkTagEngine = do let tagValid = tag < reifiedNumTags - tagInUse = readReg (select inUseVec tag) + tagInUse = readReg (select tagUsageTracker tag) if (tagValid && tagInUse) then do retireTag := tag From ca59e6eaeceff683d781883db0d3b6effdccc161 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 4 Apr 2025 15:09:56 -0400 Subject: [PATCH 07/51] handled tag engine edge case --- bs/TagEngine.bs | 59 +++++++++++++++++++++++++++++-------- bs/Tests/TagEngineTester.bs | 21 +++++++------ 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index d8e0736..f5a00ba 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -7,6 +7,7 @@ import Vector import Util import FIFO import FIFOF +import SpecialFIFOs #define UIntLog2N(n) (UInt (TLog n)) @@ -23,7 +24,7 @@ mkTagEngine = do let reifiedNumTags = fromInteger |> valueOf numTags - -- we really only use tagUsageTracker after emptying out our + -- we really only use tagUsageTracker after emptying out our -- `initialTagDistributor` buffer tagUsageTracker :: Vector numTags (Reg Bool) tagUsageTracker <- replicateM |> mkReg False @@ -32,13 +33,19 @@ mkTagEngine = -- reset, we can pretend as if the buffer within our tagFIFO is populated -- with sequentially incrementing values(starting from 0) on reset -- by having our tag engine effectively return the value of a decrementing - -- counter initialized to (numTags - 1) for the first n tag requests made + -- counter initialized to (numTags - 1) for the first n tag requests made -- to TagEngine where `n := numTags`. initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags))) initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1 - retireTag :: Wire UIntLog2N(numTags) - retireTag <- mkWire + validatedTagToRetire :: FIFO UIntLog2N(numTags) + validatedTagToRetire <- mkBypassFIFO + + updateUsageRetireTag :: RWire UIntLog2N(numTags) + updateUsageRetireTag <- mkRWire + + updateUsageRequestTag :: RWire UIntLog2N(numTags) + updateUsageRequestTag <- mkRWire tagFIFO :: FIFOF UIntLog2N(numTags) tagFIFO <- mkSizedFIFOF reifiedNumTags @@ -51,12 +58,39 @@ mkTagEngine = do $display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker) debugOnce := False - + + "update_usage_just_retire": when + Just tag <- updateUsageRetireTag.wget, + Nothing <- updateUsageRequestTag.wget ==> + do + $display $time " tagUsageTracker after update retire: " (fshow |> readVReg tagUsageTracker) + (select tagUsageTracker tag) := False + + "update_usage_just_request": when + Nothing <- updateUsageRetireTag.wget, + Just tag <- updateUsageRequestTag.wget ==> + do + $display $time " tagUsageTracker after update request: " (fshow |> readVReg tagUsageTracker) + (select tagUsageTracker tag) := True + + "update_usage_request_and_retire": when + Just retireTag <- updateUsageRetireTag.wget, + Just requestTag <- updateUsageRequestTag.wget ==> + do + $display $time " tagUsageTracker after update request and retire: " (fshow |> readVReg tagUsageTracker) + let + tagUsageTrackerInner = readVReg tagUsageTracker + tagUsageTracker' = update tagUsageTrackerInner requestTag True + tagUsageTracker'' = update tagUsageTracker' retireTag False + writeVReg tagUsageTracker tagUsageTracker'' + "retire_tags": when True ==> do - $display "firing retire_tags" (fshow retireTag) - tagFIFO.enq retireTag - (select tagUsageTracker retireTag) := False + let tagToRetire = validatedTagToRetire.first + $display "firing retire_tags" (fshow tagToRetire) + validatedTagToRetire.deq + tagFIFO.enq tagToRetire + updateUsageRetireTag.wset tagToRetire return $ interface TagEngine @@ -67,18 +101,19 @@ mkTagEngine = case initialTagDistributor of Just 0 -> do initialTagDistributor := Nothing - (select tagUsageTracker 0) := True + updateUsageRequestTag.wset 0 return 0 Just tag -> do initialTagDistributor := Just |> tag - 1 - (select tagUsageTracker tag) := True + updateUsageRequestTag.wset tag return tag Nothing -> do let tag = tagFIFO.first tagFIFO.deq + updateUsageRequestTag.wset tag return tag - -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) + -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- validates tags before attempting to retire them. @@ -90,6 +125,6 @@ mkTagEngine = tagInUse = readReg (select tagUsageTracker tag) if (tagValid && tagInUse) then do - retireTag := tag + validatedTagToRetire.enq tag else do action {} diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 6c140c3..4fc700e 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -6,23 +6,22 @@ import ActionSeq mkTagEngineTester :: Module Empty mkTagEngineTester = do tagEngine :: TagEngine 5 <- mkTagEngine - count :: Reg (UInt 32) <- mkReg 0; runOnce :: Reg Bool <- mkReg False s :: ActionSeq - s <- + s <- let requestTagAction :: Action requestTagAction = do tag <- tagEngine.requestTag - $display "got tag : " (fshow tag) + $display $time " got tag : " (fshow tag) retireTagAction :: UInt 3 -> Action retireTagAction tag = do res <- tagEngine.retireTag tag - $display "retiring tag : " (fshow tag) " " (fshow res) + $display $time " retiring tag : " (fshow tag) " " (fshow res) action {} in @@ -34,12 +33,12 @@ mkTagEngineTester = do |> do requestTagAction |> do retireTagAction 2 -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" - |> do + |> do retireTagAction 4 requestTagAction -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" - |> do + |> do retireTagAction 4 requestTagAction -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" @@ -55,11 +54,11 @@ mkTagEngineTester = do addRules $ rules - "counter": when True ==> - do - count := count + 1 - $display "count : " (fshow count) + -- "counter": when True ==> + -- do + -- count := count + 1 + -- $display "count : " (fshow count) "testIncrement": when (runOnce == False) ==> do s.start - runOnce := True \ No newline at end of file + runOnce := True From 020bc5b6460dd422e2170f5466ae8c8d90174760 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 4 Apr 2025 15:27:25 -0400 Subject: [PATCH 08/51] notable refactor with grok --- bs/TagEngine.bs | 155 ++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 91 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index f5a00ba..0d28fce 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -20,111 +20,84 @@ interface (TagEngine :: # -> *) numTags = -- on a bus for example. -- This implementation is FIFO based. mkTagEngine :: Module (TagEngine numTags) -mkTagEngine = - do - let reifiedNumTags = fromInteger |> valueOf numTags +mkTagEngine = do + -- Constants + let maxTagCount = fromInteger (valueOf numTags) - -- we really only use tagUsageTracker after emptying out our - -- `initialTagDistributor` buffer - tagUsageTracker :: Vector numTags (Reg Bool) - tagUsageTracker <- replicateM |> mkReg False + -- State + tagUsage :: Vector numTags (Reg Bool) <- replicateM (mkReg False) -- Tracks which tags are in use + initialTagCounter <- mkReg (Just (maxTagCount - 1)) -- Distributes initial tags + retireQueue <- mkBypassFIFO -- Queue for tags being retired + freeTagQueue <- mkSizedFIFOF maxTagCount -- Queue of available tags - -- Since Bluespec doesn't allow us to initialize FIFOs with values at - -- reset, we can pretend as if the buffer within our tagFIFO is populated - -- with sequentially incrementing values(starting from 0) on reset - -- by having our tag engine effectively return the value of a decrementing - -- counter initialized to (numTags - 1) for the first n tag requests made - -- to TagEngine where `n := numTags`. - initialTagDistributor :: (Reg (Maybe UIntLog2N(numTags))) - initialTagDistributor <- mkReg |> Just |> reifiedNumTags - 1 + -- Signals + retireSignal <- mkRWire -- Signals a tag retirement + requestSignal <- mkRWire -- Signals a tag request - validatedTagToRetire :: FIFO UIntLog2N(numTags) - validatedTagToRetire <- mkBypassFIFO + -- Debug + debugOnce <- mkReg True - updateUsageRetireTag :: RWire UIntLog2N(numTags) - updateUsageRetireTag <- mkRWire + -- Rules + addRules $ + rules + "debug_initial_state": when debugOnce ==> do + $display "tagUsage: " (fshow (readVReg tagUsage)) + debugOnce := False - updateUsageRequestTag :: RWire UIntLog2N(numTags) - updateUsageRequestTag <- mkRWire + "retire_tag": when True ==> do + let tag = retireQueue.first + $display "Retiring tag: " (fshow tag) + retireQueue.deq + freeTagQueue.enq tag + retireSignal.wset tag - tagFIFO :: FIFOF UIntLog2N(numTags) - tagFIFO <- mkSizedFIFOF reifiedNumTags - - debugOnce <- mkReg True - - addRules $ - rules - "display": when (debugOnce == True) ==> - do - $display "tagUsageTracker : " (fshow |> readVReg tagUsageTracker) - debugOnce := False - - "update_usage_just_retire": when - Just tag <- updateUsageRetireTag.wget, - Nothing <- updateUsageRequestTag.wget ==> - do - $display $time " tagUsageTracker after update retire: " (fshow |> readVReg tagUsageTracker) - (select tagUsageTracker tag) := False - - "update_usage_just_request": when - Nothing <- updateUsageRetireTag.wget, - Just tag <- updateUsageRequestTag.wget ==> - do - $display $time " tagUsageTracker after update request: " (fshow |> readVReg tagUsageTracker) - (select tagUsageTracker tag) := True - - "update_usage_request_and_retire": when - Just retireTag <- updateUsageRetireTag.wget, - Just requestTag <- updateUsageRequestTag.wget ==> - do - $display $time " tagUsageTracker after update request and retire: " (fshow |> readVReg tagUsageTracker) - let - tagUsageTrackerInner = readVReg tagUsageTracker - tagUsageTracker' = update tagUsageTrackerInner requestTag True - tagUsageTracker'' = update tagUsageTracker' retireTag False - writeVReg tagUsageTracker tagUsageTracker'' - - "retire_tags": when True ==> - do - let tagToRetire = validatedTagToRetire.first - $display "firing retire_tags" (fshow tagToRetire) - validatedTagToRetire.deq - tagFIFO.enq tagToRetire - updateUsageRetireTag.wset tagToRetire - - return $ - interface TagEngine + -- Combined update rules (simplified below) + "update_usage": when True ==> do + let mRetireTag = retireSignal.wget + mRequestTag = requestSignal.wget + case (mRetireTag, mRequestTag) of + (Just retireTag, Just requestTag) -> do + let usage = readVReg tagUsage + usage' = update usage requestTag True + usage'' = update usage' retireTag False + writeVReg tagUsage usage'' + $display $time " Updated usage (request + retire): " (fshow |> readVReg tagUsage) + (Just retireTag, Nothing) -> do + (select tagUsage retireTag) := False + $display $time " Updated usage (retire): " (fshow (readVReg tagUsage)) + (Nothing, Just requestTag) -> do + (select tagUsage requestTag) := True + $display $time " Updated usage (request): " (fshow (readVReg tagUsage)) + (Nothing, Nothing) -> action {} + -- Interface + return $ + interface TagEngine requestTag :: ActionValue UIntLog2N(numTags) - requestTag = - do - case initialTagDistributor of - Just 0 -> do - initialTagDistributor := Nothing - updateUsageRequestTag.wset 0 - return 0 - Just tag -> do - initialTagDistributor := Just |> tag - 1 - updateUsageRequestTag.wset tag - return tag - Nothing -> do - let tag = tagFIFO.first - tagFIFO.deq - updateUsageRequestTag.wset tag - return tag + requestTag = do + case initialTagCounter of + Just 0 -> do + initialTagCounter := Nothing + requestSignal.wset 0 + return 0 + Just tag -> do + initialTagCounter := Just (tag - 1) + requestSignal.wset tag + return tag + Nothing -> do + let tag = freeTagQueue.first + freeTagQueue.deq + requestSignal.wset tag + return tag - -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) - -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. - -- Internally, the tagEngine will keep a correct and consistent state since TagEngine - -- validates tags before attempting to retire them. retireTag :: UIntLog2N(numTags) -> Action retireTag tag = do let - tagValid = tag < reifiedNumTags - tagInUse = readReg (select tagUsageTracker tag) + tagValid = tag < maxTagCount + tagInUse = readReg (select tagUsage tag) if (tagValid && tagInUse) then do - validatedTagToRetire.enq tag + retireQueue.enq tag else do action {} From e415d981f9b40bf4a4667395245d4f3d6fa2e6bb Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 4 Apr 2025 15:31:46 -0400 Subject: [PATCH 09/51] add some comments --- bs/TagEngine.bs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 0d28fce..921e58e 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -24,9 +24,15 @@ mkTagEngine = do -- Constants let maxTagCount = fromInteger (valueOf numTags) - -- State tagUsage :: Vector numTags (Reg Bool) <- replicateM (mkReg False) -- Tracks which tags are in use - initialTagCounter <- mkReg (Just (maxTagCount - 1)) -- Distributes initial tags + + -- Since Bluespec doesn't allow us to initialize FIFOs with values at + -- reset, we can pretend as if the buffer within our freeTagQueue is populated + -- with sequentially incrementing values(starting from 0) on reset + -- by having our tag engine effectively return the value of a decrementing + -- counter initialized to (maxTagCount - 1) for the first n tag requests made + -- to TagEngine where `n := maxTagCount`. + initialTagDistributor <- mkReg (Just (maxTagCount - 1)) -- Distributes initial tags retireQueue <- mkBypassFIFO -- Queue for tags being retired freeTagQueue <- mkSizedFIFOF maxTagCount -- Queue of available tags @@ -75,13 +81,13 @@ mkTagEngine = do interface TagEngine requestTag :: ActionValue UIntLog2N(numTags) requestTag = do - case initialTagCounter of + case initialTagDistributor of Just 0 -> do - initialTagCounter := Nothing + initialTagDistributor := Nothing requestSignal.wset 0 return 0 Just tag -> do - initialTagCounter := Just (tag - 1) + initialTagDistributor := Just (tag - 1) requestSignal.wset tag return tag Nothing -> do @@ -90,6 +96,10 @@ mkTagEngine = do requestSignal.wset tag return tag + -- `retireTag` isn't guarded on tag validity(this would break Bluespec's safety model) + -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. + -- Internally, the tagEngine will keep a correct and consistent state since TagEngine + -- validates tags before attempting to retire them. retireTag :: UIntLog2N(numTags) -> Action retireTag tag = do From da761f6e4ec6fe3b3f28431919cc6d3cfb0cbaee Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 8 Apr 2025 13:05:34 -0400 Subject: [PATCH 10/51] Type system progress on bus design --- bs/Bus.bs | 13 ++++++++++ bs/BusTypes.bs | 66 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 0faaa54..87ca6ff 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -3,5 +3,18 @@ package Bus(a) where import Types import BusTypes +interface (TestType :: * -> *) t = {} + -- doSomething :: t -> Action + +mkTestType :: (Bits t n, Arith t, Eq t) => Module (TestType t) +mkTestType = do + return $ interface TestType {} + +mkTestTop :: Module Empty +mkTestTop = do + testType :: TestType (UInt 5) + testType <- mkTestType + return $ interface Empty { } + a :: UInt 5 a = 3 diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index 99d0fb4..e6943c5 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,12 +1,12 @@ package BusTypes( - BusVal(..), - BusError(..), - TransactionSize(..), - ReadRequest(..), - WriteRequest(..) + BusClient(..), BusServer(..), + BusRequest(..), BusResponse(..), + ReadRequest(..), ReadResponse(..), WriteRequest(..), WriteResponse(..), + BusVal(..), BusError(..), TransactionSize(..) ) where import Types +import Vector data BusError = UnMapped @@ -48,21 +48,51 @@ data BusResponse | BusWriteResponse WriteResponse deriving (Bits, Eq, FShow) -interface BusMaster = - -- The Bus arbiter will call the Bus Master's request method - -- if and only if it's the Bus Master's turn to make a request, and the Bus Master - -- has a request to make. - -- It is up to the BusMaster to guard it's request method such that calling - -- it's request method is only valid when the BusMaster has a request to make. - -- This has implications about for the implementor of BusMaster, namely, that it - -- should hold its request until it's request method gets called. - request :: BusRequest - -- From the masters's perspective, the response should not be called by the - -- arbiter until the master is ready to accept the response. In other words, - -- response should be guarded by the client. - response :: BusResponse -> Action +-- # BusClient.dequeueRequest +-- * The Bus arbiter will call the Bus Client's request method if it is +-- the Bus Client's turn to make a request, or if another client forfits +-- its turn. +-- * The BusClient must guard its request method such that calling its +-- request method is only valid when the BusClient has a request to make. +-- * This has implications about for the implementor of BusClient, +-- namely, that it should hold its request until it's request method +-- gets called. The arbiter tags the request so that the client can +-- later correctly correlate the response. +-- * Although the tag is technically passed in as an argument from the +-- arbiter to the client's request method, given that methods are +-- atomic in Bluespec, this is effectively equivalent to tagging the +-- transaction from the client's perspective. Thus, the client must +-- take care to appropiately store the tag. +-- # BusClient.enqueueResponse +-- * From the client's perspective, the response should not be called +-- by the arbiter until the client is ready to accept the response. +-- In other words, the response method should be guarded by the client. +interface (BusClient :: * -> *) transactionTagType = + dequeueRequest :: transactionTagType -> ActionValue BusRequest + enqueueResponse :: (BusResponse, transactionTagType) -> Action + +-- # BusServer.dequeueResponse +-- * If the arbiter is able to successfully call `dequeueResponse`, then +-- the BusServer's internal logici must update such that it understand +-- the response has been handed off. +-- # BusServer.peekClientTagDestination +-- * The arbiter looks at (peekClientTagDestination :: clientTagTye) to +-- determine whether or not it is currently safe whether to dequeue the +-- response as well as where to route the response should it dequeue the +-- response. +-- * `peekClientTagDestination` should be guarded on whether or not there is +-- a valid response available. +interface (BusServer :: * -> * -> *) transactionTagType clientTagType = + enqueueRequest :: (transactionTagType, BusRequest) -> Action + dequeueResponse :: ActionValue (clientTagType, BusResponse, transactionTagType) + peekClientTagDestination :: clientTagTye + +interface (Bus :: # -> # -> * -> * -> *) numClients numServers transactionTagType clientTagType = + clients :: Vector numClients (BusClient transactionTagType) + servers :: Vector numServers (BusServer transactionTagType clientTagType) type Token = UInt 5 +type Numeric = 5 a :: UInt 5 a = 3 From b326ac894eae69a7e53bb51c94734bcfbd8a3885 Mon Sep 17 00:00:00 2001 From: Yehowshua Date: Tue, 8 Apr 2025 23:36:08 +0000 Subject: [PATCH 11/51] Add LICENSE --- LICENSE | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..473281c --- /dev/null +++ b/LICENSE @@ -0,0 +1,198 @@ +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. + +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. + +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + +a) The work must carry prominent notices stating that you modified it, and giving a relevant date. +b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. +c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. +d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + +a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. +b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. +c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. +d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. +e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. + +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + +a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or +b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or +c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or +d) Limiting the use for publicity purposes of names of licensors or authors of the material; or +e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or +f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. + +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS \ No newline at end of file From fe2fa21fcc57d03477e82ef0bfa9281de8ea1b10 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 8 Apr 2025 23:04:30 -0400 Subject: [PATCH 12/51] skeletons of Bus module slowly forming --- bs/Bus.bs | 17 ++++++++++++++++- bs/BusTypes.bs | 5 +---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 87ca6ff..6d648f1 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -2,11 +2,16 @@ package Bus(a) where import Types import BusTypes +import TagEngine +import Vector interface (TestType :: * -> *) t = {} -- doSomething :: t -> Action -mkTestType :: (Bits t n, Arith t, Eq t) => Module (TestType t) +mkTestType :: ( + Bits t n, Arith t, Eq t + ) + => Module (TestType t) mkTestType = do return $ interface TestType {} @@ -16,5 +21,15 @@ mkTestTop = do testType <- mkTestType return $ interface Empty { } +mkBus :: Vector numClients (BusClient (UInt (TLog numClients))) + -> Vector numServers (BusServer (UInt (TLog numClients)) clientTagType) + -> Module Empty +mkBus clientVec serverVec = do + tagEngineByClient :: Vector numClients (TagEngine (TLog numClients)) + tagEngineByClient <- replicateM mkTagEngine + + return $ interface Empty { } + + a :: UInt 5 a = 3 diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index e6943c5..4828668 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,4 +1,5 @@ package BusTypes( + Bus(..), BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), ReadRequest(..), ReadResponse(..), WriteRequest(..), WriteResponse(..), @@ -87,10 +88,6 @@ interface (BusServer :: * -> * -> *) transactionTagType clientTagType = dequeueResponse :: ActionValue (clientTagType, BusResponse, transactionTagType) peekClientTagDestination :: clientTagTye -interface (Bus :: # -> # -> * -> * -> *) numClients numServers transactionTagType clientTagType = - clients :: Vector numClients (BusClient transactionTagType) - servers :: Vector numServers (BusServer transactionTagType clientTagType) - type Token = UInt 5 type Numeric = 5 From 989c4e96167174d1704367ec2424e37b1707ab82 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 8 Apr 2025 23:36:54 -0400 Subject: [PATCH 13/51] Bus types typecheck!!! --- bs/Bus.bs | 6 +++--- bs/BusTypes.bs | 27 ++++++++++++++++++--------- bs/TagEngine.bs | 11 ++++++----- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 6d648f1..318c029 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -21,11 +21,11 @@ mkTestTop = do testType <- mkTestType return $ interface Empty { } -mkBus :: Vector numClients (BusClient (UInt (TLog numClients))) - -> Vector numServers (BusServer (UInt (TLog numClients)) clientTagType) +mkBus :: Vector numClients (BusClient inFlightTransactions) + -> Vector numServers (BusServer inFlightTransactions numClients) -> Module Empty mkBus clientVec serverVec = do - tagEngineByClient :: Vector numClients (TagEngine (TLog numClients)) + tagEngineByClient :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClient <- replicateM mkTagEngine return $ interface Empty { } diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index 4828668..a9a9125 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,5 +1,5 @@ package BusTypes( - Bus(..), + ClientTagType, BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), ReadRequest(..), ReadResponse(..), WriteRequest(..), WriteResponse(..), @@ -8,6 +8,9 @@ package BusTypes( import Types import Vector +import TagEngine + +type ClientTagType a = (UInt (TLog a)) data BusError = UnMapped @@ -68,25 +71,31 @@ data BusResponse -- * From the client's perspective, the response should not be called -- by the arbiter until the client is ready to accept the response. -- In other words, the response method should be guarded by the client. -interface (BusClient :: * -> *) transactionTagType = - dequeueRequest :: transactionTagType -> ActionValue BusRequest - enqueueResponse :: (BusResponse, transactionTagType) -> Action +interface (BusClient :: # -> *) inFlightTransactions = + dequeueRequest :: TagType inFlightTransactions + -> ActionValue BusRequest + enqueueResponse :: (BusResponse, TagType inFlightTransactions) + -> Action -- # BusServer.dequeueResponse -- * If the arbiter is able to successfully call `dequeueResponse`, then -- the BusServer's internal logici must update such that it understand -- the response has been handed off. -- # BusServer.peekClientTagDestination --- * The arbiter looks at (peekClientTagDestination :: clientTagTye) to +-- * The arbiter looks at (peekClientTagDestination :: clientTagType) to -- determine whether or not it is currently safe whether to dequeue the -- response as well as where to route the response should it dequeue the -- response. -- * `peekClientTagDestination` should be guarded on whether or not there is -- a valid response available. -interface (BusServer :: * -> * -> *) transactionTagType clientTagType = - enqueueRequest :: (transactionTagType, BusRequest) -> Action - dequeueResponse :: ActionValue (clientTagType, BusResponse, transactionTagType) - peekClientTagDestination :: clientTagTye +interface (BusServer :: # -> # -> *) inFlightTransactions numClients = + enqueueRequest :: (TagType inFlightTransactions, BusRequest) + -> Action + dequeueResponse :: ActionValue ( + ClientTagType numClients, + BusResponse, transactionTagType + ) + peekClientTagDestination :: clientTagType type Token = UInt 5 type Numeric = 5 diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 921e58e..95b0d33 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -1,4 +1,5 @@ package TagEngine( + TagType, TagEngine(..), Util.BasicResult(..), mkTagEngine) where @@ -9,11 +10,11 @@ import FIFO import FIFOF import SpecialFIFOs -#define UIntLog2N(n) (UInt (TLog n)) +type TagType a = (UInt (TLog a)) interface (TagEngine :: # -> *) numTags = - requestTag :: ActionValue UIntLog2N(numTags) - retireTag :: UIntLog2N(numTags) -> Action + requestTag :: ActionValue (TagType numTags) + retireTag :: (TagType numTags) -> Action -- The tag engine returns a tag that is unique for the duration of -- the lifetime of the tag. Useful when you need to tag transactions @@ -79,7 +80,7 @@ mkTagEngine = do -- Interface return $ interface TagEngine - requestTag :: ActionValue UIntLog2N(numTags) + requestTag :: ActionValue (TagType numTags) requestTag = do case initialTagDistributor of Just 0 -> do @@ -100,7 +101,7 @@ mkTagEngine = do -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- validates tags before attempting to retire them. - retireTag :: UIntLog2N(numTags) -> Action + retireTag :: (TagType numTags) -> Action retireTag tag = do let From b4c7537a8542fdb2e9d67cf52c76167e9c231ef4 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 9 Apr 2025 01:08:42 -0400 Subject: [PATCH 14/51] things still typecheck --- bs/Bus.bs | 34 ++++++++++++++-------------------- bs/BusTypes.bs | 24 +++++++++--------------- bs/TagEngine.bs | 16 ++++++++-------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 318c029..b554ba1 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -1,25 +1,14 @@ -package Bus(a) where +package Bus(mkBus) where import Types import BusTypes import TagEngine import Vector +import Util +import Arbiter -interface (TestType :: * -> *) t = {} - -- doSomething :: t -> Action - -mkTestType :: ( - Bits t n, Arith t, Eq t - ) - => Module (TestType t) -mkTestType = do - return $ interface TestType {} - -mkTestTop :: Module Empty -mkTestTop = do - testType :: TestType (UInt 5) - testType <- mkTestType - return $ interface Empty { } +clientRequest :: Arbiter.ArbiterClient_IFC -> Action +clientRequest ifc = ifc.request mkBus :: Vector numClients (BusClient inFlightTransactions) -> Vector numServers (BusServer inFlightTransactions numClients) @@ -28,8 +17,13 @@ mkBus clientVec serverVec = do tagEngineByClient :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClient <- replicateM mkTagEngine + arbiterByServer :: Vector numServers (Arbiter_IFC numClients) + arbiterByServer <- replicateM (mkArbiter False) + + addRules |> + rules + "placeholder rule": when True ==> do + let selectedArbiter = (select arbiterByServer 0) + mapM_ clientRequest selectedArbiter.clients + return $ interface Empty { } - - -a :: UInt 5 -a = 3 diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index a9a9125..818fd3d 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,5 +1,5 @@ package BusTypes( - ClientTagType, + MkClientTagType, BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), ReadRequest(..), ReadResponse(..), WriteRequest(..), WriteResponse(..), @@ -10,7 +10,7 @@ import Types import Vector import TagEngine -type ClientTagType a = (UInt (TLog a)) +type MkClientTagType a = (UInt (TLog a)) data BusError = UnMapped @@ -72,33 +72,27 @@ data BusResponse -- by the arbiter until the client is ready to accept the response. -- In other words, the response method should be guarded by the client. interface (BusClient :: # -> *) inFlightTransactions = - dequeueRequest :: TagType inFlightTransactions + dequeueRequest :: MkTagType inFlightTransactions -> ActionValue BusRequest - enqueueResponse :: (BusResponse, TagType inFlightTransactions) + enqueueResponse :: (BusResponse, MkTagType inFlightTransactions) -> Action -- # BusServer.dequeueResponse -- * If the arbiter is able to successfully call `dequeueResponse`, then --- the BusServer's internal logici must update such that it understand +-- the BusServer's internal logic must update such that it understands -- the response has been handed off. -- # BusServer.peekClientTagDestination --- * The arbiter looks at (peekClientTagDestination :: clientTagType) to +-- * The arbiter looks at (peekClientTagDestination :: MkClientTagType) to -- determine whether or not it is currently safe whether to dequeue the -- response as well as where to route the response should it dequeue the -- response. -- * `peekClientTagDestination` should be guarded on whether or not there is -- a valid response available. interface (BusServer :: # -> # -> *) inFlightTransactions numClients = - enqueueRequest :: (TagType inFlightTransactions, BusRequest) + enqueueRequest :: (MkTagType inFlightTransactions, BusRequest) -> Action dequeueResponse :: ActionValue ( - ClientTagType numClients, + MkClientTagType numClients, BusResponse, transactionTagType ) - peekClientTagDestination :: clientTagType - -type Token = UInt 5 -type Numeric = 5 - -a :: UInt 5 -a = 3 + peekClientTagDestination :: MkClientTagType numClients diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 95b0d33..2ddb304 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -1,5 +1,5 @@ package TagEngine( - TagType, + MkTagType, TagEngine(..), Util.BasicResult(..), mkTagEngine) where @@ -10,11 +10,11 @@ import FIFO import FIFOF import SpecialFIFOs -type TagType a = (UInt (TLog a)) +type MkTagType numTags = (UInt (TLog numTags)) interface (TagEngine :: # -> *) numTags = - requestTag :: ActionValue (TagType numTags) - retireTag :: (TagType numTags) -> Action + requestTag :: ActionValue (MkTagType numTags) + retireTag :: (MkTagType numTags) -> Action -- The tag engine returns a tag that is unique for the duration of -- the lifetime of the tag. Useful when you need to tag transactions @@ -45,7 +45,7 @@ mkTagEngine = do debugOnce <- mkReg True -- Rules - addRules $ + addRules |> rules "debug_initial_state": when debugOnce ==> do $display "tagUsage: " (fshow (readVReg tagUsage)) @@ -78,9 +78,9 @@ mkTagEngine = do (Nothing, Nothing) -> action {} -- Interface - return $ + return |> interface TagEngine - requestTag :: ActionValue (TagType numTags) + requestTag :: ActionValue (MkTagType numTags) requestTag = do case initialTagDistributor of Just 0 -> do @@ -101,7 +101,7 @@ mkTagEngine = do -- so it is advisable that the caller of `retireTag` only attempt to retire valid tags. -- Internally, the tagEngine will keep a correct and consistent state since TagEngine -- validates tags before attempting to retire them. - retireTag :: (TagType numTags) -> Action + retireTag :: (MkTagType numTags) -> Action retireTag tag = do let From 076d3aed4367a48aad3cf2d4f297908707223cfa Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 9 Apr 2025 20:58:13 -0400 Subject: [PATCH 15/51] shoudl probably rethink approach... --- bs/Bus.bs | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index b554ba1..7df4955 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -10,20 +10,56 @@ import Arbiter clientRequest :: Arbiter.ArbiterClient_IFC -> Action clientRequest ifc = ifc.request -mkBus :: Vector numClients (BusClient inFlightTransactions) +busRequestToAddr :: BusRequest -> Addr +busRequestToAddr req = case req of + BusReadRequest (ReadRequest addr _) -> addr + WriteReadRequest (WriteRequest addr _) -> addr + +mkBus :: (Addr -> Integer) + -> Vector numClients (BusClient inFlightTransactions) -> Vector numServers (BusServer inFlightTransactions numClients) -> Module Empty -mkBus clientVec serverVec = do - tagEngineByClient :: Vector numClients (TagEngine inFlightTransactions) - tagEngineByClient <- replicateM mkTagEngine +mkBus addrToServerTranslation clientVec serverVec = do + tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) + tagEngineByClientVec <- replicateM mkTagEngine - arbiterByServer :: Vector numServers (Arbiter_IFC numClients) - arbiterByServer <- replicateM (mkArbiter False) + arbiterByServerVec :: Vector numServers (Arbiter_IFC numClients) + arbiterByServerVec <- replicateM (mkArbiter False) + + -- statically determinate criteria + let + clientIdx :: Integer = 0 + selectedClient ::(BusClient inFlightTransactions) + selectedClient = (select clientVec clientIdx) + selectedTagEngine = (select tagEngineByClientVec clientIdx) addRules |> rules "placeholder rule": when True ==> do - let selectedArbiter = (select arbiterByServer 0) - mapM_ clientRequest selectedArbiter.clients + let selectedServerArbiter = (select arbiterByServerVec 0) + mapM_ clientRequest selectedServerArbiter.clients + + "connect request client 0": + when True + ==> do + tag <- selectedTagEngine.requestTag + + busRequest :: BusRequest + busRequest <- selectedClient.dequeueRequest tag + + -- let + -- addr = busRequestToAddr busRequest + -- targetServerIdx = addrToServerTranslation addr + -- targetServer = (select serverVec targetServerIdx) + -- targetServerArbiter = (select arbiterByServerVec targetServerIdx) + + -- targetServerArbiter.request + + -- if targetServerArbiter.grant + -- then targetServer.enqueueRequest (tag, busRequest) + -- else action {} + + -- targetServer + action {} return $ interface Empty { } From ca02c88be31d0ccc188688bb052a3b42af5cc171 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 9 Apr 2025 22:31:26 -0400 Subject: [PATCH 16/51] stubbed out mkBus for now - awaits full implementation --- bs/Bus.bs | 86 +++++++++++++++++++++++++++----------------------- bs/BusTypes.bs | 82 +++++++++++++++++++++++------------------------ 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 7df4955..73f9e76 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -6,60 +6,66 @@ import TagEngine import Vector import Util import Arbiter +import FIFO +import FIFOF +import SpecialFIFOs clientRequest :: Arbiter.ArbiterClient_IFC -> Action clientRequest ifc = ifc.request -busRequestToAddr :: BusRequest -> Addr +busRequestToAddr :: BusRequest -> Maybe Addr busRequestToAddr req = case req of BusReadRequest (ReadRequest addr _) -> addr - WriteReadRequest (WriteRequest addr _) -> addr + BusWriteRequest (WriteRequest addr _) -> addr -mkBus :: (Addr -> Integer) - -> Vector numClients (BusClient inFlightTransactions) - -> Vector numServers (BusServer inFlightTransactions numClients) - -> Module Empty -mkBus addrToServerTranslation clientVec serverVec = do +mkBus :: (Addr -> Maybe Integer) + -> Module (Bus inFlightTransactions numClients numServers) +mkBus addrToServerTranslation = do + -- Tag engines for each client to manage transaction tags tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - arbiterByServerVec :: Vector numServers (Arbiter_IFC numClients) - arbiterByServerVec <- replicateM (mkArbiter False) + -- Arbitration for clients to send requests to servers + clientArbiter :: Arbiter.Arbiter_IFC numClients + clientArbiter <- mkArbiter False - -- statically determinate criteria - let - clientIdx :: Integer = 0 - selectedClient ::(BusClient inFlightTransactions) - selectedClient = (select clientVec clientIdx) - selectedTagEngine = (select tagEngineByClientVec clientIdx) + dummyVar :: Reg(Bool) + dummyVar <- mkReg False - addRules |> - rules - "placeholder rule": when True ==> do - let selectedServerArbiter = (select arbiterByServerVec 0) - mapM_ clientRequest selectedServerArbiter.clients + -- Queues to hold requests from clients to servers + requestQueues :: Vector numServers (FIFOF BusRequest) + requestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - "connect request client 0": - when True - ==> do - tag <- selectedTagEngine.requestTag + -- Queues to hold responses from servers to clients + responseQueues :: Vector numClients (FIFOF (BusResponse, MkTagType inFlightTransactions)) + responseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - busRequest :: BusRequest - busRequest <- selectedClient.dequeueRequest tag + -- Client interface vector + let clients :: Vector numClients (BusClient inFlightTransactions) + clients = genWith $ \clientIdx -> + interface BusClient + submitRequest req = do + dummyVar := (not dummyVar) + return 0 - -- let - -- addr = busRequestToAddr busRequest - -- targetServerIdx = addrToServerTranslation addr - -- targetServer = (select serverVec targetServerIdx) - -- targetServerArbiter = (select arbiterByServerVec targetServerIdx) - - -- targetServerArbiter.request + consumeResponse = do + dummyVar := (not dummyVar) + let dummyResponse = BusReadResponse (Left UnMapped) + return (dummyResponse, 0) - -- if targetServerArbiter.grant - -- then targetServer.enqueueRequest (tag, busRequest) - -- else action {} - - -- targetServer - action {} + -- Server interface vector + let servers :: Vector numServers (BusServer inFlightTransactions numClients) + servers = genWith $ \serverIdx -> + interface BusServer + consumeRequest = do + dummyVar := (not dummyVar) + let dummyBusRequest = BusReadRequest (ReadRequest 0 SizeByte) + return (0, dummyBusRequest) - return $ interface Empty { } + submitResponse (clientTag, busResponse, transactionTag) = do + dummyVar := (not dummyVar) + + return $ + interface Bus + clients = clients + servers = servers diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index 818fd3d..f0ae7fa 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,4 +1,5 @@ package BusTypes( + Bus(..), MkClientTagType, BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), @@ -44,7 +45,7 @@ type WriteResponse = Either BusError () data BusRequest = BusReadRequest ReadRequest - | WriteReadRequest WriteRequest + | BusWriteRequest WriteRequest deriving (Bits, Eq, FShow) data BusResponse @@ -52,47 +53,44 @@ data BusResponse | BusWriteResponse WriteResponse deriving (Bits, Eq, FShow) --- # BusClient.dequeueRequest --- * The Bus arbiter will call the Bus Client's request method if it is --- the Bus Client's turn to make a request, or if another client forfits --- its turn. --- * The BusClient must guard its request method such that calling its --- request method is only valid when the BusClient has a request to make. --- * This has implications about for the implementor of BusClient, --- namely, that it should hold its request until it's request method --- gets called. The arbiter tags the request so that the client can --- later correctly correlate the response. --- * Although the tag is technically passed in as an argument from the --- arbiter to the client's request method, given that methods are --- atomic in Bluespec, this is effectively equivalent to tagging the --- transaction from the client's perspective. Thus, the client must --- take care to appropiately store the tag. --- # BusClient.enqueueResponse --- * From the client's perspective, the response should not be called --- by the arbiter until the client is ready to accept the response. --- In other words, the response method should be guarded by the client. +-- # BusClient.submitRequest +-- * The bus client calls the `submitRequest` method of the `BusClient` interface +-- with the `BusRequest` it wishes to submit and immediately recieves back +-- a transaction-duration-unqiue tag that it can later correlate with the +-- returned response should responses arrive out of order(OOO). OOO can +-- happen if a bus server is is able to process bus requests faster than +-- other bus servers for example. +-- # BusClient.consumeResponse +-- * The bus client is able to consume a response when a response is available. +-- Responses are tagged with the tag given to bus client when it called +-- `submitRequest` interface (BusClient :: # -> *) inFlightTransactions = - dequeueRequest :: MkTagType inFlightTransactions - -> ActionValue BusRequest - enqueueResponse :: (BusResponse, MkTagType inFlightTransactions) + submitRequest :: BusRequest + -> ActionValue (MkTagType inFlightTransactions) + consumeResponse :: ActionValue (BusResponse, MkTagType inFlightTransactions) + +-- # BusServer.consumeRequest +-- * The bus server calls the `consumeRequest` method of the `BusServer` interface +-- to retrieve a pending bus request initiated by a client. It immediately +-- receives a tuple containing a transaction-duration-unique tag +-- (associated with the original request) and the `BusRequest` itself. This +-- tag is used to track the transaction and correlate it with the eventual +-- response. +-- # BusServer.submitResponse +-- * The bus server calls the `submitResponse` method to send a `BusResponse` +-- back to the originating client. The method takes a tuple containing: +-- - A client tag (of type `MkClientTagType numClients`) identifying the +-- client that submitted the request. +-- - The `BusResponse` containing the result of the request (either a read +-- or write response). +-- - The transaction tag (of type `transactionTagType`) that matches the tag +-- received from `consumeRequest`, ensuring the response is correctly +-- associated with the original request. +interface (BusServer :: # -> # -> *) inFlightTransactions numClients = + consumeRequest :: ActionValue (MkTagType inFlightTransactions, BusRequest) + submitResponse :: (MkClientTagType numClients, BusResponse, transactionTagType) -> Action --- # BusServer.dequeueResponse --- * If the arbiter is able to successfully call `dequeueResponse`, then --- the BusServer's internal logic must update such that it understands --- the response has been handed off. --- # BusServer.peekClientTagDestination --- * The arbiter looks at (peekClientTagDestination :: MkClientTagType) to --- determine whether or not it is currently safe whether to dequeue the --- response as well as where to route the response should it dequeue the --- response. --- * `peekClientTagDestination` should be guarded on whether or not there is --- a valid response available. -interface (BusServer :: # -> # -> *) inFlightTransactions numClients = - enqueueRequest :: (MkTagType inFlightTransactions, BusRequest) - -> Action - dequeueResponse :: ActionValue ( - MkClientTagType numClients, - BusResponse, transactionTagType - ) - peekClientTagDestination :: MkClientTagType numClients +interface (Bus :: # -> # -> # -> *) inFlightTransactions numClients numServers = + clients :: Vector numClients (BusClient inFlightTransactions) + servers :: Vector numServers (BusServer inFlightTransactions numClients) From 979adf36604826c4850f973858963b02bcd2a55e Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 00:36:29 -0400 Subject: [PATCH 17/51] preliminary work on client methods and some type repair --- bs/Bus.bs | 36 +++++++++++++++++++++++++----------- bs/BusTypes.bs | 13 +++++++++++-- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 73f9e76..51e5784 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -13,14 +13,14 @@ import SpecialFIFOs clientRequest :: Arbiter.ArbiterClient_IFC -> Action clientRequest ifc = ifc.request -busRequestToAddr :: BusRequest -> Maybe Addr +busRequestToAddr :: BusRequest -> Addr busRequestToAddr req = case req of BusReadRequest (ReadRequest addr _) -> addr BusWriteRequest (WriteRequest addr _) -> addr mkBus :: (Addr -> Maybe Integer) -> Module (Bus inFlightTransactions numClients numServers) -mkBus addrToServerTranslation = do +mkBus busMap = do -- Tag engines for each client to manage transaction tags tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine @@ -33,7 +33,7 @@ mkBus addrToServerTranslation = do dummyVar <- mkReg False -- Queues to hold requests from clients to servers - requestQueues :: Vector numServers (FIFOF BusRequest) + requestQueues :: Vector numServers (FIFOF (TaggedBusRequest inFlightTransactions)) requestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) -- Queues to hold responses from servers to clients @@ -43,25 +43,39 @@ mkBus addrToServerTranslation = do -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) clients = genWith $ \clientIdx -> - interface BusClient - submitRequest req = do - dummyVar := (not dummyVar) - return 0 + let + selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientRequestQueue = (select requestQueues clientIdx) - consumeResponse = do - dummyVar := (not dummyVar) - let dummyResponse = BusReadResponse (Left UnMapped) - return (dummyResponse, 0) + selectedTagEngine :: TagEngine inFlightTransactions + selectedTagEngine = (select tagEngineByClientVec clientIdx) + in + interface BusClient + submitRequest :: BusRequest + -> ActionValue (MkTagType inFlightTransactions) + submitRequest busRequest = do + tag <- selectedTagEngine.requestTag + selectedClientRequestQueue.enq (TaggedBusRequest tag busRequest) + return tag + + consumeResponse :: ActionValue (TaggedBusResponse inFlightTransactions) + consumeResponse = do + dummyVar := (not dummyVar) + let dummyResponse = BusReadResponse (Left UnMapped) + return (TaggedBusResponse 0 dummyResponse) -- Server interface vector let servers :: Vector numServers (BusServer inFlightTransactions numClients) servers = genWith $ \serverIdx -> interface BusServer + consumeRequest :: ActionValue (MkTagType inFlightTransactions, BusRequest) consumeRequest = do dummyVar := (not dummyVar) let dummyBusRequest = BusReadRequest (ReadRequest 0 SizeByte) return (0, dummyBusRequest) + submitResponse :: (MkClientTagType numClients, BusResponse, transactionTagType) + -> Action submitResponse (clientTag, busResponse, transactionTag) = do dummyVar := (not dummyVar) diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index f0ae7fa..cf11af0 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -4,7 +4,8 @@ package BusTypes( BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), ReadRequest(..), ReadResponse(..), WriteRequest(..), WriteResponse(..), - BusVal(..), BusError(..), TransactionSize(..) + BusVal(..), BusError(..), TransactionSize(..), + TaggedBusRequest(..), TaggedBusResponse(..) ) where import Types @@ -53,6 +54,14 @@ data BusResponse | BusWriteResponse WriteResponse deriving (Bits, Eq, FShow) +data TaggedBusRequest inFlightTransactions = + TaggedBusRequest (MkTagType inFlightTransactions) BusRequest + deriving (Bits, Eq, FShow) + +data TaggedBusResponse inFlightTransactions = + TaggedBusResponse (MkTagType inFlightTransactions) BusResponse + deriving (Bits, Eq, FShow) + -- # BusClient.submitRequest -- * The bus client calls the `submitRequest` method of the `BusClient` interface -- with the `BusRequest` it wishes to submit and immediately recieves back @@ -67,7 +76,7 @@ data BusResponse interface (BusClient :: # -> *) inFlightTransactions = submitRequest :: BusRequest -> ActionValue (MkTagType inFlightTransactions) - consumeResponse :: ActionValue (BusResponse, MkTagType inFlightTransactions) + consumeResponse :: ActionValue (TaggedBusResponse inFlightTransactions) -- # BusServer.consumeRequest -- * The bus server calls the `consumeRequest` method of the `BusServer` interface From c9356eecfdb890db0684b58368a4b78ec2411731 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 01:27:33 -0400 Subject: [PATCH 18/51] client methods presumably finished --- bs/Bus.bs | 22 ++++++++++++++-------- bs/BusTypes.bs | 7 +++++-- bs/TagEngine.bs | 3 +-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 51e5784..58ad27e 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -18,7 +18,7 @@ busRequestToAddr req = case req of BusReadRequest (ReadRequest addr _) -> addr BusWriteRequest (WriteRequest addr _) -> addr -mkBus :: (Addr -> Maybe Integer) +mkBus :: (Addr -> Maybe ServerIdx) -> Module (Bus inFlightTransactions numClients numServers) mkBus busMap = do -- Tag engines for each client to manage transaction tags @@ -37,7 +37,7 @@ mkBus busMap = do requestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) -- Queues to hold responses from servers to clients - responseQueues :: Vector numClients (FIFOF (BusResponse, MkTagType inFlightTransactions)) + responseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) responseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) -- Client interface vector @@ -47,6 +47,9 @@ mkBus busMap = do selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) selectedClientRequestQueue = (select requestQueues clientIdx) + selectedClientResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) + selectedClientResponseQueue = (select responseQueues clientIdx) + selectedTagEngine :: TagEngine inFlightTransactions selectedTagEngine = (select tagEngineByClientVec clientIdx) in @@ -60,9 +63,11 @@ mkBus busMap = do consumeResponse :: ActionValue (TaggedBusResponse inFlightTransactions) consumeResponse = do - dummyVar := (not dummyVar) - let dummyResponse = BusReadResponse (Left UnMapped) - return (TaggedBusResponse 0 dummyResponse) + let + busResponse :: (TaggedBusResponse inFlightTransactions) + busResponse = selectedClientResponseQueue.first + selectedClientResponseQueue.deq + return busResponse -- Server interface vector let servers :: Vector numServers (BusServer inFlightTransactions numClients) @@ -74,9 +79,10 @@ mkBus busMap = do let dummyBusRequest = BusReadRequest (ReadRequest 0 SizeByte) return (0, dummyBusRequest) - submitResponse :: (MkClientTagType numClients, BusResponse, transactionTagType) - -> Action - submitResponse (clientTag, busResponse, transactionTag) = do + submitResponse :: ( MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) -> Action + submitResponse (clientTag, taggedBusResponse) = do dummyVar := (not dummyVar) return $ diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index cf11af0..e91626c 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,5 +1,6 @@ package BusTypes( Bus(..), + ServerIdx, MkClientTagType, BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), @@ -13,6 +14,7 @@ import Vector import TagEngine type MkClientTagType a = (UInt (TLog a)) +type ServerIdx = Integer data BusError = UnMapped @@ -97,8 +99,9 @@ interface (BusClient :: # -> *) inFlightTransactions = -- associated with the original request. interface (BusServer :: # -> # -> *) inFlightTransactions numClients = consumeRequest :: ActionValue (MkTagType inFlightTransactions, BusRequest) - submitResponse :: (MkClientTagType numClients, BusResponse, transactionTagType) - -> Action + submitResponse :: ( MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) -> Action interface (Bus :: # -> # -> # -> *) inFlightTransactions numClients numServers = clients :: Vector numClients (BusClient inFlightTransactions) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 2ddb304..f86c811 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -7,7 +7,6 @@ package TagEngine( import Vector import Util import FIFO -import FIFOF import SpecialFIFOs type MkTagType numTags = (UInt (TLog numTags)) @@ -35,7 +34,7 @@ mkTagEngine = do -- to TagEngine where `n := maxTagCount`. initialTagDistributor <- mkReg (Just (maxTagCount - 1)) -- Distributes initial tags retireQueue <- mkBypassFIFO -- Queue for tags being retired - freeTagQueue <- mkSizedFIFOF maxTagCount -- Queue of available tags + freeTagQueue <- mkSizedFIFO maxTagCount -- Queue of available tags -- Signals retireSignal <- mkRWire -- Signals a tag retirement From 71fbb7d2e5c603e05a142c2b9fb3804424ddda40 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 10:59:52 -0400 Subject: [PATCH 19/51] add bus diagram and further work on Bus --- bs/Bus.bs | 20 ++- diagrams/.$bus.drawio.bkp | 360 ++++++++++++++++++++++++++++++++++++++ diagrams/bus.drawio | 360 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 732 insertions(+), 8 deletions(-) create mode 100644 diagrams/.$bus.drawio.bkp create mode 100644 diagrams/bus.drawio diff --git a/bs/Bus.bs b/bs/Bus.bs index 58ad27e..7313953 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -32,23 +32,27 @@ mkBus busMap = do dummyVar :: Reg(Bool) dummyVar <- mkReg False - -- Queues to hold requests from clients to servers - requestQueues :: Vector numServers (FIFOF (TaggedBusRequest inFlightTransactions)) - requestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) + -- Queues to hold requests from clients to arbiter + clientRequestQueues :: Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) + clientRequestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- Queues to hold responses from servers to clients - responseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) - responseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) + -- Queues to hold responses from arbiter to clients + clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) + clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) + + -- -- Queues to hold requests from arbiter to server + -- serverRequestQueues :: Vector numServers (FIFOF (TaggedBusRequest inFlightTransactions)) + -- serverRequestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) clients = genWith $ \clientIdx -> let selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) - selectedClientRequestQueue = (select requestQueues clientIdx) + selectedClientRequestQueue = (select clientRequestQueues clientIdx) selectedClientResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) - selectedClientResponseQueue = (select responseQueues clientIdx) + selectedClientResponseQueue = (select clientResponseQueues clientIdx) selectedTagEngine :: TagEngine inFlightTransactions selectedTagEngine = (select tagEngineByClientVec clientIdx) diff --git a/diagrams/.$bus.drawio.bkp b/diagrams/.$bus.drawio.bkp new file mode 100644 index 0000000..bc4e718 --- /dev/null +++ b/diagrams/.$bus.drawio.bkp @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio new file mode 100644 index 0000000..97ba9e7 --- /dev/null +++ b/diagrams/bus.drawio @@ -0,0 +1,360 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 548a2f26bd56ffa92bb102d659ddfeb3190ec7af Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 11:01:41 -0400 Subject: [PATCH 20/51] don't commit bkp files --- .gitignore | 1 + diagrams/.$bus.drawio.bkp | 360 -------------------------------------- 2 files changed, 1 insertion(+), 360 deletions(-) delete mode 100644 diagrams/.$bus.drawio.bkp diff --git a/.gitignore b/.gitignore index 85c69dc..9291deb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.vcd +*.bkp *.so # bluespec files diff --git a/diagrams/.$bus.drawio.bkp b/diagrams/.$bus.drawio.bkp deleted file mode 100644 index bc4e718..0000000 --- a/diagrams/.$bus.drawio.bkp +++ /dev/null @@ -1,360 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 5efef8b19cc9f651b01af5b5d2e00d9ce96101eb Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 20:46:53 -0400 Subject: [PATCH 21/51] quieter builds, more type uniformity, full compiles - made builds less verbose on Mac by removing `-cpp` - made type constructors for most instances of `(UInt (TLog n))` - addressed cases where types built upon `(UInt (TLog n))` may have a max value of `n`, which necessitates changing the type to ` (UInt (TLog (TAdd 1 n)))` - compiler wouldn't fully evaluate types unless mkBus was instantiated --- Makefile | 1 - bs/Bus.bs | 41 ++++++++++++++++++++++++++++++++--------- bs/BusTypes.bs | 2 +- bs/ClkDivider.bs | 14 ++++++++++---- bs/Core.bs | 4 ++-- bs/TagEngine.bs | 2 +- bs/Top.bs | 14 ++++++++++++-- 7 files changed, 58 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 7579e84..d92f15a 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,6 @@ BSC_COMP_FLAGS += \ -aggressive-conditions \ -no-warn-action-shadowing \ -check-assert \ - -cpp \ -show-schedule \ +RTS -K128M -RTS -show-range-conflict \ $(BSC_COMP_FLAG1) $(BSC_COMP_FLAG2) $(BSC_COMP_FLAG3) diff --git a/bs/Bus.bs b/bs/Bus.bs index 7313953..bf6d0c5 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -1,4 +1,4 @@ -package Bus(mkBus) where +package Bus(mkBus, Bus(..)) where import Types import BusTypes @@ -18,6 +18,12 @@ busRequestToAddr req = case req of BusReadRequest (ReadRequest addr _) -> addr BusWriteRequest (WriteRequest addr _) -> addr +dummyRule :: Rules +dummyRule = + rules + "test rule": when True ==> do + $display "test rule" + mkBus :: (Addr -> Maybe ServerIdx) -> Module (Bus inFlightTransactions numClients numServers) mkBus busMap = do @@ -25,24 +31,41 @@ mkBus busMap = do tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - -- Arbitration for clients to send requests to servers - clientArbiter :: Arbiter.Arbiter_IFC numClients - clientArbiter <- mkArbiter False + clientArbiters :: Arbiter.Arbiter_IFC numClients + clientArbiters <- mkArbiter False + + serverArbiters :: Arbiter.Arbiter_IFC numServers + serverArbiters <- mkArbiter False dummyVar :: Reg(Bool) dummyVar <- mkReg False - -- Queues to hold requests from clients to arbiter + -- Queues to hold requests from clients clientRequestQueues :: Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) clientRequestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- Queues to hold responses from arbiter to clients + -- Queues to hold responses to clients clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- -- Queues to hold requests from arbiter to server - -- serverRequestQueues :: Vector numServers (FIFOF (TaggedBusRequest inFlightTransactions)) - -- serverRequestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) + let clientRouter :: Vector numClients (Rules) + clientRouter = genWith $ \clientIdx -> + rules + "test rule": when True ==> do + $display "client test rule" + + let clientRouter :: Rules + clientRouter = + rules + "test rule": when True ==> do + $display "client test rule" + + -- Rules + addRules |> + rules + "test rule": when True ==> do + $display "test rule" + <+> clientRouter -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index e91626c..112e923 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -13,7 +13,7 @@ import Types import Vector import TagEngine -type MkClientTagType a = (UInt (TLog a)) +type MkClientTagType numClients = (UInt (TLog numClients)) type ServerIdx = Integer data BusError diff --git a/bs/ClkDivider.bs b/bs/ClkDivider.bs index 789489e..cd94bc9 100644 --- a/bs/ClkDivider.bs +++ b/bs/ClkDivider.bs @@ -1,4 +1,8 @@ -package ClkDivider(mkClkDivider, ClkDivider(..)) where +package ClkDivider( + mkClkDivider, + MkClkDivType, + ClkDivider(..) + ) where interface (ClkDivider :: # -> *) hi = { @@ -7,11 +11,13 @@ interface (ClkDivider :: # -> *) hi = ;isHalfCycle :: Bool } +type MkClkDivType maxCycles = (UInt (TLog (TAdd 1 maxCycles))) + mkClkDivider :: Handle -> Module (ClkDivider hi) mkClkDivider fileHandle = do - counter <- mkReg(0 :: UInt (TLog hi)) - let hi_value :: UInt (TLog hi) = (fromInteger $ valueOf hi) - let half_hi_value :: UInt (TLog hi) = (fromInteger $ valueOf (TDiv hi 2)) + counter <- mkReg(0 :: MkClkDivType hi) + let hi_value :: (MkClkDivType hi) = (fromInteger $ valueOf hi) + let half_hi_value :: (MkClkDivType hi) = (fromInteger $ valueOf (TDiv hi 2)) let val :: Real = (fromInteger $ valueOf hi) let msg = "Clock Div Period : " + (realToString val) + "\n" diff --git a/bs/Core.bs b/bs/Core.bs index 1b821ec..2ef5fd9 100644 --- a/bs/Core.bs +++ b/bs/Core.bs @@ -11,13 +11,13 @@ interface (Core :: # -> *) clkFreq = { mkCore :: Module (Core clkFreq) mkCore = do - counter :: Reg (UInt (TLog clkFreq)) <- mkReg 0 + counter :: Reg (MkClkDivType clkFreq) <- mkReg 0 tickSecond :: Wire Bool <- mkDWire False uartOut :: Wire (Bit 8) <- mkWire; ledOut :: Reg (Bit 8) <- mkReg 0 let clkFreqInt :: Integer = valueOf clkFreq - let clkFreqUInt :: UInt (TLog clkFreq) = fromInteger clkFreqInt + let clkFreqUInt :: (MkClkDivType clkFreq) = fromInteger clkFreqInt let val :: Real = fromInteger clkFreqInt messageM $ "mkCore clkFreq" + realToString val diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index f86c811..8b12b9d 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -9,7 +9,7 @@ import Util import FIFO import SpecialFIFOs -type MkTagType numTags = (UInt (TLog numTags)) +type MkTagType numTags = (UInt (TLog (TAdd 1 numTags))) interface (TagEngine :: # -> *) numTags = requestTag :: ActionValue (MkTagType numTags) diff --git a/bs/Top.bs b/bs/Top.bs index f4f1cda..a125406 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -10,6 +10,9 @@ import TagEngine import List import ActionSeq +import Vector +import BusTypes + import TagEngineTester type FCLK = 25000000 @@ -57,11 +60,18 @@ mkTop = do mkSim :: Module Empty mkSim = do _ :: Empty <- mkTagEngineTester - initCFunctions :: Reg Bool <- mkReg False; - core :: Core FCLK <- mkCore; + initCFunctions :: Reg Bool <- mkReg False + core :: Core FCLK <- mkCore + let busMap _ = Just 0 + bus :: (Bus 4 2 2) <- mkBus busMap addRules $ rules + "test bus": when True ==> + do + let server = (Vector.select bus.servers 0) + result <- server.consumeRequest + $display (fshow result) "initCFunctionsOnce": when not initCFunctions ==> do initTerminal From cffbadd1ccb3ea56f1fad6a7dba6b2a27edc36d4 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 10 Apr 2025 21:42:15 -0400 Subject: [PATCH 22/51] incomplete but need to come to stopping point --- bs/Bus.bs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index bf6d0c5..69034ae 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -24,17 +24,19 @@ dummyRule = "test rule": when True ==> do $display "test rule" +-- we need a way to make serverMap safer... mkBus :: (Addr -> Maybe ServerIdx) -> Module (Bus inFlightTransactions numClients numServers) -mkBus busMap = do +mkBus serverMap = do -- Tag engines for each client to manage transaction tags tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - clientArbiters :: Arbiter.Arbiter_IFC numClients + -- each + clientArbiters :: Arbiter.Arbiter_IFC numServers clientArbiters <- mkArbiter False - serverArbiters :: Arbiter.Arbiter_IFC numServers + serverArbiters :: Arbiter.Arbiter_IFC numClients serverArbiters <- mkArbiter False dummyVar :: Reg(Bool) @@ -50,22 +52,30 @@ mkBus busMap = do let clientRouter :: Vector numClients (Rules) clientRouter = genWith $ \clientIdx -> - rules - "test rule": when True ==> do - $display "client test rule" + let + selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientRequestQueue = (select clientRequestQueues clientIdx) + in + rules + "route request": when True ==> do + let + clientRequest :: (TaggedBusRequest inFlightTransactions) + clientRequest = selectedClientRequestQueue.first - let clientRouter :: Rules - clientRouter = - rules - "test rule": when True ==> do - $display "client test rule" + -- targetAddr :: Addr = busRequestToAddr clientRequest + -- targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr + -- case targetServerIdx of + -- Just serverIdx -> do + -- targetServerArbiter :: + + $display "client test rule " (fromInteger clientIdx) + + addRules |> foldr (<+>) (rules {}) clientRouter - -- Rules addRules |> rules "test rule": when True ==> do $display "test rule" - <+> clientRouter -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) From 45191a2abd11acd4788580eeadd3d3fe1350ce91 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 11 Apr 2025 07:54:47 -0400 Subject: [PATCH 23/51] WIP : client request should handle unmapped case --- bs/Bus.bs | 32 ++++++++++++++++++-------------- bs/BusTypes.bs | 12 ++++++++---- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 69034ae..4bb081b 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -32,12 +32,14 @@ mkBus serverMap = do tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - -- each - clientArbiters :: Arbiter.Arbiter_IFC numServers - clientArbiters <- mkArbiter False + -- There are `numClients` clients, each of which needs its own + -- arbiter as there are up to `numServer` servers that may wish + -- to submit a response to a given client. + clientArbiters :: Vector numClients (Arbiter.Arbiter_IFC numServers) + clientArbiters <- replicateM (mkArbiter False) - serverArbiters :: Arbiter.Arbiter_IFC numClients - serverArbiters <- mkArbiter False + serverArbiters :: Vector numServers (Arbiter.Arbiter_IFC numClients) + serverArbiters <- replicateM (mkArbiter False) dummyVar :: Reg(Bool) dummyVar <- mkReg False @@ -50,27 +52,28 @@ mkBus serverMap = do clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - let clientRouter :: Vector numClients (Rules) - clientRouter = genWith $ \clientIdx -> + let clientRules :: Vector numClients (Rules) + clientRules = genWith $ \clientIdx -> let selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) selectedClientRequestQueue = (select clientRequestQueues clientIdx) in rules - "route request": when True ==> do + "request": when True ==> do let - clientRequest :: (TaggedBusRequest inFlightTransactions) + clientRequest :: TaggedBusRequest inFlightTransactions clientRequest = selectedClientRequestQueue.first - -- targetAddr :: Addr = busRequestToAddr clientRequest - -- targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr + targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest + targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr -- case targetServerIdx of -- Just serverIdx -> do - -- targetServerArbiter :: + -- targetServerArbiter :: Arbiter.Arbiter_IFC numClients + -- targetServerArbiter = (select serverArbiters serverIdx) $display "client test rule " (fromInteger clientIdx) - addRules |> foldr (<+>) (rules {}) clientRouter + addRules |> foldr (<+>) (rules {}) clientRules addRules |> rules @@ -95,7 +98,8 @@ mkBus serverMap = do -> ActionValue (MkTagType inFlightTransactions) submitRequest busRequest = do tag <- selectedTagEngine.requestTag - selectedClientRequestQueue.enq (TaggedBusRequest tag busRequest) + let taggedReuqest = TaggedBusRequest {tag = tag; busRequest = busRequest} + selectedClientRequestQueue.enq taggedReuqest return tag consumeResponse :: ActionValue (TaggedBusResponse inFlightTransactions) diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index 112e923..ed6de3b 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -56,12 +56,16 @@ data BusResponse | BusWriteResponse WriteResponse deriving (Bits, Eq, FShow) -data TaggedBusRequest inFlightTransactions = - TaggedBusRequest (MkTagType inFlightTransactions) BusRequest +struct TaggedBusRequest inFlightTransactions = + { tag :: (MkTagType inFlightTransactions); + busRequest :: BusRequest + } deriving (Bits, Eq, FShow) -data TaggedBusResponse inFlightTransactions = - TaggedBusResponse (MkTagType inFlightTransactions) BusResponse +struct TaggedBusResponse inFlightTransactions = + { tag :: (MkTagType inFlightTransactions); + busResponse :: BusResponse + } deriving (Bits, Eq, FShow) -- # BusClient.submitRequest From 628319709e3a3ad813ec89cfa27b421b400e40c0 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 11 Apr 2025 12:36:43 -0400 Subject: [PATCH 24/51] stopping point --- bs/Bus.bs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 4bb081b..3217cb5 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -19,7 +19,7 @@ busRequestToAddr req = case req of BusWriteRequest (WriteRequest addr _) -> addr dummyRule :: Rules -dummyRule = +dummyRule = rules "test rule": when True ==> do $display "test rule" @@ -32,14 +32,18 @@ mkBus serverMap = do tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - -- There are `numClients` clients, each of which needs its own - -- arbiter as there are up to `numServer` servers that may wish - -- to submit a response to a given client. - clientArbiters :: Vector numClients (Arbiter.Arbiter_IFC numServers) - clientArbiters <- replicateM (mkArbiter False) + -- There are `numClients` clients, each of which needs its own arbiter as + -- there are up to `numServer` servers that may wish to submit a response + -- to a given client. Furthermore the rule that routes client requests to + -- servers makes for another potential requestor as it may determine that + -- a request is unmappable and instead opt to form and submit a + -- `BusError UnMapped` response directly to a client response arbiter. Thus + -- we must arbit between a total of `numServers + 1` requestors. + clientResponseArbiter :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) + clientResponseArbiter <- replicateM (mkArbiter False) - serverArbiters :: Vector numServers (Arbiter.Arbiter_IFC numClients) - serverArbiters <- replicateM (mkArbiter False) + serverRequestArbiter :: Vector numServers (Arbiter.Arbiter_IFC numClients) + serverRequestArbiter <- replicateM (mkArbiter False) dummyVar :: Reg(Bool) dummyVar <- mkReg False @@ -60,7 +64,7 @@ mkBus serverMap = do in rules "request": when True ==> do - let + let clientRequest :: TaggedBusRequest inFlightTransactions clientRequest = selectedClientRequestQueue.first From 813f543b424eed5a5eea985c5d13e0cb1fb12f30 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 11 Apr 2025 14:26:40 -0400 Subject: [PATCH 25/51] request server from client rule in client issue --- bs/Bus.bs | 35 ++++++++++++++++++++--------------- bs/Top.bs | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 3217cb5..b9d5b32 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -9,6 +9,7 @@ import Arbiter import FIFO import FIFOF import SpecialFIFOs +import Printf clientRequest :: Arbiter.ArbiterClient_IFC -> Action clientRequest ifc = ifc.request @@ -39,11 +40,14 @@ mkBus serverMap = do -- a request is unmappable and instead opt to form and submit a -- `BusError UnMapped` response directly to a client response arbiter. Thus -- we must arbit between a total of `numServers + 1` requestors. - clientResponseArbiter :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) - clientResponseArbiter <- replicateM (mkArbiter False) + responseArbiterByClient :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) + responseArbiterByClient <- replicateM (mkArbiter False) - serverRequestArbiter :: Vector numServers (Arbiter.Arbiter_IFC numClients) - serverRequestArbiter <- replicateM (mkArbiter False) + -- There are `numServer` servers, each of which needs its own arbiter as + -- there are up to `numClient` clients that may wish to submit a response + -- to a given client. + requestArbiterByServer :: Vector numServers (Arbiter.Arbiter_IFC numClients) + requestArbiterByServer <- replicateM (mkArbiter False) dummyVar :: Reg(Bool) dummyVar <- mkReg False @@ -63,27 +67,28 @@ mkBus serverMap = do selectedClientRequestQueue = (select clientRequestQueues clientIdx) in rules - "request": when True ==> do + (sprintf "request server from client %d" clientIdx): when True ==> do let clientRequest :: TaggedBusRequest inFlightTransactions clientRequest = selectedClientRequestQueue.first targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr - -- case targetServerIdx of - -- Just serverIdx -> do - -- targetServerArbiter :: Arbiter.Arbiter_IFC numClients - -- targetServerArbiter = (select serverArbiters serverIdx) + -- $display "clientRequest" (fshow clientRequest) + case targetServerIdx of + Just serverIdx -> do + let + targetServerArbiter :: Arbiter.Arbiter_IFC numClients + targetServerArbiter = (select requestArbiterByServer serverIdx) + arbiterClientSlot :: Arbiter.ArbiterClient_IFC + arbiterClientSlot = (select targetServerArbiter.clients clientIdx) + arbiterClientSlot.request + Nothing -> do action {} + - $display "client test rule " (fromInteger clientIdx) addRules |> foldr (<+>) (rules {}) clientRules - addRules |> - rules - "test rule": when True ==> do - $display "test rule" - -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) clients = genWith $ \clientIdx -> diff --git a/bs/Top.bs b/bs/Top.bs index a125406..a0816a0 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -71,7 +71,7 @@ mkSim = do do let server = (Vector.select bus.servers 0) result <- server.consumeRequest - $display (fshow result) + $display "Top.bs:74" (fshow result) "initCFunctionsOnce": when not initCFunctions ==> do initTerminal From 98f2f5cdfd7886ea3907c48ffa8655cb2331a24f Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 11 Apr 2025 20:35:26 -0400 Subject: [PATCH 26/51] having trouble with type constraints around clientIdx --- bs/Bus.bs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index b9d5b32..3afe1e8 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -67,6 +67,9 @@ mkBus serverMap = do selectedClientRequestQueue = (select clientRequestQueues clientIdx) in rules + "rule" : when True ==> do + $display "Bus.bs:71" + (sprintf "request server from client %d" clientIdx): when True ==> do let clientRequest :: TaggedBusRequest inFlightTransactions @@ -75,6 +78,7 @@ mkBus serverMap = do targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr -- $display "clientRequest" (fshow clientRequest) + $display "Bus.bs:81" (fshow clientRequest) case targetServerIdx of Just serverIdx -> do let @@ -83,7 +87,20 @@ mkBus serverMap = do arbiterClientSlot :: Arbiter.ArbiterClient_IFC arbiterClientSlot = (select targetServerArbiter.clients clientIdx) arbiterClientSlot.request - Nothing -> do action {} + Nothing -> do + let + idx = fromInteger clientIdx + targetClientResponseArbiter :: Arbiter.Arbiter_IFC numClients + targetClientResponseArbiter = (select responseArbiterByClient idx) + + clientResponseArbiterSlot :: Arbiter.ArbiterClient_IFC + -- arbiters 0 to n-1 are where `n:=numServer` are reserved + -- for servers to make requests to. Arbiter n is reserved for + -- when this rule needs to skip making a request to a server + -- and should instead forward the `BusError UnMapped` response + -- back to the client. Vector.last selects arbiter `n` + clientResponseArbiterSlot = Vector.last targetClientResponseArbiter + clientResponseArbiterSlot.request From 373d170c3ffce4050af1142fdb9e839fb2c137f7 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 13 Apr 2025 22:40:59 -0400 Subject: [PATCH 27/51] notable progress WRT client requests invoking arbiter request --- bs/Bus.bs | 44 +++++++--- bs/BusTypes.bs | 4 +- diagrams/bus.drawio | 208 ++++++++++++++++++++++++++------------------ 3 files changed, 159 insertions(+), 97 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 3afe1e8..4a516f4 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -25,8 +25,13 @@ dummyRule = "test rule": when True ==> do $display "test rule" +data DispatchFromClient inFlightTransactions numServers + = DispatchRequest (TaggedBusRequest inFlightTransactions) (MkServerIdx numServers) + | DispatchResponse (TaggedBusResponse inFlightTransactions) + deriving (Bits, Eq, FShow) + -- we need a way to make serverMap safer... -mkBus :: (Addr -> Maybe ServerIdx) +mkBus :: (Addr -> Maybe (MkServerIdx numServers)) -> Module (Bus inFlightTransactions numClients numServers) mkBus serverMap = do -- Tag engines for each client to manage transaction tags @@ -43,6 +48,13 @@ mkBus serverMap = do responseArbiterByClient :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) responseArbiterByClient <- replicateM (mkArbiter False) + -- After we inspect the head/oldest request in the `clientRequestQueues` and perform an + -- arbiter request to the destination arbiter, we need to inspect for grant in another + -- rule as I don't believe grant and request can be called simultaneously. + -- The following vector allows us to move + dispatchByClient :: Vector numClients (Wire (DispatchFromClient inFlightTransactions numServers)) + dispatchByClient <- replicateM mkWire + -- There are `numServer` servers, each of which needs its own arbiter as -- there are up to `numClient` clients that may wish to submit a response -- to a given client. @@ -76,9 +88,11 @@ mkBus serverMap = do clientRequest = selectedClientRequestQueue.first targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest - targetServerIdx :: (Maybe ServerIdx) = serverMap targetAddr - -- $display "clientRequest" (fshow clientRequest) - $display "Bus.bs:81" (fshow clientRequest) + targetServerIdx :: (Maybe (MkServerIdx numServers)) = serverMap targetAddr + + dispatchByClientWire :: Wire (DispatchFromClient inFlightTransactions numServers) + dispatchByClientWire = (select dispatchByClient clientIdx) + case targetServerIdx of Just serverIdx -> do let @@ -87,22 +101,30 @@ mkBus serverMap = do arbiterClientSlot :: Arbiter.ArbiterClient_IFC arbiterClientSlot = (select targetServerArbiter.clients clientIdx) arbiterClientSlot.request + dispatchByClientWire := DispatchRequest clientRequest serverIdx Nothing -> do let - idx = fromInteger clientIdx - targetClientResponseArbiter :: Arbiter.Arbiter_IFC numClients - targetClientResponseArbiter = (select responseArbiterByClient idx) + targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + targetClientResponseArbiter = (select responseArbiterByClient clientIdx) clientResponseArbiterSlot :: Arbiter.ArbiterClient_IFC - -- arbiters 0 to n-1 are where `n:=numServer` are reserved + -- arbiters 0 to n-1 where `n:=numServer` are reserved -- for servers to make requests to. Arbiter n is reserved for -- when this rule needs to skip making a request to a server -- and should instead forward the `BusError UnMapped` response -- back to the client. Vector.last selects arbiter `n` - clientResponseArbiterSlot = Vector.last targetClientResponseArbiter + clientResponseArbiterSlot = Vector.last targetClientResponseArbiter.clients + responseUnMapped = case clientRequest.busRequest of + BusReadRequest _ -> BusReadResponse (Left UnMapped) + BusWriteRequest _ -> BusWriteResponse (Left UnMapped) + response :: TaggedBusResponse inFlightTransactions + response = TaggedBusResponse { + tag = clientRequest.tag; + busResponse = responseUnMapped + } + clientResponseArbiterSlot.request - - + dispatchByClientWire := DispatchResponse response addRules |> foldr (<+>) (rules {}) clientRules diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index ed6de3b..7746669 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -1,6 +1,6 @@ package BusTypes( Bus(..), - ServerIdx, + MkServerIdx, MkClientTagType, BusClient(..), BusServer(..), BusRequest(..), BusResponse(..), @@ -14,7 +14,7 @@ import Vector import TagEngine type MkClientTagType numClients = (UInt (TLog numClients)) -type ServerIdx = Integer +type MkServerIdx numServers = (UInt (TLog numServers)) data BusError = UnMapped diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio index 97ba9e7..fb90bc2 100644 --- a/diagrams/bus.drawio +++ b/diagrams/bus.drawio @@ -1,272 +1,278 @@ - + - + - + + + + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -277,7 +283,7 @@ - + @@ -288,7 +294,7 @@ - + @@ -299,7 +305,7 @@ - + @@ -310,50 +316,84 @@ - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From cd3d728083b1a9231375507124d6a88d896431d9 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Mon, 14 Apr 2025 14:33:13 -0400 Subject: [PATCH 28/51] some prep work to towards having a server accept a request --- bs/Bus.bs | 14 +++++++++++--- bs/BusTypes.bs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 4a516f4..5e6ddfe 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -72,6 +72,14 @@ mkBus serverMap = do clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) + -- The following two vectors of FIFOs make it easier to push/pull data to/from internal + -- server methods: + consumeRequestQueues :: Vector numServers (FIFOF (TaggedBusResponse inFlightTransactions)) + consumeRequestQueues <- replicateM mkBypassFIFOF + + submitResponseQueues :: Vector numServers (FIFOF (TaggedBusResponse inFlightTransactions)) + submitResponseQueues <- replicateM mkBypassFIFOF + let clientRules :: Vector numClients (Rules) clientRules = genWith $ \clientIdx -> let @@ -82,7 +90,7 @@ mkBus serverMap = do "rule" : when True ==> do $display "Bus.bs:71" - (sprintf "request server from client %d" clientIdx): when True ==> do + (sprintf "dispatch client request %d" clientIdx): when True ==> do let clientRequest :: TaggedBusRequest inFlightTransactions clientRequest = selectedClientRequestQueue.first @@ -162,11 +170,11 @@ mkBus serverMap = do let servers :: Vector numServers (BusServer inFlightTransactions numClients) servers = genWith $ \serverIdx -> interface BusServer - consumeRequest :: ActionValue (MkTagType inFlightTransactions, BusRequest) + consumeRequest :: ActionValue (TaggedBusRequest inFlightTransactions) consumeRequest = do dummyVar := (not dummyVar) let dummyBusRequest = BusReadRequest (ReadRequest 0 SizeByte) - return (0, dummyBusRequest) + return (TaggedBusRequest {tag = 0; busRequest = dummyBusRequest}) submitResponse :: ( MkClientTagType numClients, TaggedBusResponse inFlightTransactions diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index 7746669..ed8838e 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -102,7 +102,7 @@ interface (BusClient :: # -> *) inFlightTransactions = -- received from `consumeRequest`, ensuring the response is correctly -- associated with the original request. interface (BusServer :: # -> # -> *) inFlightTransactions numClients = - consumeRequest :: ActionValue (MkTagType inFlightTransactions, BusRequest) + consumeRequest :: ActionValue (TaggedBusRequest inFlightTransactions) submitResponse :: ( MkClientTagType numClients, TaggedBusResponse inFlightTransactions ) -> Action From 180eeeefbed7c5ed6edee281feae0d1f86c2b870 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 15 Apr 2025 13:50:50 -0400 Subject: [PATCH 29/51] we may not need dispatch by client --- bs/Bus.bs | 14 +- diagrams/bus.drawio | 393 +++++++++++++++++++++++--------------------- 2 files changed, 214 insertions(+), 193 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 5e6ddfe..62d13ac 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -27,7 +27,7 @@ dummyRule = data DispatchFromClient inFlightTransactions numServers = DispatchRequest (TaggedBusRequest inFlightTransactions) (MkServerIdx numServers) - | DispatchResponse (TaggedBusResponse inFlightTransactions) + | BypassResponse (TaggedBusResponse inFlightTransactions) deriving (Bits, Eq, FShow) -- we need a way to make serverMap safer... @@ -57,7 +57,7 @@ mkBus serverMap = do -- There are `numServer` servers, each of which needs its own arbiter as -- there are up to `numClient` clients that may wish to submit a response - -- to a given client. + -- to a given server. requestArbiterByServer :: Vector numServers (Arbiter.Arbiter_IFC numClients) requestArbiterByServer <- replicateM (mkArbiter False) @@ -87,9 +87,6 @@ mkBus serverMap = do selectedClientRequestQueue = (select clientRequestQueues clientIdx) in rules - "rule" : when True ==> do - $display "Bus.bs:71" - (sprintf "dispatch client request %d" clientIdx): when True ==> do let clientRequest :: TaggedBusRequest inFlightTransactions @@ -126,13 +123,13 @@ mkBus serverMap = do BusReadRequest _ -> BusReadResponse (Left UnMapped) BusWriteRequest _ -> BusWriteResponse (Left UnMapped) response :: TaggedBusResponse inFlightTransactions - response = TaggedBusResponse { - tag = clientRequest.tag; + response = TaggedBusResponse { + tag = clientRequest.tag; busResponse = responseUnMapped } clientResponseArbiterSlot.request - dispatchByClientWire := DispatchResponse response + dispatchByClientWire := BypassResponse response addRules |> foldr (<+>) (rules {}) clientRules @@ -163,6 +160,7 @@ mkBus serverMap = do let busResponse :: (TaggedBusResponse inFlightTransactions) busResponse = selectedClientResponseQueue.first + selectedTagEngine.retireTag busResponse.tag selectedClientResponseQueue.deq return busResponse diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio index fb90bc2..442e443 100644 --- a/diagrams/bus.drawio +++ b/diagrams/bus.drawio @@ -1,399 +1,422 @@ - + - + - - + + - - + + - + - + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - - + + - - + + - + - - - - - - - - - - - - - - + + - - - - - - - + - - + + - + - - + + + - + + + + + + + - - + + - + + + + + + + + + + + + + - - + + - + - + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - - + + - + - - + + - - + + - - + + - + - - + + - + - - + + - + - - + + - - + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - - - + + + + - - + + - + - - + + - - + + - - - - - - - - - - - - - - + + + - - + + - - - - + + + + - - + + - - - - + + + + - - + + - + + + + + + + + + + + + - - - - - - - - - - - - + - - + + - - - - + + + + - + + - - - - + + + + - - + - + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + From f3acae0c1cc42a67117aa5bed3f807e4f97bfdb2 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 15 Apr 2025 14:15:49 -0400 Subject: [PATCH 30/51] potential scaffolding for new approach --- bs/Bus.bs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 62d13ac..335b2e6 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -25,11 +25,6 @@ dummyRule = "test rule": when True ==> do $display "test rule" -data DispatchFromClient inFlightTransactions numServers - = DispatchRequest (TaggedBusRequest inFlightTransactions) (MkServerIdx numServers) - | BypassResponse (TaggedBusResponse inFlightTransactions) - deriving (Bits, Eq, FShow) - -- we need a way to make serverMap safer... mkBus :: (Addr -> Maybe (MkServerIdx numServers)) -> Module (Bus inFlightTransactions numClients numServers) @@ -48,13 +43,6 @@ mkBus serverMap = do responseArbiterByClient :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) responseArbiterByClient <- replicateM (mkArbiter False) - -- After we inspect the head/oldest request in the `clientRequestQueues` and perform an - -- arbiter request to the destination arbiter, we need to inspect for grant in another - -- rule as I don't believe grant and request can be called simultaneously. - -- The following vector allows us to move - dispatchByClient :: Vector numClients (Wire (DispatchFromClient inFlightTransactions numServers)) - dispatchByClient <- replicateM mkWire - -- There are `numServer` servers, each of which needs its own arbiter as -- there are up to `numClient` clients that may wish to submit a response -- to a given server. @@ -87,17 +75,13 @@ mkBus serverMap = do selectedClientRequestQueue = (select clientRequestQueues clientIdx) in rules - (sprintf "dispatch client request %d" clientIdx): when True ==> do + (sprintf "client[%d] route request" clientIdx): when True ==> do let clientRequest :: TaggedBusRequest inFlightTransactions clientRequest = selectedClientRequestQueue.first targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest targetServerIdx :: (Maybe (MkServerIdx numServers)) = serverMap targetAddr - - dispatchByClientWire :: Wire (DispatchFromClient inFlightTransactions numServers) - dispatchByClientWire = (select dispatchByClient clientIdx) - case targetServerIdx of Just serverIdx -> do let @@ -106,7 +90,6 @@ mkBus serverMap = do arbiterClientSlot :: Arbiter.ArbiterClient_IFC arbiterClientSlot = (select targetServerArbiter.clients clientIdx) arbiterClientSlot.request - dispatchByClientWire := DispatchRequest clientRequest serverIdx Nothing -> do let targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) @@ -119,6 +102,7 @@ mkBus serverMap = do -- and should instead forward the `BusError UnMapped` response -- back to the client. Vector.last selects arbiter `n` clientResponseArbiterSlot = Vector.last targetClientResponseArbiter.clients + let responseUnMapped = case clientRequest.busRequest of BusReadRequest _ -> BusReadResponse (Left UnMapped) BusWriteRequest _ -> BusWriteResponse (Left UnMapped) @@ -127,9 +111,11 @@ mkBus serverMap = do tag = clientRequest.tag; busResponse = responseUnMapped } - clientResponseArbiterSlot.request - dispatchByClientWire := BypassResponse response + + (sprintf "client[%d] arbit server response" clientIdx): when True ==> do + return |> action {} + addRules |> foldr (<+>) (rules {}) clientRules From a58c836981df55a81232d8325b0088b9dbe432ea Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 15 Apr 2025 18:21:42 -0400 Subject: [PATCH 31/51] worked on client arbiter but need to consider if starving is possible when multiple client arbiters grant access to the same server --- bs/Bus.bs | 49 ++++++++++++++++++++++++++++++++++++++++++--- diagrams/bus.drawio | 8 ++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 335b2e6..e2545f9 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -26,7 +26,8 @@ dummyRule = $display "test rule" -- we need a way to make serverMap safer... -mkBus :: (Addr -> Maybe (MkServerIdx numServers)) +mkBus :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) + => (Addr -> Maybe (MkServerIdx numServers)) -> Module (Bus inFlightTransactions numClients numServers) mkBus serverMap = do -- Tag engines for each client to manage transaction tags @@ -113,9 +114,51 @@ mkBus serverMap = do } clientResponseArbiterSlot.request - (sprintf "client[%d] arbit server response" clientIdx): when True ==> do - return |> action {} + (sprintf "client[%d] arbit submission" clientIdx): when True ==> do + let + selectedClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + selectedClientResponseArbiter = (select responseArbiterByClient clientIdx) + selectedClientResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) + selectedClientResponseQueue = (select clientResponseQueues clientIdx) + + -- `TAdd numServers 1` because we can receive request from all servers + -- as well as a bypass requests from our one corresponding client request + -- queue + grantedIdx :: UInt (TLog (TAdd numServers 1)) + grantedIdx = unpack selectedClientResponseArbiter.grant_id + + isClientRequest :: Bool + isClientRequest = grantedIdx == fromInteger (valueOf numServers) + if isClientRequest then do + let + clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = selectedClientRequestQueue.first + + responseUnMapped :: BusResponse + responseUnMapped = case clientRequest.busRequest of + BusReadRequest _ -> BusReadResponse (Left UnMapped) + BusWriteRequest _ -> BusWriteResponse (Left UnMapped) + + response :: TaggedBusResponse inFlightTransactions + response = TaggedBusResponse { + tag = clientRequest.tag; + busResponse = responseUnMapped + } + selectedClientResponseQueue.enq response + selectedClientRequestQueue.deq + else do + let + grantedServerIdx :: MkServerIdx numServers + grantedServerIdx = truncate grantedIdx + + selectedSubmitResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) + selectedSubmitResponseQueue = (select submitResponseQueues grantedServerIdx) + + response :: TaggedBusResponse inFlightTransactions + response = selectedSubmitResponseQueue.first + selectedClientResponseQueue.enq response + selectedSubmitResponseQueue.deq addRules |> foldr (<+>) (rules {}) clientRules diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio index 442e443..1d3ed48 100644 --- a/diagrams/bus.drawio +++ b/diagrams/bus.drawio @@ -1,6 +1,6 @@ - + @@ -329,11 +329,11 @@ - - + + - + From c28425f10c137c86adfd571c0e943c8472ed7328 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 16 Apr 2025 16:55:45 -0400 Subject: [PATCH 32/51] first attempt at server rule, also implemented consumeRequest of the server part of the Bus interface --- bs/Bus.bs | 65 ++++++++++++++++++++++++++++++++++++--------- bs/BusTypes.bs | 5 +++- diagrams/bus.drawio | 10 +++---- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index e2545f9..680eb57 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -63,7 +63,12 @@ mkBus serverMap = do -- The following two vectors of FIFOs make it easier to push/pull data to/from internal -- server methods: - consumeRequestQueues :: Vector numServers (FIFOF (TaggedBusResponse inFlightTransactions)) + consumeRequestQueues :: Vector numServers ( + FIFOF ( + MkClientTagType numClients, + TaggedBusRequest inFlightTransactions + ) + ) consumeRequestQueues <- replicateM mkBypassFIFOF submitResponseQueues :: Vector numServers (FIFOF (TaggedBusResponse inFlightTransactions)) @@ -160,6 +165,33 @@ mkBus serverMap = do selectedClientResponseQueue.enq response selectedSubmitResponseQueue.deq + let serverRules :: Vector numServers (Rules) + serverRules = genWith $ \serverIdx -> + let + selectedServerArbiter :: Arbiter.Arbiter_IFC numClients + selectedServerArbiter = (select requestArbiterByServer serverIdx) + + selectedConsumeRequestQueue :: FIFOF ( + MkClientTagType numClients, + TaggedBusRequest inFlightTransactions + ) + selectedConsumeRequestQueue = (select consumeRequestQueues serverIdx) + in + rules + (sprintf "server[%d] handle request" serverIdx): when True ==> do + let + grantedClientIdx :: MkClientTagType numClients + grantedClientIdx = unpack selectedServerArbiter.grant_id + + selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientRequestQueue = (select clientRequestQueues grantedClientIdx) + + clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = selectedClientRequestQueue.first + + selectedConsumeRequestQueue.enq (grantedClientIdx, clientRequest) + selectedClientRequestQueue.deq + addRules |> foldr (<+>) (rules {}) clientRules -- Client interface vector @@ -196,18 +228,27 @@ mkBus serverMap = do -- Server interface vector let servers :: Vector numServers (BusServer inFlightTransactions numClients) servers = genWith $ \serverIdx -> - interface BusServer - consumeRequest :: ActionValue (TaggedBusRequest inFlightTransactions) - consumeRequest = do - dummyVar := (not dummyVar) - let dummyBusRequest = BusReadRequest (ReadRequest 0 SizeByte) - return (TaggedBusRequest {tag = 0; busRequest = dummyBusRequest}) + let + selectedConsumeRequestQueue :: FIFOF ( + MkClientTagType numClients, + TaggedBusRequest inFlightTransactions + ) + selectedConsumeRequestQueue = (select consumeRequestQueues serverIdx) + in + interface BusServer + consumeRequest :: ActionValue ( + MkClientTagType numClients, + TaggedBusRequest inFlightTransactions + ) + consumeRequest = do + selectedConsumeRequestQueue.deq + return selectedConsumeRequestQueue.first - submitResponse :: ( MkClientTagType numClients, - TaggedBusResponse inFlightTransactions - ) -> Action - submitResponse (clientTag, taggedBusResponse) = do - dummyVar := (not dummyVar) + submitResponse :: ( MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) -> Action + submitResponse (clientTag, taggedBusResponse) = do + dummyVar := (not dummyVar) return $ interface Bus diff --git a/bs/BusTypes.bs b/bs/BusTypes.bs index ed8838e..a5f344f 100644 --- a/bs/BusTypes.bs +++ b/bs/BusTypes.bs @@ -102,7 +102,10 @@ interface (BusClient :: # -> *) inFlightTransactions = -- received from `consumeRequest`, ensuring the response is correctly -- associated with the original request. interface (BusServer :: # -> # -> *) inFlightTransactions numClients = - consumeRequest :: ActionValue (TaggedBusRequest inFlightTransactions) + consumeRequest :: ActionValue ( + MkClientTagType numClients, + TaggedBusRequest inFlightTransactions + ) submitResponse :: ( MkClientTagType numClients, TaggedBusResponse inFlightTransactions ) -> Action diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio index 1d3ed48..7f93ffd 100644 --- a/diagrams/bus.drawio +++ b/diagrams/bus.drawio @@ -1,6 +1,6 @@ - + @@ -91,7 +91,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -223,7 +223,7 @@ - + @@ -248,7 +248,7 @@ - + From ece1f865742a3431356e41a7b9182d677475ebca Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 16 Apr 2025 17:58:29 -0400 Subject: [PATCH 33/51] in theory bus is now complete --- bs/Bus.bs | 73 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/bs/Bus.bs b/bs/Bus.bs index 680eb57..4a8bb31 100644 --- a/bs/Bus.bs +++ b/bs/Bus.bs @@ -11,21 +11,16 @@ import FIFOF import SpecialFIFOs import Printf -clientRequest :: Arbiter.ArbiterClient_IFC -> Action -clientRequest ifc = ifc.request - busRequestToAddr :: BusRequest -> Addr busRequestToAddr req = case req of BusReadRequest (ReadRequest addr _) -> addr BusWriteRequest (WriteRequest addr _) -> addr -dummyRule :: Rules -dummyRule = - rules - "test rule": when True ==> do - $display "test rule" - --- we need a way to make serverMap safer... +-- Create a Bus Module that supports multiple clients and servers +-- submitting requests and simultaneously returning responses. +-- Responses can be consumed by clients out of order as all client +-- submitted requests are tagged - and servers keep that tag +-- when responding. mkBus :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) => (Addr -> Maybe (MkServerIdx numServers)) -> Module (Bus inFlightTransactions numClients numServers) @@ -61,9 +56,9 @@ mkBus serverMap = do clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- The following two vectors of FIFOs make it easier to push/pull data to/from internal + -- The following two vectors of FIFOs make it easier to push/pull data to/from internal -- server methods: - consumeRequestQueues :: Vector numServers ( + consumeRequestQueues :: Vector numServers ( FIFOF ( MkClientTagType numClients, TaggedBusRequest inFlightTransactions @@ -71,7 +66,12 @@ mkBus serverMap = do ) consumeRequestQueues <- replicateM mkBypassFIFOF - submitResponseQueues :: Vector numServers (FIFOF (TaggedBusResponse inFlightTransactions)) + submitResponseQueues :: Vector numServers ( + FIFOF ( + MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) + ) submitResponseQueues <- replicateM mkBypassFIFOF let clientRules :: Vector numClients (Rules) @@ -102,9 +102,9 @@ mkBus serverMap = do targetClientResponseArbiter = (select responseArbiterByClient clientIdx) clientResponseArbiterSlot :: Arbiter.ArbiterClient_IFC - -- arbiters 0 to n-1 where `n:=numServer` are reserved - -- for servers to make requests to. Arbiter n is reserved for - -- when this rule needs to skip making a request to a server + -- arbiters 0 to n-1 where `n:=numServer` are reserved + -- for servers to make requests to. Arbiter n is reserved for + -- when this rule needs to skip making a request to a server -- and should instead forward the `BusError UnMapped` response -- back to the client. Vector.last selects arbiter `n` clientResponseArbiterSlot = Vector.last targetClientResponseArbiter.clients @@ -157,12 +157,15 @@ mkBus serverMap = do grantedServerIdx :: MkServerIdx numServers grantedServerIdx = truncate grantedIdx - selectedSubmitResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) + selectedSubmitResponseQueue :: FIFOF ( + MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) selectedSubmitResponseQueue = (select submitResponseQueues grantedServerIdx) - response :: TaggedBusResponse inFlightTransactions + response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) response = selectedSubmitResponseQueue.first - selectedClientResponseQueue.enq response + selectedClientResponseQueue.enq response.snd selectedSubmitResponseQueue.deq let serverRules :: Vector numServers (Rules) @@ -178,7 +181,7 @@ mkBus serverMap = do selectedConsumeRequestQueue = (select consumeRequestQueues serverIdx) in rules - (sprintf "server[%d] handle request" serverIdx): when True ==> do + (sprintf "server[%d] arbit requests" serverIdx): when True ==> do let grantedClientIdx :: MkClientTagType numClients grantedClientIdx = unpack selectedServerArbiter.grant_id @@ -192,7 +195,29 @@ mkBus serverMap = do selectedConsumeRequestQueue.enq (grantedClientIdx, clientRequest) selectedClientRequestQueue.deq + (sprintf "server[%d] route response" serverIdx): when True ==> do + let + selectedSubmitResponseQueue :: FIFOF ( + MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) + selectedSubmitResponseQueue = (select submitResponseQueues serverIdx) + + response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + response = selectedSubmitResponseQueue.first + + clientTag :: MkClientTagType numClients + clientTag = response.fst + + targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + targetClientResponseArbiter = (select responseArbiterByClient clientTag) + + arbiterClientSlot :: Arbiter.ArbiterClient_IFC + arbiterClientSlot = (select targetClientResponseArbiter.clients serverIdx) + arbiterClientSlot.request + addRules |> foldr (<+>) (rules {}) clientRules + addRules |> foldr (<+>) (rules {}) serverRules -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) @@ -248,7 +273,13 @@ mkBus serverMap = do TaggedBusResponse inFlightTransactions ) -> Action submitResponse (clientTag, taggedBusResponse) = do - dummyVar := (not dummyVar) + let + selectedSubmitResponseQueue :: FIFOF ( + MkClientTagType numClients, + TaggedBusResponse inFlightTransactions + ) + selectedSubmitResponseQueue = (select submitResponseQueues serverIdx) + selectedSubmitResponseQueue.enq (clientTag, taggedBusResponse) return $ interface Bus From 1557cf9cc9f95196b488c120d529403aaeae6bd1 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 16 Apr 2025 22:10:49 -0400 Subject: [PATCH 34/51] working towards re-factoring into functions --- Makefile | 2 +- bs/{ => Bus}/Bus.bs | 0 bs/{ => Bus}/BusTypes.bs | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename bs/{ => Bus}/Bus.bs (100%) rename bs/{ => Bus}/BusTypes.bs (100%) diff --git a/Makefile b/Makefile index d92f15a..28921c9 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ $(BDPI_OBJ): $(BDPI_SRC) BSC_LINK_FLAGS += -keep-fires -BSC_PATHS = -p bs/:bs/Tests/:bsv/:+ +BSC_PATHS = -p bs/Bus/:bs/:bs/Tests/:bsv/:+ .PHONY: help help: diff --git a/bs/Bus.bs b/bs/Bus/Bus.bs similarity index 100% rename from bs/Bus.bs rename to bs/Bus/Bus.bs diff --git a/bs/BusTypes.bs b/bs/Bus/BusTypes.bs similarity index 100% rename from bs/BusTypes.bs rename to bs/Bus/BusTypes.bs From 2fee6a3bd8136736dbf84ff2a4b475388530604b Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 16 Apr 2025 22:34:52 -0400 Subject: [PATCH 35/51] refactored client rules --- bs/Bus/Bus.bs | 116 +++++++++++------------------------------------ bs/Bus/Client.bs | 107 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 90 deletions(-) create mode 100644 bs/Bus/Client.bs diff --git a/bs/Bus/Bus.bs b/bs/Bus/Bus.bs index 4a8bb31..d409b29 100644 --- a/bs/Bus/Bus.bs +++ b/bs/Bus/Bus.bs @@ -2,6 +2,7 @@ package Bus(mkBus, Bus(..)) where import Types import BusTypes +import Client import TagEngine import Vector import Util @@ -76,97 +77,32 @@ mkBus serverMap = do let clientRules :: Vector numClients (Rules) clientRules = genWith $ \clientIdx -> - let - selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) - selectedClientRequestQueue = (select clientRequestQueues clientIdx) + let selectedClientReqQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientReqQueue = select clientRequestQueues clientIdx + + selectedClientRespQueue :: FIFOF (TaggedBusResponse inFlightTransactions) + selectedClientRespQueue = select clientResponseQueues clientIdx + + selectedClientRespArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + selectedClientRespArbiter = select responseArbiterByClient clientIdx + + clientRouterRule :: Rules + clientRouterRule = clientRouteRequest + clientIdx + selectedClientReqQueue + requestArbiterByServer + responseArbiterByClient + serverMap + + clientArbiterRule :: Rules + clientArbiterRule = clientArbitSubmission + clientIdx + selectedClientReqQueue + selectedClientRespQueue + selectedClientRespArbiter + submitResponseQueues in - rules - (sprintf "client[%d] route request" clientIdx): when True ==> do - let - clientRequest :: TaggedBusRequest inFlightTransactions - clientRequest = selectedClientRequestQueue.first - - targetAddr :: Addr = busRequestToAddr |> clientRequest.busRequest - targetServerIdx :: (Maybe (MkServerIdx numServers)) = serverMap targetAddr - case targetServerIdx of - Just serverIdx -> do - let - targetServerArbiter :: Arbiter.Arbiter_IFC numClients - targetServerArbiter = (select requestArbiterByServer serverIdx) - arbiterClientSlot :: Arbiter.ArbiterClient_IFC - arbiterClientSlot = (select targetServerArbiter.clients clientIdx) - arbiterClientSlot.request - Nothing -> do - let - targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) - targetClientResponseArbiter = (select responseArbiterByClient clientIdx) - - clientResponseArbiterSlot :: Arbiter.ArbiterClient_IFC - -- arbiters 0 to n-1 where `n:=numServer` are reserved - -- for servers to make requests to. Arbiter n is reserved for - -- when this rule needs to skip making a request to a server - -- and should instead forward the `BusError UnMapped` response - -- back to the client. Vector.last selects arbiter `n` - clientResponseArbiterSlot = Vector.last targetClientResponseArbiter.clients - let - responseUnMapped = case clientRequest.busRequest of - BusReadRequest _ -> BusReadResponse (Left UnMapped) - BusWriteRequest _ -> BusWriteResponse (Left UnMapped) - response :: TaggedBusResponse inFlightTransactions - response = TaggedBusResponse { - tag = clientRequest.tag; - busResponse = responseUnMapped - } - clientResponseArbiterSlot.request - - (sprintf "client[%d] arbit submission" clientIdx): when True ==> do - let - selectedClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) - selectedClientResponseArbiter = (select responseArbiterByClient clientIdx) - - selectedClientResponseQueue :: FIFOF (TaggedBusResponse inFlightTransactions) - selectedClientResponseQueue = (select clientResponseQueues clientIdx) - - -- `TAdd numServers 1` because we can receive request from all servers - -- as well as a bypass requests from our one corresponding client request - -- queue - grantedIdx :: UInt (TLog (TAdd numServers 1)) - grantedIdx = unpack selectedClientResponseArbiter.grant_id - - isClientRequest :: Bool - isClientRequest = grantedIdx == fromInteger (valueOf numServers) - if isClientRequest then do - let - clientRequest :: TaggedBusRequest inFlightTransactions - clientRequest = selectedClientRequestQueue.first - - responseUnMapped :: BusResponse - responseUnMapped = case clientRequest.busRequest of - BusReadRequest _ -> BusReadResponse (Left UnMapped) - BusWriteRequest _ -> BusWriteResponse (Left UnMapped) - - response :: TaggedBusResponse inFlightTransactions - response = TaggedBusResponse { - tag = clientRequest.tag; - busResponse = responseUnMapped - } - selectedClientResponseQueue.enq response - selectedClientRequestQueue.deq - else do - let - grantedServerIdx :: MkServerIdx numServers - grantedServerIdx = truncate grantedIdx - - selectedSubmitResponseQueue :: FIFOF ( - MkClientTagType numClients, - TaggedBusResponse inFlightTransactions - ) - selectedSubmitResponseQueue = (select submitResponseQueues grantedServerIdx) - - response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) - response = selectedSubmitResponseQueue.first - selectedClientResponseQueue.enq response.snd - selectedSubmitResponseQueue.deq + clientRouterRule <+> clientArbiterRule let serverRules :: Vector numServers (Rules) serverRules = genWith $ \serverIdx -> diff --git a/bs/Bus/Client.bs b/bs/Bus/Client.bs new file mode 100644 index 0000000..4d3d10a --- /dev/null +++ b/bs/Bus/Client.bs @@ -0,0 +1,107 @@ +package Client( + clientRouteRequest, + clientArbitSubmission +) where + +import Types +import BusTypes +import TagEngine +import Vector +import Util +import Arbiter +import FIFO +import FIFOF +import SpecialFIFOs +import Printf + +busRequestToAddr :: BusRequest -> Addr +busRequestToAddr req = case req of + BusReadRequest (ReadRequest addr _) -> addr + BusWriteRequest (WriteRequest addr _) -> addr + +clientRouteRequest :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) + => Integer + -> FIFOF (TaggedBusRequest inFlightTransactions) + -> Vector numServers (Arbiter.Arbiter_IFC numClients) + -> Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) + -> (Addr -> Maybe (MkServerIdx numServers)) + -> Rules +clientRouteRequest clientIdx clientReqQueue requestArbiterByServer responseArbiterByClient serverMap = + rules + (sprintf "client[%d] route request" clientIdx): when True ==> do + let clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = clientReqQueue.first + + targetAddr :: Addr + targetAddr = busRequestToAddr |> clientRequest.busRequest + + targetServerIdx :: Maybe (MkServerIdx numServers) + targetServerIdx = serverMap targetAddr + case targetServerIdx of + Just serverIdx -> do + let targetServerArbiter :: Arbiter.Arbiter_IFC numClients + targetServerArbiter = select requestArbiterByServer serverIdx + + arbiterClientSlot :: Arbiter.ArbiterClient_IFC + arbiterClientSlot = select targetServerArbiter.clients clientIdx + arbiterClientSlot.request + Nothing -> do + let targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + targetClientResponseArbiter = select responseArbiterByClient clientIdx + + -- arbiters 0 to n-1 where `n:=numServer` are reserved + -- for servers to make requests to. Arbiter n is reserved for + -- when this rule needs to skip making a request to a server + -- and should instead forward the `BusError UnMapped` response + -- back to the client. Vector.last selects arbiter `n` + clientResponseArbiterSlot :: Arbiter.ArbiterClient_IFC + clientResponseArbiterSlot = Vector.last targetClientResponseArbiter.clients + + responseUnMapped :: BusResponse + responseUnMapped = case clientRequest.busRequest of + BusReadRequest _ -> BusReadResponse (Left UnMapped) + BusWriteRequest _ -> BusWriteResponse (Left UnMapped) + + response :: TaggedBusResponse inFlightTransactions + response = TaggedBusResponse { tag = clientRequest.tag; busResponse = responseUnMapped } + clientResponseArbiterSlot.request + +clientArbitSubmission :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) + => Integer + -> FIFOF (TaggedBusRequest inFlightTransactions) + -> FIFOF (TaggedBusResponse inFlightTransactions) + -> Arbiter.Arbiter_IFC (TAdd numServers 1) + -> Vector numServers (FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions)) + -> Rules +clientArbitSubmission clientIdx clientReqQueue clientRespQueue clientRespArbiter submitRespQueues = + rules + (sprintf "client[%d] arbit submission" clientIdx): when True ==> do + let grantedIdx :: UInt (TLog (TAdd numServers 1)) + grantedIdx = unpack clientRespArbiter.grant_id + + isClientRequest :: Bool + isClientRequest = grantedIdx == fromInteger (valueOf numServers) + if isClientRequest then do + let clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = clientReqQueue.first + + responseUnMapped :: BusResponse + responseUnMapped = case clientRequest.busRequest of + BusReadRequest _ -> BusReadResponse (Left UnMapped) + BusWriteRequest _ -> BusWriteResponse (Left UnMapped) + + response :: TaggedBusResponse inFlightTransactions + response = TaggedBusResponse { tag = clientRequest.tag; busResponse = responseUnMapped } + clientRespQueue.enq response + clientReqQueue.deq + else do + let grantedServerIdx :: MkServerIdx numServers + grantedServerIdx = truncate grantedIdx + + selectedSubmitRespQueue :: FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + selectedSubmitRespQueue = select submitRespQueues grantedServerIdx + + response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + response = selectedSubmitRespQueue.first + clientRespQueue.enq response.snd + selectedSubmitRespQueue.deq \ No newline at end of file From a58c908763fc31a21c3ecf8c5aca9f5f98f6b17d Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Wed, 16 Apr 2025 22:47:50 -0400 Subject: [PATCH 36/51] refactored server functions as well --- bs/Bus/Bus.bs | 76 ++++++++++++++++++------------------------------ bs/Bus/Server.bs | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 48 deletions(-) create mode 100644 bs/Bus/Server.bs diff --git a/bs/Bus/Bus.bs b/bs/Bus/Bus.bs index d409b29..cf1cafd 100644 --- a/bs/Bus/Bus.bs +++ b/bs/Bus/Bus.bs @@ -3,7 +3,9 @@ package Bus(mkBus, Bus(..)) where import Types import BusTypes import Client +import Server import TagEngine + import Vector import Util import Arbiter @@ -76,7 +78,7 @@ mkBus serverMap = do submitResponseQueues <- replicateM mkBypassFIFOF let clientRules :: Vector numClients (Rules) - clientRules = genWith $ \clientIdx -> + clientRules = genWith |> \clientIdx -> let selectedClientReqQueue :: FIFOF (TaggedBusRequest inFlightTransactions) selectedClientReqQueue = select clientRequestQueues clientIdx @@ -105,59 +107,37 @@ mkBus serverMap = do clientRouterRule <+> clientArbiterRule let serverRules :: Vector numServers (Rules) - serverRules = genWith $ \serverIdx -> - let - selectedServerArbiter :: Arbiter.Arbiter_IFC numClients - selectedServerArbiter = (select requestArbiterByServer serverIdx) + serverRules = genWith |> \serverIdx -> + let selectedServerArbiter :: Arbiter.Arbiter_IFC numClients + selectedServerArbiter = select requestArbiterByServer serverIdx - selectedConsumeRequestQueue :: FIFOF ( - MkClientTagType numClients, - TaggedBusRequest inFlightTransactions - ) - selectedConsumeRequestQueue = (select consumeRequestQueues serverIdx) + selectedConsumeReqQueue :: FIFOF (MkClientTagType numClients, TaggedBusRequest inFlightTransactions) + selectedConsumeReqQueue = select consumeRequestQueues serverIdx + + selectedSubmitRespQueue :: FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + selectedSubmitRespQueue = select submitResponseQueues serverIdx + + serverRouterRule :: Rules + serverRouterRule = serverRouteResponse + serverIdx + selectedSubmitRespQueue + responseArbiterByClient + + serverArbiterRule :: Rules + serverArbiterRule = serverArbitRequests + serverIdx + selectedServerArbiter + selectedConsumeReqQueue + clientRequestQueues in - rules - (sprintf "server[%d] arbit requests" serverIdx): when True ==> do - let - grantedClientIdx :: MkClientTagType numClients - grantedClientIdx = unpack selectedServerArbiter.grant_id - - selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) - selectedClientRequestQueue = (select clientRequestQueues grantedClientIdx) - - clientRequest :: TaggedBusRequest inFlightTransactions - clientRequest = selectedClientRequestQueue.first - - selectedConsumeRequestQueue.enq (grantedClientIdx, clientRequest) - selectedClientRequestQueue.deq - - (sprintf "server[%d] route response" serverIdx): when True ==> do - let - selectedSubmitResponseQueue :: FIFOF ( - MkClientTagType numClients, - TaggedBusResponse inFlightTransactions - ) - selectedSubmitResponseQueue = (select submitResponseQueues serverIdx) - - response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) - response = selectedSubmitResponseQueue.first - - clientTag :: MkClientTagType numClients - clientTag = response.fst - - targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) - targetClientResponseArbiter = (select responseArbiterByClient clientTag) - - arbiterClientSlot :: Arbiter.ArbiterClient_IFC - arbiterClientSlot = (select targetClientResponseArbiter.clients serverIdx) - arbiterClientSlot.request + serverRouterRule <+> serverArbiterRule addRules |> foldr (<+>) (rules {}) clientRules addRules |> foldr (<+>) (rules {}) serverRules -- Client interface vector let clients :: Vector numClients (BusClient inFlightTransactions) - clients = genWith $ \clientIdx -> + clients = genWith |> \clientIdx -> let selectedClientRequestQueue :: FIFOF (TaggedBusRequest inFlightTransactions) selectedClientRequestQueue = (select clientRequestQueues clientIdx) @@ -188,7 +168,7 @@ mkBus serverMap = do -- Server interface vector let servers :: Vector numServers (BusServer inFlightTransactions numClients) - servers = genWith $ \serverIdx -> + servers = genWith |> \serverIdx -> let selectedConsumeRequestQueue :: FIFOF ( MkClientTagType numClients, @@ -217,7 +197,7 @@ mkBus serverMap = do selectedSubmitResponseQueue = (select submitResponseQueues serverIdx) selectedSubmitResponseQueue.enq (clientTag, taggedBusResponse) - return $ + return |> interface Bus clients = clients servers = servers diff --git a/bs/Bus/Server.bs b/bs/Bus/Server.bs new file mode 100644 index 0000000..794a161 --- /dev/null +++ b/bs/Bus/Server.bs @@ -0,0 +1,54 @@ +package Server( + serverArbitRequests, + serverRouteResponse +) where + +import Types +import BusTypes +import TagEngine +import Vector +import Util +import Arbiter +import FIFO +import FIFOF +import SpecialFIFOs +import Printf + +serverArbitRequests :: Integer + -> Arbiter.Arbiter_IFC numClients + -> FIFOF (MkClientTagType numClients, TaggedBusRequest inFlightTransactions) + -> Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) + -> Rules +serverArbitRequests serverIdx serverArbiter consumeReqQueue clientReqQueues = + rules + (sprintf "server[%d] arbit requests" serverIdx): when True ==> do + let grantedClientIdx :: MkClientTagType numClients + grantedClientIdx = unpack serverArbiter.grant_id + + selectedClientReqQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientReqQueue = select clientReqQueues grantedClientIdx + + clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = selectedClientReqQueue.first + consumeReqQueue.enq (grantedClientIdx, clientRequest) + selectedClientReqQueue.deq + +serverRouteResponse :: Integer + -> FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + -> Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) + -> Rules +serverRouteResponse serverIdx submitRespQueue responseArbiterByClient = + rules + (sprintf "server[%d] route response" serverIdx): when True ==> do + let response :: (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) + response = submitRespQueue.first + + clientTag :: MkClientTagType numClients + clientTag = response.fst + + targetClientRespArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) + targetClientRespArbiter = select responseArbiterByClient clientTag + + arbiterClientSlot :: Arbiter.ArbiterClient_IFC + arbiterClientSlot = select targetClientRespArbiter.clients serverIdx + arbiterClientSlot.request \ No newline at end of file From d552934b95c3b4f42f0d4944da4309ecdb97ecac Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Thu, 17 Apr 2025 22:47:24 -0400 Subject: [PATCH 37/51] Fixed grant bug Just becasue we have a grant id doesn't mean that anything has actually been granted... --- bs/Bus/Bus.bs | 42 +++++------ bs/Bus/Client.bs | 16 +++-- bs/Bus/Server.bs | 43 +++++------ diagrams/bus.drawio | 169 ++++++++++++++++++++++---------------------- 4 files changed, 140 insertions(+), 130 deletions(-) diff --git a/bs/Bus/Bus.bs b/bs/Bus/Bus.bs index cf1cafd..2386995 100644 --- a/bs/Bus/Bus.bs +++ b/bs/Bus/Bus.bs @@ -14,16 +14,14 @@ import FIFOF import SpecialFIFOs import Printf -busRequestToAddr :: BusRequest -> Addr -busRequestToAddr req = case req of - BusReadRequest (ReadRequest addr _) -> addr - BusWriteRequest (WriteRequest addr _) -> addr - --- Create a Bus Module that supports multiple clients and servers +-- Creates a Bus Module that supports multiple clients and servers -- submitting requests and simultaneously returning responses. --- Responses can be consumed by clients out of order as all client --- submitted requests are tagged - and servers keep that tag --- when responding. +-- Responses can be consumed by clients out of order(useful when some +-- servers respond before others) as all client submitted requests are +-- tagged with tags that are unique for the duration of the transaction +-- - and well-behaved servers should keep that tag when responding. + +-- Explicitly inform the compiler that log2 n <= log2(n + 1) mkBus :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) => (Addr -> Maybe (MkServerIdx numServers)) -> Module (Bus inFlightTransactions numClients numServers) @@ -32,13 +30,15 @@ mkBus serverMap = do tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - -- There are `numClients` clients, each of which needs its own arbiter as - -- there are up to `numServer` servers that may wish to submit a response - -- to a given client. Furthermore the rule that routes client requests to - -- servers makes for another potential requestor as it may determine that - -- a request is unmappable and instead opt to form and submit a - -- `BusError UnMapped` response directly to a client response arbiter. Thus - -- we must arbit between a total of `numServers + 1` requestors. + -- There are `numClients` clients, each of which needs its own client + -- response arbiter as there are `numServer` servers that may wish to + -- submit a response to a given client. Furthermore the rule that routes + -- client requests to servers makes for another potential submitter to + -- the client response arbiter as it may determine that a request is + -- unmappable and simply bypass submitting the request to a server, + -- instead opting to form a `BusError UnMapped` response to be submitted + -- directly to a client response arbiter. Thus the client response arbiter + -- must arbit between a total of `numServers + 1` requestors. responseArbiterByClient :: Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) responseArbiterByClient <- replicateM (mkArbiter False) @@ -48,9 +48,6 @@ mkBus serverMap = do requestArbiterByServer :: Vector numServers (Arbiter.Arbiter_IFC numClients) requestArbiterByServer <- replicateM (mkArbiter False) - dummyVar :: Reg(Bool) - dummyVar <- mkReg False - -- Queues to hold requests from clients clientRequestQueues :: Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) clientRequestQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) @@ -59,8 +56,11 @@ mkBus serverMap = do clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- The following two vectors of FIFOs make it easier to push/pull data to/from internal - -- server methods: + -- The following two vectors of single depth FIFOs make it easier to push/pull data + -- to/from internal server methods as they provide back-pressure in both directions, + -- and behave as a wire when queue is empty. + -- If looking at the example bus.drawio diagram, the following two vectors effectively + -- correspond to the two arrows going from the blue box to the servers. consumeRequestQueues :: Vector numServers ( FIFOF ( MkClientTagType numClients, diff --git a/bs/Bus/Client.bs b/bs/Bus/Client.bs index 4d3d10a..e3cedb3 100644 --- a/bs/Bus/Client.bs +++ b/bs/Bus/Client.bs @@ -45,6 +45,9 @@ clientRouteRequest clientIdx clientReqQueue requestArbiterByServer responseArbit arbiterClientSlot :: Arbiter.ArbiterClient_IFC arbiterClientSlot = select targetServerArbiter.clients clientIdx arbiterClientSlot.request + -- We bypass sensing the request to the server instead option to form + -- a `BusError Unmapped` response which we request to send directly to + -- the appropiate client response queue. Nothing -> do let targetClientResponseArbiter :: Arbiter.Arbiter_IFC (TAdd numServers 1) targetClientResponseArbiter = select responseArbiterByClient clientIdx @@ -74,12 +77,15 @@ clientArbitSubmission :: (Add n (TLog numServers) (TLog (TAdd numServers 1))) -> Vector numServers (FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions)) -> Rules clientArbitSubmission clientIdx clientReqQueue clientRespQueue clientRespArbiter submitRespQueues = - rules - (sprintf "client[%d] arbit submission" clientIdx): when True ==> do - let grantedIdx :: UInt (TLog (TAdd numServers 1)) - grantedIdx = unpack clientRespArbiter.grant_id + let grantedIdx :: UInt (TLog (TAdd numServers 1)) + grantedIdx = unpack clientRespArbiter.grant_id - isClientRequest :: Bool + selectedServerInterface :: ArbiterClient_IFC + selectedServerInterface = select clientRespArbiter.clients grantedIdx + in + rules + (sprintf "client[%d] arbit submission" clientIdx): when selectedServerInterface.grant ==> do + let isClientRequest :: Bool isClientRequest = grantedIdx == fromInteger (valueOf numServers) if isClientRequest then do let clientRequest :: TaggedBusRequest inFlightTransactions diff --git a/bs/Bus/Server.bs b/bs/Bus/Server.bs index 794a161..eaeb541 100644 --- a/bs/Bus/Server.bs +++ b/bs/Bus/Server.bs @@ -14,25 +14,6 @@ import FIFOF import SpecialFIFOs import Printf -serverArbitRequests :: Integer - -> Arbiter.Arbiter_IFC numClients - -> FIFOF (MkClientTagType numClients, TaggedBusRequest inFlightTransactions) - -> Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) - -> Rules -serverArbitRequests serverIdx serverArbiter consumeReqQueue clientReqQueues = - rules - (sprintf "server[%d] arbit requests" serverIdx): when True ==> do - let grantedClientIdx :: MkClientTagType numClients - grantedClientIdx = unpack serverArbiter.grant_id - - selectedClientReqQueue :: FIFOF (TaggedBusRequest inFlightTransactions) - selectedClientReqQueue = select clientReqQueues grantedClientIdx - - clientRequest :: TaggedBusRequest inFlightTransactions - clientRequest = selectedClientReqQueue.first - consumeReqQueue.enq (grantedClientIdx, clientRequest) - selectedClientReqQueue.deq - serverRouteResponse :: Integer -> FIFOF (MkClientTagType numClients, TaggedBusResponse inFlightTransactions) -> Vector numClients (Arbiter.Arbiter_IFC (TAdd numServers 1)) @@ -51,4 +32,26 @@ serverRouteResponse serverIdx submitRespQueue responseArbiterByClient = arbiterClientSlot :: Arbiter.ArbiterClient_IFC arbiterClientSlot = select targetClientRespArbiter.clients serverIdx - arbiterClientSlot.request \ No newline at end of file + arbiterClientSlot.request + +serverArbitRequests :: Integer + -> Arbiter.Arbiter_IFC numClients + -> FIFOF (MkClientTagType numClients, TaggedBusRequest inFlightTransactions) + -> Vector numClients (FIFOF (TaggedBusRequest inFlightTransactions)) + -> Rules +serverArbitRequests serverIdx serverArbiter consumeReqQueue clientReqQueues = + let grantedClientIdx :: MkClientTagType numClients + grantedClientIdx = unpack serverArbiter.grant_id + + selectedClientInterface :: ArbiterClient_IFC + selectedClientInterface = select serverArbiter.clients grantedClientIdx + in + rules + (sprintf "server[%d] arbit requests" serverIdx): when selectedClientInterface.grant ==> do + let selectedClientReqQueue :: FIFOF (TaggedBusRequest inFlightTransactions) + selectedClientReqQueue = select clientReqQueues grantedClientIdx + + clientRequest :: TaggedBusRequest inFlightTransactions + clientRequest = selectedClientReqQueue.first + consumeReqQueue.enq (grantedClientIdx, clientRequest) + selectedClientReqQueue.deq \ No newline at end of file diff --git a/diagrams/bus.drawio b/diagrams/bus.drawio index 7f93ffd..a199715 100644 --- a/diagrams/bus.drawio +++ b/diagrams/bus.drawio @@ -1,75 +1,75 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -78,7 +78,7 @@ - + @@ -91,20 +91,20 @@ - + - + - + @@ -117,25 +117,25 @@ - + - + - + - + @@ -145,63 +145,63 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -210,7 +210,7 @@ - + @@ -223,19 +223,20 @@ - - - - + + + + + - + - + @@ -248,32 +249,32 @@ - + - + - + - + - + @@ -284,7 +285,7 @@ - + @@ -295,7 +296,7 @@ - + @@ -306,7 +307,7 @@ - + @@ -317,18 +318,7 @@ - - - - - - - - - - - - + @@ -339,7 +329,7 @@ - + @@ -350,18 +340,18 @@ - + - - + + - + @@ -371,7 +361,7 @@ - + @@ -382,20 +372,7 @@ - - - - - - - - - - - - - - + @@ -406,7 +383,7 @@ - + @@ -417,6 +394,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + From 0dd4b60b704a29a59077b38bee045a3067a8602e Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 2 Apr 2025 02:59:21 +0300 Subject: [PATCH 38/51] Add initial flake --- flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 14 ----------- 3 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..aa2e659 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1735821806, + "narHash": "sha256-cuNapx/uQeCgeuhUhdck3JKbgpsml259sjUQnWM7zW8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d6973081434f88088e5321f83ebafe9a1167c367", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d014baf --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + inputs = { + nixpkgs = { + url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + inputs: + inputs.utils.lib.eachDefaultSystem ( + system: + let + pkgs = import inputs.nixpkgs { + localSystem = system; + overlays = [ + (final: prev: { + + riscv-bluespec-classic = pkgs.callPackage ( + { + stdenv, + bluespec, + nextpnr, + openfpgaloader, + trellis, + which, + yosys, + TOPMODULE ? "mkTop", + makeFlags ? [ ], + }: + stdenv.mkDerivation { + pname = "riscv-bluespec-classic"; + version = "0.1.0"; + src = ./.; + + # Versions can be checked with + # `nix eval --json ".#bluespec-joh-template.nativeBuildInputs" | nix-shell -p jq --run jq` + nativeBuildInputs = [ + bluespec + nextpnr + openfpgaloader + trellis + which + yosys + ]; + + # TODO: Build and install something + + } + ) { }; + + }) + ]; + }; + in + { + packages = { + default = inputs.self.packages."${system}".riscv-bluespec-classic; + riscv-bluespec-classic = pkgs.riscv-bluespec-classic; + }; + + devShells.default = + with pkgs; + mkShell { + inputsFrom = [ riscv-bluespec-classic ]; + }; + } + ); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 328453b..0000000 --- a/shell.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/d34a98666913267786d9ab4aa803a1fc75f81f4d.tar.gz") {} }: - -pkgs.mkShell { - buildInputs = [ - pkgs.yosys - pkgs.nextpnr - pkgs.bluespec - pkgs.yosys-bluespec - ]; - - shellHook = '' - echo "Dev environment for Manna Chip." - ''; -} \ No newline at end of file From 1622e3ab6be51644dc687c33435355f52f64d0f3 Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 2 Apr 2025 03:04:44 +0300 Subject: [PATCH 39/51] Remove all trailing spaces `git grep -I --name-only -z -e '' | xargs -0 sed -i 's/[ \t]\+\(\r\?\)$/\1/'` Remember to setup your editor so that these are automatically removed :) --- Makefile | 4 ++-- bs/Bus/Bus.bs | 8 ++++---- bs/ClkDivider.bs | 2 +- bs/Deserializer.bs | 12 ++++++------ bs/Serializer.bs | 13 ++++++------- bs/State.bs | 10 +++++----- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 28921c9..45d6558 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ b_all: b_compile b_link b_sim b_compile: mkdir -p build_b_sim @echo Compiling for Bluesim ... - bsc -u -sim $(B_SIM_DIRS) $(BSC_COMP_FLAGS) $(BSC_PATHS) -g $(TOPMODULE) $(TOPFILE) + bsc -u -sim $(B_SIM_DIRS) $(BSC_COMP_FLAGS) $(BSC_PATHS) -g $(TOPMODULE) $(TOPFILE) @echo Compiling for Bluesim finished .PHONY: b_link @@ -141,7 +141,7 @@ v_compile: .PHONY: v_link v_link: $(BDPI_OBJ) @echo Linking for Verilog sim ... - bsc -e $(TOPMODULE) -verilog -o ./$(V_SIM_EXE) $(V_DIRS) -vsim $(V_SIM) verilog_RTL/$(TOPMODULE).v + bsc -e $(TOPMODULE) -verilog -o ./$(V_SIM_EXE) $(V_DIRS) -vsim $(V_SIM) verilog_RTL/$(TOPMODULE).v @echo Linking for Verilog sim finished .PHONY: v_sim diff --git a/bs/Bus/Bus.bs b/bs/Bus/Bus.bs index 2386995..67e96dc 100644 --- a/bs/Bus/Bus.bs +++ b/bs/Bus/Bus.bs @@ -30,8 +30,8 @@ mkBus serverMap = do tagEngineByClientVec :: Vector numClients (TagEngine inFlightTransactions) tagEngineByClientVec <- replicateM mkTagEngine - -- There are `numClients` clients, each of which needs its own client - -- response arbiter as there are `numServer` servers that may wish to + -- There are `numClients` clients, each of which needs its own client + -- response arbiter as there are `numServer` servers that may wish to -- submit a response to a given client. Furthermore the rule that routes -- client requests to servers makes for another potential submitter to -- the client response arbiter as it may determine that a request is @@ -56,7 +56,7 @@ mkBus serverMap = do clientResponseQueues :: Vector numClients (FIFOF (TaggedBusResponse inFlightTransactions)) clientResponseQueues <- replicateM (mkSizedBypassFIFOF (valueOf inFlightTransactions)) - -- The following two vectors of single depth FIFOs make it easier to push/pull data + -- The following two vectors of single depth FIFOs make it easier to push/pull data -- to/from internal server methods as they provide back-pressure in both directions, -- and behave as a wire when queue is empty. -- If looking at the example bus.drawio diagram, the following two vectors effectively @@ -89,7 +89,7 @@ mkBus serverMap = do selectedClientRespArbiter = select responseArbiterByClient clientIdx clientRouterRule :: Rules - clientRouterRule = clientRouteRequest + clientRouterRule = clientRouteRequest clientIdx selectedClientReqQueue requestArbiterByServer diff --git a/bs/ClkDivider.bs b/bs/ClkDivider.bs index cd94bc9..ab39cab 100644 --- a/bs/ClkDivider.bs +++ b/bs/ClkDivider.bs @@ -34,7 +34,7 @@ mkClkDivider fileHandle = do counter := if (counter == hi_value) then 0 else counter + 1 - + return $ interface ClkDivider reset :: Action diff --git a/bs/Deserializer.bs b/bs/Deserializer.bs index 51c98ed..cebc355 100644 --- a/bs/Deserializer.bs +++ b/bs/Deserializer.bs @@ -1,15 +1,15 @@ package Deserializer( mkDeserialize, IDeserializer(..), - State(..)) + State(..)) where import ClkDivider import State -interface (IDeserializer :: # -> # -> *) clkFreq baudRate = - get :: Bit 8 +interface (IDeserializer :: # -> # -> *) clkFreq baudRate = + get :: Bit 8 putBitIn :: (Bit 1) -> Action {-# always_enabled, always_ready #-} mkDeserialize :: Handle -> Module (IDeserializer clkFreq baudRate) @@ -35,10 +35,10 @@ mkDeserialize fileHandle = do ftdiState := ftdiState' ftdiState {-# ASSERT fire when enabled #-} - "SAMPLING" : when + "SAMPLING" : when DATA(n) <- ftdiState, n >= 0, - n <= 7, + n <= 7, let sampleTrigger = clkDivider.isHalfCycle in sampleTrigger ==> @@ -48,6 +48,6 @@ mkDeserialize fileHandle = do return $ interface IDeserializer {get = shiftReg when (ftdiState == STOP), (clkDivider.isAdvancing) - ;putBitIn bit = + ;putBitIn bit = ftdiRxIn := bit } \ No newline at end of file diff --git a/bs/Serializer.bs b/bs/Serializer.bs index acfb196..ff445fa 100644 --- a/bs/Serializer.bs +++ b/bs/Serializer.bs @@ -1,7 +1,7 @@ package Serializer( mkSerialize, ISerializer(..), - State(..)) + State(..)) where import ClkDivider @@ -14,7 +14,7 @@ serialize ftdiState dataReg = (DATA n) -> dataReg[n:n] _ -> 1'b1 -interface (ISerializer :: # -> # -> *) clkFreq baudRate = +interface (ISerializer :: # -> # -> *) clkFreq baudRate = putBit8 :: (Bit 8) -> Action {-# always_enabled, always_ready #-} bitLineOut :: Bit 1 {-# always_ready #-} @@ -29,8 +29,8 @@ mkSerialize fileHandle = do addRules $ rules {-# ASSERT fire when enabled #-} - "ADVANCE UART STATE WHEN NOT IDLE" : when - (ftdiState /= IDLE), + "ADVANCE UART STATE WHEN NOT IDLE" : when + (ftdiState /= IDLE), (clkDivider.isAdvancing) ==> do ftdiState := ftdiState' ftdiState @@ -42,11 +42,10 @@ mkSerialize fileHandle = do return $ interface ISerializer - putBit8 bit8Val = + putBit8 bit8Val = do clkDivider.reset - dataReg := bit8Val + dataReg := bit8Val ftdiState := ftdiState' ftdiState when (ftdiState == IDLE) bitLineOut = ftdiTxOut - \ No newline at end of file diff --git a/bs/State.bs b/bs/State.bs index e68a482..0186f2a 100644 --- a/bs/State.bs +++ b/bs/State.bs @@ -2,15 +2,15 @@ package State( State(..), ftdiState') where -data State = IDLE - | START - | DATA (UInt (TLog 8)) - | PARITY +data State = IDLE + | START + | DATA (UInt (TLog 8)) + | PARITY | STOP deriving (Bits, Eq, FShow) ftdiState' :: State -> State -ftdiState' state = +ftdiState' state = case state of IDLE -> START START -> DATA(0) From 7471c0188a8c5fd684fccf54fb4b73bbbdc1a8ce Mon Sep 17 00:00:00 2001 From: Artturin Date: Wed, 2 Apr 2025 03:10:29 +0300 Subject: [PATCH 40/51] Make `make fpga` work `ERROR: IO 'ftdi_txd_1' is unconstrained in LPF (override this error with --lpf-allow-unconstrained)` --- .gitignore | 2 ++ Makefile | 2 +- ulx3s_fpga/makefile | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9291deb..e2d164b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ verilog_RTL # files generated for FPGA ULX3s implementation ulx3s_fpga/mkTop.d ulx3s_fpga/mkTop.json +ulx3s_fpga/mkTop.bit +ulx3s_fpga/mkTop.config # generated experiment outputs experiments/bram/*.cxx diff --git a/Makefile b/Makefile index 45d6558..1a42d46 100644 --- a/Makefile +++ b/Makefile @@ -159,7 +159,7 @@ v_sim_vcd: # ---------------------------------------------------------------- fpga: - make -C ulx3s_fpga + make -C ulx3s_fpga mkTop.bit .PHONY: clean clean: diff --git a/ulx3s_fpga/makefile b/ulx3s_fpga/makefile index 681fade..ea44793 100644 --- a/ulx3s_fpga/makefile +++ b/ulx3s_fpga/makefile @@ -5,7 +5,7 @@ IDCODE ?= 0x41113043 # 85f all: prog -../verilog_RTL/$(TOPMODULE).v: ../src/Top.bsv +../verilog_RTL/$(TOPMODULE).v: ../bs/Top.bs V_SIM=verilator TOPMODULE=$(TOPMODULE) make -C ../ v_compile $(TOPMODULE).json: ../verilog_RTL/$(TOPMODULE).v @@ -21,6 +21,7 @@ $(TOPMODULE).config: $(TOPMODULE).json --textcfg $@ \ --lpf ulx3s_v20.lpf \ --85k \ + --lpf-allow-unconstrained \ --package CABGA381 $(TOPMODULE).bit: $(TOPMODULE).config From c02e7b0de600caacc6bbf870b237c6aa6cb75689 Mon Sep 17 00:00:00 2001 From: Artturin Date: Thu, 3 Apr 2025 22:27:27 +0300 Subject: [PATCH 41/51] flake: Install the same file that fpga-starter-project-uart installed --- flake.nix | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index d014baf..6f8f727 100644 --- a/flake.nix +++ b/flake.nix @@ -25,8 +25,6 @@ trellis, which, yosys, - TOPMODULE ? "mkTop", - makeFlags ? [ ], }: stdenv.mkDerivation { pname = "riscv-bluespec-classic"; @@ -34,7 +32,7 @@ src = ./.; # Versions can be checked with - # `nix eval --json ".#bluespec-joh-template.nativeBuildInputs" | nix-shell -p jq --run jq` + # `nix eval --json ".#riscv-bluespec-classic.nativeBuildInputs" | nix-shell -p jq --run jq` nativeBuildInputs = [ bluespec nextpnr @@ -44,7 +42,18 @@ yosys ]; - # TODO: Build and install something + makeFlags = [ + "fpga" + ]; + + installPhase = '' + runHook preInstall + + mkdir -p "$out" + cp "./ulx3s_fpga/mkTop.bit" "$out/" + + runHook postInstall + ''; } ) { }; From b89090f3cec1eedc3d877ec5507d0a2aa9c7b451 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 18 Apr 2025 18:59:23 +0300 Subject: [PATCH 42/51] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/d6973081434f88088e5321f83ebafe9a1167c367?narHash=sha256-cuNapx/uQeCgeuhUhdck3JKbgpsml259sjUQnWM7zW8%3D' (2025-01-02) → 'github:NixOS/nixpkgs/18dd725c29603f582cf1900e0d25f9f1063dbf11?narHash=sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38%3D' (2025-04-13) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index aa2e659..d3a02b0 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1735821806, - "narHash": "sha256-cuNapx/uQeCgeuhUhdck3JKbgpsml259sjUQnWM7zW8=", + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d6973081434f88088e5321f83ebafe9a1167c367", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", "type": "github" }, "original": { From 7bc43946a963b81218bcc16ce2fadeac15ba30e3 Mon Sep 17 00:00:00 2001 From: Artturin Date: Fri, 18 Apr 2025 19:01:25 +0300 Subject: [PATCH 43/51] Add compat files for non flakes users --- default.nix | 25 +++++++++++++++++++++++++ shell.nix | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 default.nix create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..2ba2a3e --- /dev/null +++ b/default.nix @@ -0,0 +1,25 @@ +{ + system ? builtins.currentSystem, +}: +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + + root = lock.nodes.${lock.root}; + inherit (lock.nodes.${root.inputs.flake-compat}.locked) + owner + repo + rev + narHash + ; + + flake-compat = fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; + + flake = import flake-compat { + inherit system; + src = ./.; + }; +in +flake.defaultNix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..9332b75 --- /dev/null +++ b/shell.nix @@ -0,0 +1,25 @@ +{ + system ? builtins.currentSystem, +}: +let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + + root = lock.nodes.${lock.root}; + inherit (lock.nodes.${root.inputs.flake-compat}.locked) + owner + repo + rev + narHash + ; + + flake-compat = fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; + + flake = import flake-compat { + inherit system; + src = ./.; + }; +in +flake.shellNix From 44324eb80367574e1ecc9414c208ad86cf0fa379 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 18 Apr 2025 19:42:03 -0400 Subject: [PATCH 44/51] need to start re-thinking structure of uart etc --- Makefile | 4 ++-- bs/{ => Uart}/ClkDivider.bs | 0 bs/{ => Uart}/Deserializer.bs | 0 bs/{ => Uart}/Serializer.bs | 4 ++-- bs/{ => Uart}/State.bs | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename bs/{ => Uart}/ClkDivider.bs (100%) rename bs/{ => Uart}/Deserializer.bs (100%) rename bs/{ => Uart}/Serializer.bs (90%) rename bs/{ => Uart}/State.bs (100%) diff --git a/Makefile b/Makefile index 1a42d46..5ad0e41 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ $(BDPI_OBJ): $(BDPI_SRC) BSC_LINK_FLAGS += -keep-fires -BSC_PATHS = -p bs/Bus/:bs/:bs/Tests/:bsv/:+ +BSC_PATHS = -p bs/Uart/:bs/Bus/:bs/:bs/Tests/:bsv/:+ .PHONY: help help: @@ -159,7 +159,7 @@ v_sim_vcd: # ---------------------------------------------------------------- fpga: - make -C ulx3s_fpga mkTop.bit + make -C ulx3s_fpga mkTop.bit prog .PHONY: clean clean: diff --git a/bs/ClkDivider.bs b/bs/Uart/ClkDivider.bs similarity index 100% rename from bs/ClkDivider.bs rename to bs/Uart/ClkDivider.bs diff --git a/bs/Deserializer.bs b/bs/Uart/Deserializer.bs similarity index 100% rename from bs/Deserializer.bs rename to bs/Uart/Deserializer.bs diff --git a/bs/Serializer.bs b/bs/Uart/Serializer.bs similarity index 90% rename from bs/Serializer.bs rename to bs/Uart/Serializer.bs index ff445fa..cf39721 100644 --- a/bs/Serializer.bs +++ b/bs/Uart/Serializer.bs @@ -15,8 +15,8 @@ serialize ftdiState dataReg = _ -> 1'b1 interface (ISerializer :: # -> # -> *) clkFreq baudRate = - putBit8 :: (Bit 8) -> Action {-# always_enabled, always_ready #-} - bitLineOut :: Bit 1 {-# always_ready #-} + putBit8 :: (Bit 8) -> Action + bitLineOut :: Bit 1 mkSerialize :: Handle -> Module (ISerializer clkFreq baudRate) mkSerialize fileHandle = do diff --git a/bs/State.bs b/bs/Uart/State.bs similarity index 100% rename from bs/State.bs rename to bs/Uart/State.bs From 9d897fccdc2dacd32c25667cf207e332a9337aa9 Mon Sep 17 00:00:00 2001 From: Artturin Date: Sat, 19 Apr 2025 13:53:20 +0300 Subject: [PATCH 45/51] flake: Add missing input I forgot to add this when I copied the default.nix and shell.nix from a another repo. --- flake.lock | 17 +++++++++++++++++ flake.nix | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/flake.lock b/flake.lock index d3a02b0..27d3923 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1744536153, @@ -18,6 +34,7 @@ }, "root": { "inputs": { + "flake-compat": "flake-compat", "nixpkgs": "nixpkgs", "utils": "utils" } diff --git a/flake.nix b/flake.nix index 6f8f727..0103273 100644 --- a/flake.nix +++ b/flake.nix @@ -4,6 +4,10 @@ url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; }; outputs = From 2d9bc945c53d9db66a4e491ee145ef518a6ddfea Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sat, 19 Apr 2025 21:51:30 -0400 Subject: [PATCH 46/51] improve simulation egornomics a bit --- bs/TagEngine.bs | 3 +- bs/Tests/TagEngineTester.bs | 63 +++++++++++++++++++++---------------- bs/Top.bs | 2 +- bs/Util.bs | 45 ++++++++++++++++---------- 4 files changed, 67 insertions(+), 46 deletions(-) diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 8b12b9d..7726811 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -1,7 +1,6 @@ package TagEngine( - MkTagType, + MkTagType(..), TagEngine(..), - Util.BasicResult(..), mkTagEngine) where import Vector diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 4fc700e..5a26477 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -2,6 +2,10 @@ package TagEngineTester(mkTagEngineTester) where import TagEngine import ActionSeq +import Printf +import Util + +type NumTags = 5 mkTagEngineTester :: Module Empty mkTagEngineTester = do @@ -26,39 +30,44 @@ mkTagEngineTester = do in actionSeq $ - do requestTagAction - |> do requestTagAction - |> do requestTagAction - |> do requestTagAction - |> do requestTagAction + do + let expectedTag = 4 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 3 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 2 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 1 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 0 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" |> do retireTagAction 2 - -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" |> do - retireTagAction 4 - requestTagAction - -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" - -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + retireTagAction 4 + let expectedTag :: MkTagType NumTags + expectedTag = 2 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" |> do - retireTagAction 4 - requestTagAction - -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" - |> do $finish - -- |> do retireTagAction 4 - -- |> do retireTagAction 4 - -- |> do retireTagAction 0 - -- |> do requestTagAction - -- |> do requestTagAction - -- |> do retireTagAction 1 - -- |> do requestTagAction - -- |> do $finish + retireTagAction 2 + let expectedTag = 3 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + terminateSimNoError addRules $ rules - -- "counter": when True ==> - -- do - -- count := count + 1 - -- $display "count : " (fshow count) - "testIncrement": when (runOnce == False) ==> + "start unit test": when (runOnce == False) ==> do s.start runOnce := True diff --git a/bs/Top.bs b/bs/Top.bs index a0816a0..b5276fd 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -7,9 +7,9 @@ import BRAM import CBindings import Bus import TagEngine + import List import ActionSeq - import Vector import BusTypes diff --git a/bs/Util.bs b/bs/Util.bs index 89492f5..0448782 100644 --- a/bs/Util.bs +++ b/bs/Util.bs @@ -1,24 +1,37 @@ package Util( (|>), - BasicResult(..), - simulate_for) where + terminateSimNoError, + terminateSimWithError, + dynamicAssert + ) where + +import CBindings infixr 0 |> -data BasicResult = Success - | Failure - deriving (Bits, Eq, FShow) - (|>) :: (a -> b) -> a -> b f |> x = f x; -simulate_for :: (Bits a n, Arith a, Eq a) => Reg a -> Reg a -> Rules -simulate_for curr_cycle end_cycle = - rules - "count_cycle_rule": when True ==> action - curr_cycle := curr_cycle + 1 - if curr_cycle == end_cycle - then - $finish - else - $display "cycle = " curr_cycle +assertMessage :: String -> String -> String +assertMessage which mess = + letseq pos = getStringPosition mess -- get position of original message literal + in (which +++" assertion failed: " +++ printPosition pos +++ mess) + +dynamicAssert :: Bool -> String -> Action +dynamicAssert = if not testAssert then (\ _ _ -> noAction) + else (\ b s -> if b then noAction else + action + $display (assertMessage "Dynamic" s) + restoreTerminal + $finish 1 + ) + +terminateSimNoError :: Action +terminateSimNoError = do + restoreTerminal + $finish 0 + +terminateSimWithError :: Action +terminateSimWithError = do + restoreTerminal + $finish 1 From 89664a01f6b213f306f74545ac031588eb29152a Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sat, 19 Apr 2025 22:04:38 -0400 Subject: [PATCH 47/51] reduce noise in tag engine unit test as well as make results apparent --- bs/TagEngine.bs | 12 +++---- bs/Tests/BusTester.bs | 67 +++++++++++++++++++++++++++++++++++++ bs/Tests/TagEngineTester.bs | 9 +++-- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 bs/Tests/BusTester.bs diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 7726811..cd172d3 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -40,18 +40,18 @@ mkTagEngine = do requestSignal <- mkRWire -- Signals a tag request -- Debug - debugOnce <- mkReg True + debugOnce <- mkReg False -- Rules addRules |> rules "debug_initial_state": when debugOnce ==> do - $display "tagUsage: " (fshow (readVReg tagUsage)) + -- $display "tagUsage: " (fshow (readVReg tagUsage)) debugOnce := False "retire_tag": when True ==> do let tag = retireQueue.first - $display "Retiring tag: " (fshow tag) + -- $display "Retiring tag: " (fshow tag) retireQueue.deq freeTagQueue.enq tag retireSignal.wset tag @@ -66,13 +66,13 @@ mkTagEngine = do usage' = update usage requestTag True usage'' = update usage' retireTag False writeVReg tagUsage usage'' - $display $time " Updated usage (request + retire): " (fshow |> readVReg tagUsage) + -- $display $time " Updated usage (request + retire): " (fshow |> readVReg tagUsage) (Just retireTag, Nothing) -> do (select tagUsage retireTag) := False - $display $time " Updated usage (retire): " (fshow (readVReg tagUsage)) + -- $display $time " Updated usage (retire): " (fshow (readVReg tagUsage)) (Nothing, Just requestTag) -> do (select tagUsage requestTag) := True - $display $time " Updated usage (request): " (fshow (readVReg tagUsage)) + -- $display $time " Updated usage (request): " (fshow (readVReg tagUsage)) (Nothing, Nothing) -> action {} -- Interface diff --git a/bs/Tests/BusTester.bs b/bs/Tests/BusTester.bs new file mode 100644 index 0000000..16b1ef5 --- /dev/null +++ b/bs/Tests/BusTester.bs @@ -0,0 +1,67 @@ +package TagEngineTester(mkTagEngineTester) where + +import TagEngine +import ActionSeq +import Assert + +mkTagEngineTester :: Module Empty +mkTagEngineTester = do + tagEngine :: TagEngine 5 <- mkTagEngine + runOnce :: Reg Bool <- mkReg False + + s :: ActionSeq + s <- + let + requestTagAction :: Action + requestTagAction = + do + tag <- tagEngine.requestTag + $display $time " got tag : " (fshow tag) + + retireTagAction :: UInt 3 -> Action + retireTagAction tag = + do + res <- tagEngine.retireTag tag + $display $time " retiring tag : " (fshow tag) " " (fshow res) + action {} + + in + actionSeq $ + do requestTagAction + |> do + requestTagAction + -- tag <- tagEngine.requestTag + |> do requestTagAction + |> do requestTagAction + |> do requestTagAction + |> do retireTagAction 2 + -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + |> do + retireTagAction 4 + requestTagAction + -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" + -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + |> do + retireTagAction 4 + requestTagAction + -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" + |> do $finish + -- |> do retireTagAction 4 + -- |> do retireTagAction 4 + -- |> do retireTagAction 0 + -- |> do requestTagAction + -- |> do requestTagAction + -- |> do retireTagAction 1 + -- |> do requestTagAction + -- |> do $finish + + addRules $ + rules + -- "counter": when True ==> + -- do + -- count := count + 1 + -- $display "count : " (fshow count) + "testIncrement": when (runOnce == False) ==> + do + s.start + runOnce := True diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 5a26477..a109161 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -19,18 +19,20 @@ mkTagEngineTester = do requestTagAction = do tag <- tagEngine.requestTag - $display $time " got tag : " (fshow tag) + -- $display $time " got tag : " (fshow tag) + action {} retireTagAction :: UInt 3 -> Action retireTagAction tag = do res <- tagEngine.retireTag tag - $display $time " retiring tag : " (fshow tag) " " (fshow res) + -- $display $time " retiring tag : " (fshow tag) " " (fshow res) action {} in actionSeq $ do + $display "=== TESTING TagEngine ===" let expectedTag = 4 tag <- tagEngine.requestTag dynamicAssert (tag == expectedTag) "" @@ -59,10 +61,11 @@ mkTagEngineTester = do dynamicAssert (tag == expectedTag) "" |> do retireTagAction 2 - let expectedTag = 3 + let expectedTag = 4 tag <- tagEngine.requestTag dynamicAssert (tag == expectedTag) "" |> do + $display "=== PASSED ===" terminateSimNoError addRules $ From 7290af88fb90f55fc85515172dc720a91dae89aa Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 20 Apr 2025 15:22:14 -0400 Subject: [PATCH 48/51] scaffolding for new uart interface in place --- bs/Top.bs | 7 ++++--- bs/Uart/Deserializer.bs | 8 ++++---- bs/Uart/Serializer.bs | 8 ++++---- bs/Uart/Uart.bs | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 bs/Uart/Uart.bs diff --git a/bs/Top.bs b/bs/Top.bs index b5276fd..8244a1b 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -1,8 +1,8 @@ package Top(mkTop, ITop(..)) where +import Serializer import Deserializer import Core -import Serializer import BRAM import CBindings import Bus @@ -12,6 +12,7 @@ import List import ActionSeq import Vector import BusTypes +import Uart import TagEngineTester @@ -27,8 +28,8 @@ interface ITop = { mkTop :: Module ITop mkTop = do fileHandle :: Handle <- openFile "compile.log" WriteMode - deserializer :: IDeserializer FCLK BAUD <- mkDeserialize fileHandle - serializer :: ISerializer FCLK BAUD <- mkSerialize fileHandle + deserializer :: Deserializer FCLK BAUD <- mkDeserialize fileHandle + serializer :: Serializer FCLK BAUD <- mkSerialize fileHandle core :: Core FCLK <- mkCore persistLed :: Reg (Bit 8) <- mkReg 0 diff --git a/bs/Uart/Deserializer.bs b/bs/Uart/Deserializer.bs index cebc355..6f642bf 100644 --- a/bs/Uart/Deserializer.bs +++ b/bs/Uart/Deserializer.bs @@ -1,6 +1,6 @@ package Deserializer( mkDeserialize, - IDeserializer(..), + Deserializer(..), State(..)) where @@ -8,11 +8,11 @@ import ClkDivider import State -interface (IDeserializer :: # -> # -> *) clkFreq baudRate = +interface (Deserializer :: # -> # -> *) clkFreq baudRate = get :: Bit 8 putBitIn :: (Bit 1) -> Action {-# always_enabled, always_ready #-} -mkDeserialize :: Handle -> Module (IDeserializer clkFreq baudRate) +mkDeserialize :: Handle -> Module (Deserializer clkFreq baudRate) mkDeserialize fileHandle = do ftdiRxIn :: Wire(Bit 1) <- mkBypassWire shiftReg :: Reg(Bit 8) <- mkReg(0) @@ -46,7 +46,7 @@ mkDeserialize fileHandle = do shiftReg := ftdiRxIn ++ shiftReg[7:1] return $ - interface IDeserializer + interface Deserializer {get = shiftReg when (ftdiState == STOP), (clkDivider.isAdvancing) ;putBitIn bit = ftdiRxIn := bit diff --git a/bs/Uart/Serializer.bs b/bs/Uart/Serializer.bs index cf39721..2b93872 100644 --- a/bs/Uart/Serializer.bs +++ b/bs/Uart/Serializer.bs @@ -1,6 +1,6 @@ package Serializer( mkSerialize, - ISerializer(..), + Serializer(..), State(..)) where @@ -14,11 +14,11 @@ serialize ftdiState dataReg = (DATA n) -> dataReg[n:n] _ -> 1'b1 -interface (ISerializer :: # -> # -> *) clkFreq baudRate = +interface (Serializer :: # -> # -> *) clkFreq baudRate = putBit8 :: (Bit 8) -> Action bitLineOut :: Bit 1 -mkSerialize :: Handle -> Module (ISerializer clkFreq baudRate) +mkSerialize :: Handle -> Module (Serializer clkFreq baudRate) mkSerialize fileHandle = do ftdiTxOut :: Wire(Bit 1) <- mkBypassWire @@ -41,7 +41,7 @@ mkSerialize fileHandle = do ftdiTxOut := serialize ftdiState dataReg return $ - interface ISerializer + interface Serializer putBit8 bit8Val = do clkDivider.reset diff --git a/bs/Uart/Uart.bs b/bs/Uart/Uart.bs new file mode 100644 index 0000000..20d18f5 --- /dev/null +++ b/bs/Uart/Uart.bs @@ -0,0 +1,26 @@ +package Uart( + mkUartPhy, + UartPhy(..) + ) where + +import Serializer +import Deserializer +import BusTypes +import Util + +-- Out is out from the FPGA and In is in to the FPGA +interface (UartPhy :: # -> # -> *) clkFreq baudRate = + bitOut :: Bit 1 + bitIn :: Bit 1 -> Action + +mkUartPhy :: (BusTypes.BusServer inFlightTransactions numClients) + -> Module (UartPhy clkFreq baudRate) +mkUartPhy dedicatedServerInterface = do + fileHandle :: Handle <- openFile "mkUartPhy.log" WriteMode + deserializer :: Deserializer clkFreq baudRate <- mkDeserialize fileHandle + serializer :: Serializer clkFreq baudRate <- mkSerialize fileHandle + return |> + interface UartPhy + bitOut = 1 + bitIn bitVal = do + action {} \ No newline at end of file From 842c19d441548fe43086e8c83d65ceaaad95d654 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 20 Apr 2025 18:06:17 -0400 Subject: [PATCH 49/51] make server map, normalize uart interfaces --- bs/ServerMap.bs | 35 +++++++++++++++++++++++++++++++++++ bs/Top.bs | 1 + bs/Uart/Uart.bs | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 bs/ServerMap.bs diff --git a/bs/ServerMap.bs b/bs/ServerMap.bs new file mode 100644 index 0000000..85d0d17 --- /dev/null +++ b/bs/ServerMap.bs @@ -0,0 +1,35 @@ +package ServerMap( + ramServerStart, + ramServerEnd, + uartServerStart, + uartServerEnd, + serverMap + ) where + +import Types +import BusTypes + +bytesInRam :: Types.Addr +bytesInRam = 1024 + +-- number of servers currently supported by this bus map +type NumServers = 2 + +ramServerStart :: Types.Addr +ramServerStart = 0x80000000 +ramServerEnd :: Types.Addr +ramServerEnd = ramServerStart + (bytesInRam - 1) + +uartServerStart :: Types.Addr +uartServerStart = 0x10000000 +uartServerEnd :: Types.Addr +uartServerEnd = uartServerStart + 7 + +-- be careful when hooking up the servers that +-- the uart is attached to index 0 whilst the ram +-- is attached to index 1 +serverMap :: Types.Addr -> Maybe (MkServerIdx 2) +serverMap addr = + if addr >= ramServerStart && addr <= ramServerEnd then Just 1 + else if addr >= uartServerStart && addr <= uartServerEnd then Just 0 + else Nothing \ No newline at end of file diff --git a/bs/Top.bs b/bs/Top.bs index 8244a1b..400f37a 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -13,6 +13,7 @@ import ActionSeq import Vector import BusTypes import Uart +import ServerMap import TagEngineTester diff --git a/bs/Uart/Uart.bs b/bs/Uart/Uart.bs index 20d18f5..7cc45b4 100644 --- a/bs/Uart/Uart.bs +++ b/bs/Uart/Uart.bs @@ -22,5 +22,5 @@ mkUartPhy dedicatedServerInterface = do return |> interface UartPhy bitOut = 1 - bitIn bitVal = do - action {} \ No newline at end of file + bitIn bitVal = do + deserializer.putBitIn bitVal \ No newline at end of file From 1b620210296ae95c0ce183738503095b79f138d5 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Mon, 21 Apr 2025 08:58:55 -0400 Subject: [PATCH 50/51] more work on uart server now with diagram --- bs/Uart/Uart.bs | 10 ++- diagrams/uart-server.drawio | 119 ++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 diagrams/uart-server.drawio diff --git a/bs/Uart/Uart.bs b/bs/Uart/Uart.bs index 7cc45b4..fa86fb1 100644 --- a/bs/Uart/Uart.bs +++ b/bs/Uart/Uart.bs @@ -6,8 +6,13 @@ package Uart( import Serializer import Deserializer import BusTypes +import Types import Util +import FIFO +import FIFOF +import SpecialFIFOs + -- Out is out from the FPGA and In is in to the FPGA interface (UartPhy :: # -> # -> *) clkFreq baudRate = bitOut :: Bit 1 @@ -18,7 +23,10 @@ mkUartPhy :: (BusTypes.BusServer inFlightTransactions numClients) mkUartPhy dedicatedServerInterface = do fileHandle :: Handle <- openFile "mkUartPhy.log" WriteMode deserializer :: Deserializer clkFreq baudRate <- mkDeserialize fileHandle - serializer :: Serializer clkFreq baudRate <- mkSerialize fileHandle + serializer :: Serializer clkFreq baudRate <- mkSerialize fileHandle + + taggedResponseBuffer :: (FIFO (BusTypes.TaggedBusResponse inFlightTransactions)) <- mkFIFO + return |> interface UartPhy bitOut = 1 diff --git a/diagrams/uart-server.drawio b/diagrams/uart-server.drawio new file mode 100644 index 0000000..f6af8cb --- /dev/null +++ b/diagrams/uart-server.drawio @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 51b96c9ea75d112a805a332ac56ed43c8423ca06 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Tue, 22 Apr 2025 11:59:53 -0400 Subject: [PATCH 51/51] simplify C BSV Bindings wrappers --- bsv/CBindings.bsv | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/bsv/CBindings.bsv b/bsv/CBindings.bsv index e54d0ea..e5fc0c7 100644 --- a/bsv/CBindings.bsv +++ b/bsv/CBindings.bsv @@ -1,13 +1,13 @@ package CBindings; // Original function imports -import "BDPI" function Action init_terminal(); -import "BDPI" function Action restore_terminal(); -import "BDPI" function Bit#(8) get_char_from_terminal(); -import "BDPI" function Int#(32) is_char_available(); -import "BDPI" function Action write_char_to_terminal(Bit#(8) chr); -import "BDPI" function Action setup_sigint_handler(); -import "BDPI" function Bool was_ctrl_c_received(); +import "BDPI" init_terminal = function Action initTerminal(); +import "BDPI" restore_terminal = function Action restoreTerminal(); +import "BDPI" get_char_from_terminal = function Bit#(8) getCharFromTerminal(); +import "BDPI" is_char_available = function Int#(32) isCharAvailable(); +import "BDPI" write_char_to_terminal = function Action writeCharToTerminal(Bit#(8) chr); +import "BDPI" setup_sigint_handler = function Action setupSigintHandler(); +import "BDPI" was_ctrl_c_received = function Bool wasCtrlCReceived(); // Aliased exports export initTerminal; @@ -18,33 +18,4 @@ export writeCharToTerminal; export setupSigintHandler; export wasCtrlCReceived; -// Aliased function definitions -function Action initTerminal(); - return init_terminal(); -endfunction - -function Action restoreTerminal(); - return restore_terminal(); -endfunction - -function Bit#(8) getCharFromTerminal(); - return get_char_from_terminal(); -endfunction - -function Int#(32) isCharAvailable(); - return is_char_available(); -endfunction - -function Action writeCharToTerminal(Bit#(8) chr); - return write_char_to_terminal(chr); -endfunction - -function Action setupSigintHandler(); - return setup_sigint_handler(); -endfunction - -function Bool wasCtrlCReceived(); - return was_ctrl_c_received(); -endfunction - endpackage