Skip to content

scx_cosmos: use PMU library for perf event handling#3220

Merged
arighi merged 2 commits intosched-ext:mainfrom
etsal:cosmos-pmu-lib
Feb 19, 2026
Merged

scx_cosmos: use PMU library for perf event handling#3220
arighi merged 2 commits intosched-ext:mainfrom
etsal:cosmos-pmu-lib

Conversation

@etsal
Copy link
Copy Markdown
Contributor

@etsal etsal commented Jan 12, 2026

The perf_event tracking logic in scx_cosmos and that of the pmu library are relatively similar and can be merged. Expand the PMU library API, and use the newly exposed functionality in scx_cosmos to handle PMU events.

@etsal etsal requested a review from arighi January 12, 2026 19:26
Copy link
Copy Markdown
Contributor

@arighi arighi left a comment

Choose a reason for hiding this comment

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

Thanks @etsal for working at this! I haven't looked at the changes in details, but something is not working for me with this changes (I just tested it on my AMD laptop, where 0xc3 == branch misses) and I get this:

  • before:
23:43:00 [INFO] scheduler options: ./target/release/scx_cosmos -d -c 0 -p 0 -s 20000 -e 0xc3 -E 10 --stats 1
23:43:00 [INFO] scheduler flags: 0x36
23:43:01 [INFO] Setting up performance counters for 24 CPUs...
23:43:01 [INFO] Performance counters configured successfully for all CPUs
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=227
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=986
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=494
...
  • after:
23:41:57 [INFO] scheduler options: ./target/release/scx_cosmos -d -c 0 -p 0 -s 20000 -e 0xc3 -E 10 --stats 1
23:41:57 [INFO] scheduler flags: 0x36
23:41:57 [INFO] Setting up performance counters for 24 CPUs...
23:41:57 [INFO] Performance counters configured successfully for all CPUs
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=0
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=0
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=0
...

It looks like the stats are not read correctly? I'll investigate more tomorrow morning.

@etsal
Copy link
Copy Markdown
Contributor Author

etsal commented Jan 12, 2026

Hi Andrea, sorry about that! I will do some debugging too and update accordingly.

@etsal
Copy link
Copy Markdown
Contributor Author

etsal commented Jan 13, 2026

Ok, should work now:

$ sudo /home/etsal/scx/target/debug/scx_cosmos -d -c 0 -p 0 -s 20000 -e 0xc3 -E 10 --stats 1
13:35:18 [INFO] NUMA nodes: 1
13:35:18 [INFO] Disabling NUMA optimizations
13:35:18 [INFO] scx_cosmos 1.0.6-gce170e81 x86_64-unknown-linux-gnu/debug SMT on
13:35:18 [INFO] scheduler options: /home/etsal/scx/target/debug/scx_cosmos -d -c 0 -p 0 -s 20000 -e 0xc3 -E 10 --stats 1
13:35:18 [INFO] scheduler flags: 0x36
13:35:18 [INFO] Setting up performance counters for 32 CPUs...
13:35:18 [INFO] Performance counters configured successfully for all CPUs
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=4
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=161
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=110
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=179
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=195
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=450
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=2169
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=22259
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=30619
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=12857
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=5567
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=1106
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=1547
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=2862
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=18071
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=8703
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=7125
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=7128
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=3529
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=11095
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=9308
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=5938
[scx_cosmos] CPUs   0.0% [deadline] ev_dispatches=6154

There were two errors, a) no setup/teardown for per-task counters on task_init/task_exit, and b) the code was reading the PMU after it was cleared each time we computed the delta, always returning 0. Both are fixed.

Copy link
Copy Markdown
Contributor

@arighi arighi left a comment

Choose a reason for hiding this comment

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

I left a small comment, but overall looks good now, thanks!

* Return true if the task is triggering too many PMU events.
*/
static inline bool is_event_heavy(const struct task_ctx *tctx)
static inline bool is_event_heavy(struct task_struct *p)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer to pass tctx to this function to potentially save some unnecessary calls to try_lookup_task_ctx(). The compiler might optimize this away, but passing tctx explicitly guarantees we don't incur the extra lookup. And if the verifier isn't happy we an still check if tctx == NULL inside the function and return.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late reply! Sounds good, will update.

@arighi
Copy link
Copy Markdown
Contributor

arighi commented Feb 15, 2026

Hi @etsal I've udpated your branch with the changes that I suggested, can you check if it still looks good? In that case we can merge this. Thanks!

@arighi
Copy link
Copy Markdown
Contributor

arighi commented Feb 19, 2026

I did some tests with this and it looks good, so let's merge it.

@arighi arighi added this pull request to the merge queue Feb 19, 2026
Merged via the queue into sched-ext:main with commit 81ddb56 Feb 19, 2026
22 checks passed
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