myxce/src/scheduler/include/scheduler.h
2025-12-18 14:55:58 +08:00

101 lines
2.5 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 "mylock.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_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;
} 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 void* host_selection_t;
typedef struct {
host_selection_t* select;
int nres;
uint32_t* resources;
float* amount;
} rank_req_t;
typedef struct {
uint64_t jobid;
time_t sub_time;
time_t queue_time;
time_t start_time;
unsigned int state;
char* queue;
char* user;
char* project;
uint32_t mintasks;
uint32_t maxtasks;
xce_job_alloc_t* allocs;
} xce_sched_job_t;
typedef struct {
char* name;
uint32_t attrs;
uint32_t status;
int32_t priority;
int32_t accept_interval;
int32_t sched_delay;
char* resreq;
} xce_sched_queue_t;
typedef struct {
char* name;
xce_val_t* res_avail; /* resources in worker */
xce_val_t* res_in_use; /* used resources in worker */
} xce_sched_worker_t;
typedef struct {
mylock_t lock;
int stop;
xcecli_ctx_t apictx;
dataq_t* pend_updates[2];
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_update(xce_scheduler_t*);
extern void sched_go(xce_scheduler_t*);
#endif