-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft of counting lock #74
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt this be moved inside the when statement above? We only put threads to sleep when they write to the wait register
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, thx
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: