-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
sched: fix deadline init value and add a test case #69429
Conversation
eacf7cd
to
9cb3cc9
Compare
Hi @andyross @peter-mitsis @cfriedt, Could you take a look? |
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.
@TaiJuWu - the provided test definitely needs to be elaborated a bit more and it looks like there are still some races.
I haven't looked to see if we already have sufficient coverage for the deadline scheduler but it might be worth looking at how some of the other scheduler experiments have been set up.
Note: the argument to k_thread_deadline_set() has the same units as the value returned from k_cycle_get_32()
, so that can be used to form the experiment in terms of time durations, which is maybe easier to deal with in terms of setting up the right conditions.
From what I understand, the lower the deadline, the earlier a thread must be scheduled.
If we're lacking a kind of stress test for the deadline scheduler it might be useful to hash that out before revising.
The test environment is 1 cpu so it's not race.
You are right, I have same idea but the init valuse is 0.
|
@TaiJuWu - After an initial reading, I think that you are on to something here. However, my poor brain is going to need some more time to parse through this. |
Thanks for your response. |
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.
After digging into it more, I think the current code is correct for the model that it uses. There are two different time scales at play here which I will call T(x) and t(x). T(x) represents the lower 32-bits of absolute time (k_cycle_get_32()). t(x) represents the sliding window of relative time such that t(0) = T(now), or t(0) = T(k_cycle_get_32()). When we call k_thread_deadline_set(), the deadline is specified in relative time. Internally we convert it to T(x) absolute time using deadline + now.
Two other important things to note ...
- Unlike T(x) which is 32 bits unsigned, t(x) is 32 bits signed.
- The number of cycles between the “first” deadline in the scheduler queue and the “last” deadline must be less than 2^31
Combining this altogether, we see that when k_cycle_get_32() exceeds 0x80000000, this means that that T(0) effectively becomes a future point in time, and z_sched_prio_cmp() will treat it as such.
If normal and deadline task coexist, the deadline task should execute first. Signed-off-by: TaiJu Wu <[email protected]>
Thanks for your answers. I need more time to think this issue more deep. And I want to check a thing which is normal task should run after deadline task, right? |
9cb3cc9
to
6b3dcb6
Compare
The init value of deadline scheduler algorithm should be INT_MIN. Case study 1: both tasks are deadline task. These condition already include test/kernel/sched/deadline In below, I will use 4-bit to replace 32-bit operation. Case study 2: T1 is deadline task, T2 is also deadline task and will make overflow Example: If T1's deadline is 0100 -> both signed and unsingend is 4. If T2's deadline is 1001 (uint4_t + int4_t) -> signed is -7 and unsigned is 9. (uint4_t)T2-(uint4_t)T1 = 9 -2 = 7 -> 0111 > 0. T1 execute first. Case study 3: T1 is normal task and T2 is deadline task. Example: If normal task deadline is INT_MIN(1000 in this case.) If deadline is 0100->both signed and unsigned is 4. (uint4_t)T2 - (uint4_t)T1 = 0100 - 1000 = -4 < 0. T2 execute first. Signed-off-by: TaiJu Wu <[email protected]>
6b3dcb6
to
4764049
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.
This isn't the way deadline comparisons work. The units of the deadline field are in units of cycles (c.f. k_cycle_get_32()) with expected rollover. They aren't absolute. Picking a different number just means that the scheduling vs. threads that don't set their deadlines will be arbitrarily different.
Really the kernel doesn't support mixing deadline and non-deadline threads in the same priority. If you have EDF enabled, you're expected to set deadlines for threads that want to share a priority, or else to leave them unset (and thus equal, which then falls through to "traditional" round robin ordering).
FWIW, one thing that's been suggested in the past is having a way to "clear" a deadline (i.e. to recover equality/round-robin scheduling behavior), which the kernel doesn't provide. IIRC I had suggested at one point doing this when the priority changes, but you could add a separate call instead. If you're worried about this area of the code, that might be more productive.
I want to summarize your response. IMHO, if users does not set deadline, a possible is they hope this task start running until deadline task finished. |
I notice a truth which is if |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
The init value of deadline scheduler algorithm should be INT_MAX.
If this value set to 0, it means normal task is going to run before deadline task.