1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "uti/sge_rmon.h"
#include "uti/sge_time.h"
#include "uti/sge_parse_num_par.h"
#include "cull/cull.h"
#include "sgeobj/sge_conf.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_ja_task.h"
#include "sgeobj/sge_qinstance.h"
#include "sgeobj/sge_qinstance_state.h"
#include "sgeobj/sge_order.h"
#include "sge_select_queue.h"
#include "schedd_monitor.h"
#include "sge_orders.h"
#include "suspend_thresholds.h"
static int select4suspension(lList *job_list, lListElem *queues, lListElem **jepp, lListElem **ja_taskp);
static int select4unsuspension(lList *job_list, lListElem *queues, lListElem **jepp, lListElem **ja_taskp);
/*
select and suspend jobs in susp_queues
*/
void
suspend_job_in_queues( lList *susp_queues, lList *job_list, order_t *orders)
{
u_long32 now;
int i, found;
lListElem *jep = NULL, *ja_task = NULL;
lListElem *qep;
DENTER(TOP_LAYER, "suspend_job_in_queues");
now = sge_get_gmt();
for_each (qep, susp_queues) {
u_long32 interval;
/* are suspend thresholds enabled? */
parse_ulong_val(NULL, &interval, TYPE_TIM,
lGetString(qep, QU_suspend_interval), NULL, 0);
if (interval == 0
|| !lGetUlong(qep, QU_nsuspend)
|| !lGetList(qep, QU_suspend_thresholds)) {
continue;
}
/* check time stamp */
if (lGetUlong(qep, QU_last_suspend_threshold_ckeck) &&
(lGetUlong(qep, QU_last_suspend_threshold_ckeck) + interval> now)) {
continue;
}
for (i = 0, found = 1;
i < (int) lGetUlong(qep, QU_nsuspend) && found;
i++) {
found = 0;
/* find one running job in suspend queue */
if (select4suspension(job_list, qep, &jep, &ja_task))
break;
/* generate suspend order for found job */
found = 1;
orders->configOrderList = sge_create_orders(orders->configOrderList,
ORT_suspend_on_threshold,
jep, ja_task, NULL, true);
DPRINTF(("++++ suspending job "sge_u32"/"sge_u32" on threshold\n",
lGetUlong(jep, JB_job_number), lGetUlong(ja_task, JAT_task_number)));
/* prevent multiple selection of this job */
lSetUlong(ja_task, JAT_state,
lGetUlong(ja_task, JAT_state) | JSUSPENDED_ON_THRESHOLD);
}
if (i==0 && !found) {
DPRINTF(("found no jobs for sot in queue %s\n", lGetString(qep, QU_full_name)));
}
}
DEXIT;
return;
}
void
unsuspend_job_in_queues( lList *queue_list, lList *job_list, order_t *orders)
{
u_long32 now;
int i, found;
lListElem *jep = NULL, *ja_task = NULL;
lListElem *qep;
DENTER(TOP_LAYER, "unsuspend_job_in_queues");
now = sge_get_gmt();
for_each (qep, queue_list) {
u_long32 interval;
dstring ds;
char buffer[128];
sge_dstring_init(&ds, buffer, sizeof(buffer));
/* are suspend thresholds enabled? */
parse_ulong_val(NULL, &interval, TYPE_TIM,
lGetString(qep, QU_suspend_interval), NULL, 0);
if (interval == 0
|| !lGetUlong(qep, QU_nsuspend)
|| !lGetList(qep, QU_suspend_thresholds)) {
continue;
}
/* check time stamp */
if (lGetUlong(qep, QU_last_suspend_threshold_ckeck) &&
(lGetUlong(qep, QU_last_suspend_threshold_ckeck) +
interval> now)) {
char tmp[128];
strcpy(tmp, sge_ctime((time_t)lGetUlong(qep, QU_last_suspend_threshold_ckeck), &ds));
DPRINTF(("queue was last checked at %s (interval = %s, now = %s)\n",
tmp,
lGetString(qep, QU_suspend_interval),
sge_ctime((time_t)now, &ds)));
continue;
}
for (i = 0, found = 1;
i < (int) lGetUlong(qep, QU_nsuspend) && found;
i++) {
found = 0;
/* find one running job in suspend queue */
if (select4unsuspension(job_list, qep, &jep, &ja_task)) {
break;
}
/* generate unsuspend order for found job */
found = 1;
orders->configOrderList = sge_create_orders(orders->configOrderList,
ORT_unsuspend_on_threshold,
jep, ja_task, NULL, true);
DPRINTF(("---- unsuspending job "sge_u32"/"sge_u32" on threshold\n",
lGetUlong(jep, JB_job_number), lGetUlong(ja_task, JAT_task_number)));
/* prevent multiple selection of this job */
lSetUlong(ja_task, JAT_state, lGetUlong(ja_task, JAT_state)
& ~JSUSPENDED_ON_THRESHOLD);
}
if (i==0 && !found) {
DPRINTF(("found no jobs for usot in queue %s\n",
lGetString(qep, QU_full_name)));
}
}
DEXIT;
return;
}
static int
select4suspension(lList *job_list, lListElem *qep, lListElem **jepp,
lListElem **ja_taskp)
{
u_long32 jstate;
lListElem *jep, *jshortest = NULL, *shortest = NULL, *ja_task;
const char *qnm;
DENTER(TOP_LAYER, "select4suspension");
qnm = lGetString(qep, QU_full_name);
if (qinstance_state_is_manual_suspended(qep) ||
qinstance_state_is_susp_on_sub(qep) ||
qinstance_state_is_cal_suspended(qep)) {
DEXIT;
return -1;
}
for_each (jep, job_list) {
/* job running */
for_each (ja_task, lGetList(jep, JB_ja_tasks)) {
jstate = lGetUlong(ja_task, JAT_state);
if (!(jstate & JRUNNING) ||
(jstate & JSUSPENDED) || (jstate & JSUSPENDED_ON_THRESHOLD)) {
continue;
}
/*
** if the current task is
** a job / one task of an array-job
** a master-task of a pe-job with sub-tasks in this queue
** then it is a potential candidate which we could suspend
*/
if (lGetSubStr(ja_task, JG_qname, qnm, JAT_granted_destin_identifier_list) == NULL) {
continue;
}
/* select job that runs shortest time for suspension */
if (!shortest || lGetUlong(shortest, JAT_start_time) <
lGetUlong(ja_task, JAT_start_time)) {
shortest = ja_task;
jshortest = jep;
}
}
}
if (shortest) {
*jepp = jshortest;
*ja_taskp = shortest;
}
DEXIT;
return shortest?0:1;
}
static int select4unsuspension(
lList *job_list,
lListElem *qep,
lListElem **jepp,
lListElem **ja_taskp
) {
u_long32 jstate;
lListElem *jep, *jlongest = NULL, *longest = NULL, *ja_task;
const char *qnm;
DENTER(TOP_LAYER, "select4unsuspension");
qnm = lGetString(qep, QU_full_name);
for_each (jep, job_list) {
for_each (ja_task, lGetList(jep, JB_ja_tasks)) {
/* job must be suspended */
jstate = lGetUlong(ja_task, JAT_state);
if (!(jstate & JSUSPENDED_ON_THRESHOLD)) {
continue;
}
/* is this the master queue of this job ? */
if (strcmp(qnm, lGetString(lFirst(lGetList(ja_task,
JAT_granted_destin_identifier_list)), JG_qname))) {
DTRACE;
continue;
}
/* select task that runs longest time for unsuspension */
if (!longest ||lGetUlong(longest, JAT_start_time) > lGetUlong(ja_task, JAT_start_time)) {
longest = ja_task;
jlongest = jep;
}
}
}
if (longest) {
*jepp = jlongest;
*ja_taskp = longest;
}
DEXIT;
return longest?0:1;
}
|