feat(libxce-alloc-preason-equality): recorded dispatch fixtures carry the session-start from (task 4.2)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-09-28 10:44:00 +00:00
parent 6110d12e5a
commit 69112c2d22
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
7 changed files with 137 additions and 60 deletions

View file

@ -842,13 +842,26 @@ static float lookup_want(uint64_t jobid)
return 0.0f;
}
/* SESSION_FROM - the `from` an allocation decided in a session that began at
* `begin_ns` (epoch nanoseconds) carries: the session start in whole
* seconds, floor division (libxce-alloc-preason-equality Decision 8;
* scheduler.c's sched_make_primary_alloc_() stamps it, and in simulation
* mode the session starts at the recorded beginRound). Hand-built recorded
* DISPATCH fixtures derive their `from` from the begin_round they are
* recorded under, so a live replay of the same round reproduces it. */
#define SESSION_FROM(begin_ns) ((uint64_t)(begin_ns) / 1000000000ULL)
/* The recorded round-1 beginRound the hand-built DISPATCH fixtures below
* are appended under (logical nanoseconds). */
#define ROUND1_BEGIN_NS 2000ULL
/* Builds the wire-shaped xce_job_alloc_t a DISPATCH decision carries --
* shared by BOTH Part A's real dispatch construction below AND Part B's
* hand-crafted decisions further down -- same field shape
* test_sim_verify.c's own make_test_alloc()/make_test_host_alloc()/
* make_test_job_alloc() establish. */
static xce_job_alloc_t* make_dispatch_alloc(uint64_t jobid, const char* host,
float value)
float value, uint64_t from)
{
xce_alloc_t* res = (xce_alloc_t*)calloc(1, sizeof(*res));
xce_host_alloc_t* h = (xce_host_alloc_t*)calloc(1, sizeof(*h));
@ -866,7 +879,7 @@ static xce_job_alloc_t* make_dispatch_alloc(uint64_t jobid, const char* host,
res->reserve = strdup("run");
res->instid = 1;
res->value = value;
res->from = 0;
res->from = from;
res->duration = 0;
allocs[0] = res;
@ -996,7 +1009,12 @@ static void* capacity_aware_allocator_thread_fn(void* arg)
g_slots_residx_normal, want);
sched_commit_job_alloc(core, job);
job->allocs = make_dispatch_alloc(jobid, WORKER_NAME, want);
/* Stamp `from` exactly as sched_make_primary_alloc_()
* (scheduler.c) stamps a real allocation: the deciding
* session's start in whole seconds. */
job->allocs = make_dispatch_alloc(
jobid, WORKER_NAME, want,
SESSION_FROM(core->session_start));
/* This file's own addition -- see this function's header
* comment for why this is required. */
@ -1416,13 +1434,15 @@ test_contention_parity_matches_real_normal_mode_recording_round_by_round(
append_job_state_change_event(f, 1800ULL, JOBC_ID, JOB_STAT_PEND,
JOB_STAT_RUN);
allocA = make_dispatch_alloc(JOBA_ID, WORKER_NAME, JOBA_WANT);
allocC = make_dispatch_alloc(JOBC_ID, WORKER_NAME, JOBC_WANT);
allocA = make_dispatch_alloc(JOBA_ID, WORKER_NAME, JOBA_WANT,
SESSION_FROM(ROUND1_BEGIN_NS));
allocC = make_dispatch_alloc(JOBC_ID, WORKER_NAME, JOBC_WANT,
SESSION_FROM(ROUND1_BEGIN_NS));
round1_decisions[0] = make_decision_dispatch(2000ULL, allocA);
round1_decisions[1] = make_decision_dispatch(2000ULL, allocC);
round1_decisions[2] = make_decision_pend(2000ULL, JOBB_ID, 0);
append_replay_session(f, 2000ULL, round1_decisions, 3);
round1_decisions[0] = make_decision_dispatch(ROUND1_BEGIN_NS, allocA);
round1_decisions[1] = make_decision_dispatch(ROUND1_BEGIN_NS, allocC);
round1_decisions[2] = make_decision_pend(ROUND1_BEGIN_NS, JOBB_ID, 0);
append_replay_session(f, ROUND1_BEGIN_NS, round1_decisions, 3);
/* Round 2: job D pushed fresh -- no reconciliation involved (D was
* never dispatched anywhere); sim's own live picker independently
@ -1707,12 +1727,14 @@ static void write_multiround_contention_rounds(FILE* f, int upto_round)
append_jobs_push_event(f, 1500ULL, JOBB_ID, "normal");
append_jobs_push_event(f, 1500ULL, JOBC_ID, "normal");
allocA = make_dispatch_alloc(JOBA_ID, WORKER_NAME, JOBA_WANT);
allocC = make_dispatch_alloc(JOBC_ID, WORKER_NAME, JOBC_WANT);
round1_decisions[0] = make_decision_dispatch(2000ULL, allocA);
round1_decisions[1] = make_decision_dispatch(2000ULL, allocC);
round1_decisions[2] = make_decision_pend(2000ULL, JOBB_ID, 0);
append_replay_session(f, 2000ULL, round1_decisions, 3);
allocA = make_dispatch_alloc(JOBA_ID, WORKER_NAME, JOBA_WANT,
SESSION_FROM(ROUND1_BEGIN_NS));
allocC = make_dispatch_alloc(JOBC_ID, WORKER_NAME, JOBC_WANT,
SESSION_FROM(ROUND1_BEGIN_NS));
round1_decisions[0] = make_decision_dispatch(ROUND1_BEGIN_NS, allocA);
round1_decisions[1] = make_decision_dispatch(ROUND1_BEGIN_NS, allocC);
round1_decisions[2] = make_decision_pend(ROUND1_BEGIN_NS, JOBB_ID, 0);
append_replay_session(f, ROUND1_BEGIN_NS, round1_decisions, 3);
if (upto_round < 2) {
return;