resource: Add CPU/BUS/GPU resource driver 86/269986/6
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 18 Jan 2022 07:26:26 +0000 (16:26 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 24 Jan 2022 09:23:58 +0000 (18:23 +0900)
Change-Id: I3aef9258ae02f80b9bf87d438352d57a33411576
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
src/resource/resource-bus.c [new file with mode: 0644]
src/resource/resource-cpu.c [new file with mode: 0644]
src/resource/resource-gpu.c [new file with mode: 0644]

index ecf536d..cbef703 100644 (file)
@@ -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 (file)
index 0000000..fb2e223
--- /dev/null
@@ -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 <glib.h>
+
+#include <hal/hal-power.h>
+
+#include <util/common.h>
+#include <util/log.h>
+#include <util/resource.h>
+
+#include <monitor/monitor.h>
+
+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 (file)
index 0000000..469dacc
--- /dev/null
@@ -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 <glib.h>
+
+#include <hal/hal-power.h>
+
+#include <util/common.h>
+#include <util/log.h>
+#include <util/resource.h>
+
+#include <monitor/monitor.h>
+
+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 (file)
index 0000000..184772c
--- /dev/null
@@ -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 <glib.h>
+
+#include <hal/hal-power.h>
+
+#include <util/common.h>
+#include <util/log.h>
+#include <util/resource.h>
+
+#include <monitor/monitor.h>
+
+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)