extern struct resmon_ops *resmon_get_ops(enum resmon_src_type src_type);
-static bool resmon_is_created(struct pass_resmon *resmon,
- enum resmon_type type,
- enum resmon_src_type src_type)
-{
- switch (type) {
- case RESMON_TIMER:
- return !!(resmon->timer_state & src_type);
- case RESMON_UEVENT:
- return !!(resmon->uevent_state & src_type);
- default:
- return false;
- }
-}
-
-static gint __compare_monitor_type(gconstpointer data, gconstpointer input)
+static gint __compare_monitor_id(gconstpointer data, gconstpointer input)
{
struct resmon *monitor = (struct resmon *)data;
- enum resmon_src_type *src_type = (enum resmon_src_type *)input;
+ guint id = *(guint *)input;
- if (monitor->src_type == *src_type)
+ if (monitor->id == id)
return 0;
return -1;
}
static struct resmon *resmon_find_monitor(struct pass_resmon *resmon,
enum resmon_type type,
- enum resmon_src_type src_type)
+ guint id)
{
GList *node;
switch (type) {
case RESMON_TIMER:
- node = g_list_find_custom(resmon->timer_list, &src_type,
- __compare_monitor_type);
+ node = g_list_find_custom(resmon->timer_list, &id,
+ __compare_monitor_id);
break;
case RESMON_UEVENT:
- node = g_list_find_custom(resmon->uevent_list, &src_type,
- __compare_monitor_type);
+ node = g_list_find_custom(resmon->uevent_list, &id,
+ __compare_monitor_id);
break;
default:
return NULL;
int ret;
/* Add new timer-based resmon to timer_list */
- if (!resmon_is_created(resmon, RESMON_TIMER, monitor->src_type)) {
- monitor->timer_id = g_timeout_add((guint)interval,
+ if (!resmon_find_monitor(resmon, RESMON_TIMER, monitor->id)) {
+ monitor->id = g_timeout_add((guint)interval,
(GSourceFunc)resmon_timer_func,
(gpointer)monitor);
- if (!monitor->timer_id)
+ if (!monitor->id)
return -EPERM;
monitor->timer_interval = interval;
if (monitor->ops && monitor->ops->init) {
ret = monitor->ops->init(monitor);
if (ret < 0) {
- g_source_remove(monitor->timer_id);
+ g_source_remove(monitor->id);
monitor->timer_interval = 0;
return ret;
}
resmon->timer_list = g_list_append(resmon->timer_list,
(gpointer)monitor);
- resmon->timer_state |= monitor->src_type;
/* Update timer interval of the registered timer-based resmon */
} else {
- g_source_remove(monitor->timer_id);
+ g_source_remove(monitor->id);
monitor->timer_interval = 0;
/* Update timer interval of timer-based resmon */
- monitor->timer_id = g_timeout_add((guint)interval,
+ monitor->id = g_timeout_add((guint)interval,
(GSourceFunc)resmon_timer_func,
(gpointer)monitor);
- if (!monitor->timer_id)
+ if (!monitor->id)
return -EPERM;
monitor->timer_interval = interval;
}
- return 0;
+ return monitor->id;
}
/**
struct pass_resmon *resmon = monitor->resmon;
int ret;
- g_source_remove(monitor->timer_id);
+ g_source_remove(monitor->id);
if (monitor->ops && monitor->ops->exit) {
ret = monitor->ops->exit(monitor);
return ret;
}
- resmon->timer_state &= ~(monitor->src_type);
resmon->timer_list = g_list_remove(resmon->timer_list,
(gpointer)monitor);
return true;
}
-void *pass_resmon_get_result(struct pass_resource *res,
- enum resmon_src_type src_type)
+void *pass_resmon_get_result(struct pass_resource *res, guint id)
{
struct resmon *monitor;
if (!res)
return NULL;
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, src_type);
+ monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
if (!monitor)
return NULL;
* @param [in] timer_interval Interval of timer (unit: millisecond)
* @param [in] user_func Callback function pointer when timer is expired
* @param [in] user_data The passed user user_data.
- * @return @c 0 on success, otherwise error value
+ * @return @c id with positive integer on success, otherwise error value
*/
int pass_resmon_register_timer(struct pass_resource *res,
enum resmon_src_type src_type,
int res_type;
int ret;
- if (!res || src_type == 0 || timer_type == 0 || user_func == NULL)
+ if (!res || timer_type == 0 || user_func == NULL)
return -EINVAL;
resmon = &res->resmon;
res_type = res->config_data.res_type;
- /* Prevent the monitoring of already required type */
- if (resmon_is_created(resmon, RESMON_TIMER, src_type)) {
- _E("timer is already created (res_type: %d, src_type: 0x%x)\n",
- res_type, src_type);
- return -EBUSY;
- }
-
/* Allocate the memory for resource monitor */
monitor = calloc(1, sizeof(struct resmon));
if (!monitor)
goto err;
}
- return 0;
+ return monitor->id;
err:
free(monitor);
/**
* @brief Unregister a timer-based resource monitor
* @param [in] res Instance of a resource monitor
- * @param [in] src_type Type of resource monitor source
+ * @param [in] id ID of resource monitor
* @return @c 0 on success, otherwise error value
*/
-int pass_resmon_unregister_timer(struct pass_resource *res,
- enum resmon_src_type src_type)
+int pass_resmon_unregister_timer(struct pass_resource *res, guint id)
{
struct resmon *monitor;
int ret;
- if (!res || src_type == 0)
+ if (!res || id == 0)
return -EINVAL;
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, src_type);
+ monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
if (!monitor) {
- _E("failed to find monitor (res_type: %d, src_type: 0x%x)\n",
- res->config_data.res_type, src_type);
+ _E("failed to find monitor (res_type: %d, id: %d)\n",
+ res->config_data.res_type, id);
return -EINVAL;
}
/* Delete timer-based resource monitor */
ret = resmon_timer_delete(monitor);
if (ret < 0) {
- _E("failed to delete monitor (res_type: %d, src_type: 0x%x)\n",
- res->config_data.res_type, src_type);
+ _E("failed to delete monitor (res_type: %d, id: %d)\n",
+ res->config_data.res_type, id);
}
return 0;
/**
* @brief Update the interval of timer
* @param [in] res Instance of a resource monitor
- * @param [in] src_type Type of resource monitor source
+ * @param [in] id ID of resource monitor
* @param [in] timer_interval Interval of timer-based resource monitor
* (unit: millisecond)
* @return @c 0 on success, otherwise error value
*/
int pass_resmon_update_timer_interval(struct pass_resource *res,
- enum resmon_src_type src_type,
+ guint id,
int timer_interval)
{
struct resmon *monitor;
return -EINVAL;
/* Find registered timer-based resmon */
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, src_type);
+ monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
if (!monitor) {
- _E("failed to find monitor (res_type:%d, src_type: 0x%x)\n",
- res->config_data.res_type, src_type);
+ _E("failed to find monitor (res_type:%d, id: %d)\n",
+ res->config_data.res_type, id);
return -EINVAL;
}
if (ret < 0)
return -EINVAL;
- return 0;
+ return monitor->id;
}
/**
*/
static int resmon_uevent_add(struct resmon *monitor)
{
+ static int uevent_id = 0;
struct udev_monitor *udev_monitor;
struct pass_resmon *resmon = monitor->resmon;
struct pass_resource *res
/* Add new uevent-based resmon to uevent_list */
resmon->uevent_list = g_list_append(resmon->uevent_list,
(gpointer)monitor);
- resmon->uevent_state |= monitor->src_type;
monitor->udev_monitor = udev_monitor;;
monitor->udev_monitor_fd = gfd;
+ monitor->id = ++uevent_id;
return 0;
monitor->udev_monitor_fd = -1;
/* Delete the uevent-based resmon from uevent_list */
- resmon->uevent_state &= ~(monitor->src_type);
resmon->uevent_list = g_list_remove(resmon->uevent_list,
(gpointer)monitor);
struct resmon *monitor;
int ret;
- if (!res || src_type == 0 || user_func == NULL) {
+ if (!res || user_func == NULL) {
_E("invalid parameter\n");
return -EINVAL;
}
resmon = &res->resmon;
- /* Prevent the monitoring of already required type */
- if (resmon_is_created(resmon, RESMON_UEVENT, src_type)) {
- _E("uevent-based resmon is already created "\
- "(res_name: %s, src_type: 0x%x)\n",
- res->config_data.res_name, src_type);
- return -EBUSY;
- }
-
/* Allocate the memory for resource monitor */
monitor = calloc(1, sizeof(struct resmon));
if (!monitor)
goto err;
}
- return 0;
+ return monitor->id;
err:
free(monitor);
/**
* @brief Unregister an uevent-based resource monitor.
* @param [in] res Instance of a resource monitor
- * @param [in] src_type Type of resource monitor source
+ * @param [in] id ID of resource monitor
* @return @c 0 on success, otherwise error value
*/
-int pass_resmon_unregister_uevent(struct pass_resource *res,
- enum resmon_src_type src_type)
+int pass_resmon_unregister_uevent(struct pass_resource *res, guint id)
{
struct resmon *monitor;
int ret;
- if (!res || src_type == 0) {
+ if (!res || id == 0) {
_E("invalid parameter\n");
return -EINVAL;
}
- monitor = resmon_find_monitor(&res->resmon, RESMON_UEVENT, src_type);
+ monitor = resmon_find_monitor(&res->resmon, RESMON_UEVENT, id);
if (!monitor) {
- _E("failed to find monitor (res_name: %s, type: 0x%x)\n",
- res->config_data.res_name, src_type);
+ _E("failed to find monitor (res_name: %s, type: %d)\n",
+ res->config_data.res_name, id);
return -EINVAL;
}
/* Delete uevent-based resource monitor */
ret = resmon_uevent_delete(monitor);
if (ret < 0) {
- _E("failed to delete monitor (res_name: %s, type: 0x%x)\n",
- res->config_data.res_name, src_type);
+ _E("failed to delete monitor (res_name: %s, type: %d)\n",
+ res->config_data.res_name, id);
}
/* Free the memory of resource monitor */
resmon = &res->resmon;
resmon->timer_list = NULL;
- resmon->timer_state = 0;
/* Initialize the uevent-related variables */
resmon->uevent_list = NULL;
- resmon->uevent_state = 0;
if (g_udev_count == 0) {
g_udev = udev_new();
g_list_free(resmon->timer_list);
resmon->timer_list = NULL;
- resmon->timer_state = 0;
/* Free the uevent-related variables */
g_list_free(resmon->uevent_list);
resmon->uevent_list = NULL;
- resmon->uevent_state = 0;
udev_unref(g_udev);
g_udev_count--;
int new_temp, prev_temp;
int i, new_scenario_idx;
int ret;
+ int timer_id;
if (!res || !thermal_result) {
_E("invalid parameter for thermal monitor\n");
if (new_timer_interval < 0)
new_timer_interval = res->thermal.timer_interval;
- ret = pass_resmon_update_timer_interval(res, RESMON_SRC_THERMAL,
+ timer_id = pass_resmon_update_timer_interval(res, res->thermal.timer_id,
new_timer_interval);
- if (ret < 0) {
+ if (timer_id < 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->timer_id = timer_id;
/* Update thermal information of each h/w resource */
thermal->curr_temp = new_temp;
int ret;
/* Get thermal_result raw data by reading directly */
- thermal_result = pass_resmon_get_result(res, RESMON_SRC_THERMAL);
+ thermal_result = pass_resmon_get_result(res, res->thermal.timer_id);
/*
* Update thermal scenario by using both the monitored raw data
int pass_thermal_init(struct pass_resource *res)
{
int ret;
+ int timer_id, uevent_id;
if (!res)
return -EINVAL;
* update the timer interval with the required value
* after first monitoring is finished.
*/
- ret = pass_resmon_register_timer(res, RESMON_SRC_THERMAL,
+ timer_id = pass_resmon_register_timer(res, RESMON_SRC_THERMAL,
RESMON_TIMER_PERIODIC, 1000,
thermal_monitor_func, res);
- if (ret < 0) {
+ if (timer_id < 0) {
_E("failed to register timer-based monitor " \
"(res_name:%s, src_type: 0x%x)\n",
res->config_data.res_name, RESMON_SRC_THERMAL);
return -EINVAL;
}
+ res->thermal.timer_id = timer_id;
/* Register uevent-based resource monitor to monitor thermal info. */
- ret = pass_resmon_register_uevent(res, RESMON_SRC_THERMAL,
+ uevent_id = pass_resmon_register_uevent(res, RESMON_SRC_THERMAL,
thermal_monitor_func, res);
- if (ret < 0) {
+ if (uevent_id < 0) {
_E("failed to register uevent-based monitor " \
"(res_name:%s, src_type: 0x%x)\n",
res->config_data.res_name, RESMON_SRC_THERMAL);
goto err_timer;
}
+ res->thermal.uevent_id = uevent_id;
/* Initialize the default scenario index */
res->thermal.curr_scenario_idx = -1;
return 0;
err_uevent:
- ret = pass_resmon_unregister_uevent(res, RESMON_SRC_THERMAL);
+ ret = pass_resmon_unregister_uevent(res, uevent_id);
if (ret < 0)
_E("failed to unregister uevent-based monitor\n");
err_timer:
- ret = pass_resmon_unregister_timer(res, RESMON_SRC_THERMAL);
+ ret = pass_resmon_unregister_timer(res, timer_id);
if (ret < 0) {
_E("failed to unregister timer-based monitor " \
"(res_name:%s, src_type: 0x%x)\n",
if (ret < 0)
_E("failed to unregister a notifier callback\n");
- ret = pass_resmon_unregister_uevent(res, RESMON_SRC_THERMAL);
+ ret = pass_resmon_unregister_uevent(res, res->thermal.uevent_id);
if (ret < 0) {
_E("failed to unregister uevent-based monitor " \
- "(res_name:%s, src_type: 0x%x)\n",
- res->config_data.res_name, RESMON_SRC_THERMAL);
+ "(res_name:%s, uevent_id:%d)\n",
+ res->config_data.res_name, res->thermal.uevent_id);
}
- ret = pass_resmon_unregister_timer(res, RESMON_SRC_THERMAL);
+ ret = pass_resmon_unregister_timer(res, res->thermal.timer_id);
if (ret < 0) {
_E("failed to unregister timer-based monitor " \
- "(res_name:%s, src_type: 0x%x)\n",
- res->config_data.res_name, RESMON_SRC_THERMAL);
+ "(res_name:%s, timer_id:%d)\n",
+ res->config_data.res_name, res->thermal.timer_id);
}
/* Initialize the default scenario index */