fix pkt size problem and fmt_jobid

This commit is contained in:
Rongsong Shen 2025-12-24 17:56:45 +08:00
parent 088afe4ea0
commit 4034fd7556
15 changed files with 130 additions and 64 deletions

12
src/flake.lock generated
View file

@ -92,11 +92,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1764667669, "lastModified": 1766309749,
"narHash": "sha256-7WUCZfmqLAssbDqwg9cUDAXrSoXN79eEEq17qhTNM/Y=", "narHash": "sha256-3xY8CZ4rSnQ0NqGhMKAy5vgC+2IVK0NoVEzDoOh4DA4=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "418468ac9527e799809c900eda37cbff999199b6", "rev": "a6531044f6d0bef691ea18d4d4ce44d0daa6e816",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -181,11 +181,11 @@
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1764926264, "lastModified": 1766562395,
"narHash": "sha256-1N8BKVwxESYUjU4SwDFhb7moCwT9lvkqiq0kmdrjeg4=", "narHash": "sha256-bbnbjJ2sru/2YqHN1jzdYs+khOhrjngaRLBJFd5nQ4Y=",
"owner": "shen390s", "owner": "shen390s",
"repo": "my-nix-channel", "repo": "my-nix-channel",
"rev": "597aa03bdb99a95853744acd349f113a9cd2b3cd", "rev": "828497661dbef0721ca1aceb0b76fd71086a720b",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -26,7 +26,7 @@ typedef struct {
typedef struct { typedef struct {
data_item_t link; data_item_t link;
uint16_t sz; uint64_t sz;
char* data; char* data;
} io_packet_t; } io_packet_t;

View file

@ -44,8 +44,7 @@
MAKE_JOBID(EXTRACT_ID_CLUSTER(id), EXTRACT_ID_APISERVER(id), \ MAKE_JOBID(EXTRACT_ID_CLUSTER(id), EXTRACT_ID_APISERVER(id), \
EXTRACT_ID_TIMESTAMP(id), 0x0, EXTRACT_ARRAY_JOB(id)) EXTRACT_ID_TIMESTAMP(id), 0x0, EXTRACT_ARRAY_JOB(id))
#define EXTRACT_ARRAY_IDX(id) \ #define EXTRACT_ARRAY_IDX(id) EXTRACT_BITS(id, 0, N_ARRAY_IDX_BITS)
EXTRACT_BITS(id, 0, (N_SEQUENCE_BITS - SEQUENCE_HIGH_SHIFT))
#define ROUNDUP(v, bits) (((v) + UMAX_BITS(bits)) & ~UMAX_BITS(bits)) #define ROUNDUP(v, bits) (((v) + UMAX_BITS(bits)) & ~UMAX_BITS(bits))

View file

@ -357,6 +357,12 @@ typedef struct {
#define QUEUE_STAT_FAIRSHARE_DEFAULT \ #define QUEUE_STAT_FAIRSHARE_DEFAULT \
0x20 /**< Fairshare queue with null user share defined*/ 0x20 /**< Fairshare queue with null user share defined*/
/* FIXME: improve following later */
#define JOB_IS_PEND(j) ((j->state & JOB_STAT_PEND) != 0)
#define JOB_IS_RUN(j) ((j->state & JOB_STAT_RUN) != 0)
#define JOB_IS_EXIT(j) ((j->state & JOB_STAT_EXIT) != 0)
#define JOB_IS_DONE(j) ((j->state & JOB_STAT_DONE) != 0)
typedef enum { typedef enum {
NORMAL = 0, NORMAL = 0,
TTY, TTY,

View file

@ -80,7 +80,7 @@ xce_host_alloc_t** make_host_allocs(int nhosts, ...)
int i; int i;
va_list ap; va_list ap;
if (nhosts == NULL) { if (nhosts <= 0) {
return NULL; return NULL;
} }

View file

@ -29,7 +29,9 @@ stdenv.mkDerivation {
readline readline
ncurses ncurses
struct2json struct2json
capnpc (capnpc.overrideAttrs (oldAttrs: {
separateDebugInfo = true;
}))
which which
findutils findutils
(libuv.overrideAttrs (oldAttrs: { (libuv.overrideAttrs (oldAttrs: {
@ -50,7 +52,9 @@ stdenv.mkDerivation {
libcyaml libcyaml
libyaml libyaml
libcgroup libcgroup
extralib (extralib.overrideAttrs (oldAttrs: {
separateDebugInfo = true;
}))
]; ];
build-system = [ pkgs.meson ]; build-system = [ pkgs.meson ];

View file

@ -11,7 +11,8 @@
typedef void* plugin_data_t; typedef void* plugin_data_t;
/* hooker of plugin, the first parameter should be xce_sched_plugin_t */ /* hooker of plugin, the first parameter should be xce_sched_plugin_t */
typedef int (*plugin_update_config_hook_t)(void*, xce_conf4sched_t*); typedef int (*plugin_update_config_hook_t)(void*, xce_conf4sched_t*,
xce_conf4sched_t*);
typedef int (*plugin_update_queue_hook_t)(void*, xce_sched_queue_t*, typedef int (*plugin_update_queue_hook_t)(void*, xce_sched_queue_t*,
xce_sched_queue_t*); xce_sched_queue_t*);
typedef int (*plugin_update_job_hook_t)(void*, xce_sched_job_t*, typedef int (*plugin_update_job_hook_t)(void*, xce_sched_job_t*,
@ -58,7 +59,7 @@ typedef struct {
extern int plugin_register(void*, void*); extern int plugin_register(void*, void*);
extern void plugin_unregister(void*); extern void plugin_unregister(void*);
extern int plugin_config_update(void*, xce_conf4sched_t*); extern int plugin_config_update(void*, xce_conf4sched_t*, xce_conf4sched_t*);
extern int plugin_queue_update(void*, xce_sched_queue_t*, xce_sched_queue_t*); extern int plugin_queue_update(void*, xce_sched_queue_t*, xce_sched_queue_t*);
extern int plugin_job_update(void*, xce_sched_job_t*, xce_sched_job_t*); extern int plugin_job_update(void*, xce_sched_job_t*, xce_sched_job_t*);
extern int plugin_worker_update(void*, xce_sched_worker_t*, extern int plugin_worker_update(void*, xce_sched_worker_t*,
@ -66,8 +67,7 @@ extern int plugin_worker_update(void*, xce_sched_worker_t*,
extern int plugin_begin_session(void*); extern int plugin_begin_session(void*);
extern int plugin_end_session(void*); extern int plugin_end_session(void*);
extern int plugin_commit_decision(void*, xce_decision_t*); extern int plugin_commit_decision(void*, xce_decision_t*);
extern int register_fcfs(void*);
extern int register_fcfs(void*); extern int register_simple_allocator(void*);
extern int register_default_allocator(void*);
#endif #endif

View file

@ -44,21 +44,22 @@ typedef struct {
link))) link)))
typedef struct { typedef struct {
mylock_t lock; mylock_t lock;
int stop; int stop;
xcecli_ctx_t apictx; xcecli_ctx_t apictx;
kvmgr_t plugins; xce_conf4sched_t* config;
dataq_t* pend_updates[2]; kvmgr_t plugins;
kvmgr_t jobs; dataq_t* pend_updates[2];
kvmgr_t queues; kvmgr_t jobs;
kvmgr_t workers; kvmgr_t queues;
kvmgr_t users; kvmgr_t workers;
kvmgr_t projects; kvmgr_t users;
pthread_t jobpicker; kvmgr_t projects;
pthread_t allocator; pthread_t jobpicker;
cbuf_t wbuf; /* action to trigger scheduling */ pthread_t allocator;
cbuf_t jbuf; /* job picked for allocation */ cbuf_t wbuf; /* action to trigger scheduling */
cbuf_t decisions; /* scheduler decisions */ cbuf_t jbuf; /* job picked for allocation */
cbuf_t decisions; /* scheduler decisions */
} xce_scheduler_t; } xce_scheduler_t;
extern int sched_init(xce_scheduler_t*, xce_client_config_t*, extern int sched_init(xce_scheduler_t*, xce_client_config_t*,

View file

@ -6,7 +6,7 @@ scheduler_srcs = [
'src/schedobj.c', 'src/schedobj.c',
'src/plugin.c', 'src/plugin.c',
'src/plugins/fcfs.c', 'src/plugins/fcfs.c',
'src/plugins/default_allocator.c', 'src/plugins/simple_allocator.c',
] ]
incdir = include_directories('src', incdir = include_directories('src',

View file

@ -124,6 +124,41 @@ static int sched_handle_dataset(xce_scheduler_t* sched, dataset_t* dataset)
return rc; return rc;
} }
int sched_handle_notify(xce_scheduler_t* sched, xce_notify_data_t* notify)
{
int rc = 0;
char jobidString[128];
switch (notify->event) {
case NotifyData_data_schedStartJob:
fmt_jobid(jobidString, sizeof(jobidString)-1, notify->data.sched_start_job);
TRACE("%s %s started", __func__, jobidString);
break;
case NotifyData_data_schedExitJob:
fmt_jobid(jobidString, sizeof(jobidString) - 1, notify->data.sched_exit_job);
TRACE("%s %s exit", __func__, jobidString);
break;
case NotifyData_data_schedFailJob:
fmt_jobid(jobidString, sizeof(jobidString) - 1, notify->data.sched_fail_job);
TRACE("%s %s fail", __func__, jobidString);
break;
case NotifyData_data_schedUpdateJob:
fmt_jobid(jobidString, sizeof(jobidString) - 1, notify->data.sched_update_job->jobid);
TRACE("%s %s updated", __func__, jobidString);
break;
case NotifyData_data_schedUpdateQueue:
break;
case NotifyData_data_schedUpdateResvals:
break;
case NotifyData_data_schedJobRusages:
break;
default:
rc = -EINVAL;
break;
}
return rc;
}
int scheduler_req_handler(xce_request_t* request, void* args) int scheduler_req_handler(xce_request_t* request, void* args)
{ {
int rc = 0; int rc = 0;
@ -158,11 +193,17 @@ int scheduler_req_handler(xce_request_t* request, void* args)
case Request_body_datamsg: case Request_body_datamsg:
rc = sched_handle_dataset(sched, request->body.datamsg); rc = sched_handle_dataset(sched, request->body.datamsg);
break; break;
case Request_body_notifymsg:
rc = sched_handle_notify(sched, request->body.notifymsg);
break;
default: default:
rc = -EINVAL; rc = -EINVAL;
break; break;
} }
break; break;
case OPCode_notify:
rc = sched_handle_notify(sched, request->body.notifymsg);
break;
default: default:
rc = -EINVAL; rc = -EINVAL;
break; break;

View file

@ -59,23 +59,26 @@ void plugin_unregister(void* arg)
static int plugin_config_update_(void* arg1, void* arg2) static int plugin_config_update_(void* arg1, void* arg2)
{ {
xce_sched_plugin_t* plugin = (xce_sched_plugin_t*)arg2; xce_sched_plugin_t* plugin = (xce_sched_plugin_t*)arg2;
update_args_t* args = (update_args_t*)arg1;
if ((arg1 == NULL) || (plugin == NULL)) { if ((arg1 == NULL) || (plugin == NULL)) {
return 0; return 0;
} }
if (plugin->hooks.config_hook != NULL) { if (plugin->hooks.config_hook != NULL) {
return plugin->hooks.config_hook(plugin, arg1); return plugin->hooks.config_hook(plugin, args->old, args->new);
} }
return 0; return 0;
} }
int plugin_config_update(void* arg, xce_conf4sched_t* config) int plugin_config_update(void* arg, xce_conf4sched_t* old,
xce_conf4sched_t* config)
{ {
xce_scheduler_t* sched = (xce_scheduler_t*)arg; xce_scheduler_t* sched = (xce_scheduler_t*)arg;
xlist_t lst; xlist_t lst;
int rc; int rc;
update_args_t args = { .old = old, .new = config };
if (sched == NULL) { if (sched == NULL) {
return -EINVAL; return -EINVAL;
@ -83,7 +86,7 @@ int plugin_config_update(void* arg, xce_conf4sched_t* config)
xlist_init(&lst, 3); xlist_init(&lst, 3);
xlist_store(&lst, plugin_config_update_); xlist_store(&lst, plugin_config_update_);
rc = kvmgr_iter(&(sched->plugins), NULL, &lst, config); rc = kvmgr_iter(&(sched->plugins), NULL, &lst, &args);
xlist_fini(&lst); xlist_fini(&lst);

View file

@ -86,8 +86,8 @@ static int fcfs_priv_data_init(fcfs_plugin_data_t* data)
return 0; return 0;
} }
static int fcfs_update_config(xce_sched_plugin_t* plugin, static int fcfs_update_config(xce_sched_plugin_t* plugin, xce_conf4sched_t* old,
xce_conf4sched_t* config) xce_conf4sched_t* config)
{ {
fcfs_plugin_data_t* privdata = NULL; fcfs_plugin_data_t* privdata = NULL;

View file

@ -15,9 +15,9 @@
static uint32_t maxslots = 8; static uint32_t maxslots = 8;
static uint32_t slotsInUse = 0; static uint32_t slotsInUse = 0;
static int default_allocator_init(xce_sched_plugin_t* plugin) { return 1; } static int simple_allocator_init(xce_sched_plugin_t* plugin) { return 1; }
static void default_allocator_fini(xce_sched_plugin_t* plugin) static void simple_allocator_fini(xce_sched_plugin_t* plugin)
{ {
if (plugin == NULL) { if (plugin == NULL) {
return; return;
@ -31,16 +31,17 @@ static int my_update_job(xce_sched_plugin_t* plugin, xce_sched_job_t* jold,
/* FIXME: we need to add logic to check whether the job should be handled by /* FIXME: we need to add logic to check whether the job should be handled by
* me */ * me */
j->allocator = plugin; j->allocator = plugin;
switch (j->state) {
case JOB_STAT_PEND: if (jold == NULL) {
break; if (JOB_IS_RUN(j)) {
case JOB_STAT_RUN: slotsInUse++;
break; }
case JOB_STAT_DONE: } else {
break; if (JOB_IS_RUN(jold) && (JOB_IS_EXIT(j) || (JOB_IS_DONE(j)))) {
default: slotsInUse--;
break; }
} }
return 1; return 1;
} }
@ -99,15 +100,15 @@ static int my_commit(xce_sched_plugin_t* plugin, xce_decision_t* decision)
return rc; return rc;
} }
int register_default_allocator(void* sched) int register_simple_allocator(void* sched)
{ {
static xce_sched_plugin_t default_allocator_plugin = { static xce_sched_plugin_t simple_allocator_plugin = {
.name = "xce_sched_default_allocator", .name = "xce_sched_simple_allocator",
.hooks = { .config_hook = NULL, .hooks = { .config_hook = NULL,
.job_hook = (plugin_update_job_hook_t)my_update_job, .job_hook = (plugin_update_job_hook_t)my_update_job,
.commit_hook = (plugin_commit_decision_hook_t)my_commit }, .commit_hook = (plugin_commit_decision_hook_t)my_commit },
.init_fn = (plugin_init_fn_t)default_allocator_init, .init_fn = (plugin_init_fn_t)simple_allocator_init,
.fini_fn = (plugin_fini_fn_t)default_allocator_fini, .fini_fn = (plugin_fini_fn_t)simple_allocator_fini,
.begin_session_fn = NULL, .begin_session_fn = NULL,
.end_session_fn = NULL, .end_session_fn = NULL,
.job_elect_fn = NULL, .job_elect_fn = NULL,
@ -122,7 +123,7 @@ int register_default_allocator(void* sched)
return -ENOMEM; return -ENOMEM;
} }
memcpy(plugin, &default_allocator_plugin, sizeof(*plugin)); memcpy(plugin, &simple_allocator_plugin, sizeof(*plugin));
return plugin_register(sched, plugin); return plugin_register(sched, plugin);
} }

View file

@ -1,3 +1,4 @@
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -33,8 +34,6 @@ xce_sched_job_t* make_sched_job(void* arg, xce_job_t* j)
job->maxtasks = j->submit->maxtasks; job->maxtasks = j->submit->maxtasks;
job->priority = 0; /* FIXME: support job level priority */ job->priority = 0; /* FIXME: support job level priority */
sched_add_job(sched, job);
return job; return job;
} }
@ -66,8 +65,6 @@ xce_sched_queue_t* make_sched_queue(void* arg, xce_queue_t* q)
queue->accept_interval = q->accept_interval; queue->accept_interval = q->accept_interval;
queue->sched_delay = q->sched_delay; queue->sched_delay = q->sched_delay;
sched_add_queue(sched, queue);
return queue; return queue;
} }
@ -95,8 +92,6 @@ xce_sched_worker_t* make_sched_worker(void* arg, xce_worker_t* w)
worker->name = strdup(w->name); worker->name = strdup(w->name);
/* FIXME: */ /* FIXME: */
sched_add_worker(sched, worker);
return worker; return worker;
} }

View file

@ -133,7 +133,7 @@ static void sched_pend_update_killer(data_item_t* it)
static int sched_register_plugins(xce_scheduler_t* sched) static int sched_register_plugins(xce_scheduler_t* sched)
{ {
register_fcfs(sched); register_fcfs(sched);
register_default_allocator(sched); register_simple_allocator(sched);
return 0; return 0;
} }
@ -241,7 +241,7 @@ static int sched_update_config(xce_scheduler_t* sched, xce_conf4sched_t* config)
{ {
int i; int i;
plugin_config_update(sched, config); plugin_config_update(sched, sched->config, config);
for (i = 0; i < config->n_queues; i++) { for (i = 0; i < config->n_queues; i++) {
xce_sched_queue_t* qold xce_sched_queue_t* qold
@ -249,6 +249,12 @@ static int sched_update_config(xce_scheduler_t* sched, xce_conf4sched_t* config)
xce_sched_queue_t* q = make_sched_queue(sched, config->queues[i]); xce_sched_queue_t* q = make_sched_queue(sched, config->queues[i]);
plugin_queue_update(sched, qold, q); plugin_queue_update(sched, qold, q);
if (qold == NULL) {
sched_add_queue(sched, q);
} else {
/* FIXME: overwrite qold with q */
}
} }
return 0; return 0;
@ -264,6 +270,12 @@ static int sched_update_jobs(xce_scheduler_t* sched, int njobs,
xce_sched_job_t* j = make_sched_job(sched, jobs[i]); xce_sched_job_t* j = make_sched_job(sched, jobs[i]);
plugin_job_update(sched, jold, j); plugin_job_update(sched, jold, j);
if (jold == NULL) {
sched_add_job(sched, j);
} else {
/**/
}
} }
return 0; return 0;
@ -278,7 +290,11 @@ static int sched_update_workers(xce_scheduler_t* sched, int nworkers,
xce_sched_worker_t* wold = sched_get_worker(sched, workers[i]->name); xce_sched_worker_t* wold = sched_get_worker(sched, workers[i]->name);
xce_sched_worker_t* w = make_sched_worker(sched, workers[i]); xce_sched_worker_t* w = make_sched_worker(sched, workers[i]);
plugin_worker_update(sched, wold,w); plugin_worker_update(sched, wold, w);
if (wold == NULL) {
sched_add_worker(sched, w);
} else {
}
} }
return 0; return 0;