scheduling using real slots number
This commit is contained in:
parent
8db4458375
commit
780e9fb313
22 changed files with 980 additions and 105 deletions
|
|
@ -53,7 +53,7 @@ static void* kvmgr_lock_(kvmgr_t* mgr, void* key, int op)
|
|||
if (op == OBJREF_NOP) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
return obj_ref(ptr, op);
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ void* kvmgr_lock_byid(kvmgr_t* mgr, int idx, int op)
|
|||
if (op == OBJREF_NOP) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
return obj_ref(ptr, op);
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +152,47 @@ int32_t kvmgr_add(kvmgr_t* mgr, void* key, void* p)
|
|||
return idx;
|
||||
}
|
||||
|
||||
static int32_t kvmgr_put_(kvmgr_t* mgr, void* key, int idx, void* p)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
int idx1 = -1;
|
||||
|
||||
e = ht_get(&(mgr->htab), key);
|
||||
if (e != NULL) {
|
||||
idx1 = e->data;
|
||||
if (idx1 >= 0) {
|
||||
zarray_del(&(mgr->data), idx1);
|
||||
}
|
||||
} else {
|
||||
e = ht_add(&(mgr->htab), (void*)key);
|
||||
if (e == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx1 != idx) {
|
||||
zarray_del(&(mgr->data), idx);
|
||||
}
|
||||
|
||||
e->data = idx;
|
||||
return zarray_put(&(mgr->data), idx, p);
|
||||
}
|
||||
|
||||
int32_t kvmgr_put(kvmgr_t* mgr, void* key, int idx, void* p)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if ((mgr == NULL) || (key == NULL) || (p == NULL) || (idx < 0)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mylock_lock(&(mgr->lock));
|
||||
rc = kvmgr_put_(mgr, key, idx, p);
|
||||
mylock_unlock(&(mgr->lock));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void kvmgr_del_(kvmgr_t* mgr, void* key)
|
||||
{
|
||||
hent_t* e = NULL;
|
||||
|
|
@ -245,6 +286,15 @@ xce_resource_t* resmgr_lockres(resmgr_t* mgr, char* resname, int op)
|
|||
return r;
|
||||
}
|
||||
|
||||
xce_resource_t* resmgr_lock_byid(resmgr_t* mgr, int idx, int op)
|
||||
{
|
||||
xce_resource_t* r = NULL;
|
||||
|
||||
r = (xce_resource_t*)kvmgr_lock_byid(&(mgr->resdef), idx, op);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void resmgr_del_res(resmgr_t* mgr, xce_resource_t* r)
|
||||
{
|
||||
kvmgr_del(&(mgr->resdef), (void*)r->name);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ libxce_test_src = ['testsuite/test.c',
|
|||
'testsuite/test_idgen.c',
|
||||
'testsuite/test_delay.c',
|
||||
'testsuite/test_ordq.c',
|
||||
'testsuite/test_preason.c'
|
||||
'testsuite/test_preason.c',
|
||||
'testsuite/test_kvmgr.c',
|
||||
]
|
||||
|
||||
libxce_test_deps = [libxce_deps, unity_dep, libxce_dep]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ extern void test_idgen(void);
|
|||
extern void test_preason(void);
|
||||
extern void test_ordq(void);
|
||||
extern void test_delay(void);
|
||||
extern void test_kvmgr(void);
|
||||
|
||||
void setUp(void) { return; }
|
||||
|
||||
|
|
@ -34,6 +35,7 @@ int main(int argc, char* argv[])
|
|||
test_preason();
|
||||
test_ordq();
|
||||
test_delay();
|
||||
test_kvmgr();
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
|
|
|||
76
src/lib/testsuite/test_kvmgr.c
Normal file
76
src/lib/testsuite/test_kvmgr.c
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "kvmgr.h"
|
||||
#include <unity.h>
|
||||
#include "objmgr.h"
|
||||
|
||||
typedef struct {
|
||||
char* key;
|
||||
int data;
|
||||
} kv_data_t;
|
||||
|
||||
static void test_kvadd(void)
|
||||
{
|
||||
kvmgr_t mgr;
|
||||
char *key = "key1";
|
||||
kv_data_t data = { .key = key, .data = 100 };
|
||||
kv_data_t* p = NULL;
|
||||
|
||||
kvmgr_init(&mgr, string_hash_key, 4, 4, NULL);
|
||||
kvmgr_add(&mgr, key, &data);
|
||||
p = kvmgr_lock(&mgr, key, OBJREF_NOP);
|
||||
TEST_ASSERT_TRUE(p != NULL);
|
||||
TEST_ASSERT_TRUE(p == &data);
|
||||
kvmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
static void test_kvput(void)
|
||||
{
|
||||
kvmgr_t mgr;
|
||||
char *key = "key1";
|
||||
kv_data_t data = { .key = key, .data = 100 };
|
||||
kv_data_t* p = NULL;
|
||||
int idx = 10;
|
||||
|
||||
kvmgr_init(&mgr, string_hash_key, 4, 4, NULL);
|
||||
kvmgr_put(&mgr, key, idx, &data);
|
||||
p = kvmgr_lock(&mgr, key, OBJREF_NOP);
|
||||
TEST_ASSERT_TRUE(p != NULL);
|
||||
TEST_ASSERT_TRUE(p == &data);
|
||||
p = kvmgr_lock_byid(&mgr, idx, OBJREF_NOP);
|
||||
TEST_ASSERT_TRUE(p != NULL);
|
||||
TEST_ASSERT_TRUE(p == &data);
|
||||
|
||||
kvmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
static void test_kvdel(void)
|
||||
{
|
||||
kvmgr_t mgr;
|
||||
char *key = "key1";
|
||||
kv_data_t data = { .key = key, .data = 100 };
|
||||
kv_data_t* p = NULL;
|
||||
|
||||
kvmgr_init(&mgr, string_hash_key, 4, 4, NULL);
|
||||
kvmgr_add(&mgr, key, &data);
|
||||
p = kvmgr_lock(&mgr, key, OBJREF_NOP);
|
||||
TEST_ASSERT_TRUE(p != NULL);
|
||||
TEST_ASSERT_TRUE(p == &data);
|
||||
|
||||
kvmgr_del(&mgr, key);
|
||||
p = kvmgr_lock(&mgr, key, OBJREF_NOP);
|
||||
|
||||
TEST_ASSERT_TRUE( p == NULL);
|
||||
|
||||
kvmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
|
||||
void test_kvmgr(void)
|
||||
{
|
||||
printf("\n>> kvmgr test\n");
|
||||
RUN_TEST(test_kvadd);
|
||||
RUN_TEST(test_kvput);
|
||||
RUN_TEST(test_kvdel);
|
||||
}
|
||||
|
|
@ -4,11 +4,12 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "xce/types.h"
|
||||
#include "xcealloc.h"
|
||||
|
||||
xce_alloc_t* make_alloc(char* resname, char* reserve, int instid, float value,
|
||||
int duration)
|
||||
xce_alloc_t* make_alloc(char* resname, char* reserve, uint64_t instid,
|
||||
float value, int duration)
|
||||
{
|
||||
xce_alloc_t* alloc = NULL;
|
||||
|
||||
|
|
@ -32,6 +33,24 @@ xce_alloc_t* make_alloc(char* resname, char* reserve, int instid, float value,
|
|||
return alloc;
|
||||
}
|
||||
|
||||
static xce_res_account_t* make_res_account(xce_alloc_t* alloc)
|
||||
{
|
||||
xce_res_account_t* account = NULL;
|
||||
|
||||
account = (xce_res_account_t*)calloc(1, sizeof(*account));
|
||||
if (account == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
account->instid = alloc->instid;
|
||||
account->resname = strdup(alloc->resname);
|
||||
account->residx = -1;
|
||||
account->used = 0.0;
|
||||
account->reserved = alloc->value;
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
xce_alloc_t** make_allocs(int nallocs, ...)
|
||||
{
|
||||
xce_alloc_t** allocs = NULL;
|
||||
|
|
@ -74,6 +93,33 @@ xce_host_alloc_t* make_host_alloc(char* host, int nalloc, xce_alloc_t** allocs)
|
|||
return halloc;
|
||||
}
|
||||
|
||||
static xce_host_account_t* make_host_account(xce_host_alloc_t* halloc)
|
||||
{
|
||||
xce_host_account_t* haccount = NULL;
|
||||
int i;
|
||||
|
||||
haccount = (xce_host_account_t*)calloc(1, sizeof(*haccount));
|
||||
if (haccount == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
haccount->accounts = (xce_res_account_t**)calloc(
|
||||
halloc->nallocs, sizeof(xce_res_account_t*));
|
||||
if (haccount->accounts == NULL) {
|
||||
FREEUP(haccount);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < halloc->nallocs; i++) {
|
||||
haccount->accounts[i] = make_res_account(halloc->allocs[i]);
|
||||
}
|
||||
|
||||
haccount->naccount = halloc->nallocs;
|
||||
haccount->host = strdup(halloc->host);
|
||||
|
||||
return haccount;
|
||||
}
|
||||
|
||||
xce_host_alloc_t** make_host_allocs(int nhosts, ...)
|
||||
{
|
||||
xce_host_alloc_t** hallocs = NULL;
|
||||
|
|
@ -111,9 +157,50 @@ xce_job_alloc_t* make_job_alloc(uint64_t jobid, int nhost,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
jalloc->jobid = jobid;
|
||||
jalloc->nhosts = nhost;
|
||||
jalloc->allocs = hallocs;
|
||||
jalloc->jobid = jobid;
|
||||
jalloc->nhosts = nhost;
|
||||
jalloc->allocs = hallocs;
|
||||
jalloc->nres_shared = 0;
|
||||
jalloc->allocs_shared = NULL;
|
||||
|
||||
return jalloc;
|
||||
}
|
||||
|
||||
xce_job_account_t* make_job_account(xce_job_alloc_t* jalloc)
|
||||
{
|
||||
xce_job_account_t* account = NULL;
|
||||
int i;
|
||||
|
||||
account = (xce_job_account_t*)calloc(1, sizeof(*account));
|
||||
if (account == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
account->accounts
|
||||
= (xce_host_account_t**)calloc(1, sizeof(xce_host_account_t*));
|
||||
if (account->accounts == NULL) {
|
||||
FREEUP(account);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < jalloc->nhosts; i++) {
|
||||
account->accounts[i] = make_host_account(jalloc->allocs[i]);
|
||||
}
|
||||
|
||||
account->nhosts = jalloc->nhosts;
|
||||
account->accounts_shared = NULL;
|
||||
|
||||
if (jalloc->nres_shared) {
|
||||
account->accounts_shared = (xce_res_account_t**)calloc(
|
||||
jalloc->nres_shared, sizeof(xce_res_account_t*));
|
||||
|
||||
for (i = 0; i < jalloc->nres_shared; i++) {
|
||||
account->accounts_shared[i]
|
||||
= make_res_account(jalloc->allocs_shared[i]);
|
||||
}
|
||||
|
||||
account->nres_shared = jalloc->nres_shared;
|
||||
}
|
||||
|
||||
return account;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,36 @@ int xlist_iter(xlist_t* l, xlist_iter_fn_t fn, void* data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void* xlist_find(xlist_t* l, xlist_find_fn_t fn, ...)
|
||||
{
|
||||
int i;
|
||||
va_list ap;
|
||||
void* it = NULL;
|
||||
|
||||
if ((l == NULL) || (fn == NULL)) {
|
||||
errno = EINVAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
va_start(ap, fn);
|
||||
for (i = 0; i < l->count; i++) {
|
||||
va_list ap1;
|
||||
int rc;
|
||||
|
||||
va_copy(ap1, ap);
|
||||
rc = fn((void*)l->data[i], ap1);
|
||||
va_end(ap1);
|
||||
|
||||
if (rc) {
|
||||
it = (void*)l->data[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
void xlist_fini(xlist_t* l)
|
||||
{
|
||||
if (l == NULL) {
|
||||
|
|
|
|||
|
|
@ -189,6 +189,40 @@ int zarray_iter(zarray_t* array, zarray_iter_fn_t f, void* arg)
|
|||
return rc;
|
||||
}
|
||||
|
||||
void* zarray_find(zarray_t* array, zarray_find_cond_fn_t fn, ...)
|
||||
{
|
||||
int i;
|
||||
va_list ap;
|
||||
void* data = NULL;
|
||||
|
||||
if ((array == NULL) || (fn == NULL)) {
|
||||
errno = EINVAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
va_start(ap, fn);
|
||||
|
||||
mylock_lock(&(array->lock));
|
||||
for (i = 0; i < array->caps; i++) {
|
||||
va_list ap1;
|
||||
int rc;
|
||||
|
||||
va_copy(ap1, ap);
|
||||
rc = fn(array->data[i], ap1);
|
||||
va_end(ap1);
|
||||
|
||||
if (rc) {
|
||||
data = array->data[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
mylock_unlock(&(array->lock));
|
||||
va_end(ap);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int zarray_del(zarray_t* array, int idx)
|
||||
{
|
||||
void* ptr = NULL;
|
||||
|
|
@ -197,10 +231,14 @@ int zarray_del(zarray_t* array, int idx)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((idx < 0) && (idx >= array->caps)) {
|
||||
if (idx < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (idx >= array->caps) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
mylock_lock(&(array->lock));
|
||||
ptr = array->data[idx];
|
||||
array->data[idx] = NULL;
|
||||
|
|
@ -273,32 +311,22 @@ int zarray_put(zarray_t* array, int idx, void* data)
|
|||
|
||||
int zarray_get_ex(zarray_t* array, int count, int* idxs, void** data)
|
||||
{
|
||||
int i, maxid;
|
||||
int i;
|
||||
|
||||
if ((array == NULL) || (count <= 0) || (idxs == NULL) || (data == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
maxid = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (idxs[i] < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (idxs[i] > maxid) {
|
||||
maxid = idxs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (maxid >= array->caps) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mylock_lock(&(array->lock));
|
||||
for (i = 0; i < count; i++) {
|
||||
int idx = idxs[i];
|
||||
|
||||
data[i] = array->data[idx];
|
||||
if (idx >= array->caps) {
|
||||
data[i] = NULL;
|
||||
}
|
||||
else {
|
||||
data[i] = array->data[idx];
|
||||
}
|
||||
}
|
||||
mylock_unlock(&(array->lock));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue