156#define IO_OVERLAPPED io::Parameters(io::Parameters::OverlappedTag())
201 const bool temporaryBuffersRequested = (op.
m_Buffer == 0);
202 if(temporaryBuffersRequested)
211 if(temporaryBuffersRequested)
212 cb.
aio_buf = (
volatile void*)(uintptr_t(
buffers.get()) + i * blockSize);
236#ifndef ENABLE_IO_STATS
237#define ENABLE_IO_STATS 0
242template<
class CompletedHook,
class IssueHook>
255 size_t numBlocks = p.blockSize?
DivideRoundUp(
static_cast<size_t>(op.
m_Size), p.blockSize) : 1;
256 for(
size_t blocksIssued = 0, blocksCompleted = 0; blocksCompleted < numBlocks; blocksCompleted++)
258 for(; blocksIssued != numBlocks && blocksIssued < blocksCompleted + (
off_t)p.queueDepth; blocksIssued++)
260 aiocb& cb = controlBlockRingBuffer[blocksIssued];
263 cb.
aio_buf = (
volatile void*)(uintptr_t(op.
m_Buffer) + blocksIssued * p.blockSize);
264 if(blocksIssued == numBlocks-1)
272 aiocb& cb = controlBlockRingBuffer[blocksCompleted];
281 const off_t totalSize = p.blockSize? numBlocks*p.blockSize : op.
m_Size;
282 debug_printf(
"IO: %.2f MB/s (%.2f)\n", totalSize/(t1-t0)/1e6, (t1-t0)*1e3);
289template<
class CompletedHook>
307template<
class CompletedHook,
class IssueHook>
308static inline Status Store(
const OsPath& pathname,
const void* data,
size_t size,
const Parameters& p =
Parameters(),
const CompletedHook& completedHook = CompletedHook(),
const IssueHook& issueHook = IssueHook())
311 int oflag = O_WRONLY;
312 if(p.queueDepth != 1)
330template<
class CompletedHook>
346template<
class CompletedHook,
class IssueHook>
347static inline Status Load(
const OsPath& pathname,
void* buf,
size_t size,
const Parameters& p =
Parameters(),
const CompletedHook& completedHook = CompletedHook(),
const IssueHook& issueHook = IssueHook())
350 int oflag = O_RDONLY;
351 if(p.queueDepth != 1)
355 return io::Run(op, p, completedHook, issueHook);
358template<
class CompletedHook>
static const size_t KiB
Definition: alignment.h:106
static const size_t g_PageSize
Definition: alignment.h:93
static const size_t allocationAlignment
Definition: alignment.h:104
bool IsAligned(T t, uintptr_t multiple)
Definition: alignment.h:32
static const uintptr_t maxSectorSize
Definition: alignment.h:117
bool is_pow2(T n)
Definition: bits.h:164
T round_up(T n, T multiple)
round number up/down to the next given multiple.
Definition: bits.h:265
Status Open(const OsPath &pathName, int openFlag)
Definition: file.h:63
void Close()
Definition: file.h:73
INLINE aiocb & operator[](size_t counter)
Definition: io.h:216
ControlBlockRingBuffer(const Operation &op, const Parameters &p)
Definition: io.h:196
io::BufferPtr buffers
Definition: io.h:222
aiocb controlBlocks[Parameters::maxQueueDepth]
Definition: io.h:223
#define INLINE
Definition: code_annotation.h:377
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:58
#define ARRAY_SIZE(name)
Definition: code_annotation.h:350
#define COMPILER_FENCE
prevent the compiler from reordering loads or stores across this point.
Definition: code_annotation.h:283
void debug_printf(const char *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
Definition: debug.cpp:143
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:277
int wtruncate(const OsPath &pathname, off_t length)
Definition: ufilesystem.cpp:123
#define O_DIRECT
Definition: filesystem.h:67
T DivideRoundUp(T dividend, T divisor)
Definition: lib.h:68
const Status IO
Definition: io.h:42
const Status OK
Definition: status.h:388
Status WaitUntilComplete(aiocb &cb, size_t queueDepth)
Definition: io.cpp:67
std::unique_ptr< u8, FreeAligned > BufferPtr
Definition: io.h:52
static Status Store(const OsPath &pathname, const void *data, size_t size, const Parameters &p=Parameters(), const CompletedHook &completedHook=CompletedHook(), const IssueHook &issueHook=IssueHook())
Definition: io.h:308
static Status Load(const OsPath &pathname, void *buf, size_t size, const Parameters &p=Parameters(), const CompletedHook &completedHook=CompletedHook(), const IssueHook &issueHook=IssueHook())
Definition: io.h:347
static io::BufferPtr Allocate(size_t size, size_t alignment=maxSectorSize)
Definition: io.h:60
static Status Run(const Operation &op, const Parameters &p=Parameters(), const CompletedHook &completedHook=CompletedHook(), const IssueHook &issueHook=IssueHook())
Definition: io.h:243
Status Issue(aiocb &cb, size_t queueDepth)
Definition: io.cpp:39
void rtl_FreeAligned(void *alignedPointer)
Definition: gcc.cpp:93
void * rtl_AllocateAligned(size_t size, size_t alignment)
Definition: gcc.cpp:66
#define RETURN_STATUS_IF_ERR(expression)
Definition: status.h:278
#define RETURN_STATUS_FROM_CALLBACK(expression)
Definition: status.h:340
i64 Status
Error handling system.
Definition: status.h:173
off_t aio_offset
Definition: waio.h:66
volatile void * aio_buf
Definition: waio.h:67
size_t aio_nbytes
Definition: waio.h:68
int aio_lio_opcode
Definition: waio.h:71
int aio_fildes
Definition: waio.h:65
Status operator()(const u8 *block, size_t blockSize) const
called after a block I/O has completed.
Definition: io.h:168
Status operator()(aiocb &cb) const
called before a block I/O is issued.
Definition: io.h:184
void operator()(void *pointer)
Definition: io.h:49
void Validate() const
Definition: io.h:86
int m_OpenFlag
Definition: io.h:97
int m_FileDescriptor
Definition: io.h:96
off_t m_Offset
Definition: io.h:99
void * m_Buffer
Definition: io.h:101
off_t m_Size
Definition: io.h:100
Operation(const File &file, void *buf, off_t size, off_t offset=0)
Definition: io.h:80
Parameters(OverlappedTag)
Definition: io.h:118
static const size_t maxQueueDepth
Definition: io.h:147
size_t blockSize
Definition: io.h:151
Parameters()
Definition: io.h:109
off_t alignment
Definition: io.h:149
Parameters(size_t blockSize, size_t queueDepth, off_t alignment=maxSectorSize)
Definition: io.h:123
size_t queueDepth
Definition: io.h:153
void Validate(const Operation &op) const
Definition: io.h:128
double timer_Time()
Definition: timer.cpp:130
uint8_t u8
Definition: types.h:37
Status waio_Preallocate(int fd, off_t size)
Definition: waio.cpp:437
@ LIO_WRITE
Definition: waio.h:93
@ LIO_READ
Definition: waio.h:92
__int64 off_t
Definition: wposix_types.h:91