diff --git a/src/scheduler/src/resource.c b/src/scheduler/src/resource.c index 46fe0d6..cd00066 100644 --- a/src/scheduler/src/resource.c +++ b/src/scheduler/src/resource.c @@ -102,9 +102,11 @@ static int unsatisfy_(xce_scheduler_t* sched, int nres, int* idxs, float* total, count = 0; for (i = 0; i < nres; i++) { - TRACE("%s resource %d total %f inuse %f uncomit %f wanted %f", __func__, - idxs[i], total[i], inuse[i], uncomitted[i], wanted[i]); if (total[i] < inuse[i] + uncomitted[i] + wanted[i]) { + TRACE("%s resource %d total %f inuse %f uncomit %f wanted %f", + __func__, idxs[i], total[i], inuse[i], uncomitted[i], + wanted[i]); + count++; } } @@ -116,8 +118,8 @@ static int unsatisfy_(xce_scheduler_t* sched, int nres, int* idxs, float* total, j = 0; for (i = 0; i < nres; i++) { if (total[i] < inuse[i] + uncomitted[i] + wanted[i]) { - xce_resource_t* r = NULL; - float need = inuse[i] + uncomitted[i] + wanted[i] - total[i]; + xce_resource_t* r = NULL; + float need = inuse[i] + uncomitted[i] + wanted[i] - total[i]; vget(sched->resmgr, idxs[i], (void**)&r); TRACE("%s unmet resource %d (%s) shortfall %f", __func__, idxs[i], @@ -132,14 +134,16 @@ static int unsatisfy_(xce_scheduler_t* sched, int nres, int* idxs, float* total, return count; } -static host_eval_ctx_t* -build_host_eval_ctx(const xce_sched_worker_t* w, int num_res) +static host_eval_ctx_t* build_host_eval_ctx(const xce_sched_worker_t* w, + int num_res) { host_eval_ctx_t* ctx = calloc(1, sizeof(*ctx)); - if (ctx == NULL) return NULL; + if (ctx == NULL) + return NULL; if (num_res <= 0) { - /* valid empty context — numvals/strvals remain NULL, bounds checks protect access */ + /* valid empty context — numvals/strvals remain NULL, bounds checks + * protect access */ ctx->num_res = 0; return ctx; } @@ -155,7 +159,8 @@ build_host_eval_ctx(const xce_sched_worker_t* w, int num_res) for (int i = 0; i < num_res; i++) { xce_val_t* v = (xce_val_t*)zarray_get((zarray_t*)&w->resvals, i); - if (v == NULL) continue; + if (v == NULL) + continue; switch (v->which) { case Value_u_fvalue: numvals[i] = (double)v->u.fvalue; @@ -175,10 +180,10 @@ build_host_eval_ctx(const xce_sched_worker_t* w, int num_res) return ctx; } -static void -free_host_eval_ctx(host_eval_ctx_t* ctx) +static void free_host_eval_ctx(host_eval_ctx_t* ctx) { - if (ctx == NULL) return; + if (ctx == NULL) + return; free((void*)ctx->numvals); free((void*)ctx->strvals); free(ctx); @@ -186,7 +191,8 @@ free_host_eval_ctx(host_eval_ctx_t* ctx) void sched_worker_release_host_ctx(xce_sched_worker_t* w) { - if (w == NULL) return; + if (w == NULL) + return; free_host_eval_ctx(w->host_eval_ctx); w->host_eval_ctx = NULL; } @@ -194,11 +200,12 @@ void sched_worker_release_host_ctx(xce_sched_worker_t* w) int sched_meet_host_selection(xce_scheduler_t* sched, xce_sched_worker_t* w, xce_select_t* s) { - if (s == NULL || s->root == NULL) return 1; + if (s == NULL || s->root == NULL) + return 1; /* Build host context lazily — reused for all jobs against this host. */ if (w->host_eval_ctx == NULL) { - int num_res = (int)w->resvals.caps; + int num_res = (int)w->resvals.caps; w->host_eval_ctx = build_host_eval_ctx(w, num_res); if (w->host_eval_ctx == NULL) { /* OOM: conservatively pass host */ @@ -216,7 +223,8 @@ int sched_meet_host_selection(xce_scheduler_t* sched, xce_sched_worker_t* w, return (rc > 0) ? 1 : 0; } - /* Fallback (no session context — e.g. unit tests or OOM at session start). */ + /* Fallback (no session context — e.g. unit tests or OOM at session start). + */ int rc = eval_select_simple(s->root, w->host_eval_ctx); return (rc > 0) ? 1 : 0; } @@ -464,7 +472,7 @@ static int sched_try_alloc_on_host_(xce_sched_worker_t* w, va_list ap) if (ctx->reason == NULL) { return -errno; } - + add_job_preason(ctx->reason->reasons, PREASON_MATCH_FAIL, w->name, NULL); @@ -496,18 +504,18 @@ static int sched_try_alloc_on_host_(xce_sched_worker_t* w, va_list ap) int i; if (ctx) - for (i = 0; i < ctx->unmeet.count; i++) { - xce_resource_t* r = NULL; + for (i = 0; i < ctx->unmeet.count; i++) { + xce_resource_t* r = NULL; - rc = vget(sched->resmgr, ((int*)ctx->unmeet.idxs.data)[i], - (void**)&r); - if (rc < 0) { - continue; + rc = vget(sched->resmgr, ((int*)ctx->unmeet.idxs.data)[i], + (void**)&r); + if (rc < 0) { + continue; + } + + add_job_preason(ctx->reason->reasons, PREASON_NO_RESOURCE, + w->name, r->name); } - - add_job_preason(ctx->reason->reasons, PREASON_NO_RESOURCE, w->name, - r->name); - } return 0; }