From cf81fd95524d6c6852740e2d8484097159b2fd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 21:45:10 +0800 Subject: [PATCH 1/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/include/hyperaio.h | 94 +++++++++ interfaces/kits/hyperaio/include/libhilog.h | 56 +++++ interfaces/kits/hyperaio/src/hyperaio.cpp | 218 ++++++++++++++++++++ 3 files changed, 368 insertions(+) create mode 100644 interfaces/kits/hyperaio/include/hyperaio.h create mode 100644 interfaces/kits/hyperaio/include/libhilog.h create mode 100644 interfaces/kits/hyperaio/src/hyperaio.cpp diff --git a/interfaces/kits/hyperaio/include/hyperaio.h b/interfaces/kits/hyperaio/include/hyperaio.h new file mode 100644 index 000000000..6ece2728b --- /dev/null +++ b/interfaces/kits/hyperaio/include/hyperaio.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2025 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. + */ + +#ifndef FILEMANAGEMENT_FILE_API_INTERFACES_KITS_IOURING_HYPER_AIO_H +#define FILEMANAGEMENT_FILE_API_INTERFACES_KITS_IOURING_HYPER_AIO_H + +#include +#include +#include "liburing.h" + +namespace OHOS { +namespace HyperAio { +#define IOURING_APP_PREMISSION (1U << 0) + +struct ReadInfo { + int32_t fd; + uint32_t len; + uint64_t offset; + void *buf; + uint64_t userData; +}; + +struct ReadReqs { + uint32_t reqNum; + struct ReadInfo *reqs; +}; + +struct OpenInfo { + int32_t dfd; + int32_t flags; + mode_t mode; + void *path; + uint64_t userData; +}; + +struct OpenReqs { + uint32_t reqNum; + struct OpenInfo *reqs; +}; + +struct CancelInfo { + uint64_t userData; + uint64_t targetUserData; +}; + +struct CancelReqs { + uint32_t reqNum; + struct CancelInfo *reqs; +}; + +struct IoResponse { + uint64_t userData; + int32_t res; + uint32_t flags; + IoResponse(uint64_t userData, int32_t res, uint32_t flags) + : userData(userData), + res(res), + flags(flags) { + } +}; + +class HyperAio { +public: + using ProcessIoResultCallBack = std::function)>; + uint32_t SupportIouring(); + int32_t CtxInit(ProcessIoResultCallBack *callBack); + int32_t StartReadReqs(ReadReqs *req); + int32_t StartOpenReqs(OpenReqs *req); + int32_t StartCancelReqs(CancelReqs *req); + int32_t DestroyCtx(); +private: + io_uring uring_; + ProcessIoResultCallBack ioResultCallBack_ = nullptr; + std::thread harvestThread_; + std::atomic stopThread_; + std::atomic initialized_; + void HarvestRes(); + struct io_uring_sqe* GetSqeWithRetry(struct io_uring *ring); +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/hyperaio/include/libhilog.h b/interfaces/kits/hyperaio/include/libhilog.h new file mode 100644 index 000000000..9e882f46b --- /dev/null +++ b/interfaces/kits/hyperaio/include/libhilog.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023-2024 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. + */ + +#ifndef FILEMGMT_LIBHILOG_H +#define FILEMGMT_LIBHILOG_H + +#include "hilog/log.h" + +#include + +namespace OHOS { +#ifndef LOG_DOMAIN +#define LOG_DOMAIN 0xD001600 +#endif + +#ifndef LOG_TAG +#define LOG_TAG "FileManagement" +#endif + +#if defined __FILE_NAME__ +#define FILEMGMT_FILE_NAME __FILE_NAME__ +#else +#include +#define FILEMGMT_FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#endif + +#define HILOGF(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGE(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGW(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGI(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +#define HILOGD(fmt, ...) \ + ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, \ + "[%{public}s:%{public}d->%{public}s] " fmt, FILEMGMT_FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__)) +} // namespace OHOS + +#endif // FILEMGMT_LIBHILOG_H \ No newline at end of file diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp new file mode 100644 index 000000000..400ba2865 --- /dev/null +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "hyperaio.h" +#include "libhilog.h" +#include +#include +#include "ipc_skeleton.h" +#include "accesstoken_kit.h" + +namespace OHOS { +namespace HyperAio { +const uint32_t URING_QUEUE_SIZE = 512; +const uint32_t DELAY = 20; +const uint32_t BATCH_SIZE = 128; +const uint32_t RETRIES = 3; + +static bool HasAccessIouringPermission() +{ + Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); + const std::string permissionName = "ohos.permission.ALLOW_IOURING"; + int32_t res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permissionName); + if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { + HILOG("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); + return false; + } + return true; +} + +uint32_t HyperAio::SupportIouring() +{ + uint32_t flags = 0; + if (HasAccessIouringPermission()) { + flags |= IOURING_APP_PERMISSION; + } + return flags; +} + +int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) +{ + int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &uring_, 0); + if (ret < 0) { + HILOGE("init io_uring failed, ret = %{public}d", ret); + return ret; + } + ioResultCallBack_ = *callBack; + stopThread_.store(false); + harvestThread_ = std::thread(&HyperAio::HarvestRes, this); + initialized_.sotre(true); + return EOK; +} + +struct io_uring_sqe* HyperAio::GetSqeWithRetry(struct io_uring *ring) +{ + struct io_uring_sqe *sqe; + for (uint32_t i = 0; i < RETRIES; i++) { + sqe = io_uring_get_sqe(ring); + if (sqe != nullptr) { + return sqe; + } + io_uring_submit(ring); + std::this_thread::sleep_for(std::chrono::milliseconds(DELAY)); + } + return nullptr; +} + +int32_t HyperAio::StartOpenReqs(OpenReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + struct OpenInfo *openInfo = &req->reqs[i]; + io_uring_sqe_set_data(sqe, reinterpret_cast(openInfo->userData)); + io_uring_prep_openat(sqe, openInfo->dfd, static_cast(openInfo->path), + openInfo->flags, openInfo->mode); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit open reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +int32_t HyperAio::StartReadReqs(ReadReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + struct ReadInfo *readInfo = &req->reqs[i]; + io_uring_sqe_set_data(sqe, reinterpret_cast(readInfo->userData)); + io_uring_prep_read(sqe, readInfo->fd, readInfo->buf, + readInfo->len, readInfo->offset); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit read reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +int32_t HyperAio::StartCancelReqs(CancelReqs *req) +{ + if (req == nullptr || req->reqs == nullptr) { + return EINVAL; + } + if (!initialized_.load()) { + HILOGE("HyperAio is not initialized"); + return EPERM; + } + uint32_t totalReqs = req->reqNum; + for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { + uint32_t end = std::min(totalReqs, start + BATCH_SIZE); + if (end < start) { + HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + return EINVAL; + } + for (uint32_t i = start; i < end; ++i) { + struct io_uring_sqe *sqe = GetSqeWithRetry(&uring_); + if (sqe == nullptr) { + HILOGE("get sqe failed"); + return ENOMEM; + } + struct CancelInfo *cancelInfo = &req->reqs[i]; + io_uring_sqe_set_data(sqe, reinterpret_cast(cancelInfo->userData)); + io_uring_prep_cancel(sqe, reinterpret_cast(cancelInfo->targetUserData), 0); + } + int32_t ret = io_uring_submit(&uring_); + if (ret < 0) { + HILOGE("submit open reqs failed, ret = %{public}d", ret); + return ret; + } + } + return EOK; +} + +void HyperAio::HarvestRes() +{ + struct __kernel_timespec timeout = { .tv_sec = 0, .tv_nsec = 200 * 1e6 }; + while (!stopThread_.load()) { + struct io_uring_cqe *cqe; + int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, %timeout); + if (ret == -ETIME) { + continue; + } + if (ret < 0 || cqe == nullptr) { + HILOGI("wait cqe failed, ret = %{public}d", ret); + continue; + } + auto response = std::make_unique(cqe->user_data, cqe->res, cqe->flags); + io_uring_cqe_seen(&uring_, cqe); + if (ioResultCallBack_) { + ioResultCallBack_(std::move(response)); + } + } +} + +int32_t HyperAio::DestroyCtx() +{ + stopThread_.store(true); + if (harvestThread_.joinable()) { + harvestThread_.join(); + } + io_uring_queue_exit(&uring_); + initialized_store(false); + return EOK; +} +} +} \ No newline at end of file -- Gitee From 826e21cdffe420b45cfd9190c2ff909628e61d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 22:58:02 +0800 Subject: [PATCH 2/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../test/unittest/hyperaio/hyperaio_test.cpp | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 interfaces/test/unittest/hyperaio/hyperaio_test.cpp diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp new file mode 100644 index 000000000..ce5b9f514 --- /dev/null +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include +#include +#include + +#include "hyperaio.h" + +namespace { + using namespace std; + using namespace OHOS::HyperAio; + + class HyperAioTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: HyperAio_StartOpenReqs_0000 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + OpenInfo openInfo = {0, O_RDWR, 0, nullptr, 12345}; + OpenReqs openReqs = {1, &openInfo}; + result = hyperAio->StartOpenReqs(&openReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0000 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio->StartReadReqs(&readReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartCancelReqs_0000 + * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + CancelInfo cancelInfo = {0, 1024, 0, nullptr, 12345}; + CancelReqs cancelReqs = {1, &cancelInfo}; + result = hyperAio->StartCancelReqs(&cancelReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; + } + +} -- Gitee From 54607f6ff2fc5d2c8b280e381abf045d7ab7b4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 22:59:15 +0800 Subject: [PATCH 3/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- .../test/unittest/hyperaio/hyperaio_test.cpp | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 interfaces/test/unittest/hyperaio/hyperaio_test.cpp diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp deleted file mode 100644 index ce5b9f514..000000000 --- a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2025 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. - */ - -#include -#include -#include -#include - -#include "hyperaio.h" - -namespace { - using namespace std; - using namespace OHOS::HyperAio; - - class HyperAioTest : public testing::Test { - public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; - }; - - /** - * @tc.name: HyperAio_StartOpenReqs_0000 - * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartOpenReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartOpenReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - OpenInfo openInfo = {0, O_RDWR, 0, nullptr, 12345}; - OpenReqs openReqs = {1, &openInfo}; - result = hyperAio->StartOpenReqs(&openReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; - } - - /** - * @tc.name: HyperAio_StartReadReqs_0000 - * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; - ReadReqs readReqs = {1, &readInfo}; - result = hyperAio->StartReadReqs(&readReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; - } - - /** - * @tc.name: HyperAio_StartCancelReqs_0000 - * @tc.desc: Test function of StartCancelReqs() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000HG8M4 - */ - HWTEST_F(HyperAioTest, HyperAio_StartCancelReqs_0000, testing::ext::TestSize.Level1) - { - GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartCancelReqs_0000"; - std::unique_ptr hyperAio = std::make_unique(); - int32_t result = hyperAio->CtxInit(nullptr); - EXPECT_EQ(result, EOK); - CancelInfo cancelInfo = {0, 1024, 0, nullptr, 12345}; - CancelReqs cancelReqs = {1, &cancelInfo}; - result = hyperAio->StartCancelReqs(&cancelReqs); - EXPECT_EQ(result, EOK); - GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartCancelReqs_0000"; - } - -} -- Gitee From a2077d87a598f49313944af0c3963d126cd4c64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:00:18 +0800 Subject: [PATCH 4/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 400ba2865..5932c113f 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -176,7 +176,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) } int32_t ret = io_uring_submit(&uring_); if (ret < 0) { - HILOGE("submit open reqs failed, ret = %{public}d", ret); + HILOGE("submit cancel reqs failed, ret = %{public}d", ret); return ret; } } -- Gitee From 879e81d5cd92bde17b87d2e7a1be970b2e580c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:01:40 +0800 Subject: [PATCH 5/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 5932c113f..3e486284c 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -188,7 +188,7 @@ void HyperAio::HarvestRes() struct __kernel_timespec timeout = { .tv_sec = 0, .tv_nsec = 200 * 1e6 }; while (!stopThread_.load()) { struct io_uring_cqe *cqe; - int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, %timeout); + int32_t ret = io_uring_wait_cqe_timeout(&uring_, &cqe, &timeout); if (ret == -ETIME) { continue; } -- Gitee From 4ef5883cd9de0188b0daed86c0c8033857eaf724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 23:07:04 +0800 Subject: [PATCH 6/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index 3e486284c..f0fec25df 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -33,7 +33,7 @@ static bool HasAccessIouringPermission() const std::string permissionName = "ohos.permission.ALLOW_IOURING"; int32_t res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, permissionName); if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - HILOG("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); + HILOGE("have no ALLOW_IOURING permission, AccessTokenID = %{public}u", tokenCaller); return false; } return true; @@ -58,7 +58,7 @@ int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) ioResultCallBack_ = *callBack; stopThread_.store(false); harvestThread_ = std::thread(&HyperAio::HarvestRes, this); - initialized_.sotre(true); + initialized_.store(true); return EOK; } @@ -89,7 +89,7 @@ int32_t HyperAio::StartOpenReqs(OpenReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -125,7 +125,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -136,8 +136,7 @@ int32_t HyperAio::StartReadReqs(ReadReqs *req) } struct ReadInfo *readInfo = &req->reqs[i]; io_uring_sqe_set_data(sqe, reinterpret_cast(readInfo->userData)); - io_uring_prep_read(sqe, readInfo->fd, readInfo->buf, - readInfo->len, readInfo->offset); + io_uring_prep_read(sqe, readInfo->fd, readInfo->buf, readInfo->len, readInfo->offset); } int32_t ret = io_uring_submit(&uring_); if (ret < 0) { @@ -161,7 +160,7 @@ int32_t HyperAio::StartCancelReqs(CancelReqs *req) for (uint32_t start = 0; start < totalReqs; start += BATCH_SIZE) { uint32_t end = std::min(totalReqs, start + BATCH_SIZE); if (end < start) { - HILOGE ("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); + HILOGE("Overflow detected: start + BATCH_SIZE exceeds uint32_t max"); return EINVAL; } for (uint32_t i = start; i < end; ++i) { @@ -211,7 +210,7 @@ int32_t HyperAio::DestroyCtx() harvestThread_.join(); } io_uring_queue_exit(&uring_); - initialized_store(false); + initialized_.store(false); return EOK; } } -- Gitee From 35e0c099e5ee3b36b183741abdf09c965fb6f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Fri, 9 May 2025 09:13:34 +0800 Subject: [PATCH 7/7] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/kits/hyperaio/src/hyperaio.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/kits/hyperaio/src/hyperaio.cpp b/interfaces/kits/hyperaio/src/hyperaio.cpp index f0fec25df..f719cf729 100644 --- a/interfaces/kits/hyperaio/src/hyperaio.cpp +++ b/interfaces/kits/hyperaio/src/hyperaio.cpp @@ -50,6 +50,10 @@ uint32_t HyperAio::SupportIouring() int32_t HyperAio::CtxInit(ProcessIoResultCallBack *callBack) { + if (callBack == nullptr) { + HILOGE("callBack is null"); + return -EINVAL; + } int32_t ret = io_uring_queue_init(URING_QUEUE_SIZE, &uring_, 0); if (ret < 0) { HILOGE("init io_uring failed, ret = %{public}d", ret); -- Gitee