Skip to content

Commit

Permalink
evanix: add max-time flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanmohd committed Aug 24, 2024
1 parent 90f0f6d commit 5acb447
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/evanix.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct evanix_opts_t {
char *system;
struct sqlite3 *estimate;
uint32_t max_builds;
uint32_t max_time;
int (*solver)(struct job **, struct job_clist *, int32_t);
};

Expand Down
32 changes: 31 additions & 1 deletion src/evanix.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static const char usage[] =
"built.\n"
" -s, --system System to build for.\n"
" -m, --max-builds Max number of builds.\n"
" -t, --max-time Max time available in seconds.\n"
" -b, --break-evanix Enable experimental features.\n"
" -r, --solver-report Print solver report.\n"
" -p, --pipelined <bool> Use evanix build pipeline.\n"
Expand All @@ -35,6 +36,7 @@ struct evanix_opts_t evanix_opts = {
.ispipelined = true,
.isdryrun = false,
.max_builds = 0,
.max_time = 0,
.system = NULL,
.solver_report = false,
.check_cache_status = true,
Expand Down Expand Up @@ -147,6 +149,7 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
{"solver", required_argument, NULL, 'k'},
{"system", required_argument, NULL, 's'},
{"solver-report", no_argument, NULL, 'r'},
{"max-time", required_argument, NULL, 't'},
{"estimate", required_argument, NULL, 'e'},
{"pipelined", required_argument, NULL, 'p'},
{"max-builds", required_argument, NULL, 'm'},
Expand All @@ -155,7 +158,7 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
{NULL, 0, NULL, 0},
};

while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:e:", longopts,
while ((c = getopt_long(argc, argv, "hfds:r::m:p:c:l:k:e:t:", longopts,
&longindex)) != -1) {
switch (c) {
case 'h':
Expand Down Expand Up @@ -232,6 +235,21 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,

opts->max_builds = ret;
break;
case 't':
ret = atoi(optarg);
if (ret <= 0) {
fprintf(stderr,
"option -%c requires a natural number "
"argument\n"
"Try 'evanix --help' for more "
"information.\n",
c);
ret = -EINVAL;
goto out_free_evanix;
}

opts->max_time = ret;
break;
case 'p':
ret = atob(optarg);
if (ret < 0) {
Expand Down Expand Up @@ -287,6 +305,18 @@ static int opts_read(struct evanix_opts_t *opts, char **expr, int argc,
"Try 'evanix --help' for more information.\n");
ret = -EINVAL;
goto out_free_evanix;
} else if (opts->max_time && opts->max_builds) {
fprintf(stderr, "evanix: option --max-time and --max-builds "
"are mutually exclusive\n"
"Try 'evanix --help' for more information.\n");
ret = -EINVAL;
goto out_free_evanix;
} else if (!opts->estimate || opts->max_time) {
fprintf(stderr, "evanix: option --max-time and --estimate "
"are mutually inclusive\n"
"Try 'evanix --help' for more information.\n");
ret = -EINVAL;
goto out_free_evanix;
}

if (opts->solver == solver_highs)
Expand Down
9 changes: 8 additions & 1 deletion src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ int queue_thread_new(struct queue_thread **queue_thread, FILE *stream)
ret = -errno;
goto out_free_qt;
}

if (evanix_opts.max_builds)
qt->queue->resources = evanix_opts.max_builds;
else if (evanix_opts.max_time)
qt->queue->resources = evanix_opts.max_time;
else
qt->queue->resources = 0;

qt->queue->htab = NULL;
qt->queue->resources = evanix_opts.max_builds;
qt->queue->jobid = NULL;
qt->queue->state = Q_SEM_WAIT;
ret = sem_init(&qt->queue->sem, 0, 0);
Expand Down

0 comments on commit 5acb447

Please sign in to comment.