-
Notifications
You must be signed in to change notification settings - Fork 192
plugins/posix: minimized IO queue abstraction #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anton-nayshtut
wants to merge
2
commits into
ai-dynamo:main
Choose a base branch
from
anton-nayshtut:antonn/posix_file_api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 "io_queue.h" | ||
|
|
||
| #ifdef HAVE_LIBAIO | ||
| std::unique_ptr<nixlPosixIOQueue> nixlPosixAioIOQueueCreate(uint32_t max_ios); | ||
| #endif | ||
| #ifdef HAVE_LIBURING | ||
| std::unique_ptr<nixlPosixIOQueue> nixlPosixIoUringIOQueueCreate(uint32_t max_ios); | ||
| #endif | ||
| #ifdef HAVE_LINUXAIO | ||
| std::unique_ptr<nixlPosixIOQueue> nixlPosixLinuxAioIOQueueCreate(uint32_t max_ios); | ||
| #endif | ||
|
|
||
| static const struct { | ||
| const char *name; | ||
| nixlPosixIOQueue::nixlPosixIOQueueCreateFn createFn; | ||
| } factories[] = { | ||
| #ifdef HAVE_LIBAIO | ||
| {"POSIXAIO", nixlPosixAioIOQueueCreate}, | ||
| #endif | ||
| #ifdef HAVE_LIBURING | ||
| {"URING", nixlPosixIoUringIOQueueCreate}, | ||
| #endif | ||
| #ifdef HAVE_LINUXAIO | ||
| {"AIO", nixlPosixLinuxAioIOQueueCreate}, | ||
| #endif | ||
| }; | ||
|
|
||
| const uint32_t nixlPosixIOQueue::MIN_IOS = 64; | ||
| const uint32_t nixlPosixIOQueue::MAX_IOS = 1024 * 64; | ||
|
|
||
| std::unique_ptr<nixlPosixIOQueue> | ||
| nixlPosixIOQueue::instantiate(std::string_view io_queue_type, uint32_t max_ios) { | ||
| for (const auto &factory : factories) { | ||
| if (io_queue_type == factory.name) { | ||
| return factory.createFn(max_ios); | ||
| } | ||
| } | ||
| return nullptr; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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 POSIX_IO_QUEUE_H | ||
| #define POSIX_IO_QUEUE_H | ||
|
|
||
| #include <stdint.h> | ||
| #include <list> | ||
| #include <memory> | ||
| #include <vector> | ||
| #include <functional> | ||
| #include <cassert> | ||
| #include "backend_aux.h" | ||
|
|
||
| typedef void (*nixlPosixIOQueueDoneCb)(void *ctx, uint32_t data_size, int error); | ||
|
|
||
| class nixlPosixIOQueue { | ||
| public: | ||
| using nixlPosixIOQueueCreateFn = | ||
| std::function<std::unique_ptr<nixlPosixIOQueue>(uint32_t max_ios)>; | ||
|
|
||
| nixlPosixIOQueue(uint32_t max_ios) : max_ios_(normalizedMaxIOS(max_ios)) {} | ||
|
|
||
| virtual ~nixlPosixIOQueue() {} | ||
|
|
||
| virtual nixl_status_t | ||
| enqueue(int fd, | ||
| void *buf, | ||
| size_t len, | ||
| off_t offset, | ||
| bool read, | ||
| nixlPosixIOQueueDoneCb clb, | ||
| void *ctx) = 0; | ||
| virtual nixl_status_t | ||
| post(void) = 0; | ||
| virtual nixl_status_t | ||
| poll(void) = 0; | ||
|
|
||
| static std::unique_ptr<nixlPosixIOQueue> | ||
| instantiate(std::string_view io_queue_type, uint32_t max_ios); | ||
|
|
||
| protected: | ||
| static uint32_t | ||
| normalizedMaxIOS(uint32_t max_ios) { | ||
| uint32_t m = std::max(MIN_IOS, max_ios); | ||
| m = std::min(m, MAX_IOS); | ||
| return m; | ||
| } | ||
|
|
||
| uint32_t max_ios_; | ||
| static const uint32_t MIN_IOS; | ||
| static const uint32_t MAX_IOS; | ||
| }; | ||
|
|
||
| template<typename Entry> class nixlPosixIOQueueImpl : public nixlPosixIOQueue { | ||
| public: | ||
| nixlPosixIOQueueImpl(uint32_t max_ios) : nixlPosixIOQueue(max_ios), ios_(max_ios_) { | ||
| for (uint32_t i = 0; i < max_ios_; i++) { | ||
| free_ios_.push_back(&ios_[i]); | ||
| } | ||
| } | ||
|
|
||
| protected: | ||
| std::vector<Entry> ios_; | ||
| std::list<Entry *> free_ios_; | ||
| std::list<Entry *> ios_to_submit_; | ||
| }; | ||
|
|
||
|
|
||
| #endif // POSIX_IO_QUEUE_H | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.