myxce/src/scheduler/include/scheduler.h
2025-12-28 14:51:54 +08:00

96 lines
3.3 KiB
C

#if !defined(_SCHEDULER_H_)
#define _SCHEDULER_H_ 1
#include <pthread.h>
#include <stdint.h>
#include <time.h>
#include "client.h"
#include "dataq.h"
#include "decision.h"
#include "kvmgr.h"
#include "mylock.h"
#include "plugin.h"
#include "xce/types.h"
#include "xlist.h"
typedef enum {
XCE_SCHED_OP_NONE = 0,
XCE_SCHED_OP_UPDATE_CONFIG,
XCE_SCHED_OP_UPDATE_JOB,
XCE_SCHED_OP_JSTATE_CHANGE,
XCE_SCHED_OP_UPDATE_WORKER
} xce_sched_op_t;
typedef struct {
data_item_t link;
xce_sched_op_t op;
union {
xce_conf4sched_t* config;
struct {
int njobs;
xce_job_t** jobs;
} jobupdate;
struct {
int nworkers;
xce_worker_t** workers;
} workerupdate;
struct {
uint64_t jobid;
uint32_t state;
} job_state_change;
} u;
} xce_sched_update_request_t;
#define ITPTR_TO_UPDATE_REQ(p) \
((xce_sched_update_request_t*)(((char*)p) \
- offsetof(xce_sched_update_request_t, \
link)))
typedef struct {
mylock_t lock;
int stop;
xcecli_ctx_t apictx;
xce_conf4sched_t* config;
kvmgr_t plugins;
dataq_t* pend_updates[2];
resmgr_t resmgr;
zarray_t sharedInst;
kvmgr_t jobs;
kvmgr_t queues;
kvmgr_t workers;
kvmgr_t users;
kvmgr_t projects;
pthread_t jobpicker;
pthread_t allocator;
cbuf_t wbuf; /* action to trigger scheduling */
cbuf_t jbuf; /* job picked for allocation */
cbuf_t decisions; /* scheduler decisions */
} xce_scheduler_t;
extern int sched_init(xce_scheduler_t*, xce_client_config_t*,
xce_request_handler_t);
extern void sched_fini(xce_scheduler_t*);
extern int sched_init_config(xce_scheduler_t* sched, xce_conf4sched_t*);
extern int sched_update(xce_scheduler_t*);
extern void sched_go(xce_scheduler_t*);
extern void sched_begin_session(xce_scheduler_t*);
extern void sched_end_session(xce_scheduler_t*);
extern xce_sched_job_t* sched_get_job(xce_scheduler_t*, uint64_t);
extern xce_sched_queue_t* sched_get_queue(xce_scheduler_t*, char*);
extern xce_sched_worker_t* sched_get_worker(xce_scheduler_t*, char*);
extern xce_sched_user_t* sched_get_user(xce_scheduler_t*, char*);
extern xce_sched_project_t* sched_get_project(xce_scheduler_t*, char*);
extern int sched_add_job(xce_scheduler_t*, xce_sched_job_t*);
extern int sched_add_queue(xce_scheduler_t*, xce_sched_queue_t*);
extern int sched_add_user(xce_scheduler_t*, xce_sched_user_t*);
extern int sched_add_worker(xce_scheduler_t*, xce_sched_worker_t*);
extern int sched_add_project(xce_scheduler_t*, xce_sched_project_t*);
extern int sched_job_is_ready(xce_sched_job_t*);
extern int sched_queue_is_ready(xce_sched_queue_t*);
extern int sched_commit_decision(xce_scheduler_t*, xce_decision_t*);
extern int sched_publish_pend_reason(xce_scheduler_t*, xce_preason_set_t*);
extern int sched_publish_dispatch(xce_scheduler_t*, xce_job_dispatch_t*);
#endif