在高通的OpenCL SDK中,其Android.mk文件中,有判斷當前kernel的版本,如果大於4.12,那麼就使用libion.so,否則則使用ion kernle uapi : 從Andriod P開始, "Kernel 4.14已推到AOSP, libion在Android P上已支持新的 ...
在高通的OpenCL SDK中,其Android.mk文件中,有判斷當前kernel的版本,如果大於4.12,那麼就使用libion.so,否則則使用ion kernle uapi:
# Tries to determine whether to use libion or ion kernel uapi
KERNEL_VERSION = $(shell ls kernel | sed -n 's/msm-\([0-9]\+\)\.\([0-9]\+\)/-v x0=\1 -v x1=\2/p')
USE_LIBION = $(shell awk $(KERNEL_VERSION) -v y0="4" -v y1="12" 'BEGIN {printf (x0>=y0 && x1>=y1?"true":"false") "\n"}')
ifeq ($(USE_LIBION), true)
$(info OpenCL SDK: Using libion)
OPENCL_SDK_CPPFLAGS := -Wno-missing-braces -DUSES_LIBION
OPENCL_SDK_SHARED_LIBS := libion libOpenCL
OPENCL_SDK_COMMON_INCLUDES := \
$(LOCAL_PATH)/src \
kernel/msm-4.14/ \
$(TARGET_OUT_INTERMEDIATES)/include/adreno
else
$(info OpenCL SDK: Using ion uapi)
OPENCL_SDK_CPPFLAGS := -Wno-missing-braces
OPENCL_SDK_SHARED_LIBS := libOpenCL
OPENCL_SDK_COMMON_INCLUDES := \
$(LOCAL_PATH)/src \
$(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include \
$(TARGET_OUT_INTERMEDIATES)/include/adreno
endif
從Andriod P開始,Kernel 4.14已推到AOSP, libion在Android P上已支持新的kernel ion介面,強烈建議 使用libion,而非直接使用ion ioctl調用.
在網上也找到關於如何使用ION的回答:https://grokbase.com/t/gg/android-kernel/141renrvzj/where-i-can-find-example-of-using-ion-for-memory-management
You can use libion.
You can find it in system http://androidxref.com/4.4.2_r1/xref/system//
core http://androidxref.com/4.4.2_r1/xref/system/core//libionhttp://androidxref.com/4.4.2_r1/xref/system/core/libion/
根據這個答案鏈接,編譯libion的mk文件如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := ion.c
LOCAL_MODULE := libion
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := liblog
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := ion.c ion_test.c
LOCAL_MODULE := iontest
LOCAL_MODULE_TAGS := optional tests
LOCAL_SHARED_LIBRARIES := liblog
include $(BUILD_EXECUTABLE)
這個mk文件使用,ion.c編譯出來libion shared library ,以及使用,ion.c和ion_test.c編一個出來一個executable。ion_test.c裡面有一個main()
函數,主要是用來test alloc,map和share功能,也可以說是提供了使用Demo;而ion.c則是libion的實現,其實也是對ion toctl的幾個功能的封裝而已。其實我們如果把這個ion.c和ion.h文件拿出來,那麼我們也能編譯出libion庫了。頭文件ion.h如下:
#ifndef __SYS_CORE_ION_H
#define __SYS_CORE_ION_H
#include <linux/ion.h>
__BEGIN_DECLS
int ion_open();
int ion_close(int fd);
int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
unsigned int flags, struct ion_handle **handle);
int ion_alloc_fd(int fd, size_t len, size_t align, unsigned int heap_mask,
unsigned int flags, int *handle_fd);
int ion_sync_fd(int fd, int handle_fd);
int ion_free(int fd, struct ion_handle *handle);
int ion_map(int fd, struct ion_handle *handle, size_t length, int prot,
int flags, off_t offset, unsigned char **ptr, int *map_fd);
int ion_share(int fd, struct ion_handle *handle, int *share_fd);
int ion_import(int fd, int share_fd, struct ion_handle **handle);
__END_DECLS
#endif /* __SYS_CORE_ION_H */