void CpuAttributes::compute( amask_t how_much ) { double val; if( IS_UPDATE(how_much) && IS_SHARED(how_much) ) { // Shared attributes that we only get a fraction of val = map->virt_mem(); if (!IS_AUTO_SHARE(c_virt_mem_fraction)) { val *= c_virt_mem_fraction; } c_virt_mem = (unsigned long)floor( val ); } if( IS_TIMEOUT(how_much) && !IS_SHARED(how_much) ) { // Dynamic, non-shared attributes we need to actually compute c_condor_load = rip->compute_condor_load(); c_total_disk = sysapi_disk_space(rip->executeDir()); if (IS_UPDATE(how_much)) { dprintf(D_FULLDEBUG, "Total execute space: %lu\n", c_total_disk); } val = c_total_disk * c_disk_fraction; c_disk = (int)floor( val ); if (0 == (int)c_slot_disk) { // only use the 1st compute ignore subsequent. c_slot_disk = c_disk; } } }
void AvailStats::compute( amask_t how_much ) { if( !compute_avail_stats ) return; if( IS_STATIC(how_much) && IS_SHARED(how_much) ) { as_avail_confidence = param_double("STARTD_AVAIL_CONFIDENCE", as_avail_confidence, 0, 1); as_max_avail_periods = param_integer("STARTD_MAX_AVAIL_PERIOD_SAMPLES", as_max_avail_periods); } if( IS_UPDATE(how_much) && IS_SHARED(how_much) ) { time_t current_time = time(0); // only compute avail time estimate if we're in non-owner state if( as_start_avail ) { // first, skip over intervals less than our idle time so far int current_idle_time = current_time - as_start_avail; int num_intervals = as_num_avail_periods; as_avail_periods.Rewind(); int item = 0; as_avail_periods.Next(item); while( num_intervals && item < current_idle_time ) { as_avail_periods.Next(item); num_intervals--; } if( !num_intervals ) { // If this is the longest we've ever been idle, our // historical data isn't too useful to us, so give an // estimate based on how long we've been idle so far. as_avail_estimate = (int)floor(current_idle_time*(2.0-as_avail_confidence)); } else { // Otherwise, find the record in our history at the // requested confidence level. int idx = (int)floor(num_intervals*(1.0-as_avail_confidence)); while( idx ) { as_avail_periods.Next(item); idx--; } as_avail_estimate = item; } as_avail_time = float(as_tot_avail_time + current_idle_time) / float(current_time - as_birthdate); } else { as_avail_time = float(as_tot_avail_time) / float(current_time - as_birthdate); } } }
/** * gst_mini_object_lock: * @object: the mini-object to lock * @flags: #GstLockFlags * * Lock the mini-object with the specified access mode in @flags. * * Returns: %TRUE if @object could be locked. */ gboolean gst_mini_object_lock (GstMiniObject * object, GstLockFlags flags) { gint access_mode, state, newstate; g_return_val_if_fail (object != NULL, FALSE); g_return_val_if_fail (GST_MINI_OBJECT_IS_LOCKABLE (object), FALSE); if (G_UNLIKELY (object->flags & GST_MINI_OBJECT_FLAG_LOCK_READONLY && flags & GST_LOCK_FLAG_WRITE)) return FALSE; do { access_mode = flags & FLAG_MASK; newstate = state = g_atomic_int_get (&object->lockstate); GST_CAT_TRACE (GST_CAT_LOCKING, "lock %p: state %08x, access_mode %d", object, state, access_mode); if (access_mode & GST_LOCK_FLAG_EXCLUSIVE) { /* shared ref */ newstate += SHARE_ONE; access_mode &= ~GST_LOCK_FLAG_EXCLUSIVE; } /* shared counter > 1 and write access is not allowed */ if (((state & GST_LOCK_FLAG_WRITE) != 0 || (access_mode & GST_LOCK_FLAG_WRITE) != 0) && IS_SHARED (newstate)) goto lock_failed; if (access_mode) { if ((state & LOCK_FLAG_MASK) == 0) { /* nothing mapped, set access_mode */ newstate |= access_mode; } else { /* access_mode must match */ if ((state & access_mode) != access_mode) goto lock_failed; } /* increase refcount */ newstate += LOCK_ONE; } } while (!g_atomic_int_compare_and_exchange (&object->lockstate, state, newstate)); return TRUE; lock_failed: { GST_CAT_DEBUG (GST_CAT_LOCKING, "lock failed %p: state %08x, access_mode %d", object, state, access_mode); return FALSE; } }
/** * gst_mini_object_is_writable: * @mini_object: the mini-object to check * * If @mini_object has the LOCKABLE flag set, check if the current EXCLUSIVE * lock on @object is the only one, this means that changes to the object will * not be visible to any other object. * * If the LOCKABLE flag is not set, check if the refcount of @mini_object is * exactly 1, meaning that no other reference exists to the object and that the * object is therefore writable. * * Modification of a mini-object should only be done after verifying that it * is writable. * * Returns: TRUE if the object is writable. */ gboolean gst_mini_object_is_writable (const GstMiniObject * mini_object) { gboolean result; g_return_val_if_fail (mini_object != NULL, FALSE); if (GST_MINI_OBJECT_IS_LOCKABLE (mini_object)) { result = !IS_SHARED (g_atomic_int_get (&mini_object->lockstate)); } else { result = (GST_MINI_OBJECT_REFCOUNT_VALUE (mini_object) == 1); } return result; }
void MachAttributes::compute( amask_t how_much ) { // the startd doesn't normally call the init() method (bug?), // it just starts calling compute, so in order to gurantee that // init happens, we put check here to see if user settings have been initialized if ( ! m_user_settings_init) init_user_settings(); if( IS_STATIC(how_much) && IS_SHARED(how_much) ) { // Since we need real values for them as soon as a // MachAttributes object is instantiated, we handle number // of CPUs and physical memory in the constructor, not // here. -Derek Wright 2/5/99 // Arch, OpSys, FileSystemDomain and UidDomain. Note: // these will always return something, since config() will // insert values if we don't have them in the config file. if( m_arch ) { free( m_arch ); } m_arch = param( "ARCH" ); if( m_opsys ) { free( m_opsys ); } m_opsys = param( "OPSYS" ); m_opsysver = param_integer( "OPSYSVER", 0 ); if( m_opsys_and_ver ) { free( m_opsys_and_ver ); } m_opsys_and_ver = param( "OPSYSANDVER" ); m_opsys_major_ver = param_integer( "OPSYSMAJORVER", 0 ); if( m_opsys_name ) { free( m_opsys_name ); } m_opsys_name = param( "OPSYSNAME" ); if( m_opsys_long_name ) { free( m_opsys_long_name ); } m_opsys_long_name = param( "OPSYSLONGNAME" ); if( m_opsys_short_name ) { free( m_opsys_short_name ); } m_opsys_short_name = param( "OPSYSSHORTNAME" ); if( m_opsys_legacy ) { free( m_opsys_legacy ); } m_opsys_legacy = param( "OPSYSLEGACY" ); // temporary attributes for raw utsname info if( m_utsname_sysname ) { free( m_utsname_sysname ); } if( m_utsname_nodename ) { free( m_utsname_nodename ); } if( m_utsname_release ) { free( m_utsname_release ); } if( m_utsname_version ) { free( m_utsname_version ); } if( m_utsname_machine ) { free( m_utsname_machine ); } m_utsname_sysname = param( "UTSNAME_SYSNAME" ); m_utsname_nodename = param( "UTSNAME_NODENAME" ); m_utsname_release = param( "UTSNAME_RELEASE" ); m_utsname_version = param( "UTSNAME_VERSION" ); m_utsname_machine = param( "UTSNAME_MACHINE" ); if( m_uid_domain ) { free( m_uid_domain ); } m_uid_domain = param( "UID_DOMAIN" ); dprintf( D_FULLDEBUG, "%s = \"%s\"\n", ATTR_UID_DOMAIN, m_uid_domain ); if( m_filesystem_domain ) { free( m_filesystem_domain ); } m_filesystem_domain = param( "FILESYSTEM_DOMAIN" ); dprintf( D_FULLDEBUG, "%s = \"%s\"\n", ATTR_FILE_SYSTEM_DOMAIN, m_filesystem_domain ); m_idle_interval = param_integer( "IDLE_INTERVAL", -1 ); // checkpoint platform signature if (m_ckptpltfrm) { free(m_ckptpltfrm); } const char * ckptpltfrm = param( ATTR_CHECKPOINT_PLATFORM ); if( ckptpltfrm == NULL ) { ckptpltfrm = sysapi_ckptpltfrm(); } m_ckptpltfrm = strdup( ckptpltfrm ); pair_strings_vector root_dirs = root_dir_list(); std::stringstream result; unsigned int chroot_count = 0; for (pair_strings_vector::const_iterator it=root_dirs.begin(); it != root_dirs.end(); ++it, ++chroot_count) { if (chroot_count) { result << ", "; } result << it->first; } if (chroot_count > 1) { std::string result_str = result.str(); dprintf(D_FULLDEBUG, "Named chroots: %s\n", result_str.c_str() ); m_named_chroot = result_str; } } if( IS_UPDATE(how_much) && IS_SHARED(how_much) ) { m_virt_mem = sysapi_swap_space(); dprintf( D_FULLDEBUG, "Swap space: %lu\n", m_virt_mem ); #if defined(WIN32) credd_test(); #endif } if( IS_TIMEOUT(how_much) && IS_SHARED(how_much) ) { m_load = sysapi_load_avg(); sysapi_idle_time( &m_idle, &m_console_idle ); time_t my_timer; struct tm *the_time; time( &my_timer ); the_time = localtime(&my_timer); m_clock_min = (the_time->tm_hour * 60) + the_time->tm_min; m_clock_day = the_time->tm_wday; if (m_last_keypress < my_timer - m_idle) { if (m_idle_interval >= 0) { int duration = my_timer - m_last_keypress; if (duration > m_idle_interval) { if (m_seen_keypress) { dprintf(D_IDLE, "end idle interval of %d sec.\n", duration); } else { dprintf(D_IDLE, "first keyboard event %d sec. after startup\n", duration); } } } m_last_keypress = my_timer; m_seen_keypress = true; } #ifdef WIN32 update_all_WinPerf_results(); #endif AttribValue *pav = NULL; m_lst_dynamic.Rewind(); while ((pav = m_lst_dynamic.Next()) ) { if (pav) { #ifdef WIN32 if ( ! update_WinPerf_Value(pav)) pav->vtype = AttribValue_DataType_Max; // undefined vtype #else if (pav->pquery) { // insert code to update pav from pav->pquery } #endif } } } if( IS_TIMEOUT(how_much) && IS_SUMMED(how_much) ) { m_condor_load = resmgr->sum( &Resource::condor_load ); if( m_condor_load > m_load ) { m_condor_load = m_load; } } }
/* fut_copy copies an existing fut. */ fut_p fut_copy (fut_p fut) { fut_p new_fut; KpInt32_t i; KpHandle_t h; if ( ! IS_FUT(fut)) { return (0); } /* allocate basic fut_structure */ new_fut = fut_alloc_fut (); if ( new_fut == FUT_NULL ) { return (FUT_NULL); } /* save handle before copying over old fut */ h = new_fut->handle; /* copy over all data (including pointers */ *new_fut = *fut; /* now copy back handle */ new_fut->handle = h; /* copy id string */ new_fut->idstr = 0; /* (void) fut_set_idstr (new_fut, fut->idstr); */ /* copy input tables */ for ( i=0; i<FUT_NICHAN; i++ ) { new_fut->itbl[i] = (IS_SHARED (fut->itbl[i])) ? fut_share_itbl (fut->itbl[i]) : fut_copy_itbl (fut->itbl[i]); new_fut->itblHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->itbl[i]); } /* copy output channels */ for ( i=0; i<FUT_NOCHAN; i++ ) { new_fut->chan[i] = fut_copy_chan (fut->chan[i]); new_fut->chanHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->chan[i]); } /* now check that all copies were succesful */ if ( new_fut->idstr == 0 && fut->idstr != 0 ) { goto ErrOut; } for ( i=0; i<FUT_NICHAN; i++ ) { if ( new_fut->itbl[i] == 0 && fut->itbl[i] != 0) { goto ErrOut; } } for ( i=0; i<FUT_NOCHAN; i++ ) { if ( new_fut->chan[i] == 0 && fut->chan[i] != 0) { goto ErrOut; } } for ( i=0; i<FUT_NMCHAN; i++ ) { /* free extra reference tables */ if (NULL != fut->mabInRefTblHandles[i]) { new_fut->mabInTblEntries[i] = fut->mabInTblEntries[i]; new_fut->mabInRefTbl[i] = (mf2_tbldat_p) allocBufferPtr (new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t)); KpMemCpy (new_fut->mabInRefTbl[i], fut->mabInRefTbl[i], new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t)); new_fut->mabInRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabInRefTbl[i]); } if (NULL != fut->mabOutRefTblHandles[i]) { new_fut->mabOutTblEntries[i] = fut->mabOutTblEntries[i]; new_fut->mabOutRefTbl[i] = (mf2_tbldat_p) allocBufferPtr (new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t)); KpMemCpy (new_fut->mabOutRefTbl[i], fut->mabOutRefTbl[i], new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t)); new_fut->mabOutRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabOutRefTbl[i]); } } return (new_fut); ErrOut: fut_free (new_fut); return (FUT_NULL); }
/* fut_copy_chan makes a copy of an existing fut_chan_t structure. */ fut_chan_p fut_copy_chan (fut_chan_p chan) { fut_chan_p new_chan; KpInt32_t i; KpHandle_t h; if ( ! IS_CHAN(chan) ) { return (FUT_NULL_CHAN); } new_chan = fut_alloc_chan (); if ( new_chan == FUT_NULL_CHAN ) { return (FUT_NULL_CHAN); } /* save handle before copying over old fut */ h = new_chan->handle; /* copy over to new structure */ *new_chan = *chan; /* move handle back to new structure */ new_chan->handle = h; /* copy itbls * if an itbl is shared, share it with the itbl in the new fut */ for ( i=0; i<FUT_NICHAN; i++ ) { new_chan->itbl[i] = (IS_SHARED (chan->itbl[i])) ? fut_share_itbl (chan->itbl[i]) : fut_copy_itbl (chan->itbl[i]); new_chan->itblHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_chan->itbl[i]); } /* copy gtbl */ new_chan->gtbl = fut_copy_gtbl (chan->gtbl); new_chan->gtblHandle = getHandleFromPtr((KpGenericPtr_t)new_chan->gtbl); /* copy otbl */ new_chan->otbl = (IS_SHARED(chan->otbl)) ? fut_share_otbl (chan->otbl) : fut_copy_otbl (chan->otbl); new_chan->otblHandle = getHandleFromPtr((KpGenericPtr_t)new_chan->otbl); /* check for successful copies */ for ( i=0; i<FUT_NICHAN; i++ ) { if ( new_chan->itbl[i] == 0 && chan->itbl[i] != 0 ) { goto ErrOut; } } if ( (new_chan->otbl == 0 && chan->otbl != 0) || (new_chan->gtbl == 0 && chan->gtbl != 0) ) { goto ErrOut; } return (new_chan); ErrOut: fut_free_chan (new_chan); return (FUT_NULL_CHAN); }