Skip to content

Conversation

likewhatevs
Copy link
Contributor

@likewhatevs likewhatevs commented May 9, 2025

Have layered only attempt to skip preemption's that it could not accomplish (i.e. due to tasks with RT sched class) when kallsyms addresses for idle sched class and ext sched class are present.

At the present, layered would exit if those addresses were unobtainable.

still works when kallsyms present for both the skip and not-skip cases:
Screenshot From 2025-05-09 13-37-40
Screenshot From 2025-05-09 13-37-30

@likewhatevs likewhatevs requested review from etsal and htejun May 9, 2025 17:40
Copy link
Contributor

@etsal etsal left a comment

Choose a reason for hiding this comment

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

Looks good, looking at the Rust code path

if (rq && (rq->curr->sched_class != ext_sched_class) &&
(rq->curr->sched_class != idle_sched_class)) {
if (!(cpuc = lookup_cpu_ctx(-1)))
if (rq && (rq->curr->sched_class != ext_sched_class) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Can skip the enable_skip_preempt variable and roll the outer loop into the inner one by writing (ext_sched_class_addr != NULL), but it's just for terseness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh that makes sense, thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still works wrt/ doing the right thing when kallsyms is present, does the C look about right (I think it is/that one can cast null like that fine)?

Copy link
Contributor

Choose a reason for hiding this comment

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

The C does look right, I assume the verifier has no issue with using the addr as a scalar right? Other than that yeah, the address is in the BSS so should be init'ed to 0, and will always be non-zero when both symbols are read.

@likewhatevs likewhatevs enabled auto-merge May 9, 2025 18:13
struct rq *rq = NULL;
s32 sib;
struct sched_class *ext_sched_class, *idle_sched_class;
struct sched_class *ext_sched_class = NULL, *idle_sched_class = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need this. The variables are unconditionally set below, right?

skel.maps.rodata_data.ext_sched_class_addr = ext_sched_class_addr.unwrap();
skel.maps.rodata_data.idle_sched_class_addr = idle_sched_class_addr.unwrap();
} else {
warn!("skip_preempt is not supported, ignoring");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe mention that the addresses couldn't be read from /proc/kallsyms so that users can hunt down what's not working more easily?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add this, but also like, do we think these symbols could be exported kernel side such that we don't need to do this in the future or no?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will probably remain this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will make this into a helper in common then, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, let's keep it in layered for now. We can move it to utils when there are other users.

@likewhatevs likewhatevs disabled auto-merge May 9, 2025 18:25
@likewhatevs likewhatevs added this pull request to the merge queue May 9, 2025
Merged via the queue into sched-ext:main with commit 38c2ab0 May 9, 2025
16 checks passed
@likewhatevs likewhatevs deleted the layered-skip-preempt-cleanup branch May 9, 2025 20:08
@etsal
Copy link
Contributor

etsal commented May 10, 2025

Followup to this: If we can check the current running task for the rq instead of the rq itself, #1844 solves this problem a bit more idiomatically.

@likewhatevs
Copy link
Contributor Author

Followup to this: If we can check the current running task for the rq instead of the rq itself, #1844 solves this problem a bit more idiomatically.

Just to make sure I follow -- more/less, store acquired/released status on cpuc, toggle it with those two callbacks, and use that instead of checking the rq?

@etsal
Copy link
Contributor

etsal commented May 10, 2025

Followup to this: If we can check the current running task for the rq instead of the rq itself, #1844 solves this problem a bit more idiomatically.

Just to make sure I follow -- more/less, store acquired/released status on cpuc, toggle it with those two callbacks, and use that instead of checking the rq?

Exactly, it requires the use of the two extra scx methods. As long as there is a kfunc for grabbing the current running task for a cpu, that should work (not sure whether that exists given that it sounds inherently racy, i.e. the function would be returning a task that may be switched out immediately after being returned).

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.

3 participants