-
Notifications
You must be signed in to change notification settings - Fork 91
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
scx_lavd: replesih time slice at ops.running() only when necessary #250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1644,7 +1644,7 @@ static void put_global_rq(struct task_struct *p, struct task_ctx *taskc, | |
* Enqueue the task to the global runqueue based on its virtual | ||
* deadline. | ||
*/ | ||
scx_bpf_dispatch_vtime(p, LAVD_GLOBAL_DSQ, LAVD_SLICE_MAX_NS, | ||
scx_bpf_dispatch_vtime(p, LAVD_GLOBAL_DSQ, LAVD_SLICE_UNDECIDED, | ||
vdeadline, enq_flags); | ||
|
||
} | ||
|
@@ -1679,7 +1679,7 @@ static bool put_local_rq(struct task_struct *p, struct task_ctx *taskc, | |
taskc->vdeadline_delta_ns = 0; | ||
taskc->eligible_delta_ns = 0; | ||
taskc->victim_cpu = (s16)LAVD_CPU_ID_NONE; | ||
scx_bpf_dispatch(p, SCX_DSQ_LOCAL, LAVD_SLICE_MAX_NS, enq_flags); | ||
scx_bpf_dispatch(p, SCX_DSQ_LOCAL, LAVD_SLICE_UNDECIDED, enq_flags); | ||
return true; | ||
} | ||
|
||
|
@@ -1804,6 +1804,27 @@ void BPF_STRUCT_OPS(lavd_runnable, struct task_struct *p, u64 enq_flags) | |
waker_taskc->last_runnable_clk = now; | ||
} | ||
|
||
static bool need_to_calc_time_slice(struct task_struct *p) | ||
{ | ||
/* | ||
* We need to calculate the task @p's time slice in two cases: 1) if it | ||
* hasn't been calculated (i.e., LAVD_SLICE_UNDECIDED) after the | ||
* enqueue or 2) if the sched_ext kernel assigns the default time slice | ||
* (i.e., SCX_SLICE_DFL). | ||
* | ||
* Calculating and assigning a time slice without checking these two | ||
* conditions could entail pathological behaviors, notably watchdog | ||
* time out. One condition that could trigger a watchdog time-out is as | ||
* follows. 1) a task is preempted by another task, which runs in a | ||
* higher scheduler class (e.g., RT or DL). 2) when the task is | ||
* re-running after, for example, the RT task preempted out, its time | ||
* slice will be replenished again. 3) If these two steps are repeated, | ||
* the task can run forever. | ||
*/ | ||
return p->scx.slice == LAVD_SLICE_UNDECIDED || | ||
p->scx.slice == SCX_SLICE_DFL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the only time the kernel assigns
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, I will keep the code as it is but later when the preemption code per tick is ready, I will change it. |
||
} | ||
|
||
void BPF_STRUCT_OPS(lavd_running, struct task_struct *p) | ||
{ | ||
struct cpu_ctx *cpuc; | ||
|
@@ -1826,9 +1847,10 @@ void BPF_STRUCT_OPS(lavd_running, struct task_struct *p) | |
cpuc->stopping_tm_est_ns = get_est_stopping_time(taskc); | ||
|
||
/* | ||
* Calcualte task's time slice based on updated load. | ||
* Calculate the task's time slice based on updated load if necessary. | ||
*/ | ||
p->scx.slice = calc_time_slice(p, taskc); | ||
if (need_to_calc_time_slice(p)) | ||
p->scx.slice = calc_time_slice(p, taskc); | ||
|
||
/* | ||
* If there is a relevant introspection command with @p, process it. | ||
|
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 should be able to sue
SCX_SLICE_INF
which is the same u64 max value. Note that if a running task has this slice value, the tick is stopped. I don't think lavd ever actually ends up running tasks with this value tho, so not really a concern but just something to note.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.
Thank! I will update it accordingly.