From 2800f12b040c7ce6da24bc7a99aa04b0ffb76fab Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Thu, 25 Jul 2024 09:16:23 +0530 Subject: solver_greedy -> solver_conformity --- include/solver_conformity.h | 3 ++ include/solver_greedy.h | 3 -- src/evanix.c | 30 +++++++++--------- src/meson.build | 4 +-- src/queue.c | 2 +- src/solver_conformity.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/solver_greedy.c | 77 --------------------------------------------- 7 files changed, 98 insertions(+), 98 deletions(-) create mode 100644 include/solver_conformity.h delete mode 100644 include/solver_greedy.h create mode 100644 src/solver_conformity.c delete mode 100644 src/solver_greedy.c diff --git a/include/solver_conformity.h b/include/solver_conformity.h new file mode 100644 index 0000000..0f6e825 --- /dev/null +++ b/include/solver_conformity.h @@ -0,0 +1,3 @@ +#include "jobs.h" + +int solver_conformity(struct job **job, struct job_clist *q, int32_t resources); diff --git a/include/solver_greedy.h b/include/solver_greedy.h deleted file mode 100644 index b76aed9..0000000 --- a/include/solver_greedy.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "jobs.h" - -int solver_greedy(struct job **job, struct job_clist *q, int32_t resources); diff --git a/src/evanix.c b/src/evanix.c index d7963ee..197beed 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -6,25 +6,25 @@ #include "build.h" #include "evanix.h" #include "queue.h" -#include "solver_greedy.h" +#include "solver_conformity.h" #include "solver_highs.h" #include "util.h" static const char usage[] = "Usage: evanix [options] expr\n" "\n" - " -h, --help Show help message and quit.\n" - " -f, --flake Build a flake.\n" - " -d, --dry-run Show what derivations would be " + " -h, --help Show help message and quit.\n" + " -f, --flake Build a flake.\n" + " -d, --dry-run Show what derivations would be " "built.\n" - " -s, --system System to build for.\n" - " -m, --max-build Max number of builds.\n" - " -b, --break-evanix Enable experimental features.\n" - " -r, --solver-report Print solver report.\n" - " -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 highs|greedy Solver to use.\n" + " -s, --system System to build for.\n" + " -m, --max-build Max number of builds.\n" + " -b, --break-evanix Enable experimental features.\n" + " -r, --solver-report Print solver report.\n" + " -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" "\n"; struct evanix_opts_t evanix_opts = { @@ -36,7 +36,7 @@ struct evanix_opts_t evanix_opts = { .system = NULL, .solver_report = false, .check_cache_status = true, - .solver = solver_greedy, + .solver = solver_conformity, .break_evanix = false, }; @@ -170,8 +170,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[]) opts->solver_report = true; break; case 'k': - if (!strcmp(optarg, "greedy")) { - opts->solver = solver_greedy; + if (!strcmp(optarg, "conformity")) { + opts->solver = solver_conformity; } else if (!strcmp(optarg, "highs")) { opts->solver = solver_highs; } else { diff --git a/src/meson.build b/src/meson.build index b0dac71..53ba531 100644 --- a/src/meson.build +++ b/src/meson.build @@ -8,14 +8,14 @@ e = executable( 'queue.c', 'build.c', 'jobid.c', - 'solver_greedy.c', + 'solver_conformity.c', 'solver_highs.c', ], include_directories: evanix_inc, dependencies: [ cjson_dep, highs_dep ], install: true, - c_args: [f'-DNIX_EVAL_JOBS_PATH=@NIX_EVAL_JOBS_PATH@'], + c_args: [f'-DNIX_EVAL_JOBS_PATH=@NIX_EVAL_JOBS_PATH@'], ) test('evanix', e) diff --git a/src/queue.c b/src/queue.c index d53dc0d..c3ae7ee 100644 --- a/src/queue.c +++ b/src/queue.c @@ -7,7 +7,7 @@ #include "evanix.h" #include "queue.h" -#include "solver_greedy.h" +#include "solver_conformity.h" #include "util.h" #define MAX_NIX_PKG_COUNT 200000 diff --git a/src/solver_conformity.c b/src/solver_conformity.c new file mode 100644 index 0000000..d2b2d82 --- /dev/null +++ b/src/solver_conformity.c @@ -0,0 +1,77 @@ +#include +#include + +#include "evanix.h" +#include "jobs.h" +#include "queue.h" +#include "solver_conformity.h" +#include "util.h" + +static float conformity(struct job *job); + +/* conformity is a ratio between number of direct feasible derivations sharing + * dependencies of a derivation and total number of dependencies */ +static float conformity(struct job *job) +{ + float conformity = 0; + + if (job->deps_filled == 0) + return 0; + + for (size_t i = 0; i < job->deps_filled; i++) { + for (size_t j = 0; j < job->deps[i]->parents_filled; j++) { + /* don't count the job itself */ + if (job->deps[i]->parents[j] == job) + continue; + /* don't count stale parents */ + if (job->deps[i]->parents[j]->stale) + continue; + + conformity++; + } + } + conformity /= job->deps_filled; + + return conformity; +} + +int solver_conformity(struct job **job, struct job_clist *q, int32_t resources) +{ + struct job *j; + float conformity_cur; + + struct job *selected = NULL; + float conformity_max = -1; + + CIRCLEQ_FOREACH (j, q, clist) { + if (j->stale) { + continue; + } else if (job_cost_recursive(j) > 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)); + } + } + } + + CIRCLEQ_FOREACH (j, q, clist) { + if (j->stale) + continue; + + conformity_cur = conformity(j); + if (conformity_cur > conformity_max) { + conformity_max = conformity_cur; + selected = j; + } else if (conformity_cur == conformity_max && + selected->deps_filled > j->deps_filled) { + selected = j; + } + } + + if (selected == NULL) + return -ESRCH; + + *job = selected; + return job_cost_recursive(selected); +} diff --git a/src/solver_greedy.c b/src/solver_greedy.c deleted file mode 100644 index 09b026f..0000000 --- a/src/solver_greedy.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include - -#include "evanix.h" -#include "jobs.h" -#include "queue.h" -#include "solver_greedy.h" -#include "util.h" - -static float conformity(struct job *job); - -/* conformity is a ratio between number of direct feasible derivations sharing - * dependencies of a derivation and total number of dependencies */ -static float conformity(struct job *job) -{ - float conformity = 0; - - if (job->deps_filled == 0) - return 0; - - for (size_t i = 0; i < job->deps_filled; i++) { - for (size_t j = 0; j < job->deps[i]->parents_filled; j++) { - /* don't count the job itself */ - if (job->deps[i]->parents[j] == job) - continue; - /* don't count stale parents */ - if (job->deps[i]->parents[j]->stale) - continue; - - conformity++; - } - } - conformity /= job->deps_filled; - - return conformity; -} - -int solver_greedy(struct job **job, struct job_clist *q, int32_t resources) -{ - struct job *j; - float conformity_cur; - - struct job *selected = NULL; - float conformity_max = -1; - - CIRCLEQ_FOREACH (j, q, clist) { - if (j->stale) { - continue; - } else if (job_cost_recursive(j) > 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)); - } - } - } - - CIRCLEQ_FOREACH (j, q, clist) { - if (j->stale) - continue; - - conformity_cur = conformity(j); - if (conformity_cur > conformity_max) { - conformity_max = conformity_cur; - selected = j; - } else if (conformity_cur == conformity_max && - selected->deps_filled > j->deps_filled) { - selected = j; - } - } - - if (selected == NULL) - return -ESRCH; - - *job = selected; - return job_cost_recursive(selected); -} -- cgit v1.2.3