经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
关于Android中ION的libion
来源:cnblogs  作者:willhua  时间:2018/12/10 9:37:24  对本文有异议

在高通的OpenCL SDK中,其Android.mk文件中,有判断当前kernel的版本,如果大于4.12,那么就使用libion.so,否则则使用ion kernle uapi

  1. # Tries to determine whether to use libion or ion kernel uapi
  2. KERNEL_VERSION = $(shell ls kernel | sed -n 's/msm-\([0-9]\+\)\.\([0-9]\+\)/-v x0=\1 -v x1=\2/p')
  3. USE_LIBION = $(shell awk $(KERNEL_VERSION) -v y0="4" -v y1="12" 'BEGIN {printf (x0>=y0 && x1>=y1?"true":"false") "\n"}')
  4. ifeq ($(USE_LIBION), true)
  5. $(info OpenCL SDK: Using libion)
  6. OPENCL_SDK_CPPFLAGS := -Wno-missing-braces -DUSES_LIBION
  7. OPENCL_SDK_SHARED_LIBS := libion libOpenCL
  8. OPENCL_SDK_COMMON_INCLUDES := $(LOCAL_PATH)/src kernel/msm-4.14/ $(TARGET_OUT_INTERMEDIATES)/include/adreno
  9. else
  10. $(info OpenCL SDK: Using ion uapi)
  11. OPENCL_SDK_CPPFLAGS := -Wno-missing-braces
  12. OPENCL_SDK_SHARED_LIBS := libOpenCL
  13. OPENCL_SDK_COMMON_INCLUDES := $(LOCAL_PATH)/src $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include $(TARGET_OUT_INTERMEDIATES)/include/adreno
  14. 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文件如下:

  1. LOCAL_PATH:= $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_SRC_FILES := ion.c
  4. LOCAL_MODULE := libion
  5. LOCAL_MODULE_TAGS := optional
  6. LOCAL_SHARED_LIBRARIES := liblog
  7. include $(BUILD_SHARED_LIBRARY)
  8. include $(CLEAR_VARS)
  9. LOCAL_SRC_FILES := ion.c ion_test.c
  10. LOCAL_MODULE := iontest
  11. LOCAL_MODULE_TAGS := optional tests
  12. LOCAL_SHARED_LIBRARIES := liblog
  13. include $(BUILD_EXECUTABLE)

这个mk文件使用,ion.c编译出来libion shared library ,以及使用,ion.cion_test.c编一个出来一个executable。ion_test.c里面有一个main()函数,主要是用来test alloc,map和share功能,也可以说是提供了使用Demo;而ion.c则是libion的实现,其实也是对ion toctl的几个功能的封装而已。其实我们如果把这个ion.c和ion.h文件拿出来,那么我们也能编译出libion库了。头文件ion.h如下:

  1. #ifndef __SYS_CORE_ION_H
  2. #define __SYS_CORE_ION_H
  3. #include <linux/ion.h>
  4. __BEGIN_DECLS
  5. int ion_open();
  6. int ion_close(int fd);
  7. int ion_alloc(int fd, size_t len, size_t align, unsigned int heap_mask,
  8. unsigned int flags, struct ion_handle **handle);
  9. int ion_alloc_fd(int fd, size_t len, size_t align, unsigned int heap_mask,
  10. unsigned int flags, int *handle_fd);
  11. int ion_sync_fd(int fd, int handle_fd);
  12. int ion_free(int fd, struct ion_handle *handle);
  13. int ion_map(int fd, struct ion_handle *handle, size_t length, int prot,
  14. int flags, off_t offset, unsigned char **ptr, int *map_fd);
  15. int ion_share(int fd, struct ion_handle *handle, int *share_fd);
  16. int ion_import(int fd, int share_fd, struct ion_handle **handle);
  17. __END_DECLS
  18. #endif /* __SYS_CORE_ION_H */
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号