Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

sberkun
Copy link
Collaborator

@sberkun sberkun commented Mar 31, 2023

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:

  • make sure it works well with delay_until and potentially other sleep sources
  • add configuration to enable this as a feature
  • proof of concept C program

Copy link
Collaborator

@erlingrj erlingrj left a 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.

Comment on lines +372 to +374
when (countinglock.sleep) {
sleep := true.B
}
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, thx

Comment on lines +62 to +69
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
}
}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants