create framework of scheduler
This commit is contained in:
parent
486b38d679
commit
30824ae5ea
6 changed files with 167 additions and 48 deletions
101
src/scheduler/src/scheduler.c
Normal file
101
src/scheduler/src/scheduler.c
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "client.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
int sched_init(xce_scheduler_t* sched, xce_client_config_t* config,
|
||||
xce_request_handler_t handler)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ((sched == NULL) || (config == NULL) || (handler == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(sched, 0x0, sizeof(*sched));
|
||||
|
||||
/* FIXME: configurable delta for xlist_init()? */
|
||||
xlist_init(&(sched->decisions), 32);
|
||||
|
||||
rc = xcecli_ctx_init(&(sched->apictx), config);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
xcecli_set_handler(sched->apictx, handler, sched);
|
||||
|
||||
rc = xcecli_start(sched->apictx);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return xcecli_join(sched->apictx, HostRole_scheduler, NULL);
|
||||
}
|
||||
|
||||
void sched_fini(xce_scheduler_t* sched)
|
||||
{
|
||||
xcecli_wakeup(sched->apictx, (int)-EINTR);
|
||||
xcecli_stop(sched->apictx);
|
||||
xcecli_ctx_fini(sched->apictx);
|
||||
|
||||
xlist_fini(&(sched->decisions));
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int sched_update_config(xce_scheduler_t* sched, xce_conf4sched_t* config)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sched_update_jobs(xce_scheduler_t* sched, int njobs,
|
||||
xce_job_t** jobs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sched_update_workers(xce_scheduler_t* sched, int nworkers,
|
||||
xce_worker_t** workers)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int sched_update(xce_scheduler_t* sched) { return 0; }
|
||||
|
||||
static xce_job_t* pick_job(xce_scheduler_t* sched) { return NULL; }
|
||||
|
||||
static int calc_job_decision(xce_scheduler_t* sched, xce_job_t* job,
|
||||
xce_decision_t** decision)
|
||||
{
|
||||
*decision = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sched_go(xce_scheduler_t* sched)
|
||||
{
|
||||
uint32_t njobs = 0;
|
||||
|
||||
while (1) {
|
||||
xce_job_t* job = NULL;
|
||||
xce_decision_t* decision = NULL;
|
||||
int rc = 0;
|
||||
|
||||
job = pick_job(sched);
|
||||
if (job == NULL) {
|
||||
return njobs;
|
||||
}
|
||||
|
||||
rc = calc_job_decision(sched, job, &decision);
|
||||
if (rc > 0) {
|
||||
njobs++;
|
||||
/* put decision of output list */
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue