Skip to content
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_layered: Add topology aware preemption #666

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hodgesds
Copy link
Contributor

@hodgesds hodgesds commented Sep 19, 2024

Add topology aware preemption, which changes the order of preemption to first attempt to preempt CPUs in the local LLC, local NUMA node and finally across all NUMA nodes. This could probably be made a little more efficient in the use of the bpf cpumasks, but should work for now. The old logic is still available behind the -t (disable topology) flag. Resolves #659

@hodgesds hodgesds force-pushed the layered-local-llc branch 3 times, most recently from b7ae3d8 to d0707cc Compare September 19, 2024 16:18
@hodgesds
Copy link
Contributor Author

Example stats output:

###### Thu, 19 Sep 2024 12:20:31 -0400 ######
tot=    776 local=17.53 open_idle=10.05 affn_viol=27.71 proc=5ms
busy= 86.0 util= 2645.9 load=   3806.8 fallback_cpu= 12
excl_coll=0.00 excl_preempt=0.00 excl_idle=0.00 excl_wakeup=0.00
  chrome: util/frac=    3.3/  0.1 load/frac=      6.8/  0.2 tasks=   157
          tot=     29 local=20.69 wake/exp/reenq=79.31/ 0.00/ 0.00
          keep/max/busy=37.93/ 0.00/ 0.00 kick= 0.00 yield/ign= 0.00/    0
          open_idle= 6.90 mig=82.76 xnuma_mig= 0.00 xllc_mig=34.48 affn_viol= 0.00
          preempt/first/xllc/xnuma/idle/fail=10.34/10.34/ 0.00/ 0.00/ 6.90/62.07 min_exec=93.10/   9.54ms
          cpus=  2 [  2,  2] 00000003
  daemon: util/frac=    2.6/  0.1 load/frac=   2188.3/ 57.5 tasks=   148
          tot=    462 local= 1.52 wake/exp/reenq=81.60/16.45/ 0.43
          keep/max/busy= 0.00/ 0.00/ 6.28 kick= 0.00 yield/ign=12.77/    0
          open_idle= 0.00 mig=25.32 xnuma_mig= 0.00 xllc_mig= 9.52 affn_viol=46.54
          preempt/first/xllc/xnuma/idle/fail= 0.00/ 0.00/ 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
          cpus=  2 [  2,  2] 0000000c
  normal: util/frac=    0.0/  0.0 load/frac=      0.0/  0.0 tasks=     0
          tot=      0 local= 0.00 wake/exp/reenq= 0.00/ 0.00/ 0.00
          keep/max/busy= 0.00/ 0.00/ 0.00 kick= 0.00 yield/ign= 0.00/    0
          open_idle= 0.00 mig= 0.00 xnuma_mig= 0.00 xllc_mig= 0.00 affn_viol= 0.00
          preempt/first/xllc/xnuma/idle/fail= 0.00/ 0.00/ 0.00/ 0.00/ 0.00/ 0.00 min_exec= 0.00/   0.00ms
          cpus=  0 [  0,  0] 00000000
  user  : util/frac= 2640.0/ 99.8 load/frac=   1611.7/ 42.3 tasks=    74
          tot=    285 local=43.16 wake/exp/reenq=25.26/27.72/ 3.86
          keep/max/busy=418.9/14.74/ 4.56 kick=11.93 yield/ign= 0.00/    0
          open_idle=26.67 mig=43.16 xnuma_mig= 0.00 xllc_mig=25.26 affn_viol= 0.00
          preempt/first/xllc/xnuma/idle/fail= 3.16/ 0.00/ 1.40/ 0.00/18.95/22.81 min_exec=45.96/   6.15ms
          cpus=  8 [  8, 10] 00000ff0

Copy link
Contributor

@JakeHillion JakeHillion left a comment

Choose a reason for hiding this comment

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

This looks good to me. I wonder if it's worth changing the stuff in the new if (!disable_topology) into two separate functions? Might make things easier to follow.

rust/Cargo.lock Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we weren't committing this before? Imo it should be committed, just surprising to see it now.

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'm not sure.... I think @likewhatevs recently removed the lock files from .gitignore so we could have reproducible builds. So maybe it hasn't been committed yet?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did remove the git ignore, but it is kinda weird one would be there at all tbh. Like a top-level Cargo.lock I'd get (workspace level), or a project level Cargo.lock I'd also get (project level).

In the middle seems off to me.

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 think I know what happened, I think I created this branch before the lock files and before some of the refactoring of the builds. Then after rebasing the old lock file was still around and I added it on accident, so should be safe to delete.

u32 cache_idx;
u32 node_idx;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did these swap for a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was thinking going from the least specific to the most specific for ordering, but either way is fine

Comment on lines +786 to +796
if (!(cachec = lookup_cache_ctx(cctx->cache_idx)) ||
!(nodec = lookup_node_ctx(cctx->node_idx)))
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would it be clearer if we split these into two early returns?

Suggested change
if (!(cachec = lookup_cache_ctx(cctx->cache_idx)) ||
!(nodec = lookup_node_ctx(cctx->node_idx)))
return;
if (!(cachec = lookup_cache_ctx(cctx->cache_idx)))
return;
if (!(nodec = lookup_node_ctx(cctx->node_idx)))
return;

Add topology aware preemption that begins in the local LLC and attempts
to preempt from cpus nearest in the topology.

Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
Add stats for XLLC/XNUMA preemptions.

Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
Use the cast_mask helper to clean up some of the bpf cpumask conversion
code for preemption.

Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
Signed-off-by: Daniel Hodges <hodges.daniel.scott@gmail.com>
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.

scx_layered: Add topology aware preemption
3 participants