Skip to content

scx_lavd: Optimize CPU selection in pick_idle_cpu#3229

Open
Dongwqiang wants to merge 1 commit intosched-ext:mainfrom
Dongwqiang:main
Open

scx_lavd: Optimize CPU selection in pick_idle_cpu#3229
Dongwqiang wants to merge 1 commit intosched-ext:mainfrom
Dongwqiang:main

Conversation

@Dongwqiang
Copy link

Optimize the CPU selection algorithm in pick_idle_cpu() to improve performance in highly loaded systems with multiple compute domains.

The current implementation iterates through all neighboring domains without considering distance or early exit conditions, which can lead to unnecessary iterations when no idle cores are available.

Changes:

  1. Add tracking of stealer domains found at each distance level
  2. Skip domains without idle cores early (nr_idle_cores == 0)
  3. Add early exit when stealer domains are found but no idle cores are available in closer domains
  4. Add optimization comments explaining the improvements

These changes reduce the search time in the critical path while maintaining the same task migration behavior and load balancing characteristics.

Optimize the CPU selection algorithm in pick_idle_cpu() to improve
performance in highly loaded systems with multiple compute domains.

The current implementation iterates through all neighboring domains
without considering distance or early exit conditions, which can
lead to unnecessary iterations when no idle cores are available.

Changes:
1. Add tracking of stealer domains found at each distance level
2. Skip domains without idle cores early (nr_idle_cores == 0)
3. Add early exit when stealer domains are found but no idle cores
   are available in closer domains
4. Add optimization comments explaining the improvements

These changes reduce the search time in the critical path while
maintaining the same task migration behavior and load balancing
characteristics.

Signed-off-by: Dong Wanqiang <dongwanqiang@xiaomi.com>
@multics69
Copy link
Contributor

@Dongwqiang -- Thanks for submitting the patch. It seems like there is a compilation error on the CI. Could you please check?

Caused by:
      0: failed to compile `src/bpf/idle.bpf.c`
      1: failed to compile /tmp/nix-shell.jfffrZ/.tmpyZiw8Y/idle.bpf.c from src/bpf/idle.bpf.c
      2: command `/nix/store/rsvannr7kvjgnqcmbchh4p7jbyi7amg1-bpf-clang-19.1.7/bin/clang -g -O2 -Wall -Wno-compare-distinct-pointer-types -D__TARGET_ARCH_x86 -mcpu=v3 -mlittle-endian -idirafter /nix/store/10mkp77lmqz8x2awd8hzv6pf7f7rkf6d-clang-19.1.7-lib/lib/clang/19/include -idirafter /nix/store/wv6zvllksczdsnv8df83j0bkkgffq9zi-linux-headers-6.18.0/usr/include -idirafter /nix/store/gf3wh0x0rzb1dkx0wx1jvmipydwfzzd5-glibc-2.40-66-dev/include -I/var/cache/private/github-runner-pulsar-2/scx/scx/target/debug/build/scx_lavd-f1d52833375bef4e/out/scx_utils-bpf_h/arch/x86 -I/var/cache/private/github-runner-pulsar-2/scx/scx/target/debug/build/scx_lavd-f1d52833375bef4e/out/scx_utils-bpf_h -I/var/cache/private/github-runner-pulsar-2/scx/scx/target/debug/build/scx_lavd-f1d52833375bef4e/out/scx_utils-bpf_h/bpf-compat -D__SCX_TARGET_ARCH_x86 -I /tmp/nix-shell.jfffrZ/.tmpK7XvET/bpf/src -fno-stack-protector -g -O2 -target bpf -c src/bpf/idle.bpf.c -o /tmp/nix-shell.jfffrZ/.tmpyZiw8Y/idle.bpf.c` failed (exit status: 1)
      3: src/bpf/idle.bpf.c:745:18: error: no member named 'nr_idle_cores' in 'struct cpdom_ctx'
           745 |                         if (mig_cpdc->nr_idle_cores == 0)
               |                             ~~~~~~~~  ^
         1 error generated.
         
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@multics69 multics69 self-requested a review January 15, 2026 01:41
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

Comments