From d8b5cf87180e807c709b512e1f3a8aba55217c37 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Fri, 4 Sep 2026 15:17:30 +0000 Subject: [PATCH] feat(scheduler-allocation): add forward-compatible allocation-mode field Adds xce_alloc_mode_t (XCE_ALLOC_NORMAL=0, XCE_ALLOC_PREEMPT, with commented-out RESERVE/BACKFILL placeholders) and alloc_mode on xce_sched_ctx_t, zero-defaulted by sched_ctx_init()'s existing memset. Purely additive: nothing branches on the field yet -- this spec only declares the extension point scheduler-preemption needs. Task 1.3 (scheduler-allocation spec). Requirement 9.5. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01XYdtrEWWZfKRRGED7raEYg --- .kiro/specs/scheduler-allocation/tasks.md | 2 +- src/scheduler/include/sched/types.h | 20 +++++++++++++++ src/scheduler/testsuite/test_job_update.c | 31 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/.kiro/specs/scheduler-allocation/tasks.md b/.kiro/specs/scheduler-allocation/tasks.md index 0975fd1d..c49d8ee1 100644 --- a/.kiro/specs/scheduler-allocation/tasks.md +++ b/.kiro/specs/scheduler-allocation/tasks.md @@ -12,7 +12,7 @@ - Write a unit test proving the fingerprint is stable across repeated computation for an identical resource request and differs when any contributing field changes - Observable: a passing test demonstrates identical requests produce identical fingerprints and any differing field changes the fingerprint - _Requirements: 7.1_ -- [ ] 1.3 Add the forward-compatible allocation-mode field +- [x] 1.3 Add the forward-compatible allocation-mode field - Add an allocation-mode field to the per-attempt allocation context, defaulting to normal-resources-only - Observable: the field exists, defaults correctly, and no existing allocation code path branches on any value other than the default - _Requirements: 9.5_ diff --git a/src/scheduler/include/sched/types.h b/src/scheduler/include/sched/types.h index eb5715cd..91934968 100644 --- a/src/scheduler/include/sched/types.h +++ b/src/scheduler/include/sched/types.h @@ -140,6 +140,22 @@ typedef struct { host_eval_ctx_t* host_eval_ctx; /* cached per-session; NULL until first use */ } xce_sched_worker_t; +/* Req 9.5 (scheduler-allocation spec): forward-compatible resource-pool-mode + * extension point on xce_sched_ctx_t. v1 (this spec) implements only + * XCE_ALLOC_NORMAL -- no allocation code path branches on any other value. + * XCE_ALLOC_PREEMPT's actual resource-borrowing behavior belongs to the + * scheduler-preemption spec; the "Future:" entries are scaffolding for + * later resource-pool modes (e.g. reservation-aware backfill) and are not + * implemented by anything yet. */ +typedef enum { + XCE_ALLOC_NORMAL = 0, /* only truly free resources */ + XCE_ALLOC_PREEMPT, /* count preemptible job resources as available */ + /* Future: + * XCE_ALLOC_RESERVE, // count reserved-but-idle resources as available + * XCE_ALLOC_BACKFILL, // count reserved + preemptible resources + */ +} xce_alloc_mode_t; + typedef struct { void* sched; xce_sched_worker_t* worker; @@ -155,6 +171,10 @@ typedef struct { xce_sched_alloc_req_t alloc_req; xce_job_alloc_t* alloc; xce_pendreason_t* reason; + /* Req 9.5: defaults to XCE_ALLOC_NORMAL via sched_ctx_init()'s existing + * memset(ctx, 0, sizeof(*ctx)) -- XCE_ALLOC_NORMAL is the enum's zero + * value, so no explicit assignment is needed. */ + xce_alloc_mode_t alloc_mode; } xce_sched_ctx_t; typedef struct { diff --git a/src/scheduler/testsuite/test_job_update.c b/src/scheduler/testsuite/test_job_update.c index 75a2566a..233cdf1e 100644 --- a/src/scheduler/testsuite/test_job_update.c +++ b/src/scheduler/testsuite/test_job_update.c @@ -372,6 +372,36 @@ test_update_queue_null_returns_einval(void) TEST_ASSERT_EQUAL_INT(-EINVAL, sched_update_existing_queue(&sched, NULL)); } +/* Allocation-mode extension point (scheduler-allocation spec, task 1.3, + * Req 9.5). Pulls the REAL sched_ctx_init() (via the schedobj.c #include + * above) to prove memset-zero-init alone defaults a freshly-initialized + * xce_sched_ctx_t's alloc_mode to XCE_ALLOC_NORMAL -- no explicit + * assignment needed in sched_ctx_init() since XCE_ALLOC_NORMAL is the + * enum's zero value. */ + +static void +test_ctx_init_defaults_alloc_mode_to_normal(void) +{ + xce_scheduler_t sched; + fixture_init(&sched); + + /* XCE_ALLOC_NORMAL must be exactly 0 for memset-zero-init to default + * to it -- pin the enum value itself, not just the observed field. */ + TEST_ASSERT_EQUAL_INT(0, XCE_ALLOC_NORMAL); + + xce_sched_obj_t obj; + memset(&obj, 0, sizeof(obj)); + obj.tag = XCE_RESREQ_PRIMARY; + + xce_sched_ctx_t ctx; + int rc = sched_ctx_init(&ctx, &sched, &obj); + + TEST_ASSERT_EQUAL_INT(0, rc); + TEST_ASSERT_EQUAL_INT(XCE_ALLOC_NORMAL, ctx.alloc_mode); + + sched_ctx_fini(&ctx); +} + int main(int argc, char* argv[]) { (void)argc; (void)argv; @@ -386,5 +416,6 @@ int main(int argc, char* argv[]) RUN_TEST(test_update_existing_queue_real, 0); RUN_TEST(test_update_unknown_queue_returns_enoent, 0); RUN_TEST(test_update_queue_null_returns_einval, 0); + RUN_TEST(test_ctx_init_defaults_alloc_mode_to_normal, 0); return UNITY_END(); }