- save tmp works

- save works
This commit is contained in:
Rongsong Shen 2026-02-06 17:30:50 +08:00
parent cd4f3953b2
commit 12dcc2a60d
14 changed files with 386 additions and 110 deletions

View file

@ -3,12 +3,15 @@
#include <stdlib.h>
#include <string.h>
#include "kvmgr.h"
#include "objmgr.h"
#include "resreq.h"
#include "rusage.h"
#include "section.h"
#include "utils.h"
#include "xce_resreq.h"
#include "xlist.h"
#include "xvec.h"
static int get_parse_errmsg(char** errmsg, const char* data, int pos)
{
@ -431,3 +434,107 @@ int format_resreq(char** buf, xce_resreq_t* resreq)
return rc;
}
int calc_wanted_global_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
xlist_t* rusages, rusage_per_type_t perflag,
int nhosts, int nslots)
{
int i;
for (i = 0; i < rusages->count; i++) {
rusage_value_t* v = (rusage_value_t*)xlist_get(rusages, i);
xce_resource_t* r = NULL;
float val;
rusage_per_type_t perflag1;
if (v == NULL) {
continue;
}
r = resmgr_lockres(resmgr, v->res, OBJREF_NOP);
if (r == NULL) {
continue;
}
if ((r->flags & XCE_RESF_GLOBAL) == 0) {
continue;
}
perflag1 = v->per_flag;
if (perflag1 == PER_DEFAULT) {
perflag1 = perflag;
}
switch (perflag1) {
case PER_TASK:
val = v->value * nslots;
break;
case PER_JOB:
val = v->value;
break;
case PER_HOST:
val = v->value * nhosts;
break;
default:
/* something wrong */
val = 0.0;
break;
}
xvec_idval_store(resvals, r->idx, val);
}
return 0;
}
int calc_wanted_host_resvals(xvec_idval_t* resvals, resmgr_t* resmgr,
xlist_t* rusages, rusage_per_type_t perfflag,
int nhosts, int nslots)
{
int i;
for (i = 0; i < rusages->count; i++) {
rusage_value_t* v = (rusage_value_t*)xlist_get(rusages, i);
xce_resource_t* r = NULL;
float val;
rusage_per_type_t perflag1;
if (v == NULL) {
continue;
}
r = resmgr_lockres(resmgr, v->res, OBJREF_NOP);
if (r == NULL) {
continue;
}
if ((r->flags & XCE_RESF_GLOBAL) != 0) {
continue;
}
perflag1 = v->per_flag;
if (perflag1 == PER_DEFAULT) {
perflag1 = perflag;
}
if (perflag1 == PER_JOB) {
/* FIXME: PER_JOB should be global? */
continue;
}
switch (perflag1) {
case PER_TASK:
val = v->value * nslots;
break;
case PER_HOST:
val = v->value;
break;
default:
/* something wrong */
val = 0.0;
break;
}
xvec_idval_store(resvals, r->idx, val);
}
return 0;
}

View file

@ -68,7 +68,7 @@ empty_decay <- { } { auxil->decay_flag = 0; }
identifier <- [a-zA-Z_][a-zA-Z_0-9]* { auxil->resname = strdup($0); }
resvalue <- number '/' per_type { auxil->resvalue = auxil->tmp_value; }
/ number { auxil->resvalue = auxil->tmp_value; auxil->per_flag = PER_TASK; }
/ number { auxil->resvalue = auxil->tmp_value; auxil->per_flag = PER_DEFAULT; }
per_type <- 'task' { auxil->per_flag = PER_TASK; }
/ 'job' { auxil->per_flag = PER_JOB; }

View file

@ -91,14 +91,14 @@ void test_parse_rusage1(void)
TEST_ASSERT_TRUE(strcmp(v->res, "mem") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 20.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 18000) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 1);
break;
case 1:
TEST_ASSERT_TRUE(strcmp(v->res, "lic") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 55.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 1200) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 0);
break;
default:
@ -140,14 +140,14 @@ void test_parse_rusage2(void)
TEST_ASSERT_TRUE(strcmp(v->res, "mem") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 20.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 18000) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 2);
TEST_ASSERT_TRUE(v->per_flag == PER_HOST);
TEST_ASSERT_TRUE(v->decay_flag == 1);
break;
case 1:
TEST_ASSERT_TRUE(strcmp(v->res, "lic") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 55.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 1200) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 1);
TEST_ASSERT_TRUE(v->per_flag == PER_JOB);
TEST_ASSERT_TRUE(v->decay_flag == 0);
break;
default:
@ -188,14 +188,14 @@ void test_resreq_primary(void)
TEST_ASSERT_TRUE(strcmp(v->res, "mem") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 20.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 18000) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 1);
break;
case 1:
TEST_ASSERT_TRUE(strcmp(v->res, "lic") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 55.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 1200) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 0);
break;
default:
@ -241,14 +241,14 @@ void test_resreq1(void)
TEST_ASSERT_TRUE(strcmp(v->res, "mem") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 20.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 18000) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 1);
break;
case 1:
TEST_ASSERT_TRUE(strcmp(v->res, "lic") == 0);
TEST_ASSERT_TRUE(fabs(v->value - 55.0) < 0.001);
TEST_ASSERT_TRUE(fabs(v->duration - 1200) < 0.001);
TEST_ASSERT_TRUE(v->per_flag == 0);
TEST_ASSERT_TRUE(v->per_flag == PER_DEFAULT);
TEST_ASSERT_TRUE(v->decay_flag == 0);
break;
default: