summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungjae Cho <y0.cho@samsung.com>2021-01-21 15:47:55 +0900
committerYunmi Ha <yunmi.ha@samsung.com>2021-02-17 10:54:16 +0900
commit58859d19606ed1e2ac81e5bf4cd555f5826dc7e3 (patch)
tree23f6a1ced42937e45f8c77ad2b9d00899d9d429a
parentbd17650aa951be85f7f726a113410b4706a0f006 (diff)
downloaddevice-tm1-58859d19606ed1e2ac81e5bf4cd555f5826dc7e3.tar.gz
device-tm1-58859d19606ed1e2ac81e5bf4cd555f5826dc7e3.tar.bz2
device-tm1-58859d19606ed1e2ac81e5bf4cd555f5826dc7e3.zip
memory: add new halapi backend
Change-Id: Ief5e654ee0e161f888cba50e38ee73cf424f29db Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--hw/memory/CMakeLists.txt18
-rw-r--r--hw/memory/memory.c113
3 files changed, 132 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6d716e1..bed189e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,3 +23,4 @@ ADD_SUBDIRECTORY(hw/thermal)
ADD_SUBDIRECTORY(hw/usb_gadget)
ADD_SUBDIRECTORY(hw/board)
ADD_SUBDIRECTORY(hw/haptic)
+ADD_SUBDIRECTORY(hw/memory)
diff --git a/hw/memory/CMakeLists.txt b/hw/memory/CMakeLists.txt
new file mode 100644
index 0000000..a35248a
--- /dev/null
+++ b/hw/memory/CMakeLists.txt
@@ -0,0 +1,18 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(hal-backend-device-memory C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED dlog)
+
+FOREACH(flag ${hal-backend-device-memory_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE memory.c)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal-backend-device-memory_pkgs_LDFLAGS})
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${HAL_LIB_DIR} COMPONENT RuntimeLibraries)
diff --git a/hw/memory/memory.c b/hw/memory/memory.c
new file mode 100644
index 0000000..45e6a5c
--- /dev/null
+++ b/hw/memory/memory.c
@@ -0,0 +1,113 @@
+/*
+ * device-node
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <hal/device/hal-memory-interface.h>
+#include <hal/hal-common-interface.h>
+
+#include </hal/include/device/hal-backend-common.h>
+
+#define GEM_INFO_PATH "/sys/kernel/debug/dri/0/gem_info"
+#define BYTES_PER_KBYTE 1024
+
+static int memory_get_gpu_info(const int pid, struct gpu_info *info)
+{
+ return -EINVAL;
+}
+
+static int memory_get_gem_info(const int pid, struct gem_info *info)
+{
+ FILE *fp;
+ char line[1024];
+ int p;
+ unsigned int hcount, total_hcount;
+ unsigned long rss, total_rss, temp;
+
+ if (!info)
+ return -EINVAL;
+
+ fp = fopen(GEM_INFO_PATH, "r");
+ if (!fp) {
+ _E("Failed to open %s, %d", GEM_INFO_PATH, -errno);
+ /* Return the designated error(EIO) instead of general error(errno)
+ * for api-level error conversion compatibility, as the api(runtime-info)
+ * has no error enum for general error(errno) */
+ return -EIO;
+ }
+
+ total_hcount = 0;
+ total_rss = 0;
+
+ /* TM1 format:
+ * pid tgid handle refcount hcount size flags pfnmap export_to_fd import_from_fd obj_addr name
+ * 2978 2978 1 2 2 0x0007f000 0x3 0 0 0 0xffffffc024941200 6
+ */
+ while (fgets(line, 1024, fp)) {
+ if (sscanf(line, "%d %*d %*d %*d %u %lx", &p, &hcount, &rss) != 3)
+ continue;
+
+ if (p != pid)
+ continue;
+
+ total_rss += rss;
+ total_hcount += hcount;
+ }
+
+ temp = total_rss / (unsigned long)BYTES_PER_KBYTE;
+ info->rss = (int)temp;
+
+ temp = (total_rss / (unsigned long)total_hcount) / (unsigned long)BYTES_PER_KBYTE;
+ info->pss = (int)temp;
+
+ fclose(fp);
+
+ return 0;
+}
+
+static int memory_init(void **data)
+{
+ hal_backend_memory_funcs *memory_funcs;
+
+ memory_funcs = calloc(1, sizeof(hal_backend_memory_funcs));
+ if (!memory_funcs)
+ return -ENOMEM;
+
+ memory_funcs->get_gpu_info = memory_get_gpu_info;
+ memory_funcs->get_gem_info = memory_get_gem_info;
+
+ *data = (void *)memory_funcs;
+
+ return 0;
+}
+
+static int memory_exit(void *data)
+{
+ free(data);
+ return 0;
+}
+
+hal_backend EXPORT hal_backend_device_memory_data = {
+ .name = "memory",
+ .vendor = "SC7730",
+ .abi_version = HAL_ABI_VERSION_TIZEN_6_5,
+ .init = memory_init,
+ .exit = memory_exit,
+};