pass: resmon: Add resmon source's skeleton code 47/170447/3
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 13 Feb 2018 07:17:16 +0000 (16:17 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 15 Mar 2018 04:45:11 +0000 (13:45 +0900)
The RESMON (resource monitor) module will monitor the various h/w resource
such as CPU, GPU, Memory, Network, Filesystem and so on. Each h/w resource
requires the common monitoring API like timer hanlding function. Add resmon
source's skeleton code.

RESMON makes the following two files to implement ths resource monitor:
- pass-resmon.c : Implment pass_resmon_init/exit() and common monitoring API
  which are used for all resource monitoring. It contains the exported API of
  both timer-based and uevent-baed resource monitor.

- pass-resmon-impl.c : Implement the h/w resource monitoring through HAL
  (Hardware Abstract Layer). Each resource-monitor would collect the data of
  h/w resource with their own method. For example, some resource-monitor just
  reads the value from fixed sysfs interface. On the other hand, other
  resource-monitor parses the multiple data and then make the meaningfull data
  from raw data.

Change-Id: I1a83c8ead16e6cba48e5ce191d55b5bde497afae
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
src/pass/pass-resmon-source.c [new file with mode: 0644]
src/pass/pass-resmon.c

index c13750f..7d901be 100644 (file)
@@ -70,6 +70,7 @@ SET(SRCS
        src/pass/pass-hal.c
        src/pass/pass-rescon.c
        src/pass/pass-resmon.c
+       src/pass/pass-resmon-source.c
        src/pass/pass-pmqos.c
        src/pmqos/pmqos.c
        src/pmqos/pmqos-parser.c
diff --git a/src/pass/pass-resmon-source.c b/src/pass/pass-resmon-source.c
new file mode 100644 (file)
index 0000000..270f5f8
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * PASS (Power Aware System Service) Resource Monitor's source implementation
+ *
+ * Copyright (c) 2018 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 <pass/log.h>
+
+#include "pass.h"
+#include "pass-resmon.h"
+#include "pass-resmon-internal.h"
+
+/* RESMON_SRC_THERMAL */
+static int resmon_thermal_init(struct resmon *monitor)
+{
+       return 0;
+}
+
+static int resmon_thermal_exit(struct resmon *monitor)
+{
+       return 0;
+}
+
+static int resmon_thermal_timer_handler(struct resmon *monitor, void *result)
+{
+       return 0;
+}
+
+/* RESMON_SRC_CPUHP */
+static int resmon_cpuhp_init(struct resmon *monitor)
+{
+       return 0;
+}
+
+static int resmon_cpuhp_exit(struct resmon *monitor)
+{
+       return 0;
+}
+
+static int resmon_cpuhp_timer_handler(struct resmon *monitor, void *result)
+{
+       return 0;
+}
+
+struct resmon_ops thermal_src_ops = {
+       .init = resmon_thermal_init,
+       .exit = resmon_thermal_exit,
+       .timer_handler = resmon_thermal_timer_handler,
+};
+
+struct resmon_ops cpuhp_src_ops = {
+       .init = resmon_cpuhp_init,
+       .exit = resmon_cpuhp_exit,
+       .timer_handler = resmon_cpuhp_timer_handler,
+};
+
+struct resmon_ops *resmon_get_ops(enum resmon_src_type src_type)
+{
+       switch (src_type) {
+       case RESMON_SRC_THERMAL:
+               return &thermal_src_ops;
+       case RESMON_SRC_CPUHP:
+               return &cpuhp_src_ops;;
+       default:
+               return NULL;
+       }
+}
index 702b1de..d82791f 100644 (file)
@@ -24,6 +24,8 @@
 #include "pass-resmon.h"
 #include "pass-resmon-internal.h"
 
+extern struct resmon_ops *resmon_get_ops(enum resmon_src_type src_type);
+
 uint64 available_resmon_timer[] = {
        [PASS_RESOURCE_UNKNOWN]         = 0,
        [PASS_RESOURCE_CPU_ID]          = RESMON_SRC_THERMAL
@@ -236,7 +238,12 @@ int pass_resmon_register_timer(struct pass_resource *res,
        monitor->user_func = user_func;
        monitor->user_data = user_data;
 
-       /* TODO: Get instance of struct resmon_ops accoring to resmon_src_type */
+       /* Get instance of struct resmon_ops accoring to resmon_src_type */
+       monitor->ops = resmon_get_ops(src_type);
+       if (!monitor->ops) {
+               ret = -EINVAL;
+               goto err;
+       }
 
        /* Add timer-based resource monitor */
        ret = resmon_timer_add(monitor, timer_interval);