From 1988cc9051c1da397d1a39dce4cd7f5f237c75c4 Mon Sep 17 00:00:00 2001 From: Don Lipari <lipari1@llnl.gov> Date: Tue, 30 Jun 2009 21:00:30 +0000 Subject: [PATCH] Create a spank_get_item() option that the SPANK cpuset plugin can use to discover the cpus that the select/cons_res plugin has allocated to a job. --- NEWS | 2 + slurm/spank.h | 3 +- src/common/plugstack.c | 5 +++ src/common/slurm_cred.c | 51 ++++++++++++++++++++++++++ src/common/slurm_cred.h | 6 +++ src/slurmd/slurmstepd/slurmstepd_job.c | 2 + src/slurmd/slurmstepd/slurmstepd_job.h | 1 + 7 files changed, 69 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1b9e657a18b..101a26bab6e 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ documents those changes that are of interest to users and admins. -- Modify job step cancel logic for scancel and srun (on reciept of SIGTERM or three SIGINT) to immediately send SIGKILL to spawned tasks. Previous logic would send SIGCONT, SIGTERM, wait KillWait seconds, SIGKILL. +-- Create a spank_get_item() option that the SPANK cpuset plugin can use to + discover the cpus that the select/cons_res plugin has allocated to a job. * Changes in SLURM 2.1.0-pre1 ============================= diff --git a/slurm/spank.h b/slurm/spank.h index 2427f6c692c..f187ef13ebd 100644 --- a/slurm/spank.h +++ b/slurm/spank.h @@ -148,8 +148,9 @@ enum spank_item { S_SLURM_VERSION_MAJOR, /* Current slurm version major release (char **) */ S_SLURM_VERSION_MINOR, /* Current slurm version minor release (char **) */ S_SLURM_VERSION_MICRO, /* Current slurm version micro release (char **) */ - S_STEP_CPUS_PER_TASK /* CPUs allocated per task (=1 if --overcommit + S_STEP_CPUS_PER_TASK, /* CPUs allocated per task (=1 if --overcommit * option is used, uint32_t *) */ + S_JOB_ALLOC_CORES /* Allocated cores in list format */ }; typedef enum spank_item spank_item_t; diff --git a/src/common/plugstack.c b/src/common/plugstack.c index ac076ee0d97..d3889ea0474 100644 --- a/src/common/plugstack.c +++ b/src/common/plugstack.c @@ -1572,6 +1572,7 @@ spank_err_t spank_get_item(spank_t spank, spank_item_t item, ...) pid_t *p2pid; pid_t pid; char ***p2argv; + char **p2str; char **p2vers; slurmd_task_info_t *task; slurmd_job_t *slurmd_job = NULL; @@ -1763,6 +1764,10 @@ spank_err_t spank_get_item(spank_t spank, spank_item_t item, ...) p2uint32 = va_arg(vargs, uint32_t *); rc = global_to_local_id (slurmd_job, uint32, p2uint32); break; + case S_JOB_ALLOC_CORES: + p2str = va_arg(vargs, char **); + *p2str = slurmd_job->alloc_cores; + break; case S_SLURM_VERSION: p2vers = va_arg(vargs, char **); *p2vers = SLURM_VERSION; diff --git a/src/common/slurm_cred.c b/src/common/slurm_cred.c index 4ff7048793e..67dc379fc15 100644 --- a/src/common/slurm_cred.c +++ b/src/common/slurm_cred.c @@ -1115,6 +1115,57 @@ slurm_cred_get_signature(slurm_cred_t cred, char **datap, uint32_t *datalen) return SLURM_SUCCESS; } +char* +format_core_allocs(slurm_cred_t cred, char *node_name) +{ + bitstr_t *core_bitmap; + char *str = NULL; + hostset_t hset = NULL; + int host_index = -1; + uint32_t i, j, i_first_bit=0, i_last_bit=0; + + if (!(hset = hostset_create(cred->job_hostlist))) { + error("Unable to create job hostlist: `%s'", + cred->job_hostlist); + } + + host_index = hostset_find(hset, node_name); + if ((host_index < 0) || (host_index >= cred->job_nhosts)) { + error("Invalid host_index %d for job %u", + host_index, cred->jobid); + return NULL; + } + host_index++; /* change from 0-origin to 1-origin */ + for (i=0; host_index; i++) { + if (host_index > cred->sock_core_rep_count[i]) { + i_first_bit += cred->sockets_per_node[i] * + cred->cores_per_socket[i] * + cred->sock_core_rep_count[i]; + host_index -= cred->sock_core_rep_count[i]; + } else { + i_first_bit += cred->sockets_per_node[i] * + cred->cores_per_socket[i] * + (host_index - 1); + i_last_bit = i_first_bit + + cred->sockets_per_node[i] * + cred->cores_per_socket[i]; + break; + } + } + + core_bitmap = bit_alloc(i_last_bit - i_first_bit); + for (i = i_first_bit, j = 0; i < i_last_bit; i++, j++) { + if (bit_test(cred->core_bitmap, i)) + bit_set(core_bitmap, j); + } + + str = xmalloc(1024); + bit_fmt(str, 1024, core_bitmap); + bit_free(core_bitmap); + + return str; +} + void slurm_cred_pack(slurm_cred_t cred, Buf buffer) { diff --git a/src/common/slurm_cred.h b/src/common/slurm_cred.h index ad046739ddd..c3090d0c7cb 100644 --- a/src/common/slurm_cred.h +++ b/src/common/slurm_cred.h @@ -292,6 +292,12 @@ slurm_cred_t slurm_cred_unpack(Buf buffer); int slurm_cred_get_signature(slurm_cred_t cred, char **datap, uint32_t *len); +/* + * Retrieve the set of cores that were allocated to the job and format them + * in the List Format (e.g., "0-2,7,12-14") + */ +char* format_core_allocs(slurm_cred_t cred, char *node_name); + /* * Print a slurm job credential using the info() call */ diff --git a/src/slurmd/slurmstepd/slurmstepd_job.c b/src/slurmd/slurmstepd/slurmstepd_job.c index 998d4acc7c0..fb6c5616feb 100644 --- a/src/slurmd/slurmstepd/slurmstepd_job.c +++ b/src/slurmd/slurmstepd/slurmstepd_job.c @@ -277,6 +277,7 @@ job_create(launch_tasks_request_msg_t *msg) job->pty = msg->pty; job->open_mode = msg->open_mode; job->options = msg->options; + job->alloc_cores = format_core_allocs(msg->cred, conf->node_name); list_append(job->sruns, (void *) srun); @@ -510,6 +511,7 @@ job_destroy(slurmd_job_t *job) xfree(job->node_name); xfree(job->task_prolog); xfree(job->task_epilog); + xfree(job->alloc_cores); xfree(job); } diff --git a/src/slurmd/slurmstepd/slurmstepd_job.h b/src/slurmd/slurmstepd/slurmstepd_job.h index 3a6574d6a43..fa88ee24758 100644 --- a/src/slurmd/slurmstepd/slurmstepd_job.h +++ b/src/slurmd/slurmstepd/slurmstepd_job.h @@ -201,6 +201,7 @@ typedef struct slurmd_job { char *restart_dir; /* restart from context */ char *resv_id; /* Cray/BASIL reservation ID */ uint16_t restart_cnt; /* batch job restart count */ + char *alloc_cores; /* needed by the SPANK cpuset plugin */ } slurmd_job_t; -- GitLab