Project reordering and mpmc code
This commit is contained in:
29
platform.c
29
platform.c
@@ -1,5 +1,5 @@
|
||||
#pragma once // ensure that a given header file is included only once in a
|
||||
// single compilation unit
|
||||
#pragma once
|
||||
|
||||
#include "arena.h"
|
||||
#include "base.h"
|
||||
#include "lf_mpmc.h"
|
||||
@@ -1296,10 +1296,10 @@ static BUILD_READ_RETURN_VALUE ioring_build_read(ThreadIoContext *thread_ctx,
|
||||
}
|
||||
|
||||
static void ioring_process_completions(ThreadIoContext *thread_ctx) {
|
||||
uint32_t waited = 0;
|
||||
uint32_t target = MIN(thread_ctx->num_submissions, MAX_WAIT_COUNT);
|
||||
uint32_t cqe_count = 0;
|
||||
uint32_t wait_count = MIN(thread_ctx->num_submissions, MAX_WAIT_COUNT);
|
||||
|
||||
while (waited < target) {
|
||||
while (cqe_count < wait_count) {
|
||||
|
||||
// ---- Drain all available CQEs (non-blocking) ----
|
||||
while (1) {
|
||||
@@ -1307,7 +1307,7 @@ static void ioring_process_completions(ThreadIoContext *thread_ctx) {
|
||||
|
||||
HRESULT hr = PopIoRingCompletion(thread_ctx->ring, &win_cqe);
|
||||
|
||||
if (hr == S_FALSE) {
|
||||
if (hr != S_OK) {
|
||||
// No more CQEs available right now
|
||||
break;
|
||||
}
|
||||
@@ -1347,12 +1347,11 @@ static void ioring_process_completions(ThreadIoContext *thread_ctx) {
|
||||
file->reads_completed++;
|
||||
thread_ctx->num_submissions--;
|
||||
|
||||
// Count only "real" completions toward wait budget
|
||||
waited++;
|
||||
cqe_count++;
|
||||
}
|
||||
|
||||
// ---- If we already waited enough, exit ----
|
||||
if (waited >= target) {
|
||||
if (cqe_count >= wait_count) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1575,18 +1574,16 @@ static int ioring_submit(ThreadIoContext *thread_ctx, uint32_t *submitted) {
|
||||
}
|
||||
|
||||
static void ioring_process_completions(ThreadIoContext *thread_ctx) {
|
||||
IoUring *impl = (IoUring *)thread_ctx->ring;
|
||||
|
||||
struct io_uring_cqe *cqes[NUM_BUFFERS_PER_THREAD];
|
||||
|
||||
unsigned count =
|
||||
io_uring_peek_batch_cqe(&impl->ring, cqes, NUM_BUFFERS_PER_THREAD);
|
||||
unsigned cqe_count = io_uring_peek_batch_cqe(&((IoUring *)thread_ctx->ring)->ring,
|
||||
cqes, NUM_BUFFERS_PER_THREAD);
|
||||
|
||||
if (count == 0) {
|
||||
if (cqe_count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
for (unsigned i = 0; i < cqe_count; i++) {
|
||||
struct io_uring_cqe *cqe = cqes[i];
|
||||
|
||||
int res = cqe->res;
|
||||
@@ -1613,7 +1610,7 @@ static void ioring_process_completions(ThreadIoContext *thread_ctx) {
|
||||
}
|
||||
|
||||
// Mark CQE as seen, equivalent to io_uring_cqe_seen() but marks multiple CQEs
|
||||
io_uring_cq_advance(&impl->ring, count);
|
||||
io_uring_cq_advance(&((IoUring *)thread_ctx->ring)->ring, cqe_count);
|
||||
}
|
||||
|
||||
FileHandle ioring_open_file(FileEntry *fe) {
|
||||
|
||||
Reference in New Issue
Block a user