feat(scheduler-core): extract xce_sched_core_t from monolithic scheduler struct (task 4.1)

Splits xce_scheduler_t along the controller-I/O seam: xce_sched_core_t
(new core.h/core.c) now holds all scheduling state (jobs/queues/workers/
users/projects/resource managers/plugins/three-thread-cbuf pipeline),
while xce_scheduler_t shrinks to {core; apictx; cluster_cfg}. Proven via
an nm-based link-time isolation test (zero netio/xcecli/idgen/delaymgr
symbols reachable from core.c) plus a reproducible wall-clock-call guard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dw5WnN3DXStaEaPYfACU1
This commit is contained in:
Rongsong Shen 2026-08-03 10:55:58 +00:00
parent 604a564904
commit 7c229284e2
Signed by: rshen
SSH key fingerprint: SHA256:8Vf2pZ3h6rJa7EhGK+WaAQ9Mta/apZvteW6g9U/WKKk
26 changed files with 1233 additions and 661 deletions

View file

@ -48,29 +48,22 @@
#include "scheduler.h"
#include "xstring.h"
/* Pull the real implementation under test into this TU. */
/* Pull the real implementations under test into this TU. sched_get_user/
* sched_get_project/sched_get_queue/sched_get_job/sched_add_user/
* sched_add_project/make_sched_user/make_sched_project relocated to core.c
* (scheduler-core spec, task 4.1) -- pulling core.c in alongside schedobj.c
* (rather than re-stubbing them) is what lets this file keep exercising the
* REAL make_sched_project, per this file's own header comment. */
#include "../src/core.c"
#include "../src/schedobj.c"
/* Stubs for scheduler-internal externs schedobj.c references but which are
* defined in other .c files not linked into this test (same set as
* test_job_update.c). Not exercised by the tests below -- present only to
* satisfy the linker for this whole-file #include. */
xce_sched_user_t* sched_get_user(xce_scheduler_t* s, char* n)
{
(void)s; (void)n; return NULL;
}
xce_sched_project_t* sched_get_project(xce_scheduler_t* s, char* n)
{
(void)s; (void)n; return NULL;
}
xce_sched_queue_t* sched_get_queue(xce_scheduler_t* s, char* n)
{
(void)s; (void)n; return NULL;
}
xce_sched_job_t* sched_get_job(xce_scheduler_t* s, uint64_t jobid)
{
(void)s; (void)jobid; return NULL;
}
/* Stubs for scheduler-internal externs schedobj.c/core.c reference but
* which are defined in other .c files not linked into this test. Not
* exercised by the tests below -- present only to satisfy the linker for
* this whole-file #include. plugin_unregister is core.c's kvmgr datakiller
* for the (never-called-in-this-test) plugins kvmgr inside
* xce_sched_core_init() -- still needs a resolvable address even though
* that code path never runs here. */
int plugin_job_update(void* s, xce_sched_job_t* j) { (void)s; (void)j; return 0; }
int plugin_queue_update(void* s, xce_sched_queue_t* q) { (void)s; (void)q; return 0; }
int plugin_job_rusage_update(void* s, xce_sched_job_t* j, xce_job_rusages_t* r)
@ -78,11 +71,10 @@ int plugin_job_rusage_update(void* s, xce_sched_job_t* j, xce_job_rusages_t* r)
(void)s; (void)j; (void)r; return 0;
}
xce_job_account_t* make_job_account(xce_job_alloc_t* a) { (void)a; return NULL; }
void free_job_account(xce_job_account_t* a) { (void)a; }
int sched_add_user(xce_scheduler_t* s, xce_sched_user_t* u) { (void)s; (void)u; return 0; }
int sched_add_project(xce_scheduler_t* s, xce_sched_project_t* p) { (void)s; (void)p; return 0; }
void free_job_account(xce_job_account_t* a) { (void)a; }
void sched_worker_release_host_ctx(xce_sched_worker_t* w) { (void)w; }
int plugin_prepare_allocation(void* s, xce_sched_ctx_t* c) { (void)s; (void)c; return 0; }
void plugin_unregister(void* arg) { (void)arg; }
void setUp(void) { return; }
void tearDown(void) { return; }
@ -117,12 +109,12 @@ static void test_scheduler_job_pick_plugin_field_is_char_star_and_unset_by_defau
xce_scheduler_t sched;
fixture_init(&sched);
TEST_ASSERT_NULL(sched.job_pick_plugin);
TEST_ASSERT_NULL(sched.core.job_pick_plugin);
/* Type check: assigning a char* literal must compile without a cast --
* this is a compile-time proof of the declared field type. */
sched.job_pick_plugin = "some_name";
TEST_ASSERT_EQUAL_STRING("some_name", sched.job_pick_plugin);
sched.core.job_pick_plugin = "some_name";
TEST_ASSERT_EQUAL_STRING("some_name", sched.core.job_pick_plugin);
}
/* Req 2 AC 1's literal wording: "defaulting to builtin_fcfs when unset". */
@ -131,12 +123,12 @@ static void test_sched_set_default_job_pick_plugin_applies_builtin_fcfs_when_uns
xce_scheduler_t sched;
fixture_init(&sched);
TEST_ASSERT_NULL(sched.job_pick_plugin);
TEST_ASSERT_NULL(sched.core.job_pick_plugin);
sched_set_default_job_pick_plugin(&sched);
TEST_ASSERT_NOT_NULL(sched.job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.job_pick_plugin);
TEST_ASSERT_NOT_NULL(sched.core.job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.core.job_pick_plugin);
}
/* "...when unset" implies idempotence: an already-configured name (however
@ -147,11 +139,11 @@ test_sched_set_default_job_pick_plugin_does_not_clobber_configured_value(void)
xce_scheduler_t sched;
fixture_init(&sched);
sched.job_pick_plugin = makeString("priority_picker");
sched.core.job_pick_plugin = makeString("priority_picker");
sched_set_default_job_pick_plugin(&sched);
TEST_ASSERT_EQUAL_STRING("priority_picker", sched.job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("priority_picker", sched.core.job_pick_plugin);
}
static void test_sched_set_default_job_pick_plugin_is_null_safe(void)
@ -201,7 +193,7 @@ static void test_queue_with_no_override_inherits_global_picker_name(void)
TEST_ASSERT_NOT_NULL(queue);
TEST_ASSERT_NULL(queue->job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.core.job_pick_plugin);
}
/* tasks.md Observable, half 2: "a queue config with an override reports
@ -228,8 +220,9 @@ test_queue_with_override_reports_its_own_override_not_global_default(void)
TEST_ASSERT_NOT_NULL(queue->job_pick_plugin);
TEST_ASSERT_EQUAL_STRING("priority_picker", queue->job_pick_plugin);
/* The override is reported, NOT the global default. */
TEST_ASSERT_TRUE(strcmp(queue->job_pick_plugin, sched.job_pick_plugin) != 0);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.job_pick_plugin);
TEST_ASSERT_TRUE(strcmp(queue->job_pick_plugin, sched.core.job_pick_plugin)
!= 0);
TEST_ASSERT_EQUAL_STRING("builtin_fcfs", sched.core.job_pick_plugin);
}
/* project_name is independently settable/readable (structural field check
@ -263,7 +256,7 @@ static void test_make_sched_project_priority_field_defaults_to_zero(void)
fixture_init(&sched);
project = make_sched_project(&sched, "acct-42");
project = make_sched_project(&sched.core, "acct-42");
TEST_ASSERT_NOT_NULL(project);
TEST_ASSERT_EQUAL_STRING("acct-42", project->name);
@ -281,7 +274,7 @@ static void test_project_priority_field_is_int32_and_independently_settable(void
fixture_init(&sched);
project = make_sched_project(&sched, "acct-7");
project = make_sched_project(&sched.core, "acct-7");
project->priority = 7;
TEST_ASSERT_EQUAL_INT32(7, project->priority);