#include "pass.h"
#include "pass-rescon.h"
+#include "pass-resmon.h"
#define MAX_NUM 255
#define MIN_TIMEOUT_MS 200
if (ret < 0)
return ret;
+ /* Initialize the ResMon's data */
+ ret = pass_resmon_prepare(res);
+ if (ret < 0)
+ return ret;
+
/* Initialize the CPUHP's data */
cpuhp->pass_cpu_threshold = 0;
cpuhp->up_threshold = 0;
if (!obj) {
_E("Failed to get json_object from %s (%s)\n",
path, json_util_get_last_err());
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_resmon;
}
ret = parse_each_resource(res, obj);
goto out;
}
+ json_object_put(obj);
+
+ return 0;
+
out:
json_object_put(obj);
+out_resmon:
+ pass_resmon_unprepare(res);
return ret;
}
* uevent-based resource monitor.
*/
struct resmon {
+ /** Instance of pass_resource */
+ struct pass_resource *res;
+
/** Instance of PASS_MODULE_RESMON (Resource Monitor) module */
struct pass_resmon *resmon;
static int resmon_thermal_init(struct resmon *monitor)
{
struct resmon_result_src_thermal *result;
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res =
- container_of(resmon, struct pass_resource, resmon);
+ struct pass_resource *res;
+
+ if (!monitor || !monitor->res)
+ return -EINVAL;
if (monitor->result)
return 0;
+ res = monitor->res;
+
result = calloc(1, sizeof(*result));
if (!result)
return -ENOMEM;
*/
static int resmon_thermal_timer_handler(struct resmon *monitor, void *result)
{
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res =
- container_of(resmon, struct pass_resource, resmon);
+ struct pass_resource *res;
struct resmon_result_src_thermal *thermal_result = result;
int temp;
+ if (!monitor || !monitor->res)
+ return -EINVAL;
+
if (!thermal_result)
return -ENOMEM;
+ res = monitor->res;
+
/* Get temperature of h/w resource */
temp = pass_hal_get_temp(res);
if (temp < 0)
static int resmon_thermal_uevent_handler(struct resmon *monitor, void *result,
struct udev_device *dev)
{
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res =
- container_of(resmon, struct pass_resource, resmon);
+ struct pass_resource *res;
struct resmon_result_src_thermal *thermal_result = result;
int temp;
+ if (!monitor || !monitor->res)
+ return -EINVAL;
+
if (!thermal_result)
return -ENOMEM;
+ res = monitor->res;
+
/* Get temperature of h/w resource */
temp = pass_hal_get_temp(res);
if (temp < 0)
*/
static int resmon_cpuhp_timer_handler(struct resmon *monitor, void *result)
{
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res =
- container_of(resmon, struct pass_resource, resmon);
+ struct pass_resource *res;
struct resmon_result_src_cpuhp *cpuhp_result = result;
char str[BUFF_MAX];
int i, j, ret;
FILE *fp = NULL;
+ if (!monitor || !monitor->res)
+ return -EINVAL;
+
if (!cpuhp_result)
return -ENOMEM;
+ res = monitor->res;
+
fp = fopen(res->config_data.path_load_table, "r");
if (!fp)
return -EIO;
#include "pass-resmon-internal.h"
/**
+ * @brief Represent PASS_MODULE_RESMON (Resource Monitor) module.
+ * It should be always enabled in order to monitor h/w resources.
+ */
+struct pass_resmon {
+ /** State of PASS_MODULE_RESMON */
+ enum pass_state state;
+
+ /** List of required timer-based resource monitor */
+ GList *timer_list;
+
+ /** List of required uevent-based resource monitor */
+ GList *uevent_list;
+};
+
+/**
* @brief Global instance indicating udev
*/
static struct udev *g_udev = NULL;
static gboolean resmon_timer_func(gpointer data)
{
struct resmon *monitor = data;
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res
- = container_of(resmon, struct pass_resource, resmon);;
+ struct pass_resource *res = monitor->res;
int ret = 0;
/* Collect resource data according to enum resmon_src_type */
{
struct resmon *monitor;
- if (!res)
+ if (!res || !res->resmon)
return NULL;
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
+ monitor = resmon_find_monitor(res->resmon, RESMON_TIMER, id);
if (!monitor)
return NULL;
int res_type;
int ret;
- if (!res || timer_type == 0 || user_func == NULL)
+ if (!res || !res->resmon || timer_type == 0 || user_func == NULL)
return -EINVAL;
- resmon = &res->resmon;
+ resmon = res->resmon;
res_type = res->config_data.res_type;
/* Allocate the memory for resource monitor */
if (!monitor)
return -ENOMEM;
+ monitor->res = res;
monitor->resmon = resmon;
monitor->src_type = src_type;
monitor->timer_type = timer_type;
struct resmon *monitor;
int ret;
- if (!res || id == 0)
+ if (!res || !res->resmon || id == 0)
return -EINVAL;
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
+ monitor = resmon_find_monitor(res->resmon, RESMON_TIMER, id);
if (!monitor) {
_E("failed to find monitor (res_type: %d, id: %d)\n",
res->config_data.res_type, id);
struct resmon *monitor;
int ret;
- if (!res)
+ if (!res || !res->resmon)
return -EINVAL;
/* Find registered timer-based resmon */
- monitor = resmon_find_monitor(&res->resmon, RESMON_TIMER, id);
+ monitor = resmon_find_monitor(res->resmon, RESMON_TIMER, id);
if (!monitor) {
_E("failed to find monitor (res_type:%d, id: %d)\n",
res->config_data.res_type, id);
static gboolean resmon_uevent_func(gint fd, GIOCondition cond, void *data)
{
struct resmon *monitor = data;
- struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res
- = container_of(resmon, struct pass_resource, resmon);;
+ struct pass_resource *res = monitor->res;
struct udev_device *dev;
int ret;
static int uevent_id = 0;
struct udev_monitor *udev_monitor;
struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res
- = container_of(resmon, struct pass_resource, resmon);;
+ struct pass_resource *res = monitor->res;
int ret;
if (!monitor->ops) {
static int resmon_uevent_delete(struct resmon *monitor)
{
struct pass_resmon *resmon = monitor->resmon;
- struct pass_resource *res
- = container_of(resmon, struct pass_resource, resmon);;
+ struct pass_resource *res = monitor->res;
int ret;
/* Invoke the .exit of each RESMON_SRC_* source */
struct resmon *monitor;
int ret;
- if (!res || user_func == NULL) {
+ if (!res || !res->resmon || user_func == NULL) {
_E("invalid parameter\n");
return -EINVAL;
}
- resmon = &res->resmon;
+ resmon = res->resmon;
/* Allocate the memory for resource monitor */
monitor = calloc(1, sizeof(struct resmon));
struct resmon *monitor;
int ret;
- if (!res || id == 0) {
+ if (!res || !res->resmon || id == 0) {
_E("invalid parameter\n");
return -EINVAL;
}
- monitor = resmon_find_monitor(&res->resmon, RESMON_UEVENT, id);
+ monitor = resmon_find_monitor(res->resmon, RESMON_UEVENT, id);
if (!monitor) {
_E("failed to find monitor (res_name: %s, type: %d)\n",
res->config_data.res_name, id);
}
+int pass_resmon_prepare(struct pass_resource *res)
+{
+ if (!res || res->resmon != NULL)
+ return -EINVAL;
+
+ res->resmon = calloc(1, sizeof(struct pass_resmon));
+ if (!res->resmon)
+ return -ENOMEM;
+
+ return 0;
+}
+
+void pass_resmon_unprepare(struct pass_resource *res)
+{
+ if (!res || res->resmon == NULL)
+ return;
+
+ free(res->resmon);
+ res->resmon = NULL;
+}
+
/**
* @brief Initialize PASS_MODULE_RESMON(Resource Monitor) module
* @param [in] res Instance of h/w resource
{
struct pass_resmon *resmon;
- if (!res)
+ if (!res || !res->resmon)
return -EINVAL;
- if (res->resmon.state == PASS_ON)
+ if (res->resmon->state == PASS_ON)
return -EINVAL;
- resmon = &res->resmon;
+ resmon = res->resmon;
resmon->timer_list = NULL;
* @param [in] res Instance of h/w resource
* @return @c 0 on success, otherwise error value
*/
-int pass_resmon_exit(struct pass_resource *res)
+int pass_resmon_exit_and_unprepare(struct pass_resource *res)
{
struct pass_resmon *resmon;
- if (!res)
+ if (!res || !res->resmon)
return -EINVAL;
- if (res->resmon.state == PASS_OFF)
+ if (res->resmon->state == PASS_OFF)
return -EINVAL;
- resmon = &res->resmon;
+ resmon = res->resmon;
g_list_free(resmon->timer_list);
resmon->timer_list = NULL;
resmon->state = PASS_OFF;
+ pass_resmon_unprepare(res);
+
return 0;
}
int pass_resmon_unregister_uevent(struct pass_resource *res,
enum resmon_src_type src_type);
+/**
+ * @brief Prepare PASS_MODULE_RESMON(Resource Monitor) module
+ * @param [in] res Instance of h/w resource
+ * @return @c 0 on success, otherwise error value
+ */
+int pass_resmon_prepare(struct pass_resource *res);
+
+/**
+ * @brief Unprepare PASS_MODULE_RESMON(Resource Monitor) module
+ * @param [in] res Instance of h/w resource
+ */
+void pass_resmon_unprepare(struct pass_resource *res);
+
+/**
+ * @brief Initialize PASS_MODULE_RESMON(Resource Monitor) module
+ * @param [in] res Instance of h/w resource
+ * @return @c 0 on success, otherwise error value
+ */
+int pass_resmon_init(struct pass_resource *res);
+
+/**
+ * @brief Exit PASS_MODULE_RESMON(Resource Monitor) module
+ * @param [in] res Instance of h/w resource
+ * @return @c 0 on success, otherwise error value
+ */
+int pass_resmon_exit_and_unprepare(struct pass_resource *res);
+
#endif /* __PASS_RESMON__ */
#include "pass-parser.h"
#include "pass-hal.h"
#include "pass-rescon.h"
+#include "pass-resmon.h"
#define PASS_JSON_PATH "/hal/etc/pass/pass.json"
| PASS_MODULE_THERMAL,
};
-extern int pass_resmon_init(struct pass_resource *res);
-extern int pass_resmon_exit(struct pass_resource *res);
extern int pass_cpuhp_init(struct pass_resource *res);
extern int pass_cpuhp_exit(struct pass_resource *res);
extern int pass_pmqos_init(struct pass_resource *res);
_E("cannot exit PASS CPUHP");
err_cpuhp:
if (is_supported_module(res, PASS_MODULE_RESMON))
- if (pass_resmon_exit(res) < 0)
+ if (pass_resmon_exit_and_unprepare(res) < 0)
_E("cannot exit PASS Resource Monitor");
err_resmon:
if (is_supported_module(res, PASS_MODULE_RESCON))
* (Resource Monitor) after called exit() function of modules.
*/
if (is_supported_module(res, PASS_MODULE_RESMON)) {
- ret = pass_resmon_exit(res);
+ ret = pass_resmon_exit_and_unprepare(res);
if (ret < 0) {
_E("cannot exit PASS Resource Monitor");
return ret;
#define PASS_LEVEL_COND_MAX 3
struct pass_rescon;
+struct pass_resmon;
struct pass_resource;
struct pass_cpuhp_governor;
* PASS Module *
******************************************************/
-
-/**
- * @brief Represent PASS_MODULE_RESMON (Resource Monitor) module.
- * It should be always enabled in order to monitor h/w resources.
- */
-struct pass_resmon {
- /** State of PASS_MODULE_RESMON */
- enum pass_state state;
-
- /** List of required timer-based resource monitor */
- GList *timer_list;
-
- /** List of required uevent-based resource monitor */
- GList *uevent_list;
-};
-
/**
* @brief Represent PASS_MODULE_PMQOS (PMQoS) module. It may be enabled
* or disabled according to configuration.
/** Instance of PASS_MODULE_RESCON module */
struct pass_rescon *rescon;
/** Instance of PASS_MODULE_RESMON module */
- struct pass_resmon resmon;
+ struct pass_resmon *resmon;
/** Instance of PASS_MODULE_CPUHP module */
struct pass_cpuhp cpuhp;
/** Instance of PASS_MODULE_PMQOS module */
${CMAKE_SOURCE_DIR}/src/pass/pass-rescon.c
${CMAKE_SOURCE_DIR}/src/pass/pass-parser.c
${CMAKE_SOURCE_DIR}/src/util/common.c
+ ${CMAKE_SOURCE_DIR}/src/util/timer.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon-source.c
)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
gmock
dlog
json-c
+ libudev
hal-api-power
)
${CMAKE_SOURCE_DIR}/src/pass/pass-rescon.c
${CMAKE_SOURCE_DIR}/src/pass/pass-parser.c
${CMAKE_SOURCE_DIR}/src/util/common.c
+ ${CMAKE_SOURCE_DIR}/src/util/timer.c
${CMAKE_SOURCE_DIR}/src/util/privilege.c
${CMAKE_SOURCE_DIR}/lib/resource-monitor/resource-monitor.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon-source.c
)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
hal-api-power
cynara-client
cynara-session
+ libudev
)
FOREACH(flag ${gtest_pkgs_CFLAGS})
SET(PASS_SRCS
${CMAKE_SOURCE_DIR}/src/util/common.c
+ ${CMAKE_SOURCE_DIR}/src/util/timer.c
${CMAKE_SOURCE_DIR}/src/pass/pass-hal.c
${CMAKE_SOURCE_DIR}/src/pass/pass-rescon.c
${CMAKE_SOURCE_DIR}/src/pass/pass-parser.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon.c
+ ${CMAKE_SOURCE_DIR}/src/pass/pass-resmon-source.c
)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ PASS_UNITTEST_SRCS)
gmock
dlog
json-c
+ libudev
hal-api-power
)