pass: resmon: Add timer-based RESMON_SRC_THERMAL source 49/170449/4
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 13 Feb 2018 13:34:01 +0000 (22:34 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 15 Mar 2018 06:03:43 +0000 (15:03 +0900)
RESMON_SRC_THERMAL indicates the thermal monitoring for h/w resource
such as CPU, GPU and so on. It is used to decide the current system status
like 'Low, Normal, High, Critical and Danger according to temperature of
h/w resource'. Also, other subsystems and user-processes can use
the temperature information.

It is standard Linux Kernel interface which provides the thermal infomation
through Thermal framework of Linux Kernel.

[Description of RESMON_SRC_THERMAL resource-monitor]
- The kind of resource data
: temperature of h/w resource (unit is centigrade)
: (e.g., 47000 means 47.0 degrees centigrade)

- Path of RESMON_SRC_THERMAL monitoring
: cat /sys/class/thermal/thermal_zone[X]/temp

- Result of RESMON_SRC_THERMAL monitoring
$ cat /sys/class/thermal/thermal_zone0/temp
47000

For exmaple on TM2 board,
: thermal_zone0 for ARM big core on TM2
: thermal_zone2 for ARM GPU on TM2
: thermal_zone3 for ARM LITTLE core on TM2

Change-Id: Ia6272621caea45a3c117d4d5bb9512ccafb9947a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-resmon-source.c
src/pass/pass-resmon.h

index 9c8efcb875058c27568437d2c868d5fa74ca3ccd..754d8542cab5303654da6344d3459a95540bdb75 100644 (file)
 #include <pass/log.h>
 
 #include "pass.h"
+#include "pass-hal.h"
 #include "pass-resmon.h"
 #include "pass-resmon-internal.h"
 
 /* RESMON_SRC_THERMAL */
 static int resmon_thermal_init(struct resmon *monitor)
 {
+       struct resmon_result_src_thermal *result;
+
+       if (monitor->result)
+               return 0;
+
+       result = calloc(1, sizeof(*result));
+       if (!result)
+               return -ENOMEM;
+
+       monitor->result = result;
+
        return 0;
 }
 
 static int resmon_thermal_exit(struct resmon *monitor)
 {
+       if (!monitor->result)
+               return 0;
+
+       free(monitor->result);
+       monitor->result = NULL;
+
        return 0;
 }
 
 static int resmon_thermal_timer_handler(struct resmon *monitor, void *result)
 {
+       struct pass_resmon *resmon = monitor->resmon;
+       struct pass_resource *res =
+                       container_of(resmon, struct pass_resource, resmon);
+       struct resmon_result_src_thermal *thermal_result = result;
+       int temp;
+
+       if (!thermal_result)
+               return -ENOMEM;
+
+       /* Get temperature of h/w resource */
+       temp = pass_get_temp(res);
+       if (temp < 0)
+               return temp;
+
+       thermal_result->temp = temp;
+
        return 0;
 }
 
index 52fdb4e1f325f8ba1cb7789a0261848e094c9009..b3fb8fc32db393e08ae3f4ba0ac6367a4db4717e 100644 (file)
@@ -38,6 +38,7 @@ enum resmon_timer_type {
  *   the linux kernel standard interface.
  *
  * Description of result format of resource monitor's source type:
+ * - RESMON_SRC_THERMAL: struct resmon_result_src_thermal
  * - RESMON_SRC_CPUHP : struct resmon_result_src_cpuhp
  */
 enum resmon_src_type {
@@ -46,6 +47,11 @@ enum resmon_src_type {
        RESMON_SRC_CPUHP                = 0x2,
 };
 
+/* Result of RESMON_SRC_THERMAL resource monitor */
+struct resmon_result_src_thermal {
+       int temp;
+};
+
 /* Result of RESMON_SRC_CPUHP's resource monitor */
 struct resmon_result_src_cpuhp {
        int64_t time;