myxce/src/scheduler/include/decision.h
Rongsong Shen de69b6288d
feat(scheduler-core): implement session-start signal + decision callback (task 4.4)
Adds xce_core_go()/xce_core_end_session() (new core_session.c):
xce_core_go() is non-blocking, performs begin-session state reset
(select-eval-ctx, resval resets), signals the picker thread via wbuf,
and returns -EINVAL on a reentrant call while a session is already
active (proven a true no-op, not just an early return). Draining
core->decisions and invoking the driver's on_decision callback is the
driver's own responsibility between core_go() and core_end_session()
(confirmed driver-owned, not core-owned, per the Driver <-> Core
protocol). xce_core_set_decision_cb() registers the callback + driver
context as a separate setter, keeping xce_sched_core_init()'s live
sched_init() call site untouched. Adds XCE_DECISION_PREEMPT to
decision.h (jobid/victims[]/reason) alongside the existing DISPATCH/
PEND types. Additive only — sched_go/sched_begin_session/
sched_end_session/sched_allocator/main.c remain untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dw5WnN3DXStaEaPYfACU1
2026-08-04 03:08:18 +00:00

55 lines
1.6 KiB
C

#if !defined(_DECISION_H_)
#define _DECISION_H_ 1
#include "xce/types.h"
#include <stdint.h>
typedef enum {
XCE_DECISION_NONE = 0,
XCE_DECISION_DISPATCH,
XCE_DECISION_PEND,
XCE_DECISION_NEW_SESSION,
XCE_DECISION_PREEMPT
} xce_decision_op_t;
/*
* xce_preempt_victim_t / xce_preempt_t - PREEMPT decision payload
* (scheduler-core spec, task 4.4, Req 5 AC 6). Scheduler-owned (not
* xce/types.h): design.md's Boundary Commitments note that the PREEMPT
* wire shape is owned by this spec while victim-*selection* semantics
* belong to the (separate, not-yet-implemented) scheduler-preemption spec
* -- so these two structs carry exactly AC 6's field list ("jobid,
* victims[] (jobid, workerid per victim), reason") and nothing more.
*
* `victims` follows the same "int count; T** items" idiom as
* xce_job_dispatch_t.allocs / xce_preason_set_t.reasons (xce/types.h) --
* an array of pointers, not a flat array, for consistency with every other
* decision-adjacent list in this codebase.
*/
typedef struct {
uint64_t jobid;
char* workerid;
} xce_preempt_victim_t;
typedef struct {
uint64_t jobid;
int nvictims;
xce_preempt_victim_t** victims;
xce_pendreason_t* reason;
} xce_preempt_t;
typedef struct {
xce_decision_op_t op;
union {
xce_job_alloc_t* alloc;
xce_pendreason_t* reason;
xce_preempt_t* preempt;
} u;
} xce_decision_t;
extern xce_decision_t* make_pend_decision(xce_pendreason_t*);
extern xce_decision_t* make_dispatch_decision(xce_job_alloc_t*);
extern xce_decision_t* make_preempt_decision(xce_preempt_t*);
#endif