lib: tmonitor: Add libpass skeleton package for Tizen Monitor (tmonitor) 23/270523/6
authorChanwoo Choi <cw00.choi@samsung.com>
Fri, 4 Feb 2022 04:21:17 +0000 (13:21 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 7 Feb 2022 03:52:06 +0000 (12:52 +0900)
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 <cw00.choi@samsung.com>
12 files changed:
CMakeLists.txt
include/monitor/monitor-internal.h [deleted file]
include/util/resource.h
lib/CMakeLists.txt [new file with mode: 0644]
lib/tmonitor/tmonitor.c [new file with mode: 0644]
lib/tmonitor/tmonitor.h [new file with mode: 0644]
packaging/pass.spec
src/resource/resource-bus.c
src/resource/resource-cpu.c
src/resource/resource-gpu.c
src/resource/resource-memory.c
src/util/resource.c

index 1ed88d1..568afd4 100644 (file)
@@ -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 (file)
index f5afbfb..0000000
+++ /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 <hal/hal-power.h>
-
-#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__ */
index 21f22de..5064e43 100644 (file)
 #include <glib.h>
 #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 (file)
index 0000000..8119f45
--- /dev/null
@@ -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 (file)
index 0000000..5b0071d
--- /dev/null
@@ -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 <glib.h>
+
+#define _GNU_SOURCE
+#include <errno.h>
+
+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 (file)
index 0000000..344ae45
--- /dev/null
@@ -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__ */
index 3856fc3..f21d2b0 100644 (file)
@@ -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
index a97d6f5..51e6f79 100644 (file)
@@ -30,7 +30,7 @@
 #include <util/log.h>
 #include <util/resource.h>
 
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
 
 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),
 };
index 7453f31..3cefa95 100644 (file)
@@ -30,7 +30,7 @@
 #include <util/log.h>
 #include <util/resource.h>
 
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
 
 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),
 };
index 02141f5..1bf885c 100644 (file)
@@ -30,7 +30,7 @@
 #include <util/log.h>
 #include <util/resource.h>
 
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
 
 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),
 };
index d0b24c7..c571329 100644 (file)
@@ -30,7 +30,7 @@
 #include <util/log.h>
 #include <util/resource.h>
 
-#include <monitor/monitor-internal.h>
+#include <tmonitor/tmonitor.h>
 
 #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),
 };
index fad00aa..523a0dc 100644 (file)
@@ -23,7 +23,8 @@
 #include <util/resource.h>
 #include <util/log.h>
 
-#include <monitor/monitor-internal.h>
+#define RESOURCE_ATTR_MASK                     (ULLONG_MAX)
+#define RESOURCE_ATTR_INDEX(id)                        (63 - __builtin_clzll(id))
 
 static GList *g_resource_driver_head;