diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-25 12:51:33 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-25 12:55:29 +0530 |
commit | c4583708c643b741eb6d4c64a9f9092f7da9546f (patch) | |
tree | b9bfeb750f69957dc3875c91a47588efdd6ccc1c /src/solver_sjf.c | |
parent | 2800f12b040c7ce6da24bc7a99aa04b0ffb76fab (diff) |
solver_sjf: init
Diffstat (limited to 'src/solver_sjf.c')
-rw-r--r-- | src/solver_sjf.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/solver_sjf.c b/src/solver_sjf.c new file mode 100644 index 0000000..34d85ec --- /dev/null +++ b/src/solver_sjf.c @@ -0,0 +1,37 @@ +#include <queue.h> +#include <errno.h> + +#include "evanix.h" +#include "jobs.h" +#include "solver_sjf.h" + +int solver_sjf(struct job **job, struct job_clist *q, int32_t resources) +{ + struct job *j; + int cost_cur; + + struct job *selected = NULL; + int cost_min = -1; + + CIRCLEQ_FOREACH (j, q, clist) { + if (j->stale) + continue; + + cost_cur = job_cost_recursive(j); + if (cost_cur > resources) { + job_stale_set(j); + if (evanix_opts.solver_report) { + printf("❌ refusing to build %s, cost: %d\n", + j->drv_path, job_cost_recursive(j)); + } + } + + if (cost_min < 0 || cost_min > cost_cur) { + selected = j; + cost_min = cost_cur; + } + } + + *job = selected; + return (cost_min < 0) ? -ESRCH : cost_min; +} |