From 4db6b039c52830e14e93fe0d679914e02b51148c Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Thu, 18 Dec 2025 14:55:58 +0800 Subject: [PATCH] save works --- src/include/utils.h | 4 ++ src/include/xce/types.h | 1 - src/lib/htab.c | 16 +------ src/lib/utils.c | 72 +++++++++++++++++++++++++++++++ src/scheduler/include/scheduler.h | 43 +++++++++++++++++- src/scheduler/src/handler.c | 3 ++ src/scheduler/src/scheduler.c | 1 + src/schema/controller.capnp | 34 +++++++-------- 8 files changed, 140 insertions(+), 34 deletions(-) diff --git a/src/include/utils.h b/src/include/utils.h index c74a6994..6c2c5190 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -133,4 +133,8 @@ extern uint64_t array_idx(uint64_t); extern void unblock_sig(int); extern void block_sig(int); +extern uint32_t hash(uint32_t, uint32_t, uint32_t, uint32_t); +extern uint32_t hash64(uint64_t); +extern uint32_t hash_string(const char*); + #endif diff --git a/src/include/xce/types.h b/src/include/xce/types.h index 7b8e7556..84789829 100644 --- a/src/include/xce/types.h +++ b/src/include/xce/types.h @@ -416,7 +416,6 @@ typedef struct { typedef struct { uint64_t jobid; job_submit_data_t* submit; - int64_t idx; time_t sub_time; time_t queue_time; time_t start_time; diff --git a/src/lib/htab.c b/src/lib/htab.c index fac81afd..029b5ebc 100644 --- a/src/lib/htab.c +++ b/src/lib/htab.c @@ -6,7 +6,7 @@ #include "utils.h" #define HASH_KEY_HASH(t, key) \ - (((t)->fn.hash != NULL) ? ((t)->fn.hash)(key) : (unsigned long)key) + (((t)->fn.hash != NULL) ? ((t)->fn.hash)(key) : hash64((uint64_t)key)) #define HASH_KEY_CMP(t, k1, k2) \ (((t)->fn.cmp != NULL) ? ((t)->fn.cmp)((k1), (k2)) : ((k1) != (k2))) @@ -21,21 +21,9 @@ } \ } while (0) -static unsigned int hash_code(const char* key) -{ - unsigned int hc = 5381; - int c; - - while ((c = *key++)) { - hc = ((hc << 5) + hc) + c; - } - - return hc; -} - static unsigned int string_hash(void* data) { - return hash_code((const char*)data); + return hash_string((const char*)data); } static int string_cmp(void* d1, void* d2) diff --git a/src/lib/utils.c b/src/lib/utils.c index b3110191..9e9a3ed7 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -3,6 +3,7 @@ #include #include #include +#include #if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 28) #include #else @@ -587,3 +588,74 @@ void block_sig(int signo) sigaddset(&mask, signo); sigprocmask(SIG_BLOCK, &mask, NULL); } + +#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) +#define mix(a, b, c) \ + { \ + a -= c; \ + a ^= rot(c, 4); \ + c += b; \ + b -= a; \ + b ^= rot(a, 6); \ + a += c; \ + c -= b; \ + c ^= rot(b, 8); \ + b += a; \ + a -= c; \ + a ^= rot(c, 16); \ + c += b; \ + b -= a; \ + b ^= rot(a, 19); \ + a += c; \ + c -= b; \ + c ^= rot(b, 4); \ + b += a; \ + } +#define final(a, b, c) \ + { \ + c ^= b; \ + c -= rot(b, 14); \ + a ^= c; \ + a -= rot(c, 11); \ + b ^= a; \ + b -= rot(a, 25); \ + c ^= b; \ + c -= rot(b, 16); \ + a ^= c; \ + a -= rot(c, 4); \ + b ^= a; \ + b -= rot(a, 14); \ + c ^= b; \ + c -= rot(b, 24); \ + } + +uint32_t hash(uint32_t a, uint32_t b,uint32_t c, uint32_t d) { + uint32_t i1 = a, i2 = b, i3 = c, i4 = d; + + mix(i1,i2,i3); + mix(i2,i3,i4); + mix(i3,i4,i1); + final(i4,i1,i2); + + return i2; +} + +uint32_t hash64(uint64_t x) { + uint32_t a = (uint32_t)(x & UMAX_BITS(32)); + uint32_t b = (uint32_t)(rot(x, 16) & UMAX_BITS(32)); + uint32_t c = (uint32_t)(rot(x,32) & UMAX_BITS(32)); + uint32_t d = (uint32_t)(rot(x, 48) & UMAX_BITS(32)); + + return hash(a,b,c,d); +} + +uint32_t hash_string(const char *key) { + uint32_t hc = 5381; + int c; + + while ((c = *key ++)) { + hc = ((hc << 5) + hc) + c; + } + + return hc; +} diff --git a/src/scheduler/include/scheduler.h b/src/scheduler/include/scheduler.h index 0ecdae65..93a821e2 100644 --- a/src/scheduler/include/scheduler.h +++ b/src/scheduler/include/scheduler.h @@ -3,10 +3,12 @@ #define _SCHEDULER_H_ 1 #include +#include +#include -#include "decision.h" #include "client.h" #include "dataq.h" +#include "decision.h" #include "mylock.h" #include "xce/types.h" #include "xlist.h" @@ -39,6 +41,45 @@ typedef struct { - 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; diff --git a/src/scheduler/src/handler.c b/src/scheduler/src/handler.c index d6c94c60..3ae19db4 100644 --- a/src/scheduler/src/handler.c +++ b/src/scheduler/src/handler.c @@ -136,6 +136,9 @@ int scheduler_req_handler(xce_request_t* request, void* args) /* configuration arriving */ rc = sched_handle_config( sched, request->body.configpushmsg->data.conf4sched); + if (rc >= 0) { + request->body.configpushmsg->data.conf4sched = NULL; + } break; case Request_body_pushmsg: /* data arriving */ diff --git a/src/scheduler/src/scheduler.c b/src/scheduler/src/scheduler.c index 09dba3ee..535bb30a 100644 --- a/src/scheduler/src/scheduler.c +++ b/src/scheduler/src/scheduler.c @@ -88,6 +88,7 @@ static void sched_pend_update_killer(data_item_t* it) req = ITPTR_TO_UPDATE_REQ(it); switch (req->op) { case XCE_SCHED_OP_UPDATE_CONFIG: + free_Conf4Sched_ptr(&(req->u.config)); break; case XCE_SCHED_OP_UPDATE_JOB: for (i = 0; i < req->u.jobupdate.njobs; i++) { diff --git a/src/schema/controller.capnp b/src/schema/controller.capnp index 6fdd1bb7..944048e4 100644 --- a/src/schema/controller.capnp +++ b/src/schema/controller.capnp @@ -252,29 +252,27 @@ struct JobStartInfo $C.mapname("job_startinfo_t"){ struct Job $C.mapname("xce_job_t"){ jobid @0: UInt64; submitData @1: JobSubmitData $C.mapname("submit"); - idx @2: UInt64; - subtime @3: UInt64 $C.mapname("sub_time"); - queuetime @4: UInt64 $C.mapname("queue_time"); - starttime @5: UInt64 $C.mapname("start_time"); - finishtime @6: UInt64 $C.mapname("finish_time"); - state @7: UInt32; - allocs @8: JobAlloc $C.mapname("allocs"); - runtime @9: UInt32 $C.mapname("run_time"); - pidinfo @10: JobPIDInfo; - pendreason @11: JobPendReason $C.mapname("pend_reasons"); + subtime @2: UInt64 $C.mapname("sub_time"); + queuetime @3: UInt64 $C.mapname("queue_time"); + starttime @4: UInt64 $C.mapname("start_time"); + finishtime @5: UInt64 $C.mapname("finish_time"); + state @6: UInt32; + allocs @7: JobAlloc $C.mapname("allocs"); + runtime @8: UInt32 $C.mapname("run_time"); + pidinfo @9: JobPIDInfo; + pendreason @10: JobPendReason $C.mapname("pend_reasons"); } struct SchedJob $C.mapname("xce_job_t"){ jobid @0: UInt64; submitData @1: JobSubmitData $C.mapname("submit"); - idx @2: UInt64; - subtime @3: UInt64 $C.mapname("sub_time"); - queuetime @4: UInt64 $C.mapname("queue_time"); - starttime @5: UInt64 $C.mapname("start_time"); - finishtime @6: UInt64 $C.mapname("finish_time"); - state @7: UInt32; - allocs @8: JobAlloc $C.mapname("allocs"); - runtime @9: UInt32 $C.mapname("run_time"); + subtime @2: UInt64 $C.mapname("sub_time"); + queuetime @3: UInt64 $C.mapname("queue_time"); + starttime @4: UInt64 $C.mapname("start_time"); + finishtime @5: UInt64 $C.mapname("finish_time"); + state @6: UInt32; + allocs @7: JobAlloc $C.mapname("allocs"); + runtime @8: UInt32 $C.mapname("run_time"); } struct SchedJobRusages $C.mapname("xce_job_rusages_t") {