📄 fifo.c
字号:
/** OpenPBS (Portable Batch System) v2.3 Software License* * Copyright (c) 1999-2000 Veridian Information Solutions, Inc.* All rights reserved.* * ---------------------------------------------------------------------------* For a license to use or redistribute the OpenPBS software under conditions* other than those described below, or to purchase support for this software,* please contact Veridian Systems, PBS Products Department ("Licensor") at:* * www.OpenPBS.org +1 650 967-4675 sales@OpenPBS.org* 877 902-4PBS (US toll-free)* ---------------------------------------------------------------------------* * This license covers use of the OpenPBS v2.3 software (the "Software") at* your site or location, and, for certain users, redistribution of the* Software to other sites and locations. Use and redistribution of* OpenPBS v2.3 in source and binary forms, with or without modification,* are permitted provided that all of the following conditions are met.* After December 31, 2001, only conditions 3-6 must be met:* * 1. Commercial and/or non-commercial use of the Software is permitted* provided a current software registration is on file at www.OpenPBS.org.* If use of this software contributes to a publication, product, or* service, proper attribution must be given; see www.OpenPBS.org/credit.html* * 2. Redistribution in any form is only permitted for non-commercial,* non-profit purposes. There can be no charge for the Software or any* software incorporating the Software. Further, there can be no* expectation of revenue generated as a consequence of redistributing* the Software.* * 3. Any Redistribution of source code must retain the above copyright notice* and the acknowledgment contained in paragraph 6, this list of conditions* and the disclaimer contained in paragraph 7.* * 4. Any Redistribution in binary form must reproduce the above copyright* notice and the acknowledgment contained in paragraph 6, this list of* conditions and the disclaimer contained in paragraph 7 in the* documentation and/or other materials provided with the distribution.* * 5. Redistributions in any form must be accompanied by information on how to* obtain complete source code for the OpenPBS software and any* modifications and/or additions to the OpenPBS software. The source code* must either be included in the distribution or be available for no more* than the cost of distribution plus a nominal fee, and all modifications* and additions to the Software must be freely redistributable by any party* (including Licensor) without restriction.* * 6. All advertising materials mentioning features or use of the Software must* display the following acknowledgment:* * "This product includes software developed by NASA Ames Research Center,* Lawrence Livermore National Laboratory, and Veridian Information * Solutions, Inc.* Visit www.OpenPBS.org for OpenPBS software support,* products, and information."* * 7. DISCLAIMER OF WARRANTY* * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT* ARE EXPRESSLY DISCLAIMED.* * IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE* U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT,* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.* * This license will be governed by the laws of the Commonwealth of Virginia,* without reference to its choice of law rules.*/#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <pbs_error.h>#include <pbs_ifl.h>#include <sched_cmds.h>#include <time.h>#include <log.h>#include "queue_info.h"#include "server_info.h"#include "check.h"#include "constant.h"#include "job_info.h"#include "node_info.h"#include "misc.h"#include "fifo.h"#include "config.h"#include "sort.h"#include "parse.h"#include "globals.h"#include "prev_job_info.h"#include "fairshare.h"#include "prime.h"#include "dedtime.h"static char *ident = "$Id: fifo.c,v 2.4.2.1.2.5 2000/08/09 00:18:58 hender Exp $";/* a list of running jobs from the last scheduling cycle */static prev_job_info *last_running = NULL;static int last_running_size = 0;static time_t last_decay;static time_t last_sync;/* * * schedinit - initialize conf struct and parse conf files * * argc - passed in from main * argv - passed in from main * * Returns Success/Failure * * */int schedinit( int argc, char *argv[] ){ init_config(); parse_config(CONFIG_FILE); parse_holidays(HOLIDAYS_FILE); time(&(cstat.current_time)); if( is_prime_time() ) init_prime_time(); else init_non_prime_time(); parse_ded_file(DEDTIME_FILE); /* preload the static members to the fairshare tree */ preload_tree(); parse_group(RESGROUP_FILE); calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED); if( conf.prime_fs || conf.non_prime_fs ) { read_usage(); /* * initialize the last_decay to the current time, since we do not know when * the last decay happened */ last_sync = last_decay = cstat.current_time; } return 0;}/* * * update_cycle_status - update global status structure which holds * status information used by the scheduler which * can change from cycle to cycle * * returns nothing * */void update_cycle_status(){ char dedtime; /* boolean: is it dedtime? */ enum prime_time prime; /* current prime time status */ time(&(cstat.current_time)); dedtime = is_ded_time(); /* it was dedtime last scheduling cycle, and it is not dedtime now */ if( cstat.is_ded_time && !dedtime ) { /* since the current dedtime is now passed, set it to zero and sort it to * the end of the dedtime array so the next dedtime is at the front */ conf.ded_time[0].from = 0; conf.ded_time[0].to = 0; qsort(conf.ded_time,MAX_DEDTIME_SIZE, sizeof(struct timegap), cmp_ded_time); } cstat.is_ded_time = dedtime; /* if we have changed from prime to nonprime or nonprime to prime * init the status respectivly */ prime = is_prime_time(); if( prime == PRIME && !cstat.is_prime ) init_prime_time( ); else if( prime == NON_PRIME && cstat.is_prime ) init_non_prime_time( );}/* * * init_scheduling_cycle - run things that need to be set up every * scheduling cycle * * returns 1 on success 0 on failure * * NOTE: failure of this function will cause schedule() to return */int init_scheduling_cycle( server_info *sinfo ){ group_info *user; /* the user for the running jobs of the last cycle */ queue_info *qinfo; /* user to cycle through the queues to sort the jobs */ char decayed = 0; /* boolean: have we decayed usage? */ time_t t; /* used in decaying fair share */ int i, j; if( cstat.fair_share ) { if( last_running != NULL ) { /* add the usage which was accumulated between the last cycle and this * one and calculate a new value */ for( i = 0; i < last_running_size ; i++ ) { user = last_running[i].ginfo; for( j = 0; sinfo -> running_jobs[j] != NULL && strcmp(last_running[i].name, sinfo -> running_jobs[j] -> name); j++) ; if( sinfo -> running_jobs[j] != NULL ) { user -> usage += calculate_usage_value( sinfo -> running_jobs[j] -> resused ) - calculate_usage_value( last_running[i].resused ); } } /* assign usage into temp usage since temp usage is used for usage * calculations. Temp usage starts at usage and can be modified later. */ for( i = 0; i < last_running_size; i++ ) last_running[i].ginfo -> temp_usage = last_running[i].ginfo -> usage; } /* The half life for the fair share tree might have passed since the last * scheduling cycle. For that matter, several half lives could have * passed. If this is the case, perform as many decays as necessary */ t = cstat.current_time; while(t - last_decay > conf.half_life) { log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_SERVER,"", "Decaying Fairshare Tree"); decay_fairshare_tree( conf.group_root ); t -= conf.half_life; decayed = 1; } if( decayed ) { /* set the time to the acuall the half-life should have occured */ last_decay = cstat.current_time - (cstat.current_time - last_decay) % conf.half_life; } if( cstat.current_time - last_sync > conf.sync_time ) { write_usage(); last_sync = cstat.current_time; log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_SERVER, "", "Usage Sync"); } } if( cstat.help_starving_jobs ) cstat.starving_job = update_starvation(sinfo -> jobs); /* sort queues by priority if requested */ if( cstat.sort_queues ) qsort( sinfo -> queues, sinfo -> num_queues, sizeof(queue_info *), cmp_queue_prio_dsc); if( cstat.sort_by[0].sort != NO_SORT ) { if(cstat.by_queue || cstat.round_robin) { for( i = 0; i < sinfo -> num_queues; i++ ) { qinfo = sinfo -> queues[i]; qsort( qinfo -> jobs, qinfo -> sc.total, sizeof(job_info *), cmp_sort ); } } else qsort( sinfo -> jobs, sinfo -> sc.total, sizeof(job_info *), cmp_sort ); } next_job(sinfo, INITIALIZE); return 1; /* SUCCESS */}/* * * schedule - this function gets called to start each scheduling cycle * It will handle the difference cases that caused a * scheduling cycle * * cmd - reason for scheduling cycle * SCH_ERROR error * SCH_SCHEDULE_NULL NULL command * SCH_SCHEDULE_NEW A new job was submited * SCH_SCHEDULE_TERM A job terminated * SCH_SCHEDULE_TIME The scheduling interval expired * SCH_SCHEDULE_RECYC A scheduling recycle(see admin guide) * SCH_SCHEDULE_CMD The server scheduling variabe was set * or reset to true * SCH_SCHEDULE_FIRST the first cycle after the server starts * SCH_CONFIGURE perform scheduling configuration * SCH_QUIT have the scheduler quit * SCH_RULESET reread the scheduler ruleset * * sd - connection desctiptor to the pbs server * * * returns 1: continue calling scheduling cycles, 0: exit scheduler */int schedule(int cmd, int sd){ switch(cmd) { case SCH_ERROR: case SCH_SCHEDULE_NULL: case SCH_RULESET: case SCH_SCHEDULE_RECYC: /* ignore and end cycle */ break; case SCH_SCHEDULE_NEW: case SCH_SCHEDULE_TERM: case SCH_SCHEDULE_FIRST: case SCH_SCHEDULE_CMD: case SCH_SCHEDULE_TIME: return scheduling_cycle(sd); case SCH_CONFIGURE: if( conf.prime_fs || conf.non_prime_fs ) write_usage(); reinit_config(); parse_config(CONFIG_FILE); parse_holidays(HOLIDAYS_FILE); parse_ded_file(DEDTIME_FILE); preload_tree(); parse_group(RESGROUP_FILE); calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED); if( conf.prime_fs || conf.non_prime_fs ) read_usage(); break; case SCH_QUIT: if( conf.prime_fs || conf.non_prime_fs ) write_usage(); return 1; /* have the scheduler exit nicely */ default: return 0; } return 0;}/* * * scheduling_cycle - the controling function of the scheduling cycle *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -