From 16ac10cfc0a441013229406b101fac5f02b26953 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 24 Aug 2024 13:41:54 +0530 Subject: evanix: add max-time flag --- include/evanix.h | 1 + src/evanix.c | 31 ++++++++++++++++++++++++++++++- src/queue.c | 9 ++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/evanix.h b/include/evanix.h index 2e69763..62dd22d 100644 --- a/include/evanix.h +++ b/include/evanix.h @@ -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); }; diff --git a/src/evanix.c b/src/evanix.c index 1a607d5..375678a 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -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 Use evanix build pipeline.\n" @@ -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, @@ -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'}, @@ -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': @@ -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) { @@ -287,6 +305,17 @@ 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: options --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->max_time && !opts->estimate) { + fprintf(stderr, "evanix: option --max-time implies --estimate\n" + "Try 'evanix --help' for more information.\n"); + ret = -EINVAL; + goto out_free_evanix; } if (opts->solver == solver_highs) diff --git a/src/queue.c b/src/queue.c index dbccd66..2474a39 100644 --- a/src/queue.c +++ b/src/queue.c @@ -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); -- cgit v1.2.3