#define DEFAULT_TEMPERATURE (-1000)
-/**
- * @brief Decide the proper thermal scenario by using both the monitored
- * raw data of thermal information and the parsed thermal
- * information from scenario section. And then notify the decided
- * thermal scenario to Thermal Monitor featrue (thermal) which
- * provides the external D-bus interface for Thermal Monitor.
- * thermal
- * @param [in] result Monitored data of thermal will be saved to it.
- * @param [in] user_data Instance of a resource monitor
- * @return @c 0 on success, otherwise error value
- */
-static int thermal_monitor_func(void *result, void *user_data)
+static int thermal_update(struct pass_resource *res,
+ struct resmon_result_src_thermal *thermal_result)
{
- struct pass_resource *res = user_data;
- struct resmon_result_src_thermal *thermal_result = result;
- struct pass_thermal *thermal;
+ struct pass_thermal *thermal = &res->thermal;;
int timer_interval_of_scenario, timer_interval;
- int curr_temp, prev_temp;
- int temp;
- int ret;
+ int curr_temp, prev_temp, temp;
int i, scenario_idx;
+ int ret;
if (!res || !thermal_result) {
_E("invalid parameter for thermal monitor\n");
return -EINVAL;
}
- thermal = &res->thermal;
prev_temp = thermal->curr_temp;
curr_temp = thermal_result->temp;
if (thermal->curr_scenario_idx == scenario_idx)
return 0;
- /*
- * Send notification with thermal scenario name according to
- * measured temperature of each h/w resource.
- */
- device_notify(DEVICE_NOTIFIER_THERMAL,
- (void *)thermal->scenarios[scenario_idx].name);
-
- _I("Monitor '%s' scenario for '%s' resource ('%d' degrees Celsius)\n",
- thermal->scenarios[scenario_idx].name,
- res->config_data.res_name, curr_temp);
-
/* Get the new timer interval of each scenario */
timer_interval_of_scenario
= thermal->scenarios[scenario_idx].thermal.timer_interval;
thermal->curr_temp = curr_temp;
thermal->curr_scenario_idx = scenario_idx;
+ _I("Monitor '%-12s' of '%s' resource ('%3d' degrees,'%5d' ms)\n",
+ thermal->scenarios[scenario_idx].name,
+ res->config_data.res_name,
+ curr_temp, timer_interval);
+
+ return 0;
+}
+
+/**
+ * @brief Decide the proper thermal scenario by using both the monitored
+ * raw data of thermal information and the parsed thermal
+ * information from scenario section. And then notify the decided
+ * thermal scenario to Thermal Monitor featrue (thermal) which
+ * provides the external D-bus interface for Thermal Monitor.
+ * thermal
+ * @param [in] result Monitored data of thermal will be saved to it.
+ * @param [in] user_data Instance of a resource monitor
+ * @return @c 0 on success, otherwise error value
+ */
+static int thermal_monitor_func(void *result, void *user_data)
+{
+ struct pass_resource *res = user_data;
+ struct pass_thermal *thermal = &res->thermal;;
+ struct resmon_result_src_thermal *thermal_result;
+ int ret;
+
+ /* Get thermal_result raw data by monitoring */
+ thermal_result = result;
+
+ /*
+ * Update thermal scenario by using both the monitored raw data
+ * of thermal information and the parsed thermal information
+ * from scenario section.
+ */
+ ret = thermal_update(res, thermal_result);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * Send notification with thermal scenario name according to
+ * measured temperature of each h/w resource.
+ */
+ device_notify(DEVICE_NOTIFIER_THERMAL,
+ (void *)thermal->scenarios[thermal->curr_scenario_idx].name);
+
return 0;
}
{
void **scenario = data;
struct pass_resource *res = user_data;
+ struct pass_thermal *thermal = &res->thermal;;
struct resmon_result_src_thermal *thermal_result;
- struct pass_thermal *thermal;
- int timer_interval_of_scenario, timer_interval;
- int curr_temp, temp;
- int i, scenario_idx;
int ret;
- if (!res) {
- _E("invalid parameter\n");
- return -EINVAL;
- }
-
- thermal = &res->thermal;
-
+ /* Get thermal_result raw data by reading directly */
thermal_result = get_thermal_result(res);
- if (!thermal_result)
- return -EINVAL;
-
- curr_temp = thermal_result->temp;
-
- for (i = thermal->num_scenarios - 1; i > 0; i--) {
- temp = thermal->scenarios[i].thermal.temperature;
-
- if (thermal->scenarios[i].state != PASS_ON)
- continue;
- if (temp <= curr_temp)
- break;
- }
- scenario_idx = i;
+ /*
+ * Update thermal scenario by using both the monitored raw data
+ * of thermal information and the parsed thermal information
+ * from scenario section.
+ */
+ ret = thermal_update(res, thermal_result);
+ if (ret < 0)
+ return ret;
/*
- * Inform the current thermal scenario name to
+ * Inform the thermal scenario name to
* DEVICE_NOTIFIER_THERMAL_GET_SCENARIO client.
*/
- *scenario = (void *)thermal->scenarios[scenario_idx].name;
-
- _I("Monitor '%s' scenario for '%s' resource ('%d' degrees Celsius)\n",
- thermal->scenarios[scenario_idx].name,
- res->config_data.res_name, curr_temp);
-
- /* Get the new timer interval of each scenario */
- timer_interval_of_scenario
- = thermal->scenarios[scenario_idx].thermal.timer_interval;
- if (timer_interval_of_scenario > 0)
- timer_interval = timer_interval_of_scenario;
- else
- timer_interval = res->thermal.timer_interval;
-
- ret = pass_resmon_update_timer_interval(res, RESMON_SRC_THERMAL,
- timer_interval);
- if (ret < 0) {
- _W("failed to update interval of timer-based monitor " \
- "(res_name:%s, src_type: 0x%x)\n",
- res->config_data.res_name, RESMON_SRC_THERMAL);
- }
-
- thermal->curr_temp = curr_temp;
- thermal->curr_scenario_idx = scenario_idx;
+ *scenario = (void *)thermal->scenarios[thermal->curr_scenario_idx].name;
return 0;
}