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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
|
/*___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 <string.h>
#include "uti/sge_rmon.h"
#include "uti/sge_hostname.h"
#include "cull/cull.h"
#include "sgeobj/sge_pe.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/sge_host.h"
#include "sgeobj/sge_qinstance.h"
#include "sgeobj/sge_centry.h"
#include "sgeobj/sge_schedd_conf.h"
#include "sgeobj/sge_advance_reservation.h"
#include "sge.h"
#include "sge_select_queue.h"
#include "sge_qeti.h"
#include "sge_resource_utilization.h"
#include "sge_select_queue.h"
#include "sge_resource_utilization_RDE_L.h"
#include "sge_resource_utilization_RUE_L.h"
/* At that point in time we only keep references to in the iterator that
* allow for efficiently iterating trough relevant queue end times in
* that affect resource utilization of a particular job.
*
* Further improvements with sge_qeti_t might allow to notably reduce
* the time for the actual resource selection: It might be useful for
* example to enhance sge_qeti_t towards keeping all information required
* for decide very quickly about eligibility of each host/queue.
*/
struct sge_qeti_s {
lList *cr_refs_pe;
lList *cr_refs_global;
lList *cr_refs_host;
lList *cr_refs_queue;
};
/*
* Assume a parallel job with a license and h_vmem request. At the time
* when we seek for reservation the changes with the resource utilization
* diagrams relevant for this job are marked with a '+'
*
* After initializing the time iterator using sge_qeti_allocate() the
* iterator keeps references to all resource instances (QETI_resource_instance)
* shown in the diagram below and all queue end next (QETI_queue_end_next)
* references refer to the very end of those resource diagrams.
*
* mpi_pe slots +------+-----------+
* Global license +------+-----------+-----+
* Host1 h_vmem +------+-----------+
* Host2 h_vmem +------+-----------+
* Queue1 slots +------+---+-------+-----+
* Queue2 slots +--+------+---+-------+
* 6 5 4 3 2 1
*
* After sge_qeti_first() returned time mark #1 the queue end next
* references for Global license and the Queue1 slot point to #2.
* Then after sge_qeti_next() returned time mark #2 the queue end
* next references for Queue1/2 slot point to #3 whereas all remaining
* queue end next references point to #4 ...
*
*/
/****** sge_qeti/sge_qeti_list_add() *******************************************
* NAME
* sge_qeti_list_add() -- Adds a resource utilization to QETI resource list
*
* SYNOPSIS
* static int sge_qeti_list_add(lList **lpp, const char *name, lList*
* rue_lp, double total, bool must_exist)
*
* FUNCTION
* ???
*
* INPUTS
* lList **lpp - QETI resource list
* const char *name - Name of the resource
* lList* rue_lp - Resource utilization entry (RUE_Type)
* double total - Total resource amount
* bool must_exist - If true the entry must exist in 'lpp'.
*
* RESULT
* static int - 0 on success
*
* NOTES
* MT-NOTE: sge_qeti_list_add() is not MT safe
*******************************************************************************/
static int sge_qeti_list_add(lList **lpp, const char *name, lList* rue_lp, double total, bool must_exist)
{
lListElem *tmp_cr_ref, *ep;
DENTER(TOP_LAYER, "sge_qeti_list_add");
if (!(tmp_cr_ref = lGetElemStr(rue_lp, RUE_name, name))) {
DRETURN(must_exist?-1:0);
}
if (!*lpp && !(*lpp = lCreateList("pe_qeti", QETI_Type))) {
DRETURN(-1);
}
if (!(ep = lCreateElem(QETI_Type))) {
lFreeList(lpp);
DRETURN(-1);
}
lSetRef(ep, QETI_resource_instance, tmp_cr_ref);
lSetDouble(ep, QETI_total, total);
lAppendElem(*lpp, ep);
DRETURN(0);
}
static int sge_add_qeti_resource_container(lList **qeti_to_add, lList* rue_list,
lList* total_list, lList* centry_list, lList* requests, bool force_slots)
{
lListElem *req, *actual, *tep;
const char *name;
lListElem *centry_config = NULL;
DENTER(TOP_LAYER, "sge_add_qeti_resource_container");
/* implicit slot request */
if ( ((tep = lGetElemStr(total_list, CE_name, SGE_ATTR_SLOTS)) != NULL) && force_slots) {
DEXIT;
return -1;
}
if (tep && sge_qeti_list_add(qeti_to_add, SGE_ATTR_SLOTS, rue_list,
lGetDouble(tep, CE_doubleval), true)) {
DEXIT;
return -1;
}
/* default request */
actual = lGetElemStr(rue_list, RUE_name, SGE_ATTR_SLOTS);
if (actual != NULL) {
name = lGetString(actual, RUE_name);
centry_config = lGetElemStr(centry_list, CE_name, name);
if (lGetUlong(centry_config, CE_consumable) != CONSUMABLE_NO && !is_requested(requests, name)) {
if (!(tep = lGetElemStr(total_list, CE_name, name)) ||
sge_qeti_list_add(qeti_to_add, name, rue_list, lGetDouble(tep, CE_doubleval), true)) {
DEXIT;
return -1;
}
}
}
/* explicit requests */
for_each(req, requests) {
name = lGetString(req, CE_name);
centry_config = lGetElemStr(centry_list, CE_name, name);
if ((centry_config && lGetUlong(centry_config, CE_consumable) != CONSUMABLE_NO) &&
(tep = lGetElemStr(total_list, CE_name, name))) {
if (sge_qeti_list_add(qeti_to_add, name, rue_list, lGetDouble(tep, CE_doubleval), false)) {
DEXIT;
return -1;
}
}
}
DEXIT;
return 0;
}
sge_qeti_t *sge_qeti_allocate2(lList *cr_list)
{
sge_qeti_t *iter;
if (!(iter = calloc(1, sizeof(sge_qeti_t)))) {
return NULL;
}
sge_qeti_list_add(&iter->cr_refs_pe, SGE_ATTR_SLOTS, cr_list, 10, true);
return iter;
}
sge_qeti_t *sge_qeti_allocate(sge_assignment_t *a)
{
int ar_id = lGetUlong(a->job, JB_ar);
sge_qeti_t *iter = NULL;
lListElem *next_queue, *qep, *hep;
lList *requests = lGetList(a->job, JB_hard_resource_list);
DENTER(TOP_LAYER, "sge_qeti_allocate");
if (!(iter = calloc(1, sizeof(sge_qeti_t)))) {
DEXIT;
return NULL;
}
if (ar_id == 0) {
/* add "slot" resource utilization entry of parallel environment */
if (sge_qeti_list_add(&iter->cr_refs_pe, SGE_ATTR_SLOTS,
lGetList(a->pe, PE_resource_utilization), lGetUlong(a->pe, PE_slots), true)) {
sge_qeti_release(&iter);
DEXIT;
return NULL;
}
/* add references to global resource utilization entries
that might affect jobs queue end time */
if ((hep = host_list_locate(a->host_list, SGE_GLOBAL_NAME))) {
if (sge_add_qeti_resource_container(&iter->cr_refs_global,
lGetList(hep, EH_resource_utilization), lGetList(hep, EH_consumable_config_list),
a->centry_list, requests, false)!=0) {
sge_qeti_release(&iter);
DEXIT;
return NULL;
}
}
}
/* add references to per host resource utilization entries
that might affect jobs queue end time */
for_each (hep, a->host_list) {
const char *eh_name;
int is_relevant;
const void *queue_iterator = NULL;
if (!strcmp((eh_name=lGetHost(hep, EH_name)), SGE_GLOBAL_NAME)) {
continue;
}
if (sge_host_match_static(a, hep) == DISPATCH_NEVER_CAT) {
continue;
}
/* There must be at least one queue referenced with the parallel
environment that resides at this host. And secondly we only
consider those hosts that match this job (statically) */
is_relevant = false;
for (next_queue = lGetElemHostFirst(a->queue_list, QU_qhostname, eh_name, &queue_iterator);
(qep = next_queue);
next_queue = lGetElemHostNext(a->queue_list, QU_qhostname, eh_name, &queue_iterator)) {
if (!qinstance_is_pe_referenced(qep, a->pe)) {
continue;
}
/* consider only those queues that match this job (statically) */
if (sge_queue_match_static(a, qep) != DISPATCH_OK) {
continue;
}
if (ar_id == 0) {
if (sge_add_qeti_resource_container(&iter->cr_refs_queue,
lGetList(qep, QU_resource_utilization), lGetList(qep, QU_consumable_config_list),
a->centry_list, requests, false)!=0) {
sge_qeti_release(&iter);
DRETURN(NULL);
}
} else {
const char *qname = lGetString(qep, QU_full_name);
lListElem *ar_queue;
lListElem *ar_ep = lGetElemUlong(a->ar_list, AR_id, ar_id);
ar_queue = lGetSubStr(ar_ep, QU_full_name, qname, AR_reserved_queues);
if (sge_add_qeti_resource_container(&iter->cr_refs_queue,
lGetList(ar_queue, QU_resource_utilization), lGetList(ar_queue, QU_consumable_config_list),
a->centry_list, requests, false)!=0) {
sge_qeti_release(&iter);
DRETURN(NULL);
}
}
is_relevant = true;
}
if (is_relevant) {
if (sge_add_qeti_resource_container(&iter->cr_refs_host,
lGetList(hep, EH_resource_utilization), lGetList(hep, EH_consumable_config_list),
a->centry_list, requests, false)!=0) {
sge_qeti_release(&iter);
DEXIT;
return NULL;
}
}
}
DPRINTF(("QETI: P %d G %d H %d Q %d\n",
lGetNumberOfElem(iter->cr_refs_pe),
lGetNumberOfElem(iter->cr_refs_global),
lGetNumberOfElem(iter->cr_refs_host),
lGetNumberOfElem(iter->cr_refs_queue)));
DEXIT;
return iter;
}
static void sge_qeti_init_refs(lList *cref_lp)
{
lListElem *cr_ep;
lList *utilization_diagram;
lListElem *rue_ep;
DENTER(TOP_LAYER, "sge_qeti_init_refs");
for_each(cr_ep, cref_lp) {
rue_ep = lGetRef(cr_ep, QETI_resource_instance);
utilization_diagram = lGetList((lListElem *)lGetRef(cr_ep, QETI_resource_instance), RUE_utilized);
DPRINTF((" QETI INIT: %s %p\n", lGetString(rue_ep, RUE_name), utilization_diagram));
/* lLast() correctly returns a NULL reference
in case of an empty resource utilization diagram */
lSetRef(cr_ep, QETI_queue_end_next, lLast(utilization_diagram));
}
DEXIT;
}
/* an empty resource utilization diagrams actually means the resource
is available now - thus we can skip it when determining the maximum */
static void sge_qeti_max_end_time(u_long32 *max_time, const lList *cref_lp)
{
lListElem *cr_ep, *ref;
u_long32 tmp_time = *max_time;
lListElem *rue_ep;
DENTER(TOP_LAYER, "sge_qeti_max_end_time");
for_each (cr_ep, cref_lp) {
rue_ep = lGetRef(cr_ep, QETI_resource_instance);
if (!(ref = lGetRef(cr_ep, QETI_queue_end_next))) {
DPRINTF((" QETI END: %s\n", lGetString(rue_ep, RUE_name)));
continue;
}
DPRINTF((" QETI END: %s "sge_U32CFormat" ("sge_U32CFormat")\n",
lGetString(rue_ep, RUE_name), lGetUlong(ref, RDE_time), tmp_time));
tmp_time = MAX(tmp_time, lGetUlong(ref, RDE_time));
}
*max_time = tmp_time;
DEXIT;
return;
}
/* switch queue end next references to the next entry
whose time is larger or equal the specified time */
static void sge_qeti_switch_to_next(u_long32 time, lList *cref_lp)
{
lListElem *cr_ep, *ref;
lListElem *rue_ep;
DENTER(TOP_LAYER, "sge_qeti_switch_to_next");
time--;
for_each (cr_ep, cref_lp) {
rue_ep = lGetRef(cr_ep, QETI_resource_instance);
if (!(ref = lGetRef(cr_ep, QETI_queue_end_next))) {
DPRINTF((" QETI NEXT: %s (finished)\n", lGetString(rue_ep, RUE_name)));
continue;
}
while (ref && time < lGetUlong(ref, RDE_time)) {
ref = lPrev(ref);
}
DPRINTF((" QETI NEXT: %s set to "sge_U32CFormat" (%p)\n",
lGetString(rue_ep, RUE_name), ref?lGetUlong(ref, RDE_time):0, ref));
lSetRef(cr_ep, QETI_queue_end_next, ref);
}
DEXIT;
}
/****** sge_qeti/sge_qeti_next_before() ****************************************
* NAME
* sge_qeti_next_before() -- ???
*
* SYNOPSIS
* void sge_qeti_next_before(sge_qeti_t *qeti, u_long32 start)
*
* FUNCTION
* All queue end next references are set in a way that will
* sge_qeti_next() return a time value that is before (i.e. less than)
* start.
*
* INPUTS
* sge_qeti_t *qeti - ???
* u_long32 start - ???
*
* NOTES
* MT-NOTE: sge_qeti_next_before() is MT safe
*******************************************************************************/
void sge_qeti_next_before(sge_qeti_t *qeti, u_long32 start)
{
sge_qeti_switch_to_next(start, qeti->cr_refs_pe);
sge_qeti_switch_to_next(start, qeti->cr_refs_global);
sge_qeti_switch_to_next(start, qeti->cr_refs_host);
sge_qeti_switch_to_next(start, qeti->cr_refs_queue);
}
/****** sge_resource_utilization/sge_qeti_first() ******************************
* NAME
* sge_qeti_first() --
*
* SYNOPSIS
* u_long32 sge_qeti_first(sge_qeti_t *qeti)
*
* FUNCTION
* Initialize/Reinitialize Queue End Time Iterator. All queue end next
* references are initialized to the queue end of all resource instances.
* Before we return the time that is most in the future queue end next
* references are switched to the next entry that is earlier than the time
* that was returned.
*
* INPUTS
* sge_qeti_t *qeti - ???
*
* RESULT
* u_long32 -
*
* NOTES
* MT-NOTE: sge_qeti_first() is MT safe
*******************************************************************************/
u_long32 sge_qeti_first(sge_qeti_t *qeti)
{
u_long32 all_resources_queue_end_time = 0;
DENTER(TOP_LAYER, "sge_qeti_first");
/* (re)init all queue end next references */
sge_qeti_init_refs(qeti->cr_refs_pe);
sge_qeti_init_refs(qeti->cr_refs_global);
sge_qeti_init_refs(qeti->cr_refs_host);
sge_qeti_init_refs(qeti->cr_refs_queue);
/* determine all resources queue end time */
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_pe);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_global);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_host);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_queue);
DPRINTF(("sge_qeti_first() determines "sge_u32"\n", all_resources_queue_end_time));
/* switch to the next entry with all queue end next references whose
time is larger (?) or equal to all resources queue end time */
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_pe);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_global);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_host);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_queue);
DEXIT;
return all_resources_queue_end_time;
}
/****** sge_resource_utilization/sge_qeti_next() *******************************
* NAME
* sge_qeti_next() -- ???
*
* SYNOPSIS
* u_long32 sge_qeti_next(sge_qeti_t *qeti)
*
* FUNCTION
* Return next the time that is most in the future. Then queue end next
* references are switched to the next entry that is earlier than the time
* that was returned.
*
* INPUTS
* sge_qeti_t *qeti - ???
*
* RESULT
* u_long32 -
*
* NOTES
* MT-NOTE: sge_qeti_next() is MT safe
*******************************************************************************/
u_long32 sge_qeti_next(sge_qeti_t *qeti)
{
u_long32 all_resources_queue_end_time = DISPATCH_TIME_NOW;
DENTER(TOP_LAYER, "sge_qeti_next");
/* determine all resources queue end time */
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_pe);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_global);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_host);
sge_qeti_max_end_time(&all_resources_queue_end_time, qeti->cr_refs_queue);
DPRINTF(("sge_qeti_next() determines "sge_u32"\n", all_resources_queue_end_time));
/* switch to the next entry with all queue end next references whose
time is larger (?) or equal to all resources queue end time */
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_pe);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_global);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_host);
sge_qeti_switch_to_next(all_resources_queue_end_time, qeti->cr_refs_queue);
DEXIT;
return all_resources_queue_end_time;
}
/****** sge_resource_utilization/sge_qeti_release() ****************************
* NAME
* sge_qeti_release() -- Release queue end time iterator
*
* SYNOPSIS
* void sge_qeti_release(sge_qeti_t *qeti)
*
* FUNCTION
* Release all resources of the queue end time iterator. Referred
* resource utilization diagrams are not affected.
*
* INPUTS
* sge_qeti_t *qeti - ???
*
* NOTES
* MT-NOTE: sge_qeti_release() is MT safe
*******************************************************************************/
void sge_qeti_release(sge_qeti_t **qeti)
{
if (qeti == NULL || *qeti == NULL) {
return;
}
lFreeList(&((*qeti)->cr_refs_pe));
lFreeList(&((*qeti)->cr_refs_global));
lFreeList(&((*qeti)->cr_refs_host));
lFreeList(&((*qeti)->cr_refs_queue));
sge_free(qeti);
}
|