From 73671a8221846eb5e8c847dccecf8a712e61884d Mon Sep 17 00:00:00 2001 From: gwx1278443 Date: Fri, 29 Dec 2023 11:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gwx1278443 --- BUILD.gn | 46 +++++++++++++++++++++++++++++ OAT.xml | 51 ++++++++++++++++++++++++++++++++ README.OpenSource | 11 +++++++ README_zh.md | 74 +++++++++++++++++++++++++++++++++++++++++++++++ bundle.json | 34 ++++++++++++++++++++++ 5 files changed, 216 insertions(+) create mode 100644 BUILD.gn create mode 100644 OAT.xml create mode 100644 README.OpenSource create mode 100644 README_zh.md create mode 100644 bundle.json diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..b8f9020 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (C) 2023 Huawei Device 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. + +import("//build/ohos.gni") + +liburing_source = [ + "//third_party/liburing/src/nolibc.c", + "//third_party/liburing/src/queue.c", + "//third_party/liburing/src/register.c", + "//third_party/liburing/src/setup.c", + "//third_party/liburing/src/syscall.c", +] + +import("//build/ohos.gni") + +config("liburing_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//third_party/liburing", + "//third_party/liburing/src", + "//third_party/liburing/src/include", + "//third_party/liburing/src/include/liburing", + "//third_party/liburing/src/arch" + + ] +} + +ohos_shared_library("liburing") { + configs = [ "//third_party/liburing:liburing_config" ] + sources = liburing_source + external_deps = [ "c_utils:utils" ] + subsystem_name = "thirdparty" + part_name = "liburing" + output_name = "liburing" +} \ No newline at end of file diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000..c2ae261 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,51 @@ + + + + + COPYING + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.OpenSource b/README.OpenSource new file mode 100644 index 0000000..3251433 --- /dev/null +++ b/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "liburing", + "License": "LGPL V2.1", + "License File": "COPYING", + "Version Number": "2.3", + "Owner": "maojingjing1@huawei.com", + "Upstream URL": "https://github.com/axboe/liburing/releases/tag/liburing-2.3", + "Description": "liburing provides helpers to setup and reardown io_uring instances, and also a simplified interface for applications that don't need (or want) to deal with the full kernel side implementation." + } +] \ No newline at end of file diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..551f759 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,74 @@ +# liburing + +由于直接使用系统调用较为复杂,Jens Axboe 还提供了封装好的用户态库liburing,简化了io_uring的使用。 +o_uring库,libouling提供了设置和拆除io_ouling实例的帮助程序,以及为不需要(或不希望)处理完整内核端实现的应用程序提供简化的接口 + +## 目录结构 + +``` +debian/ +example/ #样例代码 +man/ +src/liburing #库源代码 +test/ #测试脚本代码 +``` + + +## OpenHarmony如何使用liburing + +liburing提供了以下基本助手来完成相同任务: +struct io_uring ring; +io_uring_queue_init(ENTRIES, &ring, 0); +一旦应用程序使用io_uring实例完成,它只需调用:io_uring_queue_exit(&ring)。相关接口在src/include/liburing.h定义 +## 接口说明 + +1. 初始化 + ``` + extern int io_uring_queue_init_params(unsigned entries, struct io_uring ring,struct io_uring_params p); + extern int io_uring_queue_init(unsigned entries, struct io_uring ring, unsigned flags); + entries 表示队列大小 + ring 就是需要初始化的io_uring结构指针 + flags是标志参数,此值会改变io_uring_params p->flags + io_uring_params *p更多的设置 + ``` +2. 创建请求(获取一个sqe请求并初始化) + ``` + extern struct io_uring_sqe io_uring_get_sqe(struct io_uring ring); + static inline void io_uring_prep_readv(struct io_uring_sqe sqe,int fd, const struct iovec iovecs, unsigned nr_vecs,off_t offset); + static inline void io_uring_prep_writev(struct io_uring_sqe sqe,int fd, const struct iovec iovecs, unsigned nr_vecs,off_t offset); + sqe即前面获取的sqe结构指针 + fd为需要读写的文件描述符,可以是磁盘文件也可以是socket + iovecs为iovec数组,具体使用请参照readv和writev + nr_vecs 为iovecs数组元素个数 + offset 为文件操作的偏移量 + ``` +3. 传入用户数据 + ``` + static inline void io_uring_sqe_set_data(struct io_uring_sqe *sqe, void *data); + ``` +4. 提交请求 + ``` + extern int io_uring_submit(struct io_uring *ring); + extern int io_uring_submit_and_wait(struct io_uring *ring, unsigned wait_nr); + wait_nr 等待事件数量 + ``` +5. 获取结果(提取完成事件) + ``` + static inline int io_uring_peek_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr); + static inline int io_uring_wait_cqe(struct io_uring *ring, struct io_uring_cqe **cqe_ptr); + + cqe_ptr 输出参数,是cqe指针变量的额地址 + 注意:io_uring_peek_cqe如果没有已完成的IO操作时,也会立即返回,cqe_ptr被置空;而io_uring_wait_cqe会阻塞线程,等待IO操作完成。 + ``` +6. 获取数据 + ``` + static inline void *io_uring_cqe_get_data(const struct io_uring_cqe *cqe); + ``` +7. 清理完成时间 + ``` + static inline void io_uring_cqe_seen(struct io_uring *ring, struct io_uring_cqe *cqe); + ``` +8. 释放 + ``` + extern void io_uring_queue_exit(struct io_uring *ring); + ``` diff --git a/bundle.json b/bundle.json new file mode 100644 index 0000000..de03fb5 --- /dev/null +++ b/bundle.json @@ -0,0 +1,34 @@ +{ + "name": "@ohos/liburing", + "description": "liburing provides helpers to setup and teardown io_uring instances, and also a simplified interface for applications that don't need (or want) to deal with the full kernel side implementation.", + "version": "2.3", + "license": "LGPL V2.1", + "publishAs": "code-segment", + "segment": { + "destPath": "third_party/liburing" + }, + "dirs": {}, + "scripts": {}, + "licensePath": "COPYING", + "readmePath": { + "en": "README" + }, + "component": { + "name": "liburing", + "subsystem": "thirdparty", + "syscap": [], + "features": [], + "adapted_system_type": [], + "rom": "", + "ram": "", + "deps": { + "components": [], + "third_party": [] + }, + "build": { + "sub_component": [], + "inner_kits": [], + "test": [] + } + } +} \ No newline at end of file -- Gitee