<commit_before>/* 
** Copyright 1986, 1987, 1988, 1989, 1990, 1991 by the Condor Design Team
** 
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted,
** provided that the above copyright notice appear in all copies and that
** both that copyright notice and this permission notice appear in
** supporting documentation, and that the names of the University of
** Wisconsin and the Condor Design Team not be used in advertising or
** publicity pertaining to distribution of the software without specific,
** written prior permission.  The University of Wisconsin and the Condor
** Design Team make no representations about the suitability of this
** software for any purpose.  It is provided "as is" without express
** or implied warranty.
** 
** THE UNIVERSITY OF WISCONSIN AND THE CONDOR DESIGN TEAM DISCLAIM ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF
** WISCONSIN OR THE CONDOR DESIGN TEAM BE LIABLE FOR ANY SPECIAL, INDIRECT
** OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
** OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
** OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
** OR PERFORMANCE OF THIS SOFTWARE.
** 
** Author:  <NAME>
** 	         University of Wisconsin, Computer Sciences Dept.
** 
*/ 

#include <stdio.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/file.h>

#ifdef MIPS
#include <sys/fixpoint.h>
#endif

#if defined(SUNOS41)
#include <sys/param.h>
#endif 

#include "debug.h"
#include "except.h"
static char *_FileName_ = __FILE__;		/* Used by EXCEPT (see except.h)     */

int		Kmem;



struct nlist nl[] = {
#if defined(IRIX331) || defined(HPUX9) || defined(IRIX53)
    { "avenrun" },
#else
    { "_avenrun" },
#endif
    { "" },
};

#if defined(IRIX62)
struct nlist64  nl64[] = {
	{ "avenrun",0,0 },
	{ "" },
};
#endif /* IRIX62 */

float
calc_load_avg()
{
	float lookup_load_avg();
	return lookup_load_avg();
}

/*
* Find addresses of various kernel variables in /dev/kmem.
*/
get_k_vars()
{
	if (getuid() == 0)
		set_root_euid();

        /* Open kmem for reading */
    if( (Kmem=open("/dev/kmem",O_RDONLY,0)) < 0 ) {
		set_condor_euid();
        EXCEPT( "open(/dev/kmem,O_RDONLY,0)" );
    }

	/* Get the kernel's name list */

#if defined(IRIX62)
	/* here we assume that all IRIX 6.x kernels are compiled as a ELF binary.  If the
	 * kernel, i.e. /unix, is indeed a COFF binary, the below will fail with an exception.
	 * first try a 32-bit ELF binary, then a 64-bit ELF, then fail.-Todd 2/97 */
  if ( _libelf_nlist("/unix",nl) == -1 )
	  if (_libelf_nlist64("/unix",nl64) == -1 ) {
		  EXCEPT("cannot read /unix as an ELF binary");
	  }
  nl->n_value &= ~0x80000000;
#elif defined(IRIX331) || defined(IRIX53)
	(void)nlist( "/unix", nl );
	nl->n_value &= ~0x80000000;
#elif defined(HPUX10)
	(void)nlist( "/stand/vmunix", nl );
#elif defined(HPUX9)
	(void)nlist( "/hp-ux", nl );
#else 	/* everybody else */
	(void)nlist( "/vmunix", nl );
#endif

	if (getuid() == 0)
		set_condor_euid();

}


/*
** Berkeley style kernels maintain three variables which represent load
** averages over the previous one, five, and fifteen minute intervals.
** Systems vary in whether they use traditional floating point numbers
** for this calculation, or opt for the efficiency of some type of
** scaled integer.  Here we just look up the one minute load average,
** and if necessary convert to a float.
*/

/*
** The SGI folks apparently use a scaled integer, but where is the scale
** factor defined?  This is a wild guess -- most likely wrong! -- mike
*/
#if defined(IRIX331) || defined(IRIX53)
#define FSCALE 1000
#endif

float
lookup_load_avg()
{
    off_t addr;

#if defined(HPPAR) && defined(HPUX9)			/* HP-UX */
    double  avenrun[3];
#elif defined(ULTRIX42) || defined(ULTRIX43)
	fix		avenrun[3];
#elif defined(SUNOS41) || defined(IRIX331) || defined(IRIX53)
    long avenrun[3];
#endif

#if defined(IRIX62)
	/* if IRIX62, figure out if we grabbed a 32- or 64-bit address */
	if ( nl[0].n_type )
		addr = nl[0].n_value;
	else
		addr = nl64[0].n_value;
#else
	addr = nl[0].n_value;
#endif

	avenrun[0] = 0;
	avenrun[1] = 0;
	avenrun[2] = 0;

    if( lseek(Kmem,addr,0) != addr ) {
        dprintf( D_ALWAYS, "Can't seek to addr 0x%x in /dev/kmem\n", addr );
        EXCEPT( "lseek" );
    }

    if( read(Kmem,(char *)avenrun,sizeof avenrun) != sizeof avenrun ) {
        EXCEPT( "read" );
    }

        /* just give back the 1 minute average for now */

#if defined(HPPAR) && defined(HPUX9)		/* HP-UX */
	if ((float)avenrun[0] >= 0.01) {
        dprintf( D_ALWAYS, "load average is %g\n", avenrun[0] );
		return (float)avenrun[0];
	}
	else {
        dprintf( D_ALWAYS, "load average is %g, returning 0.0\n",
				avenrun[0] );
		return 0.0;
	}

#elif defined(ULTRIX42) || defined(ULTRIX43)
	return (float)avenrun[0]/(1<<FBITS);

#elif defined(SUNOS41) || defined(IRIX331) || defined(IRIX53)
    return (float)avenrun[0]/FSCALE;

#endif
}
<commit_msg>if we have big-cheese access, open up /dev/kmem fist time we are called. this used to be done in the startd in v5.<commit_after>/* 
** Copyright 1986, 1987, 1988, 1989, 1990, 1991 by the Condor Design Team
** 
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted,
** provided that the above copyright notice appear in all copies and that
** both that copyright notice and this permission notice appear in
** supporting documentation, and that the names of the University of
** Wisconsin and the Condor Design Team not be used in advertising or
** publicity pertaining to distribution of the software without specific,
** written prior permission.  The University of Wisconsin and the Condor
** Design Team make no representations about the suitability of this
** software for any purpose.  It is provided "as is" without express
** or implied warranty.
** 
** THE UNIVERSITY OF WISCONSIN AND THE CONDOR DESIGN TEAM DISCLAIM ALL
** WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF
** WISCONSIN OR THE CONDOR DESIGN TEAM BE LIABLE FOR ANY SPECIAL, INDIRECT
** OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
** OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
** OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
** OR PERFORMANCE OF THIS SOFTWARE.
** 
** Author:  <NAME>
** 	         University of Wisconsin, Computer Sciences Dept.
** 
*/ 

#include <stdio.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/file.h>

#ifdef MIPS
#include <sys/fixpoint.h>
#endif

#if defined(SUNOS41)
#include <sys/param.h>
#endif 

#include "debug.h"
#include "except.h"
static char *_FileName_ = __FILE__;		/* Used by EXCEPT (see except.h)     */

int		Kmem;



struct nlist nl[] = {
#if defined(IRIX331) || defined(HPUX9) || defined(IRIX53)
    { "avenrun",0,0 },
#else
    { "_avenrun" },
#endif
    { "" },
};

#if defined(IRIX62)
struct nlist64  nl64[] = {
    { "avenrun",0,0 },
    { "" },
};
#endif /* IRIX62 */

float
calc_load_avg()
{
	static int got_k_vars = 0;
	float lookup_load_avg();

	/* if we have big-cheese access, open up /dev/kmem fist time thru.. */
	if ( !got_k_vars && (getuid() == 0) ) {
		got_k_vars = 1;
		get_k_vars();
	}
		
	return lookup_load_avg();
}

/*
* Find addresses of various kernel variables in /dev/kmem.
*/
get_k_vars()
{
	set_root_euid();

        /* Open kmem for reading */
    if( (Kmem=open("/dev/kmem",O_RDONLY,0)) < 0 ) {
		set_condor_euid();
        EXCEPT( "open(/dev/kmem,O_RDONLY,0)" );
    }

	/* Get the kernel's name list */

#if defined(IRIX62)
	/* here we assume that all IRIX 6.x kernels are compiled as a ELF binary.  If the
	 * kernel, i.e. /unix, is indeed a COFF binary, the below will fail with an exception.
	 * first try a 32-bit ELF binary, then a 64-bit ELF, then fail. -Todd 2/97 */
    if ( _libelf_nlist("/unix",nl) == -1 )
		if (_libelf_nlist64("/unix",nl64) == -1 ) {
			EXCEPT("cannot read /unix as an ELF binary");
		}
	nl->n_value &= ~0x80000000;
#elif defined(IRIX331) || defined(IRIX53)
	(void)nlist( "/unix", nl );
	nl->n_value &= ~0x80000000;
#elif defined(HPUX10)
	(void)nlist( "/stand/vmunix", nl );
#elif defined(HPUX9)
	(void)nlist( "/hp-ux", nl );
#else 	/* everybody else */
	(void)nlist( "/vmunix", nl );
#endif

	set_condor_euid();

}


/*
** Berkeley style kernels maintain three variables which represent load
** averages over the previous one, five, and fifteen minute intervals.
** Systems vary in whether they use traditional floating point numbers
** for this calculation, or opt for the efficiency of some type of
** scaled integer.  Here we just look up the one minute load average,
** and if necessary convert to a float.
*/

/*
** The SGI folks apparently use a scaled integer, but where is the scale
** factor defined?  This is a wild guess -- most likely wrong! -- mike
*/
#if defined(IRIX331) || defined(IRIX53)
#define FSCALE 1000
#endif

float
lookup_load_avg()
{
    off_t addr;
	size_t result;

#if defined(HPPAR) && defined(HPUX9)			/* HP-UX */
    double  avenrun[3];
#elif defined(ULTRIX42) || defined(ULTRIX43)
	fix		avenrun[3];
#elif defined(SUNOS41) || defined(IRIX331) || defined(IRIX53)
    long avenrun[3];
#endif

#if defined(IRIX62)
	/* if IRIX62, figure out if we grabbed a 32- or 64-bit address */
	if ( nl[0].n_type ) 
		addr = nl[0].n_value;
	else
		addr = nl64[0].n_value;
#else
	addr = nl[0].n_value;
#endif

	avenrun[0] = 0;
	avenrun[1] = 0;
	avenrun[2] = 0;

    if( lseek(Kmem,addr,0) != addr ) {
        dprintf( D_ALWAYS, "Can't seek to addr 0x%x in /dev/kmem\n", addr );
        EXCEPT( "lseek" );
    }

    if( (result=read(Kmem,(char *)avenrun,sizeof avenrun)) != sizeof avenrun ) {
        EXCEPT( "read" );
    }

        /* just give back the 1 minute average for now */

#if defined(HPPAR) && defined(HPUX9)		/* HP-UX */
	if ((float)avenrun[0] >= 0.01) {
        dprintf( D_ALWAYS, "load average is %g\n", avenrun[0] );
		return (float)avenrun[0];
	}
	else {
        dprintf( D_ALWAYS, "load average is %g, returning 0.0\n",
				avenrun[0] );
		return 0.0;
	}

#elif defined(ULTRIX42) || defined(ULTRIX43)
	return (float)avenrun[0]/(1<<FBITS);

#elif defined(SUNOS41) || defined(IRIX331) || defined(IRIX53)
    return (float)avenrun[0]/FSCALE;

#endif
}

{'fraction_non_alphanumeric': 0.13137996219281664, 'fraction_numerical': 0.03100189035916824, 'mean_word_length': 3.64486391571554, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6420825', 'n_tokens_mistral': 3990, 'n_tokens_neox': 3661, 'n_words': 1251}