Skip to content

Commit

Permalink
evanix: add estimate flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Aug 24, 2024
1 parent 0080f09 commit 498a4a2
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
2 changes: 2 additions & 0 deletions include/evanix.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <sqlite3.h>
#include <stdbool.h>
#include <stdint.h>

Expand All @@ -14,6 +15,7 @@ struct evanix_opts_t {
bool check_cache_status;
bool break_evanix;
char *system;
struct sqlite3 *estimate;
uint32_t max_builds;
int (*solver)(struct job **, struct job_clist *, int32_t);
};
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_project_arguments(

cjson_dep = dependency('libcjson')
highs_dep = dependency('highs')
sqlite_dep = dependency('sqlite3')
evanix_inc = include_directories('include')

if get_option('build-python')
Expand Down
2 changes: 2 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
pkg-config,
stdenv,
uthash,
sqlite
}:
stdenv.mkDerivation (finalAttrs: {
name = "evanix";
Expand Down Expand Up @@ -37,6 +38,7 @@ stdenv.mkDerivation (finalAttrs: {
cjson
highs
uthash
sqlite
];

doCheck = true;
Expand Down
87 changes: 76 additions & 11 deletions src/evanix.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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"
" -e, --estimate <path> Path to time estimate database.\n"
" -k, --solver sjf|conformity|highs Solver to use.\n"
"\n";

Expand All @@ -39,10 +40,14 @@ struct evanix_opts_t evanix_opts = {
.check_cache_status = true,
.solver = solver_highs,
.break_evanix = false,
.estimate = NULL,
};

static int evanix_build_thread_create(struct build_thread *build_thread);
static int evanix(char *expr);
static int evanix_free(struct evanix_opts_t *opts);
static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
char *argv[]);

/* This function returns errno on failure, consistent with the POSIX threads
* functions, rather than returning -errno. */
Expand Down Expand Up @@ -125,11 +130,14 @@ static int evanix(char *expr)
return ret;
}

int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
char *argv[])
{
extern int optind, opterr, optopt;
extern char *optarg;
int ret, longindex, c;
int longindex, c;

int ret = 0;

static struct option longopts[] = {
{"help", no_argument, NULL, 'h'},
Expand All @@ -139,14 +147,15 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
{"solver", required_argument, NULL, 'k'},
{"system", required_argument, NULL, 's'},
{"solver-report", no_argument, NULL, 'r'},
{"estimate", required_argument, NULL, 'e'},
{"pipelined", required_argument, NULL, 'p'},
{"max-builds", required_argument, NULL, 'm'},
{"close-unused-fd", required_argument, NULL, 'c'},
{"check-cache-status", required_argument, NULL, 'l'},
{NULL, 0, NULL, 0},
};

while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:", longopts,
while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:e:", longopts,
&longindex)) != -1) {
switch (c) {
case 'h':
Expand All @@ -167,6 +176,28 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
break;
case 'r':
opts->solver_report = true;
break;
case 'e':
if (opts->estimate) {
fprintf(stderr,
"option -%c can't be redefined "
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
}

ret = sqlite3_open_v2(optarg, &opts->estimate,
SQLITE_OPEN_READONLY |
SQLITE_OPEN_FULLMUTEX,
NULL);
if (ret != SQLITE_OK) {
print_err("Can't open database: %s",
sqlite3_errmsg(opts->estimate));
ret = -EPERM;
goto out_free_evanix;
}

break;
case 'k':
if (!strcmp(optarg, "conformity")) {
Expand All @@ -182,7 +213,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}
break;
case 'm':
Expand All @@ -194,7 +226,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}

opts->max_builds = ret;
Expand All @@ -207,7 +240,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}

opts->ispipelined = ret;
Expand All @@ -220,7 +254,8 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}

opts->close_unused_fd = ret;
Expand All @@ -233,28 +268,54 @@ int opts_read(struct evanix_opts_t *opts, char **expr, int argc, char *argv[])
"Try 'evanix --help' for more "
"information.\n",
c);
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}

opts->check_cache_status = ret;
break;
default:
fprintf(stderr,
"Try 'evanix --help' for more information.\n");
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
break;
}
}
if (optind != argc - 1) {
fprintf(stderr, "evanix: invalid expr operand\n"
"Try 'evanix --help' for more information.\n");
return -EINVAL;
ret = -EINVAL;
goto out_free_evanix;
}

if (opts->solver == solver_highs)
opts->ispipelined = false;

*expr = argv[optind];
out_free_evanix:
if (ret != 0)
evanix_free(opts);
else
*expr = argv[optind];

return ret;
}

static int evanix_free(struct evanix_opts_t *opts)
{
int ret;

if (opts->estimate) {
ret = sqlite3_close(opts->estimate);
if (ret != SQLITE_OK) {
print_err("Can't open database: %s",
sqlite3_errmsg(opts->estimate));
return -EPERM;
}

opts->estimate = NULL;
}

return 0;
}

Expand All @@ -271,5 +332,9 @@ int main(int argc, char *argv[])
if (ret < 0)
exit(EXIT_FAILURE);

ret = evanix_free(&evanix_opts);
if (ret < 0)
exit(EXIT_FAILURE);

exit(EXIT_SUCCESS);
}
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ e = executable(
],

include_directories: evanix_inc,
dependencies: [ cjson_dep, highs_dep ],
dependencies: [ cjson_dep, highs_dep, sqlite_dep ],
install: true,
c_args: [f'-DNIX_EVAL_JOBS_PATH=@NIX_EVAL_JOBS_PATH@'],
)
Expand Down

0 comments on commit 498a4a2

Please sign in to comment.