📄 mom_mach.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 <pbs_config.h> /* the master config generated by configure */#include <assert.h>#include <limits.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <fcntl.h>#include <errno.h>#include <strings.h>#include <signal.h>#include <time.h>#include <udb.h>#include <tmpdir.h>#include <dirent.h>#include <mntent.h>#include <pwd.h>#include <sys/time.h>#include <sys/types.h>#include <sys/param.h>#include <sys/net_local.h>#include <sys/quota.h>#include <sys/restart.h>#include <sys/target.h>#include <sys/stat.h>#include <sys/statfs.h>#include <sys/sysmacros.h>#include <sys/category.h>#include <sys/resource.h>#include "portability.h"#include "pbs_error.h"#include "log.h"#include "list_link.h"#include "server_limits.h"#include "attribute.h"#include "resource.h"#include "job.h"#include "log.h"#include "mom_mach.h"#include "mom_func.h"#include "resmon.h"#include "../rm_dep.h"static char ident[] = "@(#) unicosmk2/$RCSfile: mom_mach.c,v $ $Revision: 2.6.4.5 $";#ifndef max#define max(a,b) (a>b ? a : b)#endif#ifndef TRUE#define FALSE 0#define TRUE 1#endif /* TRUE *//*** System dependent code to gather information for the resource** monitor for a Cray T3E machine.**** Resources known by this code:** cput cpu time for a pid or session** totmem total memory size** availmem available memory size** ncpus number of cpus** physmem physical memory size** size size of a file or filesystem** idletime seconds of idle time** quota quota information** srfs_reserve set srfs reservation*/extern struct pbs_err_to_txt pbs_err_to_txt[];extern time_t time_now;extern char *path_checkpoint;/*** external functions and data*/extern struct config *search A_((struct config *, char *));extern struct rm_attribute *momgetattr A_((char *));extern int rm_errno;extern unsigned int reqnum;extern char *ret_string;extern double cputfactor;extern double wallfactor;/*** local functions and data*/static char *ncpus A_((struct rm_attribute *attrib));static char *totmem A_((struct rm_attribute *attrib));static char *availmem A_((struct rm_attribute *attrib));static char *physmem A_((struct rm_attribute *attrib));static char *quota A_((struct rm_attribute *attrib));static char *srfs_reserve A_((struct rm_attribute *attrib));extern char *nullproc A_((struct rm_attribute *attrib));extern char extra_parm[];extern char no_parm[];char no_srfs[] = "SRFS request not supported";char procfs[] = "/proc";struct target tinfo;time_t wait_time;long last_time = 0;/*** local resource array*/struct config dependent_config[] = { { "ncpus", ncpus }, { "totmem", totmem }, { "availmem", availmem }, { "physmem", physmem }, { "quota", quota }, { "srfs_reserve", srfs_reserve }, { NULL, nullproc },};voidend_proc(){ return;}voiddep_initialize(){ char *id = "dep_initialize"; limit(C_PROC, 0, L_CPU, 0); /* set unlimited cpu */ if (target(MC_GET_TARGET, &tinfo) == -1) { log_err(errno, id, "target"); die(0); } DBPRT(("Primary machine type name = %s\n", &tinfo.mc_pmt)) DBPRT(("Number of memory banks = %ld\n", tinfo.mc_bank)) DBPRT(("Number of started processors = %ld\n", tinfo.mc_ncpu)) DBPRT(("Instruction Buffer Size (words) = %ld\n", tinfo.mc_ibsz)) DBPRT(("Main memory size (words) = %ld\n", tinfo.mc_msz)) DBPRT(("Number of clocks for a memory read = %ld\n", tinfo.mc_mspd)) DBPRT(("Clock period in picoseconds = %ld\n", tinfo.mc_clk)) DBPRT(("Number of cluster register sets = %ld\n", tinfo.mc_ncl)) DBPRT(("Memory bank busy time in clocks = %ld\n", tinfo.mc_bbsy)) DBPRT(("Number of clock ticks per second = %ld\n", tinfo.mc_clktck)) DBPRT(("System serial number = %ld\n", tinfo.mc_serial)) DBPRT(("UNICOS release level = %ld\n", tinfo.mc_rls)) end_proc(); return;}voiddep_cleanup(){ char *id = "dep_cleanup"; int i; log_record(PBSEVENT_SYSTEM, 0, id, "dependent cleanup");}/* * Internal size decoding routine. * * Accepts a resource pointer and a pointer to the unsigned long integer * to receive the decoded value. It returns a PBS error code, and the * decoded value in the unsigned long integer. * * For Unicos, * * sizeof(word) = sizeof(int) */static int getsize(pres, ret) resource *pres; unsigned long *ret;{ unsigned long value; if (pres->rs_value.at_type != ATR_TYPE_SIZE) return (PBSE_ATTRTYPE); value = pres->rs_value.at_val.at_size.atsv_num; if (pres->rs_value.at_val.at_size.atsv_units == ATR_SV_WORDSZ) { if (value > ULONG_MAX / sizeof(int)) return (PBSE_BADATVAL); value *= sizeof(int); } if (value > ULONG_MAX >> pres->rs_value.at_val.at_size.atsv_shift) return (PBSE_BADATVAL); *ret = value << pres->rs_value.at_val.at_size.atsv_shift; return (PBSE_NONE);}/* * Internal time decoding routine. * * Accepts a resource pointer and a pointer to the unsigned long integer * to receive the decoded value. It returns a PBS error code, and the * decoded value of time in milliseconds in the unsigned long integer. */static int gettime(pres, ret) resource *pres; unsigned long *ret;{ if (pres->rs_value.at_type != ATR_TYPE_LONG) return (PBSE_ATTRTYPE); if (pres->rs_value.at_val.at_long < 0) return (PBSE_BADATVAL); *ret = pres->rs_value.at_val.at_long; return (PBSE_NONE);}/* * Internal long decoding routine. * * Accepts a resource pointer and a pointer to a long integer * to receive the decoded value. It returns a PBS error code, and the * decoded value of number in the long integer. */static int getlong(pres, ret) resource *pres; long *ret;{ if (pres->rs_value.at_type != ATR_TYPE_LONG) return (PBSE_ATTRTYPE); if (pres->rs_value.at_val.at_long < 0) return (PBSE_BADATVAL); *ret = pres->rs_value.at_val.at_long; return (PBSE_NONE);}/* * Internal boolean decoding routine. * * Accepts a resource pointer and a pointer to the unsigned integer * to receive the decoded value. It returns a PBS error code, and the * decoded value of true (1) or false (0). */static int getbool(pres, ret) resource *pres; unsigned int *ret;{ unsigned int val; if (pres->rs_value.at_type != ATR_TYPE_LONG) return (PBSE_ATTRTYPE); val = pres->rs_value.at_val.at_long; if (val != 0 && val != 1) return (PBSE_BADATVAL); *ret = val; return (PBSE_NONE);}/* * Internal job cpu time decoding routine. * * Accepts a job pointer. Returns the sum of all cpu time * consumed for all processes executed by the job, in seconds, * adjusted by cputfactor. */static unsigned long cput_sum(pjob) job *pjob;{ static char *id = "cput_sum"; ulong cputime = 0; int nps = 0; task *ptask; struct resclim rl; DBPRT(("%s: entered %s\n", id, pjob->ji_qs.ji_jobid)) rl.resc_category = C_JOB; rl.resc_resource = L_CPU; for (ptask = (task *)GET_NEXT(pjob->ji_tasks); ptask; ptask = (task *)GET_NEXT(ptask->ti_jobtask)) { if (ptask->ti_qs.ti_sid <= 1) continue; if (getlim(ptask->ti_qs.ti_sid, &rl) == -1) continue; nps++; cputime += rl.resc_used; } if (nps == 0) pjob->ji_flags |= MOM_NO_PROC; return ((unsigned long)((double)cputime * cputfactor));}/* * Internal job cpu time decoding routine. * * Accepts a job pointer. Returns the sum of all moo time * consumed for all processes executed by the job, in seconds. */static unsigned long mppt_sum(pjob) job *pjob;{ static char *id = "mppt_sum"; ulong cputime = 0; task *ptask; struct resclim rl; DBPRT(("%s: entered %s\n", id, pjob->ji_qs.ji_jobid)) rl.resc_category = C_JOB; rl.resc_resource = L_MPPT; for (ptask = (task *)GET_NEXT(pjob->ji_tasks); ptask; ptask = (task *)GET_NEXT(ptask->ti_jobtask)) { if (ptask->ti_qs.ti_sid <= 1) continue; if (getlim(ptask->ti_qs.ti_sid, &rl) == -1) continue; cputime += rl.resc_used; } return (cputime);}extern char *msg_momsetlim;/* * Internal error routine */int error(string, value) char *string; int value;{ int i = 0; char *message; assert(string != NULL); assert(*string != '\0'); assert(value > PBSE_); /* minimum PBS error number */ assert(value <= PBSE_NOSYNCMSTR); /* maximum PBS error number */ assert(pbs_err_to_txt[i].err_no != 0); do { if (pbs_err_to_txt[i].err_no == value) break; } while (pbs_err_to_txt[++i].err_no != 0); assert(pbs_err_to_txt[i].err_txt != NULL); message = *pbs_err_to_txt[i].err_txt; assert(message != NULL); assert(*message != '\0'); (void)fprintf(stderr, msg_momsetlim, string, message); (void)fflush(stderr); return (value);}/* * which_limit - set either user's limit or udb limit: * * If user's limit is a default, then use lesser of it or udb * * Else, use user's limit unless it is greater than the udb and the * the udb limit is not unlimited. This case is an error. */static int which_limit(rlimit, udblimit, r_flags, zlimit, rtn_limit) long rlimit; /* limit value from resource_limit */ long udblimit; /* limit for that resource from UDB */ int r_flags; /* resource entry flags (ATR_VFLAG_DEFLT) */ int zlimit; /* true if 0 in udb mean real limit of zero */ long *rtn_limit; /* RETURN: the limit to set */{ if (r_flags & ATR_VFLAG_DEFLT) { /* User's limit is a default value, if default > UDB, use UDB */ if ( (udblimit == MAXUE_LONG) || ((udblimit == 0) && (zlimit == 0)) || (rlimit < udblimit) ) *rtn_limit = rlimit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -