diff options
author | Yunhee Seo <yuni.seo@samsung.com> | 2024-04-19 10:57:20 +0900 |
---|---|---|
committer | Yunhee Seo <yuni.seo@samsung.com> | 2024-04-22 10:33:10 +0900 |
commit | 03861f4a824c02be20c045b33391521f366e36cf (patch) | |
tree | 7216e02a8893b2648593676afeb64fb3557f6090 | |
parent | ad7d86dd3d9ada13752f2609501418f1fd845b01 (diff) | |
download | device-03861f4a824c02be20c045b33391521f366e36cf.tar.gz device-03861f4a824c02be20c045b33391521f366e36cf.tar.bz2 device-03861f4a824c02be20c045b33391521f366e36cf.zip |
device-memory: Apply HAL ABI versioning rule
Change-Id: Ic1153389229de02ba00908e91f52802a93d6f7c4
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
-rw-r--r-- | haltest/memory.cpp | 6 | ||||
-rw-r--r-- | include/hal-device-memory-interface-1.h | 33 | ||||
-rw-r--r-- | include/hal-device-memory-interface.h (renamed from include/hal-memory-interface.h) | 22 | ||||
-rw-r--r-- | include/hal-device-memory-types.h | 45 | ||||
-rw-r--r-- | include/hal-device-memory.h (renamed from include/hal-memory.h) | 12 | ||||
-rw-r--r-- | src/hal-api-device-memory.c | 100 | ||||
-rw-r--r-- | src/memory.c | 79 |
7 files changed, 189 insertions, 108 deletions
diff --git a/haltest/memory.cpp b/haltest/memory.cpp index 5a350cf..609762d 100644 --- a/haltest/memory.cpp +++ b/haltest/memory.cpp @@ -2,7 +2,7 @@ #include <system_info.h> #include "haltest.h" -#include "hal-memory.h" +#include "hal-device-memory.h" class MEMORY : public testing::Test { protected: @@ -28,7 +28,7 @@ TEST_F(MEMORY, GetGpuInfoP) { int ret_val; int pid; - struct gpu_info info = {-1}; + hal_device_memory_gpu_info_s info = {-1}; pid = (int)getpid(); ret_val = hal_device_memory_get_gpu_info(pid, &info); @@ -42,7 +42,7 @@ TEST_F(MEMORY, GetGemInfoP) { int ret_val; int pid; - struct gem_info info = {-1, -1}; + hal_device_memory_gem_info_s info = {-1, -1}; pid = (int)getpid(); ret_val = hal_device_memory_get_gem_info(pid, &info); diff --git a/include/hal-device-memory-interface-1.h b/include/hal-device-memory-interface-1.h new file mode 100644 index 0000000..4fa1f84 --- /dev/null +++ b/include/hal-device-memory-interface-1.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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_1_H__ +#define __HAL_MEMORY_INTERFACE_1_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct __hal_backend_device_memory_funcs { + int (*get_gpu_info)(const int pid, hal_device_memory_gpu_info_s *info); + int (*get_gem_info)(const int pid, hal_device_memory_gem_info_s *info); +} hal_backend_device_memory_funcs; + +#ifdef __cplusplus +} +#endif +#endif /* __HAL_MEMORY_INTERFACE_1_H__ */ diff --git a/include/hal-memory-interface.h b/include/hal-device-memory-interface.h index b29bffe..27acb69 100644 --- a/include/hal-memory-interface.h +++ b/include/hal-device-memory-interface.h @@ -18,25 +18,7 @@ #ifndef __HAL_MEMORY_INTERFACE_H__ #define __HAL_MEMORY_INTERFACE_H__ -#ifdef __cplusplus -extern "C" { -#endif +#include "hal-device-memory-types.h" +#include "hal-device-memory-interface-1.h" -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-device-memory-types.h b/include/hal-device-memory-types.h new file mode 100644 index 0000000..dfdc691 --- /dev/null +++ b/include/hal-device-memory-types.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 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_DEVICE_MEMORY_TYPES_H__ +#define __HAL_DEVICE_MEMORY_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Structure for gpu information data. + * @since HAL_MODULE_DEVICE_MEMORY 1.0 + */ +typedef struct { + int used_pages; +} hal_device_memory_gpu_info_s; + +/** + * @brief Structure for GEM information. + * @since HAL_MODULE_DEVICE_MEMORY 1.0 + */ +typedef struct { + int rss; /**< Resident set size in graphic execution manager (KiB) (Since HAL_MODULE_DEVICE_MEMORY 1.0) */ + int pss; +} hal_device_memory_gem_info_s; + +#ifdef __cplusplus +} +#endif +#endif /* __HAL_DEVICE_MEMORY_TYPES_H__ */ diff --git a/include/hal-memory.h b/include/hal-device-memory.h index ffcccb1..673a8cb 100644 --- a/include/hal-memory.h +++ b/include/hal-device-memory.h @@ -15,11 +15,11 @@ */ -#ifndef __HAL_MEMORY_H__ -#define __HAL_MEMORY_H__ +#ifndef __HAL_DEVICE_MEMORY_H__ +#define __HAL_DEVICE_MEMORY_H__ #include <hal/hal-common.h> -#include "hal-memory-interface.h" +#include "hal-device-memory-interface.h" #ifdef __cplusplus extern "C" { @@ -27,11 +27,11 @@ extern "C" { 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); +int hal_device_memory_get_gpu_info(int pid, hal_device_memory_gpu_info_s *info); +int hal_device_memory_get_gem_info(int pid, hal_device_memory_gem_info_s *info); #ifdef __cplusplus } #endif -#endif /* __HAL_MEMORY_H__ */ +#endif /* __HAL_DEVICE_MEMORY_H__ */ diff --git a/src/hal-api-device-memory.c b/src/hal-api-device-memory.c new file mode 100644 index 0000000..c6775db --- /dev/null +++ b/src/hal-api-device-memory.c @@ -0,0 +1,100 @@ +/* + * 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 <stdlib.h> + +#include <hal/hal-common.h> + +#include "hal-device-memory-interface.h" +#include "common.h" + +static hal_backend_device_memory_funcs *hal_device_memory_funcs = NULL; + +int hal_device_memory_get_backend(void) +{ + int ret; + + if (hal_device_memory_funcs) + return 0; + + hal_device_memory_funcs = calloc(1, sizeof(hal_backend_device_memory_funcs)); + if (!hal_device_memory_funcs) + return -ENOMEM; + + ret = hal_common_get_backend(HAL_MODULE_DEVICE_MEMORY, (void **)&hal_device_memory_funcs); + if (ret < 0) { + _E("Failed to get device-memory backend"); + free(hal_device_memory_funcs); + hal_device_memory_funcs = NULL; + return -ENOTSUP; + } + + return 0; +} + +int hal_device_memory_put_backend(void) +{ + int ret = 0; + + if (!hal_device_memory_funcs) + return 0; + + ret = hal_common_put_backend(HAL_MODULE_DEVICE_MEMORY, (void *)hal_device_memory_funcs); + if (ret < 0) { + _E("Failed to put device-memory backend"); + return ret; + } + + free(hal_device_memory_funcs); + hal_device_memory_funcs = NULL; + + return 0; +} + +int hal_device_memory_get_gpu_info(int pid, hal_device_memory_gpu_info_s *info) +{ + int ret; + + if (!info) + return -EINVAL; + + if (!hal_device_memory_funcs) { + if ((ret = hal_device_memory_get_backend()) < 0) + return ret; + } + + if (!hal_device_memory_funcs || !hal_device_memory_funcs->get_gpu_info) + return -ENOTSUP; + + return hal_device_memory_funcs->get_gpu_info(pid, info); +} + +int hal_device_memory_get_gem_info(int pid, hal_device_memory_gem_info_s *info) +{ + int ret; + + if (!info) + return -EINVAL; + + if (!hal_device_memory_funcs) { + if ((ret = hal_device_memory_get_backend()) < 0) + return ret; + } + + if (!hal_device_memory_funcs || !hal_device_memory_funcs->get_gem_info) + return -ENOTSUP; + + return hal_device_memory_funcs->get_gem_info(pid, info); +} diff --git a/src/memory.c b/src/memory.c deleted file mode 100644 index cdafb34..0000000 --- a/src/memory.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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; - -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"); - return -EINVAL; - } - - 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; - - return 0; -} - -int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info) -{ - int ret; - - if (!hal_memory_funcs) { - 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) { - 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); -} |