⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mom_mach.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/**         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/uio.h>#include	<sys/session.h>#include	<sys/param.h>#include	<sys/aoutdata.h>#include	<sys/net_local.h>#include	<sys/quota.h>#include	<sys/restart.h>#include	<sys/table.h>#include	<sys/map.h>#include	<sys/swap.h>#include	<sys/sysinfo.h>#include	<sys/pws.h>#include	<sys/target.h>#include	<sys/aoutdata.h>#include	<sys/sema.h>#include	<sys/cred.h>#include	<sys/proc.h>#include	<sys/user.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[] = "@(#) c90/$RCSfile: mom_mach.c,v $ $Revision: 2.7.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 c90 machine.****	Resources known by this code:**		cput		cpu time for a pid or session**		mem		memory size for a pid or session in KB**		sessions	list of sessions in the system**		pids		list of pids in a session**		nsessions	number of sessions in the system**		nusers		number of users in the system**		totmem		total memory size in KB**		availmem	available memory size in KB**		ncpus		number of cpus**		physmem		physical memory size in KB**		size		size of a file or filesystem in KB**		idletime	seconds of idle time**		quota		quota information**		srfs_reserve	set srfs reservation**		loadave		current load average**		swaprate	swap activity in chars / sec**		swapinrate	swapin activity in chars / sec**		swapoutrate	swapout activity in chars / sec**		swapused	chars swapped out in KB**		swapavail	KB available in swap area**		swaptotal	total KB in swap area**		cpusysw		percent cpu system wait**		cpuunix		percent cpu unicos**		cpuuser		percent cpu user**		cpuidle		percent cpu idle**		cpuguest	percent cpu guest*/#if	SRFS#include <sys/srfs.h>dev_t		srfs_tmp_dev = -1;dev_t		srfs_big_dev = -1;dev_t		srfs_fast_dev = -1;static	char	**v_name = NULL;static	char	**v_value = NULL;voidvar_init(){	char	*id = "var_init";	char	*var_conf = "/etc/tmpdir.conf";	char	line[200], *cp;	int	len, i;	FILE	*fil;	if (v_name == NULL) {		v_name = (char **)calloc(10, sizeof(char *));		v_value = (char **)calloc(10, sizeof(char *));	}	if ((fil = fopen(var_conf, "r")) == NULL) {		log_err(errno, id, var_conf);		return;	}	for (i=0; fgets(line, sizeof(line), fil); ) {		if (line[0] == '#')			continue;		len = strlen(line);		if (line[len-1] == '\n')			line[--len] = '\0';		for (cp=line; *cp; cp++) {			if (isspace(*cp))				break;		}		if (*cp)			*cp++ = '\0';		for (; *cp; cp++) {			if (!isspace(*cp))				break;		}		if (*cp == '\0')			cp = JTMPDIR;		DBPRT(("%s: var(%d) $%s = %s\n", id, i, line, cp))		v_name = realloc(v_name, (i+2)*sizeof(char *));		v_value = realloc(v_value, (i+2)*sizeof(char *));		v_name[i] = strdup(line);		v_value[i++] = strdup(cp);	}	v_name[i] = NULL;	v_value[i] = NULL;	fclose(fil);	return;}voidvar_cleanup(){	register	i;	if (v_name == NULL)		return;	for (i=0; v_name[i]; i++) {		free(v_name[i]);		free(v_value[i]);	}	return;}char	*var_value(name)char	*name;{	register	i;	for (i=0; v_name[i]; i++) {		if (strcmp(v_name[i], name) == 0)			break;	}	return v_value[i];}#endif	/* SRFS */static struct sess	*session_table;static long		session_table_size;static struct proc	*process_table;static long		process_table_size;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));static char	*swaprate	A_((struct rm_attribute *attrib));static char	*swapinrate	A_((struct rm_attribute *attrib));static char	*swapoutrate	A_((struct rm_attribute *attrib));static char	*swapused	A_((struct rm_attribute *attrib));static char	*swapavail	A_((struct rm_attribute *attrib));static char	*swaptotal	A_((struct rm_attribute *attrib));static char	*cpuidle	A_((struct rm_attribute *attrib));static char	*cpuguest	A_((struct rm_attribute *attrib));static char	*cpuuser	A_((struct rm_attribute *attrib));static char	*cpuunix	A_((struct rm_attribute *attrib));static char	*cpusysw	A_((struct rm_attribute *attrib));extern char	*loadave	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";#define	FILTER	0.75#define	SAMPLE_DELTA 10struct	target	tinfo;struct	sysinfo	sysinfo;double	swap_rate;double	swapin_rate;double	swapout_rate;double	cpu_sysw;double	cpu_unix;double	cpu_user;double	cpu_idle;double	cpu_guest;time_t	wait_time;long	last_time = 0;/*** local resource array*/struct	config	dependent_config[] = {	{ "ncpus", ncpus },	{ "totmem",	totmem },	{ "availmem",	availmem },	{ "physmem",	physmem },	{ "loadave", loadave },	{ "quota", quota },	{ "srfs_reserve", srfs_reserve },	{ "swaprate", swaprate },	{ "swapinrate", swapinrate },	{ "swapoutrate", swapoutrate },	{ "swapused", swapused },	{ "swapavail", swapavail },	{ "swaptotal", swaptotal },	{ "cpuidle", cpuidle },	{ "cpuguest", cpuguest },	{ "cpuuser", cpuuser },	{ "cpuunix", cpuunix },	{ "cpusysw", cpusysw },	{ NULL, nullproc },};voidend_proc(){	char	*id = "end_proc";	long	now, delta;	struct	tbs	info;	struct	pw	pw;	int	nidlt, nuset, nunit, nguet, nsyst, i, newsios;	double	idlt, uset, unit, guet, syst, timec, srate;	static	int	oidlt = 0;	static	int	ouset = 0;	static	int	ounit = 0;	static	int	oguet = 0;	static	int	osyst = 0;	static	int	oldsios = 0;	static	int	oldswapin = 0;	static	int	oldswapout = 0;	now = rtclock();	delta = now - last_time;	if (delta <= SAMPLE_DELTA*tinfo.mc_clktck) {		wait_time = (int)((SAMPLE_DELTA*tinfo.mc_clktck - delta) /				tinfo.mc_clktck);		return;	}	DBPRT(("%s: delta is %.3f\n", id,		(double)delta/(double)tinfo.mc_clktck))	wait_time = SAMPLE_DELTA;	if (tabinfo(PWS, &info) == -1) {		log_err(errno, id, "tabinfo(PWS)");		return;	}	if (tabread(PWS, (char *)&pw,			info.ent * info.len, info.head) == -1) {		log_err(errno, id, "tabread(PWS)");		return;	}	if (tabinfo(SINFO, &info) == -1) {		log_err(errno, id, "tabinfo(SINFO)");		return;	}	if (tabread(SINFO, (char *)&sysinfo,			info.ent * info.len, info.head) == -1) {		log_err(errno, id, "tabread(SINFO)");		return;	}	last_time = now;	/* User, sys and idle time calc */	nidlt = 0;	nuset = 0;	nunit = 0;	nguet = 0;	nsyst = 0;	for (i = 0; i < MAXCPUS; i++ ) {		nidlt += pw.pws[i].pw_idlec;		nuset += pw.pws[i].pw_userc;		nunit += pw.pws[i].pw_unixc;		nguet += pw.pws[i].pw_guestc;		nsyst += pw.pws[i].pw_syswc;        }	idlt = (double)(nidlt - oidlt);	uset = (double)(nuset - ouset);	unit = (double)(nunit - ounit);	guet = (double)(nguet - oguet);	syst = (double)(nsyst - osyst);	timec = idlt + uset + unit + guet + syst;	if( timec <= 0.0 ) {		sprintf(log_buffer, "bad time counter %.2f", timec);		log_err(-1, id, log_buffer);		return;	}	idlt = (idlt * 100.0) / timec;	uset = (uset * 100.0) / timec;	unit = (unit * 100.0) / timec;	guet = (guet * 100.0) / timec;	syst = (syst * 100.0) / timec;	oidlt = nidlt;	ouset = nuset;	ounit = nunit;	oguet = nguet;	osyst = nsyst;	cpu_sysw = FILTER * syst + (1 - FILTER) * cpu_sysw;	DBPRT(("%s: syst %.2f cpu_sysw %.2f\n", id, syst, cpu_sysw))	cpu_unix = FILTER * unit + (1 - FILTER) * cpu_unix;	DBPRT(("%s: unit %.2f cpu_unix %.2f\n", id, unit, cpu_unix))	cpu_user = FILTER * uset + (1 - FILTER) * cpu_user;	DBPRT(("%s: uset %.2f cpu_user %.2f\n", id, uset, cpu_user))	cpu_idle = FILTER * idlt + (1 - FILTER) * cpu_idle;	DBPRT(("%s: idlt %.2f cpu_idle %.2f\n", id, idlt, cpu_idle))	cpu_guest = FILTER * guet + (1 - FILTER) * cpu_guest;	DBPRT(("%s: guet %.2f cpu_guest %.2f\n", id, guet, cpu_guest))	srate = (double)((sysinfo.bswapin - oldswapin)*tinfo.mc_clktck)			/ (double)delta;	srate *= (double)BSIZE;	swapin_rate = FILTER * srate + (1 - FILTER) * swapin_rate;	DBPRT(("%s: swapin %d srate %.2f swapin_rate %.2f\n",			id, sysinfo.bswapin - oldswapin, srate, swapin_rate))	oldswapin = sysinfo.bswapin;	srate = (double)((sysinfo.bswapout - oldswapout)*tinfo.mc_clktck)			/ (double)delta;	srate *= (double)BSIZE;	swapout_rate = FILTER * srate + (1 - FILTER) * swapout_rate;	DBPRT(("%s: swapout %d srate %.2f swapout_rate %.2f\n",			id, sysinfo.bswapout - oldswapout, srate, swapout_rate))	oldswapout = sysinfo.bswapout;	newsios = sysinfo.bswapin + sysinfo.bswapout;	srate = (double)((newsios - oldsios)*tinfo.mc_clktck) / (double)delta;	srate *= (double)BSIZE;	swap_rate = FILTER * srate + (1 - FILTER) * swap_rate;	DBPRT(("%s: sios %d srate %.2f swap_rate %.2f\n",			id, newsios - oldsios, srate, swap_rate))	oldsios = newsios;	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))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -