Пример #1
0
static int _get_joules_task(uint16_t delta)
{
	acct_gather_energy_t *last_energy = NULL;
	time_t now;
	static bool first = true;
	static uint32_t start_current_energy = 0;
	uint32_t adjustment = 0;

	last_energy = local_energy;
	local_energy = NULL;

	if (slurm_get_node_energy(NULL, delta, &local_energy)) {
		error("_get_joules_task: can't get info from slurmd");
		local_energy = last_energy;
		return SLURM_ERROR;
	}
	now = time(NULL);

	local_energy->previous_consumed_energy = last_energy->consumed_energy;

	if (slurm_ipmi_conf.adjustment)
		adjustment = _get_additional_consumption(
			local_energy->poll_time, now,
			local_energy->current_watts,
			local_energy->current_watts);

	if (!first) {
		local_energy->consumed_energy -= start_current_energy;

		local_energy->base_consumed_energy =
			(local_energy->consumed_energy
			 - last_energy->consumed_energy)
			+ adjustment;
	} else {
		/* This is just for the step, so take all the pervious
		   consumption out of the mix.
		*/
		start_current_energy =
			local_energy->consumed_energy + adjustment;
		local_energy->base_consumed_energy = 0;
		first = false;
	}

	local_energy->consumed_energy = local_energy->previous_consumed_energy
		+ local_energy->base_consumed_energy;

	acct_gather_energy_destroy(last_energy);

	if (debug_flags & DEBUG_FLAG_ENERGY)
		info("_get_joules_task: consumed %u Joules "
		     "(received %u(%u watts) from slurmd)",
		     local_energy->consumed_energy,
		     local_energy->base_consumed_energy,
		     local_energy->current_watts);

	return SLURM_SUCCESS;
}
Пример #2
0
/*
 * _thread_update_node_energy calls _read_ipmi_values and updates all values
 * for node consumption
 */
static int _thread_update_node_energy(void)
{
	int rc = SLURM_SUCCESS;

	if (local_energy->current_watts == NO_VAL)
		return rc;

	rc = _read_ipmi_values();

	if (rc == SLURM_SUCCESS) {
		uint32_t additional_consumption;
		if (previous_update_time == 0) {
			additional_consumption = 0;
			previous_update_time = last_update_time;
		} else {
			additional_consumption =
				_get_additional_consumption(
					previous_update_time, last_update_time,
					local_energy->base_watts,
					local_energy->current_watts);
		}
		if (local_energy->current_watts != 0) {
			local_energy->base_watts = local_energy->current_watts;
			local_energy->current_watts = last_update_watt;
			local_energy->previous_consumed_energy =
				local_energy->consumed_energy;
			local_energy->consumed_energy += additional_consumption;
			local_energy->base_consumed_energy =
				additional_consumption;
		}
		if (local_energy->current_watts == 0) {
			local_energy->consumed_energy = 0;
			local_energy->base_watts = 0;
			local_energy->current_watts = last_update_watt;
		}
		local_energy->poll_time = time(NULL);
	}
	if (debug_flags & DEBUG_FLAG_ENERGY) {
		info("ipmi-thread = %d sec, current %d Watts, "
		     "consumed %d Joules %d new",
		     (int) (last_update_time - previous_update_time),
		     local_energy->current_watts,
		     local_energy->consumed_energy,
		     local_energy->base_consumed_energy);
	}

	return rc;
}
Пример #3
0
static uint64_t _rrd_consolidate_one(time_t t0, time_t t1,
				     char* filename, char* rra_name,
				     bool flag_approximate)
{
	int status, rra_nb = -1;
	unsigned long step = 1, ds_count, ii;
	char cf[] = "AVERAGE";
	char **ds_names;
	time_t ti, start = t0-1, end = t1+1;
	uint32_t nb_miss = 0, nb_values = 0;
	rrd_value_t *rrd_data, *rrd_data_p;
	rrd_value_t current_watt = (rrd_value_t)NO_VAL;
	rrd_value_t temp_energy = 0, consumed_energy = 0;

	last_valid_time = 0;
	last_valid_watt = (rrd_value_t)NO_VAL;

	status = rrd_fetch_r(filename, cf,
			     &start, &end, &step,
			     &ds_count, &ds_names,
			     &rrd_data);

	if (status != 0){
		if (debug_flags & DEBUG_FLAG_EXT_SENSORS)
			info("ext_sensors: error rrd_fetch %s",filename);
		return NO_VAL;
	}

	rrd_data_p = rrd_data;

	do {
		if (start == end) {
			consumed_energy = (rrd_value_t)NO_VAL;
			break;
		}
		if (ds_count == 0) {
			if (debug_flags & DEBUG_FLAG_EXT_SENSORS)
				info("ext_sensors: error ds_count==0 in RRD %s",
				     filename);
			consumed_energy = (rrd_value_t)NO_VAL;
			break;
		} else if (ds_count == 1 || rra_name == NULL)
			rra_nb = 0;
		else {
			for (ii = 0; ii < ds_count; ii++){
				if (!strcmp(ds_names[ii],rra_name)) {
					rra_nb = ii;
					break;
				}
			}
			if (rra_nb == -1) {
				if (debug_flags & DEBUG_FLAG_EXT_SENSORS)
					info("ext_sensors: error RRA %s not "
					     "found in RRD %s",
					     rra_name, filename);
				consumed_energy = (rrd_value_t)NO_VAL;
				break;
			}
		}
		ti = start;
		do {
			for (ii = 0; ii < rra_nb; ii++)
				rrd_data_p++;
			last_valid_watt = _validate_watt(rrd_data_p);
			if (last_valid_watt != (rrd_value_t)NO_VAL)
				last_valid_time = ti;
			for (ii = rra_nb; ii < ds_count; ii++)
				rrd_data_p++;
			ti += step;
		} while (ti < t0 && ti < end);

		if (ti != t0 && ti < end) {
			for (ii = 0; ii < rra_nb; ii++)
				rrd_data_p++;
			current_watt = _validate_watt(rrd_data_p);

			if (current_watt != (rrd_value_t)NO_VAL) {
				temp_energy = _get_additional_consumption(
					t0, ti < t1 ? ti : t1,
					current_watt, current_watt);
				last_valid_watt = current_watt;
				last_valid_time = ti;
				consumed_energy += temp_energy;
				nb_values += 1;
			} else {
				nb_miss += 10001;
			}

			for (ii = rra_nb; ii < ds_count; ii++)
				rrd_data_p++;
		} else if ((ti == t0) && (ti < end)) {
			for (ii = 0; ii < rra_nb; ii++)
				rrd_data_p++;
			current_watt = _validate_watt(rrd_data_p);
			if (current_watt != (rrd_value_t)NO_VAL) {
				last_valid_watt = current_watt;
				last_valid_time = ti;
			}
			for (ii = rra_nb; ii < ds_count; ii++)
				rrd_data_p++;
			ti += step;
		}
		while (((ti += step) <= t1) && (ti < end)) {
			for (ii = 0; ii < rra_nb; ii++)
				rrd_data_p++;
			current_watt = _validate_watt(rrd_data_p);
			if (current_watt != (rrd_value_t)NO_VAL &&
			    last_valid_watt != (rrd_value_t)NO_VAL) {
				temp_energy = _get_additional_consumption(
					ti-step, ti,
					last_valid_watt, current_watt);
				last_valid_watt = current_watt;
				last_valid_time = ti;
				consumed_energy += temp_energy;
				nb_values += 1;
			} else {
				nb_miss += 1;
			}
			for (ii = rra_nb; ii < ds_count; ii++)
				rrd_data_p++;
		}
		if ((ti > t1) && (t1 > (t0 + step)) && (ti-step < t1)) {
			if (current_watt != (rrd_value_t)NO_VAL) {
				temp_energy = _get_additional_consumption(
					ti-step, t1,
					current_watt, current_watt);
				consumed_energy += temp_energy;
				nb_values += 1;
			} else {
				nb_miss += 1;
			}
		}
	} while(0);

	if (nb_miss >= 10000) {
		if (debug_flags & DEBUG_FLAG_EXT_SENSORS)
			info("ext_sensors: RRD: no first value");
		nb_miss -= 10000;
	}
	if (debug_flags & DEBUG_FLAG_EXT_SENSORS)
		info("ext_sensors: RRD: have %d values and miss %d values",
		     nb_values, nb_miss);

	if (flag_approximate &&
	    current_watt == (rrd_value_t)NO_VAL &&
	    last_valid_watt != (rrd_value_t)NO_VAL) {
		temp_energy = _get_additional_consumption(
			last_valid_time, t1,
			last_valid_watt, last_valid_watt);
		consumed_energy += temp_energy;
	}

	for (ii = 0; ii < ds_count; ii++)
		free(ds_names[ii]);

	free(ds_names);
	free(rrd_data);

	return (uint64_t)consumed_energy;
}