-
Notifications
You must be signed in to change notification settings - Fork 45
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
Make the scheduler tickless #201
Conversation
7066e1d
to
26bd4a5
Compare
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.
Don't understand scheduler enough to fully comment but some suggestions.
@@ -335,7 +336,13 @@ debug_log_message_write(const char *context, | |||
DebugPrinter printer; | |||
printer.write("\x1b[35m"); | |||
printer.write(context); | |||
#if 0 |
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.
Make make this a compile time option?
#if 0 | |
#if defined(DEBUG_SHOW_THREAD_ID) |
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 probably wants wiring up in an option, it's mostly disabled for now so that I can do timing checks without it there (it slows things down quite a bit with a real UART).
4d12dee
to
cd95d17
Compare
sdk/core/scheduler/thread.h
Outdated
ThreadState state : 2; | ||
/** | ||
* If the thread is yielding, it may be scheduled before its timeout | ||
* expires, as long as no other threads are runnable. |
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.
I might leave off the "as long as..." part here and just point at the docs for ThreadSleepNoEarlyWake
or the comment down in the actual wake code.
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.
I think it's fine to have duplicated explanations, especially in doc comments. If you mouse over a use of this field in VS Code (for example), you'll get this doc comment pop up. Having it tell you to go and read other docs can be annoying.
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.
That's fair. In which case...
* expires, as long as no other threads are runnable. | |
* expires, as long as no other threads are runnable or | |
* sleeping with shorter timeouts. |
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.
Two nits, but it LGTM.
/** | ||
* Wake any threads that were sleeping until a timeout before the | ||
* current time. This also wakes yielded threads if there are no | ||
* runnable threads. |
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.
* runnable threads. | |
* threads runnable or sleeping with earlier timeouts. |
sdk/core/scheduler/thread.h
Outdated
ThreadState state : 2; | ||
/** | ||
* If the thread is yielding, it may be scheduled before its timeout | ||
* expires, as long as no other threads are runnable. |
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.
That's fair. In which case...
* expires, as long as no other threads are runnable. | |
* expires, as long as no other threads are runnable or | |
* sleeping with shorter timeouts. |
This commit incorporates several changes: Timers are now not set for a regular tick, they are set when a thread may be preempted. Specifically, the timer is set to the next timeout that will trigger a scheduling operation. This avoids timers triggering a switch to the scheduler to do nothing (resume the currently running thread). This means that if a thread sleeps for ten ticks while another runs, we will get one timer interrupt ten ticks in the future, rather than ten interrupts one tick apart. This means that ticks are now calculated retroactively based on elapsed time, rather than counted on each context switch. This, in turn, necessitates some small API changes. We previously conflated two things: - Sleep for N * (tick duration) - Yield and allow lower-priority threads to run for, at most, N * (tick duration) These are now deconflated by adding a second parameter to thread_sleep. Most sleeps are of the second form and so this is the default. This reduces the time taken to run the test suite on Sonata by around 30% and in the Ibex SAFE simulator by 13%.
Timers are now not set for a regular tick, they are set when a thread
may be preempted. Specifically, the timer is set to the next timeout
that will trigger a scheduling operation. This avoids timers
triggering a switch to the scheduler to do nothing (resume the currently
running thread).
This means that if a thread sleeps for ten ticks while another runs, we
will get one timer interrupt ten ticks in the future, rather than ten
interrupts one tick apart.
This means that ticks are now calculated retroactively based on elapsed
time, rather than counted on each context switch.
This, in turn, necessitates some small API changes. We previously
conflated two things:
duration)
These are now deconflated by adding a second parameter to thread_sleep.
Most sleeps are of the second form and so this is the default.
This reduces the time taken to run the test suite on Sonata by around
30% and in the Ibex SAFE simulator by 13%.