feat(scheduler-sim-live-allocation): thread core state through allocation context and host search (task 2.1)

Retypes xce_sched_ctx_t.sched (sched/types.h) from void* to
xce_sched_core_t* outright, and sched_try_alloc_on_host_() (resource.c)
to take xce_sched_core_t* directly -- completing what tasks 1.2/1.3
left as temporary &(sched->core) call-site wraps. Removes the two
resulting struct-prefix casts entirely (schedobj.c's
sched_ctx_set_primary(), host_iter.c's sched_host_iter_next()): both
now pass core state through honestly, with no cast.

Updates every sched_ctx_init()/sched_try_alloc_on_host_() call site
tree-wide (scheduler.c, parjob_allocator.c, seqjob_allocator.c) with
zero change to host_iter/parjob/seqjob's own host-iteration/
bucket-construction algorithm.

Adds a driver-parity test for sched_try_alloc_on_host_() proving
identical grant/deny results from normal-mode-shaped and
simulation-mode-shaped core state.

Flags (for task 2.3) a confirmed-dead, type-confused write at
plugins/limit.c:319 (ctx.sched = plugin->sched) -- never read today,
left untouched since limit.c is task 2.3's boundary, not this one's.

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-18 13:52:14 +00:00
parent 55173fca27
commit d52c78e4be
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
14 changed files with 229 additions and 54 deletions

View file

@ -30,6 +30,16 @@ typedef struct {
struct xce_sched_obj_;
typedef struct xce_sched_obj_ xce_sched_obj_t;
/* scheduler-sim-live-allocation spec, task 2.1 (Core-Safe Allocation
* Chain): forward declaration only -- the full definition lives in core.h.
* Needed here so xce_sched_ctx_t.sched below can be honestly typed
* xce_sched_core_t* instead of a bare void* + cast at every read site. Same
* idiom already used by plugin.h/core.h (an identical repeated typedef is
* valid C11/gnu17 -- see bug-1489 -- so include order relative to core.h/
* plugin.h doesn't matter here either). */
struct xce_sched_core_s;
typedef struct xce_sched_core_s xce_sched_core_t;
/* Req 7.1 (scheduler-allocation spec): pre-computed resreq portion of the
* unsatisfiable-resreq cache key -- resource-usage shape only, independent
* of job identity (user/queue/project, which the full xce_cache_key_t adds
@ -157,7 +167,18 @@ typedef enum {
} xce_alloc_mode_t;
typedef struct {
void* sched;
/* scheduler-sim-live-allocation spec, task 2.1 (Core-Safe Allocation
* Chain): honestly typed as shared core state -- populated by
* sched_ctx_init()'s `arg` parameter (still void* there, since that
* init function is intentionally generic; the implicit void*-to-typed-
* pointer assignment needs no cast). Every caller of sched_ctx_init()
* now passes &(sched->core) (or an already-core-typed pointer, e.g. a
* simulation driver's own &(sim->core)) rather than a bare
* xce_scheduler_t* -- see resource.c's sched_try_alloc_on_host_(),
* host_iter.c's sched_host_iter_next(), and schedobj.c's
* sched_ctx_set_primary() for the leaf/middle consumers this replaces
* a void*+cast with a direct, honest read. */
xce_sched_core_t* sched;
xce_sched_worker_t* worker;
xce_sched_obj_t* schedobj;
xce_primary_resreq_t* primary;

View file

@ -360,8 +360,17 @@ extern xce_alloc_t** sched_make_allocs(xce_scheduler_t*, char*, int, int*,
* deleted) so both seqjob_allocator.c and parjob_allocator.c can call this
* shared Composition-Algorithm try_alloc leaf directly with real
* parameters, instead of each carrying its own private copy. */
/* scheduler-sim-live-allocation spec, task 2.1 (Core-Safe Allocation
* Chain): retyped from xce_scheduler_t* to xce_sched_core_t* -- callers
* still owning an xce_scheduler_t* (e.g. seqjob_allocator.c's/parjob_
* allocator.c's my_alloc()/parjob_try_plan_(), which derive their own
* `sched` from the plugin's separate, untouched xce_sched_plugin_t.sched
* field) pass &(sched->core); both xce_scheduler_t and
* xce_sched_sim_driver_t embed xce_sched_core_t core as their first-class
* field, so either driver's own core state satisfies this signature
* identically. */
extern int sched_try_alloc_on_host_(xce_sched_worker_t*,
xce_scheduler_t*,
xce_sched_core_t*,
xce_sched_ctx_t*);
extern int get_resvals(zarray_t*, int, int*, float*);
extern int put_resvals(zarray_t*, int, int*, float*);