From f62705b0dcd6be49d4f5fa61bc23525546fd54f2 Mon Sep 17 00:00:00 2001 From: "Dong H. Ahn" Date: Fri, 17 Feb 2017 12:00:28 -0800 Subject: [PATCH] resrc_reqst: carve out job-to-resrc_reqst logic into its own function Add get_resrc_reqst and move the logic to fill resrc_reqst to this function. Enhance readability of schedule_job which has grown somewhat large. More importantly, being ready to encode resource aggregate info without having to modify the main schedule_job function. --- sched/sched.c | 57 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/sched/sched.c b/sched/sched.c index 05699cb9b..32f4d0115 100644 --- a/sched/sched.c +++ b/sched/sched.c @@ -1389,28 +1389,11 @@ static int req_tpexec_run (flux_t *h, flux_lwj_t *job) * * *******************************************************************************/ -/* - * schedule_job() searches through all of the idle resources to - * satisfy a job's requirements. If enough resources are found, it - * proceeds to allocate those resources and update the kvs's lwj entry - * in preparation for job execution. If less resources - * are found than the job requires, and if the job asks to reserve - * resources, then those resources will be reserved. - */ -int schedule_job (ssrvctx_t *ctx, flux_lwj_t *job, int64_t starttime) +static resrc_reqst_t *get_resrc_reqst (flux_lwj_t *job, int64_t starttime, + int64_t *nreqrd) { json_t *req_res = NULL; - flux_t *h = ctx->h; - int rc = -1; - int64_t nfound = 0; - int64_t nreqrd = 0; resrc_reqst_t *resrc_reqst = NULL; - resrc_tree_t *found_tree = NULL; - resrc_tree_t *selected_tree = NULL; - struct sched_plugin *plugin = sched_plugin_get (ctx->loader); - - if (!plugin) - return rc; /* * Require at least one task per node, and @@ -1439,7 +1422,7 @@ int schedule_job (ssrvctx_t *ctx, flux_lwj_t *job, int64_t starttime) Jadd_str (req_res, "type", "node"); Jadd_int64 (req_res, "req_qty", job->req->nnodes); - nreqrd = job->req->nnodes; + *nreqrd = job->req->nnodes; /* Since nodes are requested, make sure we look for at * least one core on each node */ @@ -1467,7 +1450,7 @@ int schedule_job (ssrvctx_t *ctx, flux_lwj_t *job, int64_t starttime) } else if (job->req->ncores > 0) { Jadd_str (req_res, "type", "core"); Jadd_int (req_res, "req_qty", job->req->ncores); - nreqrd = job->req->ncores; + *nreqrd = job->req->ncores; Jadd_int64 (req_res, "req_size", 1); /* setting exclusive to true prevents multiple jobs per core */ @@ -1478,8 +1461,36 @@ int schedule_job (ssrvctx_t *ctx, flux_lwj_t *job, int64_t starttime) Jadd_int64 (req_res, "starttime", starttime); Jadd_int64 (req_res, "endtime", starttime + job->req->walltime); resrc_reqst = resrc_reqst_from_json (req_res, NULL); - Jput (req_res); - if (!resrc_reqst) + +done: + if (req_res) + Jput (req_res); + return resrc_reqst; +} + +/* + * schedule_job() searches through all of the idle resources to + * satisfy a job's requirements. If enough resources are found, it + * proceeds to allocate those resources and update the kvs's lwj entry + * in preparation for job execution. If less resources + * are found than the job requires, and if the job asks to reserve + * resources, then those resources will be reserved. + */ +int schedule_job (ssrvctx_t *ctx, flux_lwj_t *job, int64_t starttime) +{ + flux_t *h = ctx->h; + int rc = -1; + int64_t nfound = 0; + int64_t nreqrd = 0; + resrc_reqst_t *resrc_reqst = NULL; + resrc_tree_t *found_tree = NULL; + resrc_tree_t *selected_tree = NULL; + struct sched_plugin *plugin = sched_plugin_get (ctx->loader); + + if (!plugin) + return rc; + + if (!(resrc_reqst = get_resrc_reqst (job, starttime, &nreqrd))) goto done; if ((nfound = plugin->find_resources (h, ctx->rctx.root_resrc,