Skip to content

Commit

Permalink
solver_sjf: init
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Jul 25, 2024
1 parent 2800f12 commit afbd04e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/solver_sjf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "jobs.h"

int solver_sjf(struct job **job, struct job_clist *q, int32_t resources);
5 changes: 4 additions & 1 deletion src/evanix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand All @@ -24,7 +25,7 @@ static const char usage[] =
" -p, --pipelined <bool> Use evanix build pipeline.\n"
" -l, --check_cache-status <bool> Perform cache locality check.\n"
" -c, --close-unused-fd <bool> 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 = {
Expand Down Expand Up @@ -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 "
Expand Down
37 changes: 37 additions & 0 deletions src/solver_sjf.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit afbd04e

Please sign in to comment.