Esempio n. 1
0
/** 
 * adjust_speed:
 * @iface:	struct with the userspace interface
 *
 * Returns:	TRUE/FALSE
 *
 * increases and decreases speeds
 */
static gboolean adjust_speed(struct userspace_interface *iface)
{
	GSList		*cpus	 = (GSList*)iface->cpus;
	GSList		*it	 = NULL;
	int		cpu_load = 0;

	for (it = cpus; it != NULL; it = g_slist_next(it)) {
		HAL_DEBUG(("checking cpu %d: cpu_core: %d",
			   GPOINTER_TO_INT(it->data), GPOINTER_TO_INT(it->data)));
		if (get_cpu_load(GPOINTER_TO_INT(it->data)) > cpu_load)
			 cpu_load = get_cpu_load(GPOINTER_TO_INT(it->data));
	}

	HAL_DEBUG(("cpu_max: %d cpu_high_limit: %d consider_nice: %d",
		   config.up_threshold, config.cpu_high_limit,
		   config.consider_nice));
	HAL_DEBUG(("Current: %u; current speed: %u MHz", 
		   iface->current_speed, g_a_i(iface->speeds_kHz, iface->current_speed)));
	HAL_DEBUG(("CPU load: %d, Previous CPU load %d, cpu_load diff: %d, last_step: %d, demotion: %u",
		   cpu_load, iface->prev_cpu_load, cpu_load - iface->prev_cpu_load, iface->last_step,
		   g_a_i(iface->demotion, iface->current_speed)));

	/* directly increase speed to maximum if cpu load jumped */
	if (config.cpu_high_limit &&
	    (cpu_load - iface->prev_cpu_load) > config.cpu_high_limit) {
		if (iface->current_speed != 0) {
			set_speed(iface, 0);
			iface->current_speed = 0;
			HAL_DEBUG(("jumped to max (%d kHz)", 
				   g_a_i(iface->speeds_kHz, iface->current_speed)));
		}
	} else if (cpu_load > config.up_threshold && iface->current_speed > 0) {
		iface->current_speed = increase_speed(iface);
		HAL_DEBUG(("increased to %d kHz", g_a_i(iface->speeds_kHz, iface->current_speed)));
	} else if (cpu_load < (int)g_a_i(iface->demotion, iface->current_speed) &&
		   iface->current_speed < iface->last_step) {
		iface->current_speed = decrease_speed(iface);
		HAL_DEBUG(("decreased to %d kHz", g_a_i(iface->speeds_kHz, iface->current_speed)));
	} else {
		HAL_DEBUG(("Speed not changed"));
	}

	iface->prev_cpu_load = cpu_load;
	return TRUE;
}
float stop_cpuload_measurement(IN const struct proc_stat * cpu_status_start)
{
	struct proc_stat cpu_status_end;

	if (enable_cpu_load) {
		get_cpu_status(&cpu_status_end);
		return (get_cpu_load(*cpu_status_start, cpu_status_end));
	} else {
		return (CPULOAD_NOT_ENABLED);
	}
}
Esempio n. 3
0
static void
_fill_registration_msg(slurm_node_registration_status_msg_t *msg)
{
	List steps;
	ListIterator i;
	step_loc_t *stepd;
	int  n;
	char *arch, *os;
	struct utsname buf;
	static bool first_msg = true;
	static time_t slurmd_start_time = 0;
	Buf gres_info;

	msg->node_name   = xstrdup (conf->node_name);
	msg->cpus	 = conf->cpus;
	msg->boards	 = conf->boards;
	msg->sockets	 = conf->sockets;
	msg->cores	 = conf->cores;
	msg->threads	 = conf->threads;
	msg->real_memory = conf->real_memory_size;
	msg->tmp_disk    = conf->tmp_disk_space;
	msg->hash_val    = slurm_get_hash_val();
	get_cpu_load(&msg->cpu_load);

	gres_info = init_buf(1024);
	if (gres_plugin_node_config_pack(gres_info) != SLURM_SUCCESS)
		error("error packing gres configuration");
	else
		msg->gres_info   = gres_info;

	get_up_time(&conf->up_time);
	msg->up_time     = conf->up_time;
	if (slurmd_start_time == 0)
		slurmd_start_time = time(NULL);
	msg->slurmd_start_time = slurmd_start_time;

	if (first_msg) {
		first_msg = false;
		info("CPUs=%u Boards=%u Sockets=%u Cores=%u Threads=%u "
		     "Memory=%u TmpDisk=%u Uptime=%u",
		     msg->cpus, msg->boards, msg->sockets, msg->cores,
		     msg->threads, msg->real_memory, msg->tmp_disk,
		     msg->up_time);
	} else {
		debug3("CPUs=%u Boards=%u Sockets=%u Cores=%u Threads=%u "
		       "Memory=%u TmpDisk=%u Uptime=%u",
		       msg->cpus, msg->boards, msg->sockets, msg->cores,
		       msg->threads, msg->real_memory, msg->tmp_disk,
		       msg->up_time);
	}
	uname(&buf);
	if ((arch = getenv("SLURM_ARCH")))
		msg->arch = xstrdup(arch);
	else
		msg->arch = xstrdup(buf.machine);
	if ((os = getenv("SLURM_OS")))
		msg->os   = xstrdup(os);
	else
		msg->os = xstrdup(buf.sysname);

	if (msg->startup) {
		if (switch_g_alloc_node_info(&msg->switch_nodeinfo))
			error("switch_g_alloc_node_info: %m");
		if (switch_g_build_node_info(msg->switch_nodeinfo))
			error("switch_g_build_node_info: %m");
	}

	steps = stepd_available(conf->spooldir, conf->node_name);
	msg->job_count = list_count(steps);
	msg->job_id    = xmalloc(msg->job_count * sizeof(*msg->job_id));
	/* Note: Running batch jobs will have step_id == NO_VAL */
	msg->step_id   = xmalloc(msg->job_count * sizeof(*msg->step_id));

	i = list_iterator_create(steps);
	n = 0;
	while ((stepd = list_next(i))) {
		int fd;
		fd = stepd_connect(stepd->directory, stepd->nodename,
				   stepd->jobid, stepd->stepid);
		if (fd == -1) {
			--(msg->job_count);
			continue;
		}
		if (stepd_state(fd) == SLURMSTEPD_NOT_RUNNING) {
			debug("stale domain socket for stepd %u.%u ",
			      stepd->jobid, stepd->stepid);
			--(msg->job_count);
			close(fd);
			continue;
		}

		close(fd);
		if (stepd->stepid == NO_VAL)
			debug("found apparently running job %u", stepd->jobid);
		else
			debug("found apparently running step %u.%u",
			      stepd->jobid, stepd->stepid);
		msg->job_id[n]  = stepd->jobid;
		msg->step_id[n] = stepd->stepid;
		n++;
	}
	list_iterator_destroy(i);
	list_destroy(steps);

	if (!msg->energy)
		msg->energy = acct_gather_energy_alloc();
	acct_gather_energy_g_get_data(ENERGY_DATA_STRUCT, msg->energy);

	msg->timestamp = time(NULL);

	return;
}
JNIEXPORT jdouble JNICALL
Java_com_sun_management_internal_OperatingSystemImpl_getSystemCpuLoad0
(JNIEnv *env, jobject dummy)
{
    return get_cpu_load(-1);
}