memory: add new halapi 11/251911/7 accepted/tizen/unified/20210219.134857 submit/tizen/20210217.044338 submit/tizen/20210217.071642 submit/tizen/20210218.041307
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 20 Jan 2021 03:47:39 +0000 (12:47 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Tue, 16 Feb 2021 07:08:54 +0000 (16:08 +0900)
Change-Id: I52f89b125ea4982461e5c66f85662187624b6cf5
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
include/backend/hal-memory-interface.h [new file with mode: 0644]
include/hal-memory.h [new file with mode: 0644]
src/memory.c [new file with mode: 0644]

diff --git a/include/backend/hal-memory-interface.h b/include/backend/hal-memory-interface.h
new file mode 100644 (file)
index 0000000..b29bffe
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __HAL_MEMORY_INTERFACE_H__
+#define __HAL_MEMORY_INTERFACE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct gpu_info {
+       int used_pages;
+};
+
+struct gem_info {
+       int rss;
+       int pss;
+};
+
+typedef struct __hal_backend_memory_funcs {
+       int (*get_gpu_info)(const int pid, struct gpu_info *info);
+       int (*get_gem_info)(const int pid, struct gem_info *info);
+} hal_backend_memory_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_MEMORY_INTERFACE_H__ */
diff --git a/include/hal-memory.h b/include/hal-memory.h
new file mode 100644 (file)
index 0000000..ffcccb1
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __HAL_MEMORY_H__
+#define __HAL_MEMORY_H__
+
+#include <hal/hal-common.h>
+#include "hal-memory-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_memory_get_backend(void);
+int hal_device_memory_put_backend(void);
+int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info);
+int hal_device_memory_get_gem_info(int pid, struct gem_info *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __HAL_MEMORY_H__ */
diff --git a/src/memory.c b/src/memory.c
new file mode 100644 (file)
index 0000000..9acd608
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <hal/hal-common.h>
+
+#include "hal-memory-interface.h"
+#include "common.h"
+
+static hal_backend_memory_funcs *hal_memory_funcs = NULL;
+/*
+-1 : failed to initialize
+0  : not initialized
+1  : succeeded to initialize
+*/
+static int hal_initialized = 0;
+
+int hal_device_memory_get_backend(void)
+{
+       int ret;
+
+       if (hal_memory_funcs)
+               return 0;
+
+       ret = hal_common_get_backend(HAL_MODULE_DEVICE_MEMORY, (void **)&hal_memory_funcs);
+       if (ret < 0) {
+                _E("Failed to get memory backend");
+               hal_initialized = -1;
+               return -EINVAL;
+       }
+
+       hal_initialized = 1;
+       return 0;
+}
+
+int hal_device_memory_put_backend(void)
+{
+       if (!hal_memory_funcs)
+               return 0;
+
+       hal_common_put_backend(HAL_MODULE_DEVICE_MEMORY, (void *)hal_memory_funcs);
+       hal_memory_funcs = NULL;
+       hal_initialized = 0;
+
+       return 0;
+}
+
+int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info)
+{
+       int ret;
+
+       if (!hal_memory_funcs && !hal_initialized) {
+               if ((ret = hal_device_memory_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_memory_funcs || !hal_memory_funcs->get_gpu_info)
+               return -ENODEV;
+
+       return hal_memory_funcs->get_gpu_info(pid, info);
+}
+
+int hal_device_memory_get_gem_info(int pid, struct gem_info *info)
+{
+       int ret;
+
+       if (!hal_memory_funcs && !hal_initialized) {
+               if ((ret = hal_device_memory_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_memory_funcs || !hal_memory_funcs->get_gem_info)
+               return -ENODEV;
+
+       return hal_memory_funcs->get_gem_info(pid, info);
+}