From ab465d1807e2adc581f0035e800fd3467726fa57 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Jan 2022 18:11:26 +0900 Subject: [PATCH 01/16] pass: resmon: Replace timer-related code with timer utility Change-Id: I30d9f3a8cc37036bb37c350565c6ef2c58f2bdba Signed-off-by: Chanwoo Choi --- src/pass/pass-resmon-internal.h | 5 -- src/pass/pass-resmon.c | 169 ++++++++++++---------------------------- 2 files changed, 51 insertions(+), 123 deletions(-) diff --git a/src/pass/pass-resmon-internal.h b/src/pass/pass-resmon-internal.h index 82f5bbf..011bb81 100644 --- a/src/pass/pass-resmon-internal.h +++ b/src/pass/pass-resmon-internal.h @@ -125,11 +125,6 @@ struct resmon { * uevent-based resource monitor. */ struct udev_monitor *udev_monitor; - /** - * File descriptor for udev device. It will be only used for - * uevent-based resource monitor. - */ - guint udev_monitor_fd; }; #endif /* __PASS_RESMON_INTERNAL__ */ diff --git a/src/pass/pass-resmon.c b/src/pass/pass-resmon.c index a445a7e..2c69bd0 100644 --- a/src/pass/pass-resmon.c +++ b/src/pass/pass-resmon.c @@ -36,10 +36,8 @@ * @ingroup COM_POWER_MGNT */ -#include -#include - #include +#include #include "pass.h" #include "pass-hal.h" @@ -105,42 +103,53 @@ static int resmon_timer_add(struct resmon *monitor, unsigned int interval) struct pass_resmon *resmon = monitor->resmon; int ret; - /* Add new timer-based resmon to timer_list */ - if (!resmon_find_monitor(resmon, RESMON_TIMER, monitor->id)) { - monitor->id = g_timeout_add((guint)interval, - (GSourceFunc)resmon_timer_func, - (gpointer)monitor); - 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->id); - monitor->timer_interval = 0; - return ret; - } + if (resmon_find_monitor(resmon, RESMON_TIMER, monitor->id)) + return -EINVAL; + + monitor->id = add_timer_handler(interval, resmon_timer_func, monitor); + if (!monitor->id) + return -EPERM; + monitor->timer_interval = interval; + + if (monitor->ops && monitor->ops->init) { + ret = monitor->ops->init(monitor); + if (ret < 0) { + delete_timer_handler(monitor->id); + monitor->timer_interval = 0; + return ret; } + } - resmon->timer_list = g_list_append(resmon->timer_list, - (gpointer)monitor); + resmon->timer_list = g_list_append(resmon->timer_list, (gpointer)monitor); - /* Update timer interval of the registered timer-based resmon */ - } else { - g_source_remove(monitor->id); - monitor->timer_interval = 0; + return monitor->id; +} - /* Update timer interval of timer-based resmon */ - monitor->id = g_timeout_add((guint)interval, - (GSourceFunc)resmon_timer_func, - (gpointer)monitor); - if (!monitor->id) - return -EPERM; - monitor->timer_interval = interval; +/** + * @brief Update the interval of a timer-based resource monitor. + * @param [in] monitor Instance of a resource monitor + * @param [in] interval New interval of timer-based resource monitor + * @return @c 0 on success, otherwise error value + */ +static int resmon_timer_update_interval(struct resmon *monitor, + unsigned int interval) +{ + struct pass_resmon *resmon = monitor->resmon; + + if (!resmon_find_monitor(resmon, RESMON_TIMER, monitor->id)) + return -EINVAL; + + /* Update timer interval of timer-based resmon */ + delete_timer_handler(monitor->id); + + monitor->id = add_timer_handler(interval, resmon_timer_func, monitor); + if (!monitor->id) { + _E("failed to update interval of timer (id:%d)\n\n", monitor->id); + return -EPERM; } + monitor->timer_interval = interval; - return monitor->id; + return 0; } /** @@ -153,7 +162,7 @@ static int resmon_timer_delete(struct resmon *monitor) struct pass_resmon *resmon = monitor->resmon; int ret; - g_source_remove(monitor->id); + delete_timer_handler(monitor->id); if (monitor->ops && monitor->ops->exit) { ret = monitor->ops->exit(monitor); @@ -361,7 +370,7 @@ int pass_resmon_update_timer_interval(struct pass_resource *res, return 0; /* Update new interval of timer-based resmon */ - ret = resmon_timer_add(monitor, timer_interval); + ret = resmon_timer_update_interval(monitor, timer_interval); if (ret < 0) return -EINVAL; @@ -429,84 +438,24 @@ static int resmon_uevent_add(struct resmon *monitor) struct pass_resmon *resmon = monitor->resmon; struct pass_resource *res = container_of(resmon, struct pass_resource, resmon);; - guint gfd; int ret; - int fd; - int i; if (!monitor->ops) { _E("failed to add the udev-monitor\n"); return -EINVAL; } - /* Initialize the udev-monitor instance and set buffer size */ - udev_monitor = udev_monitor_new_from_netlink(g_udev, "kernel"); + udev_monitor = add_uevent_handler(monitor->ops->uevent_subsystem, + monitor->ops->uevent_devtype, + monitor->ops->number_of_uevent, + resmon_uevent_func, + (void *)monitor); if (!udev_monitor) { - _E("failed to create the udev monitor " \ - "(res_name:%s, src_type: 0x%x)\n", - res->config_data.res_name, monitor->src_type); + _E("failed to add uevent handler\n"); return -EINVAL; } /* - * Number of uevent subsystem must be more than 0 at least. - */ - if (monitor->ops->number_of_uevent <= 0) { - _E("failed to add filter due to subsystem/devtype are NULL " \ - "(res_name:%s, src_type: 0x%x)\n", - res->config_data.res_name, monitor->src_type); - ret = -EINVAL; - goto err_udev_monitor; - } - - /* Update the kernel's subsystem and devtype for filtering */ - for (i = 0; i < monitor->ops->number_of_uevent; i++) { - ret = udev_monitor_filter_add_match_subsystem_devtype( - udev_monitor, - monitor->ops->uevent_subsystem[i], - monitor->ops->uevent_devtype[i]); - if (ret < 0) { - _E("failed to add filter with subsystem(%s)/devtype(%s) " \ - "(res_name:%s, src_type: 0x%x)\n", - monitor->ops->uevent_subsystem[i], - monitor->ops->uevent_devtype[i], - res->config_data.res_name, monitor->src_type); - goto err_udev_monitor; - } - } - - ret = udev_monitor_filter_update(udev_monitor); - if (ret < 0) { - for (i = 0; i < monitor->ops->number_of_uevent; i++) { - _E("failed to update filter with subsystem(%s)/devtype(%s) " \ - "(res_name:%s, src_type: 0x%x)\n", - monitor->ops->uevent_subsystem[i], - monitor->ops->uevent_devtype[i], - res->config_data.res_name, monitor->src_type); - } - goto err_udev_monitor; - } - - /* Register callback to subscribe the event */ - fd = udev_monitor_get_fd(udev_monitor); - if (fd <= 0) { - _E("failed to get file descriptor of udev monitor " \ - "(res_name:%s, src_type: 0x%x)\n", - res->config_data.res_name, monitor->src_type); - ret = -EINVAL; - goto err_udev_monitor; - } - - gfd = g_unix_fd_add(fd, G_IO_IN, resmon_uevent_func, monitor); - if (gfd <= 0) { - _E("failed to add uevent-based callback function " \ - "(res_name:%s, src_type: 0x%x)\n", - res->config_data.res_name, monitor->src_type); - ret = -EINVAL; - goto err_udev_monitor; - } - - /* * Invoke the .init of each RESMON_SRC_* source * before enabling the udev monitoring. */ @@ -520,30 +469,16 @@ static int resmon_uevent_add(struct resmon *monitor) } } - /* Bind udev-monitor to enable the udev monitoring */ - ret = udev_monitor_enable_receiving(udev_monitor); - if (ret < 0) { - _E("failed to bind udev monitor for receiving the event " \ - "(res_name:%s, src_type: 0x%x)\n", - res->config_data.res_name, monitor->src_type); - ret = -EAGAIN; - goto err_udev_monitor_fd; - } - /* Add new uevent-based resmon to uevent_list */ resmon->uevent_list = g_list_append(resmon->uevent_list, (gpointer)monitor); monitor->udev_monitor = udev_monitor;; - monitor->udev_monitor_fd = gfd; monitor->id = ++uevent_id; return 0; err_udev_monitor_fd: - g_source_remove(gfd); - gfd = -1; -err_udev_monitor: udev_monitor_unref(udev_monitor); udev_monitor = NULL; @@ -573,10 +508,8 @@ static int resmon_uevent_delete(struct resmon *monitor) } } - udev_monitor_unref(monitor->udev_monitor); - g_source_remove(monitor->udev_monitor_fd); + delete_uevent_handler(monitor->udev_monitor); monitor->udev_monitor = NULL; - monitor->udev_monitor_fd = -1; /* Delete the uevent-based resmon from uevent_list */ resmon->uevent_list = g_list_remove(resmon->uevent_list, -- 2.7.4 From 25163a70ac0b217eb2222ccd379735c8b4784f27 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Tue, 18 Jan 2022 16:26:26 +0900 Subject: [PATCH 02/16] resource: Add CPU/BUS/GPU resource driver Change-Id: I3aef9258ae02f80b9bf87d438352d57a33411576 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 3 + src/resource/resource-bus.c | 183 ++++++++++++++++++++++++++++++++++++++ src/resource/resource-cpu.c | 211 ++++++++++++++++++++++++++++++++++++++++++++ src/resource/resource-gpu.c | 197 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 594 insertions(+) create mode 100644 src/resource/resource-bus.c create mode 100644 src/resource/resource-cpu.c create mode 100644 src/resource/resource-gpu.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ecf536d..cbef703 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,9 @@ SET(SRCS src/pmqos/pmqos-dbus-stub.c #Generated by a custom command 'gdbus-codegen' below src/thermal/thermal-dbus-stub.c + src/resource/resource-cpu.c + src/resource/resource-bus.c + src/resource/resource-gpu.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/resource/resource-bus.c b/src/resource/resource-bus.c new file mode 100644 index 0000000..fb2e223 --- /dev/null +++ b/src/resource/resource-bus.c @@ -0,0 +1,183 @@ +/* + * PASS (Power Aware System Service) - Memory Bus Resource Driver + * + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file resource-bus.c + * @brief TBD + * @ingroup TBD + */ + +#include + +#include + +#include +#include +#include + +#include + +static int bus_get_cur_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int bus_get_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int bus_get_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int bus_get_available_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int bus_get_available_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int bus_get_curr_governor(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_governor(res->type, res->name, buf); + if (val < 0) + return -EINVAL; + + return 0; +} + +static const struct resource_attribute bus_attrs[] = { + { + .name = "BUS_CUR_FREQ", + .id = BUS_CUR_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = bus_get_cur_freq, + }, + }, { + .name = "BUS_MIN_FREQ", + .id = BUS_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = bus_get_min_freq, + }, + }, { + .name = "BUS_MAX_FREQ", + .id = BUS_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = bus_get_max_freq, + } + }, { + .name = "BUS_AVAILABLE_MIN_FREQ", + .id = BUS_AVAILABLE_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = bus_get_available_min_freq, + } + }, { + .name = "BUS_AVAILABLE_MAX_FREQ", + .id = BUS_AVAILABLE_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = bus_get_available_max_freq, + } + }, { + .name = "BUS_CUR_GOVERNOR", + .id = BUS_CUR_GOVERNOR, + .type = DATA_TYPE_STRING, + .ops = { + .get = bus_get_curr_governor, + } + }, +}; + +static const struct resource_driver bus_resource_driver = { + .name = "Memory Bus", + .type = PASS_RESOURCE_BUS_ID, + .attrs = bus_attrs, + .num_attrs = ARRAY_SIZE(bus_attrs), +}; +RESOURCE_DRIVER_REGISTER(&bus_resource_driver) diff --git a/src/resource/resource-cpu.c b/src/resource/resource-cpu.c new file mode 100644 index 0000000..469dacc --- /dev/null +++ b/src/resource/resource-cpu.c @@ -0,0 +1,211 @@ +/* + * PASS (Power Aware System Service) - CPU Resource Driver + * + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file resource-cpu.c + * @brief TBD + * @ingroup TBD + */ + +#include + +#include + +#include +#include +#include + +#include + +static int cpu_get_cur_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int cpu_get_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int cpu_get_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int cpu_get_available_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int cpu_get_available_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int cpu_get_curr_governor(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_governor(res->type, res->name, buf); + if (val < 0) + return -EINVAL; + + return 0; +} + +static int cpu_get_online_cpu(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + return 0; +} + +static int cpu_get_temperature(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + return 0; +} + +static const struct resource_attribute cpu_attrs[] = { + { + .name = "CPU_CUR_FREQ", + .id = CPU_CUR_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_cur_freq, + }, + }, { + .name = "CPU_MIN_FREQ", + .id = CPU_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_min_freq, + }, + }, { + .name = "CPU_MAX_FREQ", + .id = CPU_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_max_freq, + } + }, { + .name = "CPU_AVAILABLE_MIN_FREQ", + .id = CPU_AVAILABLE_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_available_min_freq, + } + }, { + .name = "CPU_AVAILABLE_MAX_FREQ", + .id = CPU_AVAILABLE_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_available_max_freq, + } + }, { + .name = "CPU_CUR_GOVERNOR", + .id = CPU_CUR_GOVERNOR, + .type = DATA_TYPE_STRING, + .ops = { + .get = cpu_get_curr_governor, + } + }, { + .name = "CPU_ONLINE_CPU", + .id = CPU_ONLINE_CPU, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_online_cpu, + } + }, { + .name = "CPU_TEMPERATURE", + .id = CPU_TEMPERATURE, + .type = DATA_TYPE_INT, + .ops = { + .get = cpu_get_temperature, + } + }, +}; + +static const struct resource_driver cpu_resource_driver = { + .name = "CPU", + .type = PASS_RESOURCE_CPU_ID, + .attrs = cpu_attrs, + .num_attrs = ARRAY_SIZE(cpu_attrs), +}; +RESOURCE_DRIVER_REGISTER(&cpu_resource_driver) diff --git a/src/resource/resource-gpu.c b/src/resource/resource-gpu.c new file mode 100644 index 0000000..184772c --- /dev/null +++ b/src/resource/resource-gpu.c @@ -0,0 +1,197 @@ +/* + * PASS (Power Aware System Service) - GPU Resource Driver + * + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file resource-gpu.c + * @brief TBD + * @ingroup TBD + */ + +#include + +#include + +#include +#include +#include + +#include + +static int gpu_get_cur_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int gpu_get_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int gpu_get_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int gpu_get_available_min_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_min_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int gpu_get_available_max_freq(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_available_max_freq(res->type, res->name); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int gpu_get_curr_governor(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = hal_power_dvfs_get_curr_governor(res->type, res->name, buf); + if (val < 0) + return -EINVAL; + + return 0; +} + +static int gpu_get_temperature(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + return 0; +} + +static const struct resource_attribute gpu_attrs[] = { + { + .name = "GPU_CUR_FREQ", + .id = GPU_CUR_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_cur_freq, + }, + }, { + .name = "GPU_MIN_FREQ", + .id = GPU_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_min_freq, + }, + }, { + .name = "GPU_MAX_FREQ", + .id = GPU_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_max_freq, + } + }, { + .name = "GPU_AVAILABLE_MIN_FREQ", + .id = GPU_AVAILABLE_MIN_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_available_min_freq, + } + }, { + .name = "GPU_AVAILABLE_MAX_FREQ", + .id = GPU_AVAILABLE_MAX_FREQ, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_available_max_freq, + } + }, { + .name = "GPU_CUR_GOVERNOR", + .id = GPU_CUR_GOVERNOR, + .type = DATA_TYPE_STRING, + .ops = { + .get = gpu_get_curr_governor, + } + }, { + .name = "GPU_TEMPERATURE", + .id = GPU_TEMPERATURE, + .type = DATA_TYPE_INT, + .ops = { + .get = gpu_get_temperature, + } + }, +}; + +static const struct resource_driver gpu_resource_driver = { + .name = "GPU", + .type = PASS_RESOURCE_GPU_ID, + .attrs = gpu_attrs, + .num_attrs = ARRAY_SIZE(gpu_attrs), +}; +RESOURCE_DRIVER_REGISTER(&gpu_resource_driver) -- 2.7.4 From ab4e35fcaff02635e91c2f02a9f5ae2a509b22f0 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 24 Jan 2022 15:47:35 +0900 Subject: [PATCH 03/16] util: common: Move container_of macro to common.h Change-Id: I02fc5d60110132481719ded0d805dc88e12b9d2a Signed-off-by: Chanwoo Choi --- include/util/common.h | 6 ++++++ src/pass/pass.h | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/util/common.h b/include/util/common.h index d0f0100..40b75a3 100644 --- a/include/util/common.h +++ b/include/util/common.h @@ -94,6 +94,12 @@ typedef unsigned long long uint64; #define USEC_TO_MSEC(x) ((double)x/1000) #endif +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); }) +#endif + int sys_get_str(const char *fname, char *str); const char *get_string_from_object(json_object *obj, const char *key); diff --git a/src/pass/pass.h b/src/pass/pass.h index e7272cc..0b43ad6 100644 --- a/src/pass/pass.h +++ b/src/pass/pass.h @@ -658,8 +658,4 @@ struct pass { struct pass_resource *res; }; -#define container_of(ptr, type, member) ({ \ - const typeof(((type *)0)->member) *__mptr = (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); }) - #endif /* __pass__ */ -- 2.7.4 From da0d8cc1a9fb00a5ab32c501f2fe802b98eea21f Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Mon, 24 Jan 2022 21:35:42 +0900 Subject: [PATCH 04/16] util: Add common thread utility To support multi-thread by common utility, now three types of threads are provided as like 'daemon', 'worker', and 'timer'. Change-Id: Ie2ac65187cab0ce9ec41a5610fc0b99d08f9e42a Signed-off-by: Dongwoo Lee --- CMakeLists.txt | 1 + include/util/thread.h | 64 +++++++++++++++++ src/util/thread.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 include/util/thread.h create mode 100644 src/util/thread.c diff --git a/CMakeLists.txt b/CMakeLists.txt index cbef703..0d8de97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ SET(SRCS src/util/resource.c src/util/gdbus-util.c src/util/timer.c + src/util/thread.c src/main.c #Generated by a custom command 'gdbus-codegen' below src/pass/pass-dbus-stub.c diff --git a/include/util/thread.h b/include/util/thread.h new file mode 100644 index 0000000..0f13200 --- /dev/null +++ b/include/util/thread.h @@ -0,0 +1,64 @@ +/* + * PASS + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +enum thread_type { + THREAD_TYPE_WORKER, + THREAD_TYPE_DAEMON, + THREAD_TYPE_TIMER, +}; + +enum thread_state { + THREAD_STATE_RUNNING, + THREAD_STATE_STOPPED, + THREAD_STATE_TERMINATED, +}; + +enum thread_return { + THREAD_RETURN_ERROR = -EXIT_FAILURE, + THREAD_RETURN_DONE = EXIT_SUCCESS, + THREAD_RETURN_CONTINUE, +}; + +struct thread_context { + enum thread_state state; + struct timespec timer; + int (*func)(void *arg, void **result); + void *arg; + void *result; + mtx_t lock; + cnd_t wait; +}; + +struct thread { + thrd_t id; + struct thread_context *ctx; +}; + +int create_daemon_thread(struct thread *thread, int (*func)(void *, void **), void *arg); +int create_timer_thread(struct thread *thread, u_int32_t timer_expire_msec, + int (*func)(void *, void **), void *arg); +int create_worker_thread(struct thread *thread, int (*func)(void *, void **), void *arg); +void destroy_thread(struct thread *thread); +void suspend_thread(struct thread *thread); +void resume_thread(struct thread *thread); + +#define schedule_worker resume_thread +int wait_for_completion(struct thread *thread, void **result); diff --git a/src/util/thread.c b/src/util/thread.c new file mode 100644 index 0000000..50b1bc0 --- /dev/null +++ b/src/util/thread.c @@ -0,0 +1,193 @@ +/* + * PASS + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include + +static void __thread_loop_main(void *_ctx) +{ + enum thread_return ret = THREAD_RETURN_DONE; + struct thread_context *ctx = _ctx; + void *result; + + while (ctx->state != THREAD_STATE_TERMINATED) { + if (ctx->timer.tv_sec || ctx->timer.tv_nsec) + thrd_sleep(&ctx->timer, NULL); + + mtx_lock(&ctx->lock); + while (ctx->state == THREAD_STATE_STOPPED) + cnd_wait(&ctx->wait, &ctx->lock); + if (ctx->state == THREAD_STATE_TERMINATED) + break; + + ret = ctx->func(ctx->arg, &result); + + if (ret != THREAD_RETURN_CONTINUE) { + ctx->state = THREAD_STATE_TERMINATED; + ctx->result = result; + } + mtx_unlock(&ctx->lock); + } + + thrd_exit(ret); +} + +static void do_destroy_thread(struct thread *thread) +{ + struct thread_context *ctx = thread->ctx; + + mtx_lock(&ctx->lock); + ctx->state = THREAD_STATE_TERMINATED; + mtx_unlock(&ctx->lock); + + /* try to wake up thread whether it is sleeping or not */ + cnd_signal(&ctx->wait); + + thrd_join(thread->id, NULL); + + cnd_destroy(&ctx->wait); + mtx_destroy(&ctx->lock); +} + +void destroy_thread(struct thread *thread) +{ + do_destroy_thread(thread); + free(thread->ctx); + thread->ctx = NULL; +} + +static int do_create_thread(struct thread *thread, + enum thread_type type, + u_int32_t timer_expire_msec, + int (*func)(void *, void **), void *arg) +{ + struct thread_context *ctx; + thrd_t tid; + int ret; + + if (!thread || !func) + return -EINVAL; + + ctx = calloc(1, sizeof(struct thread_context)); + if (!ctx) + return -ENOMEM; + + mtx_init(&ctx->lock, mtx_plain); + cnd_init(&ctx->wait); + ctx->func = func; + ctx->arg = arg; + + switch (type) { + case THREAD_TYPE_WORKER: + ctx->state = THREAD_STATE_STOPPED; + break; + case THREAD_TYPE_DAEMON: + ctx->state = THREAD_STATE_RUNNING; + break; + case THREAD_TYPE_TIMER: + ctx->state = THREAD_STATE_RUNNING; + ctx->timer = (struct timespec) { + .tv_sec = timer_expire_msec / 1000, + .tv_nsec = (timer_expire_msec % 1000) * 1000000, + }; + break; + default: + ret = -EINVAL; + goto err; + } + + ret = thrd_create(&tid, (thrd_start_t) __thread_loop_main, (void *)ctx); + if (ret == thrd_error) { + ret = -EINVAL; + goto err; + } + + thread->id = tid; + thread->ctx = ctx; + + return 0; + +err: + cnd_destroy(&ctx->wait); + mtx_destroy(&ctx->lock); + free(ctx); + + return ret; +} + +int create_daemon_thread(struct thread *thread, + int (*func)(void *, void **), void *arg) +{ + return do_create_thread(thread, THREAD_TYPE_DAEMON, 0, func, arg); +} + +int create_timer_thread(struct thread *thread, + u_int32_t timer_expire_msec, + int (*func)(void *, void **), void *arg) +{ + return do_create_thread(thread, THREAD_TYPE_TIMER, + timer_expire_msec, func, arg); +} + +int create_worker_thread(struct thread *thread, + int (*func)(void *, void **), void *arg) +{ + return do_create_thread(thread, THREAD_TYPE_WORKER, 0, func, arg); +} + +void suspend_thread(struct thread *thread) +{ + struct thread_context *ctx = thread->ctx; + + mtx_lock(&ctx->lock); + ctx->state = THREAD_STATE_STOPPED; + mtx_unlock(&ctx->lock); +} + +void resume_thread(struct thread *thread) +{ + struct thread_context *ctx = thread->ctx; + + mtx_lock(&ctx->lock); + ctx->state = THREAD_STATE_RUNNING; + mtx_unlock(&ctx->lock); + cnd_signal(&ctx->wait); +} + +int wait_for_completion(struct thread *thread, void **result) +{ + struct thread_context *ctx = thread->ctx; + int ret; + + thrd_join(thread->id, &ret); + if (ret == THREAD_RETURN_ERROR) + return ret; + + *result = ctx->result; + + cnd_destroy(&ctx->wait); + mtx_destroy(&ctx->lock); + + free(thread->ctx); + thread->ctx = NULL; + + return 0; +} -- 2.7.4 From bbb0803b4cdb17b055c61e62da720061d05718d0 Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Thu, 27 Jan 2022 17:26:20 +0900 Subject: [PATCH 05/16] util: monitor: Fix a typo Change-Id: I98c1d0f42073c15fddf460e79701c1a0819eb862 Signed-off-by: Sung-hun Kim --- include/monitor/monitor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index f22eac0..8da5bda 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -70,7 +70,7 @@ enum monitor_data_type { #define MEMORY_TOTAL (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 0) #define MEMORY_FREE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 1) #define MEMORY_USED (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 2) -#define MEMORY_AVAIALBLE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 3) +#define MEMORY_AVAILABLE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 3) #define MEMORY_FAULT_AROUND_BYTES (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 4) #define BATTERY_CAPACITY (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 0) -- 2.7.4 From 4e6991976a6a1b4406564e0d1f6f52ff6954d05f Mon Sep 17 00:00:00 2001 From: Sung-hun Kim Date: Thu, 27 Jan 2022 17:27:30 +0900 Subject: [PATCH 06/16] resource: Add memory resource driver Change-Id: I74291dac952a7cba3a7c56038081215cb05b7adb Signed-off-by: Sung-hun Kim --- CMakeLists.txt | 1 + include/monitor/monitor.h | 7 +- src/resource/resource-memory.c | 154 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 src/resource/resource-memory.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d8de97..24425eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ SET(SRCS src/resource/resource-cpu.c src/resource/resource-bus.c src/resource/resource-gpu.c + src/resource/resource-memory.c ) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 8da5bda..d658d76 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -68,10 +68,9 @@ enum monitor_data_type { #define GPU_TEMPERATURE (PASS_RESOURCE_GPU_ID << RESOURCE_TYPE_SHIFT | 6) #define MEMORY_TOTAL (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 0) -#define MEMORY_FREE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 1) -#define MEMORY_USED (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 2) -#define MEMORY_AVAILABLE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 3) -#define MEMORY_FAULT_AROUND_BYTES (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 4) +#define MEMORY_AVAILABLE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 1) +#define MEMORY_FREE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 2) +#define MEMORY_FAULT_AROUND_BYTES (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 3) #define BATTERY_CAPACITY (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 0) #define BATTERY_CHARGING_STATUS (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 1) diff --git a/src/resource/resource-memory.c b/src/resource/resource-memory.c new file mode 100644 index 0000000..3d62be4 --- /dev/null +++ b/src/resource/resource-memory.c @@ -0,0 +1,154 @@ +/* + * PASS (Power Aware System Service) - CPU Resource Driver + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file resource-memory.c + * @brief TBD + * @ingroup TBD + */ + +#include + +#include + +#include +#include +#include + +#include + +#define PROC_MEM_INFO_PATH "/proc/meminfo" +#define PROC_MEM_INFO_MEM_TOTAL "MemTotal" +#define PROC_MEM_INFO_MEM_AVAILABLE "MemAvailable" +#define PROC_MEM_INFO_MEM_FREE "MemFree" + +static int __memory_read_val_from_proc_node(const char *key) +{ + int ret = -EINVAL; + char buf[BUFF_MAX]; + char str[BUFF_MAX]; + FILE *fp = NULL; + + fp = fopen(PROC_MEM_INFO_PATH, "r"); + if (!fp) + return -EIO; + + while (fgets(buf, BUFF_MAX, fp)) { + if (!strncmp(buf, key, strlen(key))) { + sscanf(buf, "%s %d", str, &ret); + break; + } + } + fclose(fp); + + return ret; +} + +static inline int memory_read_val_from_proc_node(uint32_t val_id) +{ + switch (val_id) { + case MEMORY_TOTAL: + return __memory_read_val_from_proc_node(PROC_MEM_INFO_MEM_TOTAL); + case MEMORY_AVAILABLE: + return __memory_read_val_from_proc_node(PROC_MEM_INFO_MEM_AVAILABLE); + case MEMORY_FREE: + return __memory_read_val_from_proc_node(PROC_MEM_INFO_MEM_FREE); + } + return -EINVAL; +} + +static int memory_get_total_memory(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = memory_read_val_from_proc_node(attr->id); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int memory_get_available_memory(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = memory_read_val_from_proc_node(attr->id); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static int memory_get_free_memory(const struct resource *res, + const struct resource_attribute *attr, + char *buf, void *user_data) +{ + int val; + + if (!res || !attr || !buf) + return -EINVAL; + + val = memory_read_val_from_proc_node(attr->id); + if (val < 0) + return -EINVAL; + + return sprintf(buf, "%d", val); +} + +static const struct resource_attribute memory_attrs[] = { + { + .name = "MEMORY_TOTAL", + .id = MEMORY_TOTAL, + .type = DATA_TYPE_INT, + .ops = { + .get = memory_get_total_memory, + }, + }, { + .name = "MEMORY_AVAILABLE", + .id = MEMORY_AVAILABLE, + .type = DATA_TYPE_INT, + .ops = { + .get = memory_get_available_memory, + }, + }, { + .name = "MEMORY_FREE", + .id = MEMORY_FREE, + .type = DATA_TYPE_INT, + .ops = { + .get = memory_get_free_memory, + } + }, +}; + +static const struct resource_driver cpu_resource_driver = { + .name = "MEMORY", + .type = PASS_RESOURCE_MEMORY_ID, + .attrs = memory_attrs, + .num_attrs = ARRAY_SIZE(memory_attrs), +}; +RESOURCE_DRIVER_REGISTER(&cpu_resource_driver) -- 2.7.4 From ac7c1fc49d20f3f008ed74b911677a7baabca9d2 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:30:18 +0900 Subject: [PATCH 07/16] util: thread: Fix missing preprocessor This corrects that thread header is missing preprocessor define to prevent including it multiple times. Change-Id: Ic66e09df0759cbd72e03979861485fe1961b80f7 Signed-off-by: Dongwoo Lee --- include/util/thread.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/util/thread.h b/include/util/thread.h index 0f13200..6d63fb1 100644 --- a/include/util/thread.h +++ b/include/util/thread.h @@ -16,6 +16,9 @@ * limitations under the License. */ +#ifndef __THREAD_H__ +#define __THREAD_H__ + #include #include @@ -62,3 +65,5 @@ void resume_thread(struct thread *thread); #define schedule_worker resume_thread int wait_for_completion(struct thread *thread, void **result); + +#endif -- 2.7.4 From 3b6ec88399dc060105076721cd09b28f7035dd4a Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:30:36 +0900 Subject: [PATCH 08/16] util: thread: Fix to unlock mutex before doing job Change-Id: I1af301998cdae5c92ffd249b9c61dfb9696e8677 Signed-off-by: Dongwoo Lee --- src/util/thread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/thread.c b/src/util/thread.c index 50b1bc0..787c8e9 100644 --- a/src/util/thread.c +++ b/src/util/thread.c @@ -38,7 +38,9 @@ static void __thread_loop_main(void *_ctx) if (ctx->state == THREAD_STATE_TERMINATED) break; + mtx_unlock(&ctx->lock); ret = ctx->func(ctx->arg, &result); + mtx_lock(&ctx->lock); if (ret != THREAD_RETURN_CONTINUE) { ctx->state = THREAD_STATE_TERMINATED; -- 2.7.4 From 54c53f3b5f9aa578d56a2ca0c4bb3435c7620a06 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:30:50 +0900 Subject: [PATCH 09/16] util: thread: Let thread use self-allocated memory Make easy to use thread without concerning about memory using thread Change-Id: I170fd0afe772f47554dca95f3f61afd6b38e2921 Signed-off-by: Dongwoo Lee --- include/util/thread.h | 6 +++--- src/util/thread.c | 31 +++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/util/thread.h b/include/util/thread.h index 6d63fb1..a806ead 100644 --- a/include/util/thread.h +++ b/include/util/thread.h @@ -55,10 +55,10 @@ struct thread { struct thread_context *ctx; }; -int create_daemon_thread(struct thread *thread, int (*func)(void *, void **), void *arg); -int create_timer_thread(struct thread *thread, u_int32_t timer_expire_msec, +int create_daemon_thread(struct thread **thread, int (*func)(void *, void **), void *arg); +int create_timer_thread(struct thread **thread, u_int32_t timer_expire_msec, int (*func)(void *, void **), void *arg); -int create_worker_thread(struct thread *thread, int (*func)(void *, void **), void *arg); +int create_worker_thread(struct thread **thread, int (*func)(void *, void **), void *arg); void destroy_thread(struct thread *thread); void suspend_thread(struct thread *thread); void resume_thread(struct thread *thread); diff --git a/src/util/thread.c b/src/util/thread.c index 787c8e9..8bcef56 100644 --- a/src/util/thread.c +++ b/src/util/thread.c @@ -74,13 +74,16 @@ void destroy_thread(struct thread *thread) do_destroy_thread(thread); free(thread->ctx); thread->ctx = NULL; + + free(thread); } -static int do_create_thread(struct thread *thread, +static int do_create_thread(struct thread **thread, enum thread_type type, u_int32_t timer_expire_msec, int (*func)(void *, void **), void *arg) { + struct thread *new_thread; struct thread_context *ctx; thrd_t tid; int ret; @@ -88,10 +91,16 @@ static int do_create_thread(struct thread *thread, if (!thread || !func) return -EINVAL; - ctx = calloc(1, sizeof(struct thread_context)); - if (!ctx) + new_thread = malloc(sizeof(struct thread)); + if (!new_thread) return -ENOMEM; + ctx = calloc(1, sizeof(struct thread_context)); + if (!ctx) { + ret = -ENOMEM; + goto err_malloc; + } + mtx_init(&ctx->lock, mtx_plain); cnd_init(&ctx->wait); ctx->func = func; @@ -122,8 +131,10 @@ static int do_create_thread(struct thread *thread, goto err; } - thread->id = tid; - thread->ctx = ctx; + new_thread->id = tid; + new_thread->ctx = ctx; + + *thread = new_thread; return 0; @@ -131,17 +142,19 @@ err: cnd_destroy(&ctx->wait); mtx_destroy(&ctx->lock); free(ctx); +err_malloc: + free(new_thread); return ret; } -int create_daemon_thread(struct thread *thread, +int create_daemon_thread(struct thread **thread, int (*func)(void *, void **), void *arg) { return do_create_thread(thread, THREAD_TYPE_DAEMON, 0, func, arg); } -int create_timer_thread(struct thread *thread, +int create_timer_thread(struct thread **thread, u_int32_t timer_expire_msec, int (*func)(void *, void **), void *arg) { @@ -149,7 +162,7 @@ int create_timer_thread(struct thread *thread, timer_expire_msec, func, arg); } -int create_worker_thread(struct thread *thread, +int create_worker_thread(struct thread **thread, int (*func)(void *, void **), void *arg) { return do_create_thread(thread, THREAD_TYPE_WORKER, 0, func, arg); @@ -191,5 +204,7 @@ int wait_for_completion(struct thread *thread, void **result) free(thread->ctx); thread->ctx = NULL; + free(thread); + return 0; } -- 2.7.4 From cb5f362fa076c033cf3e726a0aff20a4eaa2a5a3 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:30:59 +0900 Subject: [PATCH 10/16] util: Add lock-free queue utility Now lock-free queue for supporting multi-thread without lock contention will be provided. Change-Id: I6459e397954c95831ca3b31359cb9136eb59705e Signed-off-by: Dongwoo Lee --- CMakeLists.txt | 1 + include/util/queue.h | 59 ++++++++++++++++++++++++++++++ src/util/queue.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 include/util/queue.h create mode 100644 src/util/queue.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 24425eb..686a478 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ SET(SRCS src/util/gdbus-util.c src/util/timer.c src/util/thread.c + src/util/queue.c src/main.c #Generated by a custom command 'gdbus-codegen' below src/pass/pass-dbus-stub.c diff --git a/include/util/queue.h b/include/util/queue.h new file mode 100644 index 0000000..23b8331 --- /dev/null +++ b/include/util/queue.h @@ -0,0 +1,59 @@ +/* + * PASS + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __QUEUE_H__ +#define __QUEUE_H__ + +#define smp_mb() dmb() +#define smp_rmb() dmb() +#define smp_wmb() dmb() + +#ifdef __aarch64__ +#define dmb() __asm__ __volatile__ ("dmb sy" : : : "memory") +#elif __arm__ +#define dmb() __asm__ __volatile__ ("dmb" : : : "memory") +#else +#define dmb() __asm__ __volatile__ ("" : : : "memory") +#endif + +#define ATOMIC_SUB __sync_sub_and_fetch +#define ATOMIC_ADD __sync_add_and_fetch +#define CAS __sync_bool_compare_and_swap +#define XCHG __sync_lock_test_and_set + +struct queue_node { + void *data; + struct queue_node *next; +}; + +struct queue { + struct queue_node *head; + struct queue_node *tail; +}; + +static inline void cpu_relax(void) +{ + asm volatile("yield" ::: "memory"); +} + +int enqueue(struct queue *queue, void *data); +int dequeue(struct queue *queue, void **data); +int create_queue(struct queue **queue); +void destroy_queue(struct queue *queue); + +#endif diff --git a/src/util/queue.c b/src/util/queue.c new file mode 100644 index 0000000..ec3819d --- /dev/null +++ b/src/util/queue.c @@ -0,0 +1,101 @@ +/* + * PASS + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +int enqueue(struct queue *queue, void *data) +{ + struct queue_node *node; + struct queue_node *new_node; + + new_node = (struct queue_node *)malloc(sizeof(struct queue_node)); + if (!new_node) + return -ENOMEM; + + new_node->data = data; + new_node->next = NULL; + + for (;;) { + node = queue->tail; + if (CAS(&(node->next), NULL, new_node)) + break; + + CAS(&(queue->tail), node, node->next); + } + CAS(&(queue->tail), node, new_node); + + return 0; +} + +int dequeue(struct queue *queue, void **data) +{ + struct queue_node *node; + + for (;;) { + node = queue->head; + if (!node->next) + return -ENOENT; + + if (CAS(&(queue->head), node, node->next)) + break; + } + if (data) + *data = (void *) node->next->data; + free(node); + + return 0; +} + +int create_queue(struct queue **queue) +{ + struct queue *new_queue; + struct queue_node *sentinel; + + new_queue = (struct queue *)malloc(sizeof(struct queue)); + if (!new_queue) + return -ENOMEM; + + sentinel = (struct queue_node *)malloc(sizeof(struct queue_node)); + if (!sentinel) { + free(new_queue); + return -ENOMEM; + } + + new_queue->head = new_queue->tail = sentinel; + new_queue->head->data = NULL; + new_queue->head->next = NULL; + + *queue = new_queue; + + return 0; +} + +void destroy_queue(struct queue *queue) +{ + do { } while (!dequeue(queue, NULL)); + + /* freeing remaining sentinel */ + free(queue->head); + + queue->head = queue->tail = NULL; + free(queue); +} -- 2.7.4 From 2011e18baa4895726be9b0e9f26eeab7da9f2389 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:31:16 +0900 Subject: [PATCH 11/16] monitor: Rename monitor.h to monitor-internal.h Change-Id: I2a6463736ec92ba808c56d7c1cc0c2f083e4588b Signed-off-by: Dongwoo Lee --- include/monitor/{monitor.h => monitor-internal.h} | 0 src/resource/resource-bus.c | 2 +- src/resource/resource-cpu.c | 2 +- src/resource/resource-gpu.c | 2 +- src/resource/resource-memory.c | 2 +- src/util/resource.c | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename include/monitor/{monitor.h => monitor-internal.h} (100%) diff --git a/include/monitor/monitor.h b/include/monitor/monitor-internal.h similarity index 100% rename from include/monitor/monitor.h rename to include/monitor/monitor-internal.h diff --git a/src/resource/resource-bus.c b/src/resource/resource-bus.c index fb2e223..a97d6f5 100644 --- a/src/resource/resource-bus.c +++ b/src/resource/resource-bus.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int bus_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, diff --git a/src/resource/resource-cpu.c b/src/resource/resource-cpu.c index 469dacc..7453f31 100644 --- a/src/resource/resource-cpu.c +++ b/src/resource/resource-cpu.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int cpu_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, diff --git a/src/resource/resource-gpu.c b/src/resource/resource-gpu.c index 184772c..02141f5 100644 --- a/src/resource/resource-gpu.c +++ b/src/resource/resource-gpu.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int gpu_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, diff --git a/src/resource/resource-memory.c b/src/resource/resource-memory.c index 3d62be4..d0b24c7 100644 --- a/src/resource/resource-memory.c +++ b/src/resource/resource-memory.c @@ -30,7 +30,7 @@ #include #include -#include +#include #define PROC_MEM_INFO_PATH "/proc/meminfo" #define PROC_MEM_INFO_MEM_TOTAL "MemTotal" diff --git a/src/util/resource.c b/src/util/resource.c index 846fa43..609cbbc 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -23,7 +23,7 @@ #include #include -#include +#include static GList *g_resource_driver_head; -- 2.7.4 From f2146733b33fe54bb569054076a2951d6f8841a8 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:31:21 +0900 Subject: [PATCH 12/16] util: resource: Change resource attribute id This do refactoring resource attribute ids can be distinguished by bitfield operation. Change-Id: I07da21e442f761ffc212cab4507f4d7cd48d73d5 Signed-off-by: Dongwoo Lee --- include/monitor/monitor-internal.h | 75 ++++++++++++++++++++------------------ include/util/resource.h | 11 +++--- src/util/resource.c | 19 +++------- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/include/monitor/monitor-internal.h b/include/monitor/monitor-internal.h index d658d76..f5afbfb 100644 --- a/include/monitor/monitor-internal.h +++ b/include/monitor/monitor-internal.h @@ -24,14 +24,12 @@ #include -#ifndef __UNIFIED_RESOURCE_MONITOR__ -#define __UNIFIED_RESOURCE_MONITOR__ +#ifndef __MONITOR_INTERNAL__ +#define __MONITOR_INTERNAL__ -#define RESOURCE_TYPE_SHIFT 16 -#define RESOURCE_ATTR_INDEX_MASK (0xffff) - -#define RESOURCE_TYPE(command) (command >> RESOURCE_TYPE_SHIFT) -#define RESOURCE_ATTR_INDEX(command) (command & RESOURCE_ATTR_INDEX_MASK) +#define BIT(x) (1ULL << x) +#define RESOURCE_ATTR_MASK (ULLONG_MAX) +#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id)) enum monitor_data_type { DATA_TYPE_UNKNOWN = 0, @@ -43,37 +41,42 @@ enum monitor_data_type { DATA_TYPE_NUM }; -#define CPU_CUR_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 0) -#define CPU_MIN_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 1) -#define CPU_MAX_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 2) -#define CPU_AVAILABLE_MIN_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 3) -#define CPU_AVAILABLE_MAX_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 4) -#define CPU_CUR_GOVERNOR (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 5) -#define CPU_ONLINE_CPU (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 6) -#define CPU_TEMPERATURE (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 7) +/* CPU attributes */ +#define CPU_CUR_FREQ BIT(0) +#define CPU_MIN_FREQ BIT(1) +#define CPU_MAX_FREQ BIT(2) +#define CPU_AVAILABLE_MIN_FREQ BIT(3) +#define CPU_AVAILABLE_MAX_FREQ BIT(4) +#define CPU_CUR_GOVERNOR BIT(5) +#define CPU_ONLINE_CPU BIT(6) +#define CPU_TEMPERATURE BIT(7) -#define BUS_CUR_FREQ (PASS_RESOURCE_BUS_ID << RESOURCE_TYPE_SHIFT | 0) -#define BUS_MIN_FREQ (PASS_RESOURCE_BUS_ID << RESOURCE_TYPE_SHIFT | 1) -#define BUS_MAX_FREQ (PASS_RESOURCE_BUS_ID << RESOURCE_TYPE_SHIFT | 2) -#define BUS_AVAILABLE_MIN_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 3) -#define BUS_AVAILABLE_MAX_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 4) -#define BUS_CUR_GOVERNOR (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 5) +/* BUS attributes */ +#define BUS_CUR_FREQ BIT(0) +#define BUS_MIN_FREQ BIT(1) +#define BUS_MAX_FREQ BIT(2) +#define BUS_AVAILABLE_MIN_FREQ BIT(3) +#define BUS_AVAILABLE_MAX_FREQ BIT(4) +#define BUS_CUR_GOVERNOR BIT(5) -#define GPU_CUR_FREQ (PASS_RESOURCE_GPU_ID << RESOURCE_TYPE_SHIFT | 0) -#define GPU_MIN_FREQ (PASS_RESOURCE_GPU_ID << RESOURCE_TYPE_SHIFT | 1) -#define GPU_MAX_FREQ (PASS_RESOURCE_GPU_ID << RESOURCE_TYPE_SHIFT | 2) -#define GPU_AVAILABLE_MIN_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 3) -#define GPU_AVAILABLE_MAX_FREQ (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 4) -#define GPU_CUR_GOVERNOR (PASS_RESOURCE_CPU_ID << RESOURCE_TYPE_SHIFT | 5) -#define GPU_TEMPERATURE (PASS_RESOURCE_GPU_ID << RESOURCE_TYPE_SHIFT | 6) +/* GPU attributes */ +#define GPU_CUR_FREQ BIT(0) +#define GPU_MIN_FREQ BIT(1) +#define GPU_MAX_FREQ BIT(2) +#define GPU_AVAILABLE_MIN_FREQ BIT(3) +#define GPU_AVAILABLE_MAX_FREQ BIT(4) +#define GPU_CUR_GOVERNOR BIT(5) +#define GPU_TEMPERATURE BIT(6) -#define MEMORY_TOTAL (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 0) -#define MEMORY_AVAILABLE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 1) -#define MEMORY_FREE (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 2) -#define MEMORY_FAULT_AROUND_BYTES (PASS_RESOURCE_MEMORY_ID << RESOURCE_TYPE_SHIFT | 3) +/* MEMORY attributes */ +#define MEMORY_TOTAL BIT(0) +#define MEMORY_AVAILABLE BIT(1) +#define MEMORY_FREE BIT(2) +#define MEMORY_FAULT_AROUND_BYTES BIT(3) -#define BATTERY_CAPACITY (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 0) -#define BATTERY_CHARGING_STATUS (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 1) -#define BATTERY_TEMPERATURE (PASS_RESOURCE_BATTERY_ID << RESOURCE_TYPE_SHIFT | 2) +/* BATTERY attributes */ +#define BATTERY_CAPACITY BIT(0) +#define BATTERY_CHARGING_STATUS BIT(1) +#define BATTERY_TEMPERATURE BIT(2) -#endif /* __UNIFIED_RESOURCE_MONITOR__ */ +#endif /* __MONITOR_INTERNAL__ */ diff --git a/include/util/resource.h b/include/util/resource.h index 09ba985..bae4314 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -56,7 +56,7 @@ struct resource_attribute_ops { struct resource_attribute { const char name[BUFF_MAX]; - const uint32 id; + const u_int64_t id; const int type; const struct resource_attribute_ops ops; }; @@ -94,10 +94,11 @@ void remove_resource_driver(const struct resource_driver *resource_driver); struct resource *create_resource(int resource_type, const char *resource_name, void *user_data); void delete_resource(struct resource *resource); -int update_resource_attr(struct resource *resource, int attr_id); +int update_resource_attr(struct resource *resource, u_int64_t attr_id); int update_resource_attrs(struct resource *resource); -struct resource_attribute_value *get_resource_attr_value(struct resource *resource, int attr_id); -int get_resource_attr_integer(struct resource *resource, int attr_id); -int get_resource_attr_integer_sync(struct resource *resource, int attr_id); +struct resource_attribute_value * +get_resource_attr_value(struct resource *resource, u_int64_t attr_id); +int get_resource_attr_integer(struct resource *resource, u_int64_t attr_id); +int get_resource_attr_integer_sync(struct resource *resource, u_int64_t attr_id); #endif diff --git a/src/util/resource.c b/src/util/resource.c index 609cbbc..73bf429 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -114,19 +114,15 @@ struct resource *create_resource(int resource_type, const char *resource_name, v return resource; } -int update_resource_attr(struct resource *resource, int attr_id) +int update_resource_attr(struct resource *resource, u_int64_t attr_id) { - int resource_type = RESOURCE_TYPE(attr_id); int attr_index = RESOURCE_ATTR_INDEX(attr_id); const struct resource_attribute *attr = NULL; struct resource_attribute_value *attr_value = NULL; char buf[BUFF_MAX]; int ret; - if (!resource || resource->type != resource_type) - return -EINVAL; - - if (attr_index < 0 || attr_index >= resource->num_attrs) + if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) return -EINVAL; attr = &resource->attrs[attr_index]; @@ -157,7 +153,7 @@ int update_resource_attrs(struct resource *resource) for (i = 0; i < resource->num_attrs; i++) { ret = update_resource_attr(resource, resource->attrs[i].id); if (ret < 0) { - _E("failed to update resource attr \n"); + _E("failed to update resource attr\n"); } } @@ -165,20 +161,17 @@ int update_resource_attrs(struct resource *resource) } struct resource_attribute_value * -get_resource_attr_value(struct resource *resource, int attr_id) +get_resource_attr_value(struct resource *resource, u_int64_t attr_id) { int attr_index = RESOURCE_ATTR_INDEX(attr_id); - if (!resource || resource->type != RESOURCE_TYPE(attr_id)) - return NULL; - if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) return NULL; return &resource->attrs_value[attr_index]; } -int get_resource_attr_integer(struct resource *resource, int attr_id) +int get_resource_attr_integer(struct resource *resource, u_int64_t attr_id) { struct resource_attribute_value *attr_value = get_resource_attr_value(resource, attr_id); @@ -189,7 +182,7 @@ int get_resource_attr_integer(struct resource *resource, int attr_id) return attr_value->data.int_value; } -int get_resource_attr_integer_sync(struct resource *resource, int attr_id) +int get_resource_attr_integer_sync(struct resource *resource, u_int64_t attr_id) { int ret; -- 2.7.4 From 5e20233848f9c166d5c3d0be940c5d86f6094e46 Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 3 Feb 2022 15:31:33 +0900 Subject: [PATCH 13/16] util: resource: Enable updating resources with interest mask Change-Id: I0ea7b2b9bae7ad1c5291307581cbfae78004400f Signed-off-by: Dongwoo Lee --- include/util/resource.h | 1 + src/util/resource.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/util/resource.h b/include/util/resource.h index bae4314..49d7f45 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -96,6 +96,7 @@ void delete_resource(struct resource *resource); int update_resource_attr(struct resource *resource, u_int64_t attr_id); int update_resource_attrs(struct resource *resource); +int update_resource_attrs_interest(struct resource *resource, u_int64_t attr_interest_mask); struct resource_attribute_value * get_resource_attr_value(struct resource *resource, u_int64_t attr_id); int get_resource_attr_integer(struct resource *resource, u_int64_t attr_id); diff --git a/src/util/resource.c b/src/util/resource.c index 73bf429..f164593 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -143,7 +143,7 @@ int update_resource_attr(struct resource *resource, u_int64_t attr_id) return 0; } -int update_resource_attrs(struct resource *resource) +int update_resource_attrs_interest(struct resource *resource, u_int64_t interest_mask) { int i, ret; @@ -151,6 +151,8 @@ int update_resource_attrs(struct resource *resource) return -EINVAL; for (i = 0; i < resource->num_attrs; i++) { + if (!(resource->attrs[i].id & interest_mask)) + continue; ret = update_resource_attr(resource, resource->attrs[i].id); if (ret < 0) { _E("failed to update resource attr\n"); @@ -160,6 +162,11 @@ int update_resource_attrs(struct resource *resource) return 0; } +int update_resource_attrs(struct resource *resource) +{ + return update_resource_attrs_interest(resource, RESOURCE_ATTR_MASK); +} + struct resource_attribute_value * get_resource_attr_value(struct resource *resource, u_int64_t attr_id) { -- 2.7.4 From 412f5a5dcc85537d663de0728bb0deecb7229d27 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 4 Feb 2022 12:28:08 +0900 Subject: [PATCH 14/16] util: resource: Check data type is integer or not when getting value Each resource_attribute has the only one data type like integer, string and so on. When using the getter function for specific data type such as get_resource_attr_integer(), must need to check the data type of resource attribute. Change-Id: I868c31011d61efe05ae8a72966db462370408977 Signed-off-by: Chanwoo Choi --- include/util/resource.h | 2 ++ src/util/resource.c | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/util/resource.h b/include/util/resource.h index 49d7f45..21f22de 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -97,6 +97,8 @@ void delete_resource(struct resource *resource); int update_resource_attr(struct resource *resource, u_int64_t attr_id); int update_resource_attrs(struct resource *resource); int update_resource_attrs_interest(struct resource *resource, u_int64_t attr_interest_mask); + +const struct resource_attribute *get_resource_attr(struct resource *resource, u_int64_t attr_id); struct resource_attribute_value * get_resource_attr_value(struct resource *resource, u_int64_t attr_id); int get_resource_attr_integer(struct resource *resource, u_int64_t attr_id); diff --git a/src/util/resource.c b/src/util/resource.c index f164593..fad00aa 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -167,6 +167,17 @@ int update_resource_attrs(struct resource *resource) return update_resource_attrs_interest(resource, RESOURCE_ATTR_MASK); } +const struct resource_attribute * +get_resource_attr(struct resource *resource, u_int64_t attr_id) +{ + int attr_index = RESOURCE_ATTR_INDEX(attr_id); + + if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) + return NULL; + + return &resource->attrs[attr_index]; +} + struct resource_attribute_value * get_resource_attr_value(struct resource *resource, u_int64_t attr_id) { @@ -180,9 +191,15 @@ get_resource_attr_value(struct resource *resource, u_int64_t attr_id) int get_resource_attr_integer(struct resource *resource, u_int64_t attr_id) { - struct resource_attribute_value *attr_value = - get_resource_attr_value(resource, attr_id); + const struct resource_attribute *attr = NULL; + struct resource_attribute_value *attr_value = NULL; + + /* Check whether the data type is integer or not */ + attr = get_resource_attr(resource, attr_id); + if (!attr || attr->type != DATA_TYPE_INT) + return -EINVAL; + attr_value = get_resource_attr_value(resource, attr_id); if (!attr_value) return -EINVAL; -- 2.7.4 From 7f0b325a53b5d562374ef420b3e4357dd1f63e11 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 4 Feb 2022 12:44:59 +0900 Subject: [PATCH 15/16] pass: Move pass.pc.in into packaging and remove unused files Move pass.pc.in into packaging directory and commit 469051e30f820 ("pass: hal: Replace HAL interface with hal-api-power") has removed the pass-hal-devel package. But, pass-hal-devel.pc.in/.manifest files were not removed. Remove unused pass-hal-devel related files. Change-Id: I7d568a8389c35c5d76064fbb844e76bb65a06a52 Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 6 ++++-- packaging/pass-hal-devel.manifest | 5 ----- pass.pc.in => packaging/pass.pc.in | 0 pass-hal-devel.pc.in | 13 ------------- 4 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 packaging/pass-hal-devel.manifest rename pass.pc.in => packaging/pass.pc.in (100%) delete mode 100644 pass-hal-devel.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 686a478..1ed88d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,8 +111,10 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/systemd/${PROJECT_NAME}.service.in ${CMAKE_SO INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.pass.service DESTINATION /usr/share/dbus-1/system-services) INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.thermal.service DESTINATION /usr/share/dbus-1/system-services) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc + @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system FILES_MATCHING diff --git a/packaging/pass-hal-devel.manifest b/packaging/pass-hal-devel.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/packaging/pass-hal-devel.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/pass.pc.in b/packaging/pass.pc.in similarity index 100% rename from pass.pc.in rename to packaging/pass.pc.in diff --git a/pass-hal-devel.pc.in b/pass-hal-devel.pc.in deleted file mode 100644 index 16fcdfc..0000000 --- a/pass-hal-devel.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -# Package Information for pkg-config - -package_name=pass-hal-devel -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@ - -Name: ${package_name} -Description: -- -Version: @VERSION@ -Requires: -Cflags: -I${includedir} -- 2.7.4 From 6e4f2dc2a25acb73c2596da7a6d2b8888966555a Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 4 Feb 2022 13:21:17 +0900 Subject: [PATCH 16/16] lib: tmonitor: Add libpass skeleton package for Tizen Monitor (tmonitor) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add libpass skelegon packages which contains the shared library and header files. Initial version just contains the Tizen Monitor's shared library and header file. But it just defines the tmonitor interface without any detailed implementation. It shold be implemnted. [Newlyd Added Packages] - libpass-1.2.0-1.aarch64.rpm - libpass-debuginfo-1.2.0-1.aarch64.rpm - libpass-devel-1.2.0-1.aarch64.rpm [File Hierarchy] └── usr ├── include │   └── pass │   └── tmonitor.h ├── lib │   └── debug │   └── usr │   └── lib64 │   └── libpass.so.0.1.0.debug ├── lib64 │   ├── libpass.so -> libpass.so.0 │   ├── libpass.so.0 -> libpass.so.0.1.0 │   ├── libpass.so.0.1.0 │   └── pkgconfig │   └── pass.pc └── share └── licenses └── libpass └── LICENSE Change-Id: I28d0e07e70db80471b50e749991f375267c8a0cb Signed-off-by: Chanwoo Choi --- CMakeLists.txt | 7 +- include/monitor/monitor-internal.h | 82 -------------------- include/util/resource.h | 10 +++ lib/CMakeLists.txt | 49 ++++++++++++ lib/tmonitor/tmonitor.c | 90 ++++++++++++++++++++++ lib/tmonitor/tmonitor.h | 151 +++++++++++++++++++++++++++++++++++++ packaging/pass.spec | 28 +++++++ src/resource/resource-bus.c | 4 +- src/resource/resource-cpu.c | 4 +- src/resource/resource-gpu.c | 4 +- src/resource/resource-memory.c | 4 +- src/util/resource.c | 3 +- 12 files changed, 340 insertions(+), 96 deletions(-) delete mode 100644 include/monitor/monitor-internal.h create mode 100644 lib/CMakeLists.txt create mode 100644 lib/tmonitor/tmonitor.c create mode 100644 lib/tmonitor/tmonitor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed88d1..568afd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ SET(SRCS INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib) SET(PKG_MODULES dlog @@ -111,14 +112,10 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/systemd/${PROJECT_NAME}.service.in ${CMAKE_SO INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.pass.service DESTINATION /usr/share/dbus-1/system-services) INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.thermal.service DESTINATION /usr/share/dbus-1/system-services) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc.in - ${CMAKE_CURRENT_SOURCE_DIR}/packaging/${PROJECT_NAME}.pc - @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/packaging/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system FILES_MATCHING PATTERN "*.service" ) ADD_SUBDIRECTORY(unittest) +ADD_SUBDIRECTORY(lib) diff --git a/include/monitor/monitor-internal.h b/include/monitor/monitor-internal.h deleted file mode 100644 index f5afbfb..0000000 --- a/include/monitor/monitor-internal.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * PASS (Power Aware System Service) - Header file of Unified Resource Monitor - * - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file monitor.h - * @brief Define the data structure for Unified Resource Monitor - * @ingroup COM_POWER_MGNT - */ - -#include - -#ifndef __MONITOR_INTERNAL__ -#define __MONITOR_INTERNAL__ - -#define BIT(x) (1ULL << x) -#define RESOURCE_ATTR_MASK (ULLONG_MAX) -#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id)) - -enum monitor_data_type { - DATA_TYPE_UNKNOWN = 0, - DATA_TYPE_INT, - DATA_TYPE_DOUBLE, - DATA_TYPE_STRING, - DATA_TYPE_ARRAY, - - DATA_TYPE_NUM -}; - -/* CPU attributes */ -#define CPU_CUR_FREQ BIT(0) -#define CPU_MIN_FREQ BIT(1) -#define CPU_MAX_FREQ BIT(2) -#define CPU_AVAILABLE_MIN_FREQ BIT(3) -#define CPU_AVAILABLE_MAX_FREQ BIT(4) -#define CPU_CUR_GOVERNOR BIT(5) -#define CPU_ONLINE_CPU BIT(6) -#define CPU_TEMPERATURE BIT(7) - -/* BUS attributes */ -#define BUS_CUR_FREQ BIT(0) -#define BUS_MIN_FREQ BIT(1) -#define BUS_MAX_FREQ BIT(2) -#define BUS_AVAILABLE_MIN_FREQ BIT(3) -#define BUS_AVAILABLE_MAX_FREQ BIT(4) -#define BUS_CUR_GOVERNOR BIT(5) - -/* GPU attributes */ -#define GPU_CUR_FREQ BIT(0) -#define GPU_MIN_FREQ BIT(1) -#define GPU_MAX_FREQ BIT(2) -#define GPU_AVAILABLE_MIN_FREQ BIT(3) -#define GPU_AVAILABLE_MAX_FREQ BIT(4) -#define GPU_CUR_GOVERNOR BIT(5) -#define GPU_TEMPERATURE BIT(6) - -/* MEMORY attributes */ -#define MEMORY_TOTAL BIT(0) -#define MEMORY_AVAILABLE BIT(1) -#define MEMORY_FREE BIT(2) -#define MEMORY_FAULT_AROUND_BYTES BIT(3) - -/* BATTERY attributes */ -#define BATTERY_CAPACITY BIT(0) -#define BATTERY_CHARGING_STATUS BIT(1) -#define BATTERY_TEMPERATURE BIT(2) - -#endif /* __MONITOR_INTERNAL__ */ diff --git a/include/util/resource.h b/include/util/resource.h index 21f22de..5064e43 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -24,6 +24,16 @@ #include #include "common.h" +enum monitor_data_type { + DATA_TYPE_UNKNOWN = 0, + DATA_TYPE_INT, + DATA_TYPE_DOUBLE, + DATA_TYPE_STRING, + DATA_TYPE_ARRAY, + + DATA_TYPE_NUM +}; + struct resource; struct resource_attribute; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..8119f45 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,49 @@ +PROJECT(libpass C) + +SET(NAME pass) +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.1.0") + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(INCLUDEDIR "${PREFIX}/include") +SET(LIBDIR ${CMAKE_LIBDIR_PREFIX}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) + +SET(PKG_MODULES + dlog + gio-2.0 + glib-2.0 +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt") +SET(CMAKE_EXE_LINKER_FLAGS "-pie") + +SET(SRCS ./tmonitor/tmonitor.c) + +ADD_LIBRARY( ${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${pkgs_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) +SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) +SET_TARGET_PROPERTIES( ${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${NAME}) + +CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc.in + ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc + @ONLY) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tmonitor/ + DESTINATION ${INCLUDEDIR}/${NAME}/ + FILES_MATCHING PATTERN "*.h") +INSTALL(FILES ${CMAKE_SOURCE_DIR}/packaging/${NAME}.pc + DESTINATION ${LIBDIR}/pkgconfig) diff --git a/lib/tmonitor/tmonitor.c b/lib/tmonitor/tmonitor.c new file mode 100644 index 0000000..5b0071d --- /dev/null +++ b/lib/tmonitor/tmonitor.c @@ -0,0 +1,90 @@ +/* + * PASS (Power Aware System Service) - Tizen Monitor Library + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define _GNU_SOURCE +#include + +extern char *program_invocation_name; + +#ifndef EXPORT +#define EXPORT __attribute__ ((visibility("default"))) +#endif + +EXPORT +int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data) +{ + /* TODO */ + return 0; +} + +EXPORT +void tmonitor_exit(int id) +{ + /* TODO */ +} + +EXPORT +int tmonitor_set_attrs(int id, int resource_type, u_int64_t attr_mask) +{ + /* TODO */ + return 0; +} + +EXPORT +int tmonitor_get_available_attrs(int id, int resource_type, + int *available_attrs[], int *num_attrs) +{ + /* TODO */ + return 0; +} + +EXPORT +int tmonitor_start(int id) +{ + /* TODO */ + return 0; +} + +EXPORT +void tmonitor_stop(int id) +{ + /* TODO */ +} + +EXPORT +int tmonitor_update(int id) +{ + /* TODO */ + return 0; +} + +EXPORT +int tmonitor_get_value_int(int id, int resource_type, u_int64_t attr) +{ + /* TODO */ + return 0; +} + +EXPORT +int tmonitor_get_resource_num(int id, int resource_type) +{ + /* TODO */ + return 0; +} diff --git a/lib/tmonitor/tmonitor.h b/lib/tmonitor/tmonitor.h new file mode 100644 index 0000000..344ae45 --- /dev/null +++ b/lib/tmonitor/tmonitor.h @@ -0,0 +1,151 @@ +/* + * PASS (Power Aware System Service) - Tizen Monitor Header File + * + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TMONITOR__ +#define __TMONITOR__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define BIT(x) (1ULL << x) + +/** + * @brief Define the supported resource type for monitoring + */ +#define RESOURCE_TYPE_UNKNOWN 0 +#define RESOURCE_TYPE_CPU 1 +#define RESOURCE_TYPE_BUS 2 +#define RESOURCE_TYPE_GPU 3 +#define RESOURCE_TYPE_MEMORY 4 +#define RESOURCE_TYPE_BATTERY 5 +#define RESOURCE_TYPE_PROCESS 6 +#define RESOURCE_TYPE_NONSTANDARD 99 + +/** + * @brief Define the supported attributes according to resource type + */ +#define CPU_CUR_FREQ BIT(0) +#define CPU_MIN_FREQ BIT(1) +#define CPU_MAX_FREQ BIT(2) +#define CPU_AVAILABLE_MIN_FREQ BIT(3) +#define CPU_AVAILABLE_MAX_FREQ BIT(4) +#define CPU_CUR_GOVERNOR BIT(5) +#define CPU_ONLINE_CPU BIT(6) +#define CPU_TEMPERATURE BIT(7) + +#define BUS_CUR_FREQ BIT(0) +#define BUS_MIN_FREQ BIT(1) +#define BUS_MAX_FREQ BIT(2) +#define BUS_AVAILABLE_MIN_FREQ BIT(3) +#define BUS_AVAILABLE_MAX_FREQ BIT(4) +#define BUS_CUR_GOVERNOR BIT(5) + +#define GPU_CUR_FREQ BIT(0) +#define GPU_MIN_FREQ BIT(1) +#define GPU_MAX_FREQ BIT(2) +#define GPU_AVAILABLE_MIN_FREQ BIT(3) +#define GPU_AVAILABLE_MAX_FREQ BIT(4) +#define GPU_CUR_GOVERNOR BIT(5) +#define GPU_TEMPERATURE BIT(6) + +#define MEMORY_TOTAL BIT(0) +#define MEMORY_AVAILABLE BIT(1) +#define MEMORY_FREE BIT(2) +#define MEMORY_FAULT_AROUND_BYTES BIT(3) + +#define BATTERY_CAPACITY BIT(0) +#define BATTERY_CHARGING_STATUS BIT(1) +#define BATTERY_TEMPERATURE BIT(2) + +/** + * @brief Initialize the tizen monitor + * @param[in] Timer period (unit: millisecond, minimum value is 100ms) + * @param[in] Timer callback function + * @param[in] User data be passed to timer callback function + * @return @c positive integer on success, otherwise a negative error value + */ +int tmonitor_init(int period, int (*func)(void *data, void* user_data), void *user_data); + +/** + * @brief Exit the tizem monitor + * @param[in] Unique id of tizen monitor which be returnted by tmonitor_init + */ +void tmonitor_exit(int id); + +/** + * @brief Set the interested attributes for monitoring + * @param[in] Unique id of tizen monitor + * @param[in] Resource type + * @param[in] Attribute mask including the various attributes + * @return @c 0 on success, otherwise a negative error value + */ +int tmonitor_set_attrs(int id, int resource_type, u_int64_t attr_mask); + +/** + * @brief Get the available attribute list according to resource type + * @param[in] Unique id of tizen monitor + * @param[in] Resource type + * @param[out] List of available attribute list + * @param[out] Number of available attributes + * @return @c 0 on success, otherwise a negative error value + */ +int tmonitor_get_available_attrs(int id, int resource_type, + int *available_attrs[], int *num_attrs); + +/** + * @brief Start tizen monitor with asynchronous method + * @param[in] Unique id of tizen monitor + * @return @c 0 on success, otherwise a negative error value + */ +int tmonitor_start(int id); + +/** + * @brief Stop tizen monitor + * @param[in] Unique id of tizen monitor + */ +void tmonitor_stop(int id); + +/** + * @brief Update value of the interested attributes by tmonitor_set_attrs() + * @param[in] Unique id of tizen monitor + * @return @c 0 on success, otherwise a negative error value + */ +int tmonitor_update(int id); + +/** + * @brief Get integer value of resource attribute + * @param[in] Unique id of tizen monitor + * @param[in] Resource type + * @param[in] Resoruce attribute id + * @return @c positive integer value, otherwise a negative error value + */ +int tmonitor_get_value_int(int id, int resource_type, u_int64_t attr); + +/** + * @brief Get the supported resource number + * @param[in] Unique id of tizen monitor + * @param[in] Resource type + * @return @c positive integer value, otherwise a negative error value + */ +int tmonitor_get_resource_num(int id, int resource_type); + +#ifdef __cplusplus +} +#endif +#endif /* __TMONITOR__ */ diff --git a/packaging/pass.spec b/packaging/pass.spec index 3856fc3..f21d2b0 100644 --- a/packaging/pass.spec +++ b/packaging/pass.spec @@ -3,6 +3,7 @@ %define daemon_name pass %define haltest_name pass-haltests %define unittest_name pass-unittest +%define libpass_name libpass Name: %{daemon_name} Summary: Power Aware System Service @@ -51,6 +52,22 @@ Requires: pass = %{version}-%{release} %description -n %{unittest_name} PASS unit test package with gtest +%package -n %{libpass_name} +Summary: Tizen Monitor Library package +Group: Development/Libraries +Requires: pass = %{version}-%{release} + +%description -n %{libpass_name} +Tizen Monitor Library package + +%package -n %{libpass_name}-devel +Summary: Tizen Monitor Headler Files +Group: Development/Libraries +Requires: pass = %{version}-%{release} + +%description -n %{libpass_name}-devel +Tizen Monitor Headler Files + %prep %setup -q @@ -105,3 +122,14 @@ systemctl daemon-reload %files -n %{unittest_name} %defattr(-,root,root,-) %{_bindir}/pass-unittests + +%files -n %{libpass_name} +%license LICENSE +%manifest %{name}.manifest +%defattr(-,root,root,-) +%{_libdir}/*.so* + +%files -n %{libpass_name}-devel +%defattr(-,root,root,-) +%{_includedir}/%{name}/*.h +%{_libdir}/pkgconfig/%{name}.pc diff --git a/src/resource/resource-bus.c b/src/resource/resource-bus.c index a97d6f5..51e6f79 100644 --- a/src/resource/resource-bus.c +++ b/src/resource/resource-bus.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int bus_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, @@ -176,7 +176,7 @@ static const struct resource_attribute bus_attrs[] = { static const struct resource_driver bus_resource_driver = { .name = "Memory Bus", - .type = PASS_RESOURCE_BUS_ID, + .type = RESOURCE_TYPE_BUS, .attrs = bus_attrs, .num_attrs = ARRAY_SIZE(bus_attrs), }; diff --git a/src/resource/resource-cpu.c b/src/resource/resource-cpu.c index 7453f31..3cefa95 100644 --- a/src/resource/resource-cpu.c +++ b/src/resource/resource-cpu.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int cpu_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, @@ -204,7 +204,7 @@ static const struct resource_attribute cpu_attrs[] = { static const struct resource_driver cpu_resource_driver = { .name = "CPU", - .type = PASS_RESOURCE_CPU_ID, + .type = RESOURCE_TYPE_CPU, .attrs = cpu_attrs, .num_attrs = ARRAY_SIZE(cpu_attrs), }; diff --git a/src/resource/resource-gpu.c b/src/resource/resource-gpu.c index 02141f5..1bf885c 100644 --- a/src/resource/resource-gpu.c +++ b/src/resource/resource-gpu.c @@ -30,7 +30,7 @@ #include #include -#include +#include static int gpu_get_cur_freq(const struct resource *res, const struct resource_attribute *attr, @@ -190,7 +190,7 @@ static const struct resource_attribute gpu_attrs[] = { static const struct resource_driver gpu_resource_driver = { .name = "GPU", - .type = PASS_RESOURCE_GPU_ID, + .type = RESOURCE_TYPE_GPU, .attrs = gpu_attrs, .num_attrs = ARRAY_SIZE(gpu_attrs), }; diff --git a/src/resource/resource-memory.c b/src/resource/resource-memory.c index d0b24c7..c571329 100644 --- a/src/resource/resource-memory.c +++ b/src/resource/resource-memory.c @@ -30,7 +30,7 @@ #include #include -#include +#include #define PROC_MEM_INFO_PATH "/proc/meminfo" #define PROC_MEM_INFO_MEM_TOTAL "MemTotal" @@ -147,7 +147,7 @@ static const struct resource_attribute memory_attrs[] = { static const struct resource_driver cpu_resource_driver = { .name = "MEMORY", - .type = PASS_RESOURCE_MEMORY_ID, + .type = RESOURCE_TYPE_MEMORY, .attrs = memory_attrs, .num_attrs = ARRAY_SIZE(memory_attrs), }; diff --git a/src/util/resource.c b/src/util/resource.c index fad00aa..523a0dc 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -23,7 +23,8 @@ #include #include -#include +#define RESOURCE_ATTR_MASK (ULLONG_MAX) +#define RESOURCE_ATTR_INDEX(id) (63 - __builtin_clzll(id)) static GList *g_resource_driver_head; -- 2.7.4