Skip to content

Commit 45d0278

Browse files
committed
scx_flow: fix autotuner ratio and target_cpu validation
Address two remaining issues from Copilot review PR sched-ext#3525: 1. main.rs: Fix direct_mismatch_ratio denominator The original code used cpu_biases as the denominator, but direct_local_mismatches can increment even when no bias was applied (when no stability bias was available). This could cause inflated ratios and incorrect autotuner decisions. Now uses cpu_biases.saturating_add(direct_mismatches) as the denominator to properly represent all attempts. 2. main.bpf.c: Add target_cpu >= 0 guard scx_bpf_task_cpu(p) can return -1 in test scenarios. Passing a negative CPU to bpf_cpumask_test_cpu() or using SCX_DSQ_LOCAL_ON | target_cpu is undefined behavior. Now validates target_cpu before cpumask operations. Fixes: sched-ext#3525 (comment) Fixes: sched-ext#3525 (comment)
1 parent 7c0311a commit 45d0278

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

scheds/experimental/scx_flow/src/bpf/main.bpf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,8 @@ void BPF_STRUCT_OPS(flow_enqueue, struct task_struct *p, u64 enq_flags)
13621362
if (is_wakeup && !containment_active)
13631363
enq_flags |= SCX_ENQ_HEAD;
13641364

1365-
if (has_wake_target || bpf_cpumask_test_cpu(target_cpu, p->cpus_ptr)) {
1365+
if (has_wake_target ||
1366+
(target_cpu >= 0 && bpf_cpumask_test_cpu(target_cpu, p->cpus_ptr))) {
13661367
bool should_preempt;
13671368

13681369
should_preempt = rt_sensitive_wakeup || ipc_confidence_wakeup ||

scheds/experimental/scx_flow/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ impl AutoTuner {
481481
let exhaustion_ratio = exhaustions as f64 / positive.max(1) as f64;
482482
let contained_ratio = contained_enqueues as f64 / positive.max(1) as f64;
483483
let direct_reject_ratio = direct_rejections as f64 / direct_candidates.max(1) as f64;
484-
let direct_mismatch_ratio = direct_mismatches as f64 / cpu_biases.max(1) as f64;
484+
let direct_mismatch_attempts = cpu_biases.saturating_add(direct_mismatches);
485+
let direct_mismatch_ratio =
486+
direct_mismatches as f64 / direct_mismatch_attempts.max(1) as f64;
485487
let rescue_total = contained_rescues + shared_rescues;
486488
let rescue_ratio = rescue_total as f64 / dispatch_total.max(1) as f64;
487489
let latency_dispatch_ratio = total_latency_dispatches as f64 / dispatch_total.max(1) as f64;

0 commit comments

Comments
 (0)