Skip to content

Commit 67b95fd

Browse files
committed
scx_p2dq: Add L2 cluster-aware CPU selection
Add L2 cluster awareness to improve cache locality by preferring CPUs within the same cluster before searching the wider LLC domain. Infrastructure: - Add cluster_id to cpu_ctx for per-CPU cluster tracking - Add has_clusters flag to topo_config - Initialize cluster_id for each CPU during BPF setup - Populate cluster IDs from topology in userspace Implementation: - Add pick_idle_cpu_in_cluster() helper to search cluster cpumask - Enhance pick_idle_cpu() to try cluster-level before LLC-level - Update wakeup paths for interactive tasks to prefer cluster - Check same-cluster waker/wakee before wider search This improves cache locality by keeping related tasks on CPUs sharing L2 cache, reducing cache misses and improving performance. Signed-off-by: Daniel Hodges <[email protected]>
1 parent d86cd11 commit 67b95fd

File tree

4 files changed

+1074
-714
lines changed

4 files changed

+1074
-714
lines changed

scheds/rust/scx_p2dq/src/bpf/intf.h

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,44 @@
1414
#endif
1515

1616
#ifndef __KERNEL__
17-
typedef unsigned char u8;
18-
typedef unsigned int u32;
17+
typedef unsigned char u8;
18+
typedef unsigned int u32;
1919
typedef unsigned long long u64;
2020
#endif
2121

22-
2322
enum consts {
24-
MAX_CPUS = 512,
25-
MAX_NUMA_NODES = 64,
26-
MAX_LLCS = 64,
27-
MAX_DSQS_PER_LLC = 8,
28-
MAX_LLC_SHARDS = 32,
29-
MAX_TASK_PRIO = 39,
30-
MAX_TOPO_NODES = 1024,
23+
MAX_CPUS = 512,
24+
MAX_NUMA_NODES = 64,
25+
MAX_LLCS = 64,
26+
MAX_CLUSTERS = 128,
27+
MAX_DSQS_PER_LLC = 8,
28+
MAX_LLC_SHARDS = 32,
29+
MAX_TASK_PRIO = 39,
30+
MAX_TOPO_NODES = 1024,
3131

32-
NSEC_PER_USEC = 1000ULL,
33-
NSEC_PER_MSEC = (1000ULL * NSEC_PER_USEC),
34-
MSEC_PER_SEC = 1000ULL,
35-
NSEC_PER_SEC = NSEC_PER_MSEC * MSEC_PER_SEC,
32+
NSEC_PER_USEC = 1000ULL,
33+
NSEC_PER_MSEC = (1000ULL * NSEC_PER_USEC),
34+
MSEC_PER_SEC = 1000ULL,
35+
NSEC_PER_SEC = NSEC_PER_MSEC * MSEC_PER_SEC,
3636

37-
MIN_SLICE_USEC = 10ULL,
38-
MIN_SLICE_NSEC = (10ULL * NSEC_PER_USEC),
37+
MIN_SLICE_USEC = 10ULL,
38+
MIN_SLICE_NSEC = (10ULL * NSEC_PER_USEC),
3939

40-
LOAD_BALANCE_SLACK = 20ULL,
40+
LOAD_BALANCE_SLACK = 20ULL,
4141

42-
P2DQ_MIG_DSQ = 1LLU << 60,
43-
P2DQ_INTR_DSQ = 1LLU << 32,
42+
P2DQ_MIG_DSQ = 1LLU << 60,
43+
P2DQ_INTR_DSQ = 1LLU << 32,
4444

4545
// PELT (Per-Entity Load Tracking) constants
46-
PELT_HALFLIFE_MS = 32, // 32ms half-life for exponential decay
47-
PELT_PERIOD_MS = 1, // 1ms update period (simplified from kernel's 1024us)
48-
PELT_MAX_UTIL = 1024, // Maximum utilization value
49-
PELT_DECAY_SHIFT = 7, // Decay factor: (127/128) ≈ 0.98 per ms
50-
PELT_SUM_MAX = 131072, // Maximum sum value (128 * 1024)
46+
PELT_HALFLIFE_MS = 32, // 32ms half-life for exponential decay
47+
PELT_PERIOD_MS =
48+
1, // 1ms update period (simplified from kernel's 1024us)
49+
PELT_MAX_UTIL = 1024, // Maximum utilization value
50+
PELT_DECAY_SHIFT = 7, // Decay factor: (127/128) ≈ 0.98 per ms
51+
PELT_SUM_MAX = 131072, // Maximum sum value (128 * 1024)
5152

5253
// kernel definitions
53-
CLOCK_BOOTTIME = 7,
54+
CLOCK_BOOTTIME = 7,
5455
};
5556

5657
enum p2dq_timers_defs {

0 commit comments

Comments
 (0)