From c4583708c643b741eb6d4c64a9f9092f7da9546f Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Thu, 25 Jul 2024 12:51:33 +0530 Subject: solver_sjf: init --- include/solver_sjf.h | 3 +++ src/evanix.c | 5 ++++- src/meson.build | 1 + src/solver_sjf.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 include/solver_sjf.h create mode 100644 src/solver_sjf.c diff --git a/include/solver_sjf.h b/include/solver_sjf.h new file mode 100644 index 0000000..8d1ace5 --- /dev/null +++ b/include/solver_sjf.h @@ -0,0 +1,3 @@ +#include "jobs.h" + +int solver_sjf(struct job **job, struct job_clist *q, int32_t resources); diff --git a/src/evanix.c b/src/evanix.c index 197beed..608345d 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -8,6 +8,7 @@ #include "queue.h" #include "solver_conformity.h" #include "solver_highs.h" +#include "solver_sjf.h" #include "util.h" static const char usage[] = @@ -24,7 +25,7 @@ static const char usage[] = " -p, --pipelined Use evanix build pipeline.\n" " -l, --check_cache-status Perform cache locality check.\n" " -c, --close-unused-fd Close stderr on exec.\n" - " -k, --solver conformity|highs Solver to use.\n" + " -k, --solver sjf|conformity|highs Solver to use.\n" "\n"; struct evanix_opts_t evanix_opts = { @@ -174,6 +175,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[]) opts->solver = solver_conformity; } else if (!strcmp(optarg, "highs")) { opts->solver = solver_highs; + } else if (!strcmp(optarg, "sjf")) { + opts->solver = solver_sjf; } else { fprintf(stderr, "option -%c has an invalid solver " diff --git a/src/meson.build b/src/meson.build index 53ba531..d6cfb00 100644 --- a/src/meson.build +++ b/src/meson.build @@ -10,6 +10,7 @@ e = executable( 'jobid.c', 'solver_conformity.c', 'solver_highs.c', + 'solver_sjf.c', ], include_directories: evanix_inc, 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 +#include + +#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; +} -- cgit v1.2.3