save works

This commit is contained in:
Rongsong Shen 2025-12-18 10:23:43 +08:00
parent f44ad07116
commit d0174f2f30
7 changed files with 241 additions and 12 deletions

View file

@ -6,6 +6,7 @@
#include <string.h>
#include "client.h"
#include "controller.capnp.h"
#include "scheduler.h"
#include "utils.h"
@ -61,7 +62,8 @@ static void* sched_allocator(void* arg)
cbuf_get(&(sched->jbuf), &jobid);
if (jobid == 0) {
/* end of scheduling session */
cbuf_put(&(sched->decisions), NULL);
decision = NULL;
cbuf_put(&(sched->decisions), &decision);
continue;
}
@ -74,6 +76,40 @@ static void* sched_allocator(void* arg)
return NULL;
}
static void sched_pend_update_killer(data_item_t* it)
{
xce_sched_update_request_t* req;
int i;
if (it == NULL) {
return;
}
req = ITPTR_TO_UPDATE_REQ(it);
switch (req->op) {
case XCE_SCHED_OP_UPDATE_CONFIG:
break;
case XCE_SCHED_OP_UPDATE_JOB:
for (i = 0; i < req->u.jobupdate.njobs; i++) {
free_Job_ptr(&(req->u.jobupdate.jobs[i]));
}
free(req->u.jobupdate.jobs);
break;
case XCE_SCHED_OP_UPDATE_WORKER:
for (i = 0; i < req->u.workerupdate.nworkers; i++) {
free_Worker_ptr(&(req->u.workerupdate.workers[i]));
}
free(req->u.workerupdate.workers);
break;
default:
break;
}
free(req);
}
int sched_init(xce_scheduler_t* sched, xce_client_config_t* config,
xce_request_handler_t handler)
{
@ -87,10 +123,17 @@ int sched_init(xce_scheduler_t* sched, xce_client_config_t* config,
memset(sched, 0x0, sizeof(*sched));
mylock_init(&(sched->lock));
cbuf_init(&(sched->wbuf), 1, sizeof(int));
cbuf_init(&(sched->jbuf), njobs, sizeof(uint64_t));
cbuf_init(&(sched->decisions), ndecisions, sizeof(xce_decision_t*));
sched->pend_updates[0] = (dataq_t*)calloc(1, sizeof(dataq_t));
dataq_init(sched->pend_updates[0], sched_pend_update_killer);
sched->pend_updates[1] = (dataq_t*)calloc(1, sizeof(dataq_t));
dataq_init(sched->pend_updates[1], sched_pend_update_killer);
rc = xcecli_ctx_init(&(sched->apictx), config);
if (rc < 0) {
return rc;
@ -140,10 +183,14 @@ void sched_fini(xce_scheduler_t* sched)
cbuf_fini(&(sched->jbuf));
cbuf_fini(&(sched->wbuf));
dataq_fini(sched->pend_updates[0]);
dataq_fini(sched->pend_updates[1]);
mylock_fini(&(sched->lock));
return;
}
#if 0
static int sched_update_config(xce_scheduler_t* sched, xce_conf4sched_t* config)
{
return 0;
@ -160,9 +207,55 @@ static int sched_update_workers(xce_scheduler_t* sched, int nworkers,
{
return 0;
}
#endif
int sched_update(xce_scheduler_t* sched) { return 0; }
int sched_update(xce_scheduler_t* sched)
{
dataq_t* q = NULL;
/* swap dataq */
mylock_lock(&(sched->lock));
q = sched->pend_updates[0];
sched->pend_updates[0] = sched->pend_updates[1];
sched->pend_updates[1] = q;
mylock_unlock(&(sched->lock));
while (1) {
data_item_t* it;
xce_sched_update_request_t* req;
int rc;
it = dataq_deq(q, NULL);
if (it == NULL) {
break;
}
req = ITPTR_TO_UPDATE_REQ(it);
switch (req->op) {
case XCE_SCHED_OP_UPDATE_CONFIG:
rc = sched_update_config(sched, req->u.config);
break;
case XCE_SCHED_OP_UPDATE_JOB:
rc = sched_update_jobs(sched, req->u.jobupdate.njobs,
req->u.jobupdate.jobs);
break;
case XCE_SCHED_OP_UPDATE_WORKER:
rc = sched_update_workers(sched, req->u.workerupdate.nworkers,
req->u.workerupdate.workers);
break;
default:
rc = -EINVAL;
break;
}
sched_pend_update_killer(it);
if (rc < 0) {
/* something wrong? */
}
}
return 0;
}
void sched_go(xce_scheduler_t* sched)
{