Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 0 additions & 151 deletions src/plugins/posix/aio_queue.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions src/plugins/posix/aio_queue.h

This file was deleted.

56 changes: 56 additions & 0 deletions src/plugins/posix/io_queue.cpp
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;
}
84 changes: 84 additions & 0 deletions src/plugins/posix/io_queue.h
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
Loading