float sysapi_load_avg_raw(void) { struct pst_dynamic d; /* make numcpus static so we do not have to recompute * numcpus every time the load average is requested. * after all, the number of cpus is not going to change! * we need to multiply the value the HPUX kerenel gives * us by the number of CPUs, because on SMP HPUX the kernel * "distributes" the load average across all CPUs. But * no other Unix does that, so our startd assumes otherwise. * So we multiply by the number of CPUs so HPUX SMP load avg * is reported the same way as other Unixes. -Todd */ static int numcpus = 0; sysapi_internal_reconfig(); if ( numcpus == 0 ) { numcpus = sysapi_ncpus(); if ( numcpus < 1 ) { numcpus = 1; } } if ( pstat_getdynamic ( &d, sizeof(d), (size_t)1, 0) != -1 ) { return (d.psd_avg_1_min * numcpus); } else { return -1.0; } }
float sysapi_load_avg_raw(void) { static HANDLE threadHandle = NULL; static int threadID = -1; time_t currentTime; double totalLoad=0.0; DWORD exitCode = 0; BOOL createNewThread = FALSE; int numSamples=0, i; sysapi_internal_reconfig(); if (threadHandle == NULL) { ncpus = sysapi_ncpus(); InitializeCriticalSection(&cs); createNewThread = TRUE; } else { if ( ! GetExitCodeThread( threadHandle, &exitCode ) ) { dprintf(D_ALWAYS, "GetExitCodeThread() failed. (err=%li)\n", GetLastError()); } else { if ( exitCode != STILL_ACTIVE ) { // somehow the thread died, so we should get its // return code, dprintf it and then start a new thread. dprintf(D_ALWAYS, "loadavg thread died, restarting. " "(exit code=%li)\n", exitCode); CloseHandle(threadHandle); createNewThread = TRUE; } else { // thread is still alive and well. Go in peace. createNewThread = FALSE; } } } if ( createNewThread == TRUE ) { threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)sample_load, NULL, 0, (LPDWORD)&threadID); if (threadHandle == NULL) { #ifndef TESTING dprintf(D_ALWAYS, "failed to create loadavg thread, errno = %d\n", GetLastError()); #endif return 0.0; } Sleep(SAMPLE_INTERVAL*5); /* wait for ~5 samples */ } currentTime = time(NULL); EnterCriticalSection(&cs); for (i=0; i < NUM_SAMPLES; i++) { /* if this sample occurred within the minute, then add to total */ if ((currentTime-60) <= samples[i].sampletime) { totalLoad += samples[i].load; numSamples++; } } LeaveCriticalSection(&cs); if (numSamples == 0) { #ifndef TESTING dprintf(D_ALWAYS, "no loadavg samples this minute, maybe thread died???\n"); #endif return 0.0; } #ifndef TESTING dprintf(D_LOAD, "loadavg=%.2f with %d samples\n", ((float)totalLoad)/((float)numSamples), numSamples); #endif return ((float)totalLoad)/((float)numSamples); }
MachAttributes::MachAttributes() : m_user_specified(NULL, ";"), m_user_settings_init(false), m_named_chroot() { m_mips = -1; m_kflops = -1; m_last_benchmark = 0; m_last_keypress = time(0)-1; m_seen_keypress = false; m_arch = NULL; m_opsys = NULL; m_opsysver = 0; m_opsys_and_ver = NULL; m_opsys_major_ver = 0; m_opsys_name = NULL; m_opsys_long_name = NULL; m_opsys_short_name = NULL; m_opsys_legacy = NULL; m_uid_domain = NULL; m_filesystem_domain = NULL; m_idle_interval = -1; m_ckptpltfrm = NULL; m_clock_day = -1; m_clock_min = -1; m_condor_load = -1.0; m_console_idle = 0; m_idle = 0; m_load = -1.0; m_owner_load = -1.0; m_virt_mem = 0; // Number of CPUs. Since this is used heavily by the ResMgr // instantiation and initialization, we need to have a real // value for this as soon as the MachAttributes object exists. m_num_cpus = sysapi_ncpus(); m_num_real_cpus = sysapi_ncpus_raw(); // The same is true of physical memory. If we had an error in // sysapi_phys_memory(), we need to just EXCEPT with a message // telling the user to define MEMORY manually. m_phys_mem = sysapi_phys_memory(); if( m_phys_mem <= 0 ) { dprintf( D_ALWAYS, "Error computing physical memory with calc_phys_mem().\n" ); dprintf( D_ALWAYS | D_NOHEADER, "\t\tMEMORY parameter not defined in config file.\n" ); dprintf( D_ALWAYS | D_NOHEADER, "\t\tTry setting MEMORY to the number of megabytes of RAM.\n" ); EXCEPT( "Can't compute physical memory." ); } dprintf( D_FULLDEBUG, "Memory: Detected %d megs RAM\n", m_phys_mem ); // identification of the checkpointing platform signature const char * ckptpltfrm = param( ATTR_CHECKPOINT_PLATFORM ); if( ckptpltfrm == NULL ) { ckptpltfrm = sysapi_ckptpltfrm(); } m_ckptpltfrm = strdup( ckptpltfrm ); // temporary attributes for raw utsname info m_utsname_sysname = NULL; m_utsname_nodename = NULL; m_utsname_release = NULL; m_utsname_version = NULL; m_utsname_machine = NULL; #if defined ( WIN32 ) // Get the version information of the copy of Windows // we are running ZeroMemory ( &m_window_version_info, sizeof ( OSVERSIONINFOEX ) ); m_window_version_info.dwOSVersionInfoSize = sizeof ( OSVERSIONINFOEX ); m_got_windows_version_info = GetVersionEx ( (OSVERSIONINFO*) &m_window_version_info ); if ( !m_got_windows_version_info ) { m_window_version_info.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO ); m_got_windows_version_info = GetVersionEx ( (OSVERSIONINFO*) &m_window_version_info ); if ( !m_got_windows_version_info ) { dprintf ( D_ALWAYS, "MachAttributes: failed to " "get Windows version information.\n" ); } } m_local_credd = NULL; m_last_credd_test = 0; m_dot_Net_Versions = NULL; #endif }