Skip to content

Commit d6b2ed2

Browse files
committed
resource: add subsystem for core reservation
Problem: There is no way to reserve cores so they are not used for scheduling. Add a 'reserve' subsystem to the core resource module that takes a reserved set of cores via the 'cores[@Ranks]' spec. Nothing is done with the reserve subsystem at this point.
1 parent 98cf89e commit d6b2ed2

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

src/modules/resource/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ libresource_la_SOURCES = \
4040
drainset.h \
4141
drainset.c \
4242
upgrade.h \
43-
upgrade.c
43+
upgrade.c \
44+
reserve.c \
45+
reserve.h
4446

4547
TESTS = \
4648
test_rutil.t \

src/modules/resource/reserve.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/************************************************************\
2+
* Copyright 2025 Lawrence Livermore National Security, LLC
3+
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
4+
*
5+
* This file is part of the Flux resource manager framework.
6+
* For details, see https://github.com/flux-framework.
7+
*
8+
* SPDX-License-Identifier: LGPL-3.0
9+
\************************************************************/
10+
11+
/* reserve.c - get static set of resources to reserve for the OS
12+
*/
13+
14+
#if HAVE_CONFIG_H
15+
#include "config.h"
16+
#endif
17+
#include <flux/core.h>
18+
#include <jansson.h>
19+
20+
#include "src/common/librlist/rlist.h"
21+
22+
#include "resource.h"
23+
#include "inventory.h"
24+
25+
struct reserve {
26+
struct resource_ctx *ctx;
27+
struct rlist *rl;
28+
};
29+
30+
const struct rlist *reserve_get (struct reserve *reserve)
31+
{
32+
return reserve->rl;
33+
}
34+
35+
void reserve_destroy (struct reserve *reserve)
36+
{
37+
if (reserve) {
38+
int saved_errno = errno;
39+
rlist_destroy (reserve->rl);
40+
free (reserve);
41+
errno = saved_errno;
42+
}
43+
}
44+
45+
struct reserve *reserve_create (struct resource_ctx *ctx,
46+
const char *spec)
47+
{
48+
struct reserve *reserve;
49+
struct rlist *rl = NULL;
50+
51+
if (!(reserve = calloc (1, sizeof (*reserve))))
52+
return NULL;
53+
reserve->ctx = ctx;
54+
if (spec) {
55+
flux_error_t error;
56+
if (!(rl = rlist_from_json (inventory_get (ctx->inventory), NULL))) {
57+
flux_log (ctx->h,
58+
LOG_ERR,
59+
"reserve: failed to get resources from inventory");
60+
goto error;
61+
}
62+
if (!(reserve->rl = rlist_copy_core_spec (rl, spec, &error))) {
63+
flux_log (ctx->h,
64+
LOG_ERR,
65+
"error decoding reserve spec %s: %s",
66+
spec,
67+
error.text);
68+
goto error;
69+
}
70+
rlist_destroy (rl);
71+
}
72+
return reserve;
73+
error:
74+
rlist_destroy (rl);
75+
reserve_destroy (reserve);
76+
return NULL;
77+
}
78+
79+
/*
80+
* vi:tabstop=4 shiftwidth=4 expandtab
81+
*/

src/modules/resource/reserve.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/************************************************************\
2+
* Copyright 2025 Lawrence Livermore National Security, LLC
3+
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
4+
*
5+
* This file is part of the Flux resource manager framework.
6+
* For details, see https://github.com/flux-framework.
7+
*
8+
* SPDX-License-Identifier: LGPL-3.0
9+
\************************************************************/
10+
11+
#ifndef _FLUX_RESOURCE_RESERVE_H
12+
#define _FLUX_RESOURCE_RESERVE_H
13+
14+
struct reserve *reserve_create (struct resource_ctx *ctx, const char *spec);
15+
void reserve_destroy (struct reserve *exclude);
16+
17+
const struct rlist *reserve_get (struct reserve *reserve);
18+
19+
#endif /* !_FLUX_RESOURCE_RESERVE_H */
20+
21+
/*
22+
* vi:tabstop=4 shiftwidth=4 expandtab
23+
*/
24+

0 commit comments

Comments
 (0)