Conversation
erlingrj
left a comment
There was a problem hiding this comment.
This is a good start. Just a few comments. BTW, I highly recommend you to make your assumptions explicit with assertions. I always put assertions on everything to catch bugs.
| when (countinglock.sleep) { | ||
| sleep := true.B | ||
| } |
There was a problem hiding this comment.
Shouldnt this be moved inside the when statement above? We only put threads to sleep when they write to the wait register
| for (tid <- 0 until conf.threads) { | ||
| when ((tid.U =/= io.tid) && regWaitingOn(tid) === io.tid && regUntil(tid) <= regValue(io.tid)) { | ||
| io.wake(tid) := true.B | ||
| regWaitingOn(tid) := tid.U // set to not waiting on anything | ||
| } .otherwise { | ||
| io.wake(tid) := false.B | ||
| } | ||
| } |
There was a problem hiding this comment.
Why must regWaitingOn(tid) === io.tid to wake up? This means you can only wake up in a cycle where the thread whose lock you are waiting for is doing an operation.
There was a problem hiding this comment.
regWaitingOn(tid) is which thread tid (some other thread) is waiting on. Essentially regWaitingOn(tid) == io.tid means that some other thread tid is waiting on the current thread.
The when statement roughly translates to "if some other thread is waiting on the current thread, and the value that thread is waiting for has been met, wake that thread".
Yes, you should only wake up when the thread you are waiting on does an increment operation.
Maybe I should clarify this logic in comments?
Currently, this stores the value that each thread is waiting for inside the module, and does a comparison per thread every clock cycle (similar to delay_until).
TODOs: