feat(scheduler-sim-live-allocation): extract shared picker/allocator into sched_election.c (task 3.1)

Relocates sched_job_picker()/sched_allocator() out of scheduler.c
(1382 lines, already over this project's 800-line cap) into a new
sched_election.c, retyped to xce_sched_core_t* -- the single
implementation both drivers will spawn (task 4.1 wires simulation
mode onto it). Independently verified bit-for-bit identical to the
pre-relocation bodies modulo the sched->/core-> rename; no statement
reordered, no branch changed.

sched_make_allocation() becomes extern (was static, sole caller moved
translation units); the old commit_decision() thin wrapper is deleted,
its sole caller now calls sched_commit_decision() directly with
identical semantics. sched_init() updated to spawn the relocated pair
against &(sched->core).

Adds an end-to-end fixture test proving a job flows from picked to a
committed decision against bare (non-xce_scheduler_t) core state.
Routes around, rather than fixes, two pre-existing out-of-boundary
gaps this fixture exposed (seqjob/parjob allocator init still reading
plugin->sched; make_sched_job()'s parse path not threading
maxtasks/mintasks) -- both documented in the test's own comments for
future follow-up.

sched_election.c added to the normal build only; sched_sim_isolation_lib
membership deferred to task 4.1, which is where sim mode actually
starts spawning these threads.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RLSNJhNoULvVcUhXEFafQC
This commit is contained in:
Rongsong Shen 2026-09-19 02:50:38 +00:00
parent fc23ea8d31
commit 4195331b47
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
8 changed files with 675 additions and 242 deletions

View file

@ -160,21 +160,25 @@ sched_picker_wiring_test = executable('sched_picker_wiring_test',
# Regression guard for the core scheduling loop boundary (scheduler-core
# spec, task 2.5, Req 1 AC 1 / AC 7): "the core loop calls only
# picker->next_job() ... no project/queue/job iteration or ordering logic
# remains in the loop itself." Does NOT #include scheduler.c (that file's
# external dependency surface is why test_picker_wiring.c's own header
# comment already ruled out driving sched_job_picker() directly) -- instead
# it reads scheduler.c's real on-disk text at test run time and mechanically
# checks sched_job_picker()'s body for required picker-interface call sites
# and absent direct-traversal symbols. XCE_SCHEDULER_C_PATH bakes in the
# absolute path via meson.current_source_dir() so the check has no
# dependency on the test's cwd at run time.
# remains in the loop itself." Does NOT #include sched_election.c (that
# file's external dependency surface is why test_picker_wiring.c's own
# header comment already ruled out driving sched_job_picker() directly) --
# instead it reads sched_election.c's real on-disk text at test run time and
# mechanically checks sched_job_picker()'s body for required picker-
# interface call sites and absent direct-traversal symbols.
# XCE_SCHED_ELECTION_C_PATH bakes in the absolute path via
# meson.current_source_dir() so the check has no dependency on the test's
# cwd at run time. Repointed from scheduler.c to sched_election.c
# (scheduler-sim-live-allocation spec, task 3.1): sched_job_picker() moved
# there, unchanged in body -- see that file's own header comment.
sched_picker_core_loop_boundary_test = executable(
'sched_picker_core_loop_boundary_test',
['test_picker_core_loop_boundary.c'],
include_directories:[incdir],
dependencies: [scheduler_test_deps],
c_args: ['-DXCE_SCHEDULER_C_PATH="'
+ (meson.current_source_dir() / '..' / 'src' / 'scheduler.c')
c_args: ['-DXCE_SCHED_ELECTION_C_PATH="'
+ (meson.current_source_dir() / '..' / 'src'
/ 'sched_election.c')
+ '"'],
install: false)
@ -2042,3 +2046,34 @@ sched_maxtasks_wiring_sim_driver_parity_test = executable(
test('scheduler maxtasks wiring sim driver parity test',
sched_maxtasks_wiring_sim_driver_parity_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
# scheduler-sim-live-allocation spec, task 3.1 (Req 1.1, 1.2, 5.1, boundary:
# Unified Picker/Allocator Threads): proves sched_job_picker()/
# sched_allocator() -- relocated out of scheduler.c into their own file,
# sched_election.c, and re-typed to cast their void* arg directly to
# xce_sched_core_t* -- run correctly when pthread_create() is handed
# nothing but a bare xce_sched_core_t*, the exact shape a future
# simulation driver (task 4.1) will use. Same real-scheduler_srcs link
# technique as sched_scheduler_dispatch_commit_test above (scheduler_srcs,
# defined in the parent meson.build, minus src/main.c, built via a loop so
# it can never drift from the production source list) -- no `-Wl,--wrap=`
# needed since this file never calls sched_init() (see the test file's own
# header comment for why a real, but never-sched_init()'d, xce_scheduler_t
# is still used incidentally during setup).
sched_election_sim_fixture_test_srcs = ['test_sched_election_sim_fixture.c']
foreach f : scheduler_srcs
if f != 'src/main.c'
sched_election_sim_fixture_test_srcs += ['../' + f]
endif
endforeach
sched_election_sim_fixture_test = executable(
'sched_election_sim_fixture_test',
sched_election_sim_fixture_test_srcs,
include_directories:[incdir],
dependencies: [scheduler_test_deps],
install: false)
test('scheduler election sim fixture test',
sched_election_sim_fixture_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])