source: libcfa/src/concurrency/io.cfa@ 0521a1a

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since 0521a1a was 78a580d, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

I/O now updates the timestamps when draining.
Timestamps are not used yet.

  • Property mode set to 100644
File size: 17.6 KB
RevLine 
[ecf6b46]1//
2// Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// io.cfa --
8//
9// Author : Thierry Delisle
10// Created On : Thu Apr 23 17:31:00 2020
11// Last Modified By :
12// Last Modified On :
13// Update Count :
14//
15
[3e2b9c9]16#define __cforall_thread__
[43784ac]17#define _GNU_SOURCE
[3e2b9c9]18
[20ab637]19#if defined(__CFA_DEBUG__)
[d60d30e]20 // #define __CFA_DEBUG_PRINT_IO__
21 // #define __CFA_DEBUG_PRINT_IO_CORE__
[20ab637]22#endif
[4069faad]23
[f6660520]24
[3e2b9c9]25#if defined(CFA_HAVE_LINUX_IO_URING_H)
[31bb2e1]26 #include <errno.h>
[3e2b9c9]27 #include <signal.h>
[31bb2e1]28 #include <stdint.h>
29 #include <string.h>
30 #include <unistd.h>
31
[92976d9]32 extern "C" {
33 #include <sys/syscall.h>
[dddb3dd0]34 #include <sys/eventfd.h>
[d3605f8]35 #include <sys/uio.h>
[92976d9]36
37 #include <linux/io_uring.h>
38 }
39
[3e2b9c9]40 #include "stats.hfa"
41 #include "kernel.hfa"
42 #include "kernel/fwd.hfa"
[708ae38]43 #include "kernel/private.hfa"
[78a580d]44 #include "kernel/cluster.hfa"
[3e2b9c9]45 #include "io/types.hfa"
[185efe6]46
[2fab24e3]47 __attribute__((unused)) static const char * opcodes[] = {
[426f60c]48 "OP_NOP",
49 "OP_READV",
50 "OP_WRITEV",
51 "OP_FSYNC",
52 "OP_READ_FIXED",
53 "OP_WRITE_FIXED",
54 "OP_POLL_ADD",
55 "OP_POLL_REMOVE",
56 "OP_SYNC_FILE_RANGE",
57 "OP_SENDMSG",
58 "OP_RECVMSG",
59 "OP_TIMEOUT",
60 "OP_TIMEOUT_REMOVE",
61 "OP_ACCEPT",
62 "OP_ASYNC_CANCEL",
63 "OP_LINK_TIMEOUT",
64 "OP_CONNECT",
65 "OP_FALLOCATE",
66 "OP_OPENAT",
67 "OP_CLOSE",
68 "OP_FILES_UPDATE",
69 "OP_STATX",
70 "OP_READ",
71 "OP_WRITE",
72 "OP_FADVISE",
73 "OP_MADVISE",
74 "OP_SEND",
75 "OP_RECV",
76 "OP_OPENAT2",
77 "OP_EPOLL_CTL",
78 "OP_SPLICE",
79 "OP_PROVIDE_BUFFERS",
80 "OP_REMOVE_BUFFERS",
81 "OP_TEE",
82 "INVALID_OP"
83 };
84
[11054eb]85 static $io_context * __ioarbiter_allocate( $io_arbiter & this, __u32 idxs[], __u32 want );
86 static void __ioarbiter_submit( $io_context * , __u32 idxs[], __u32 have, bool lazy );
87 static void __ioarbiter_flush ( $io_context & );
[dddb3dd0]88 static inline void __ioarbiter_notify( $io_context & ctx );
[92976d9]89//=============================================================================================
90// I/O Polling
91//=============================================================================================
[78da4ab]92 static inline unsigned __flush( struct $io_context & );
93 static inline __u32 __release_sqes( struct $io_context & );
[24e321c]94 extern void __kernel_unpark( thread$ * thrd, unpark_hint );
[1d5e4711]95
[78a580d]96 bool __cfa_io_drain( $io_context * ctx, cluster * cltr ) {
[dddb3dd0]97 /* paranoid */ verify( ! __preemption_enabled() );
[e9c0b4c]98 /* paranoid */ verify( ready_schedule_islocked() );
[4ecc35a]99 /* paranoid */ verify( ctx );
[6f121b8]100
[d384787]101 // Drain the queue
[dddb3dd0]102 unsigned head = *ctx->cq.head;
103 unsigned tail = *ctx->cq.tail;
104 const __u32 mask = *ctx->cq.mask;
[92976d9]105
[4998155]106 __u32 count = tail - head;
[dddb3dd0]107 __STATS__( false, io.calls.drain++; io.calls.completed += count; )
[d60d30e]108
[c1c95b1]109 if(count == 0) return false;
110
[4ecc35a]111 if(!__atomic_try_acquire(&ctx->cq.lock)) {
112 return false;
113 }
114
[78a580d]115 unsigned long long ts_prev = ctx->cq.ts;
116
[d384787]117 for(i; count) {
[6f121b8]118 unsigned idx = (head + i) & mask;
[dddb3dd0]119 volatile struct io_uring_cqe & cqe = ctx->cq.cqes[idx];
[92976d9]120
[d384787]121 /* paranoid */ verify(&cqe);
[92976d9]122
[78da4ab]123 struct io_future_t * future = (struct io_future_t *)(uintptr_t)cqe.user_data;
124 __cfadbg_print_safe( io, "Kernel I/O : Syscall completed : cqe %p, result %d for %p\n", &cqe, cqe.res, future );
125
[24e321c]126 __kernel_unpark( fulfil( *future, cqe.res, false ), UNPARK_LOCAL );
[78da4ab]127 }
128
[dddb3dd0]129 __cfadbg_print_safe(io, "Kernel I/O : %u completed\n", count);
[78a580d]130 unsigned long long ts_next = ctx->cq.ts = rdtscl();
[2d8f7b0]131
[92976d9]132 // Mark to the kernel that the cqe has been seen
133 // Ensure that the kernel only sees the new value of the head index after the CQEs have been read.
[dddb3dd0]134 __atomic_store_n( ctx->cq.head, head + count, __ATOMIC_SEQ_CST );
[92976d9]135
[e9c0b4c]136 /* paranoid */ verify( ready_schedule_islocked() );
[dddb3dd0]137 /* paranoid */ verify( ! __preemption_enabled() );
138
[4ecc35a]139 __atomic_unlock(&ctx->cq.lock);
140
[78a580d]141 touch_tsc( cltr->sched.io.tscs, ctx->cq.id, ts_prev, ts_next );
142
[c1c95b1]143 return true;
[92976d9]144 }
145
[c7b2215]146 bool __cfa_io_flush( processor * proc, int min_comp ) {
[dddb3dd0]147 /* paranoid */ verify( ! __preemption_enabled() );
148 /* paranoid */ verify( proc );
149 /* paranoid */ verify( proc->io.ctx );
[1539bbd]150
[78a580d]151 cluster * cltr = proc->cltr;
[dddb3dd0]152 $io_context & ctx = *proc->io.ctx;
[78da4ab]153
[11054eb]154 __ioarbiter_flush( ctx );
[3c039b0]155
[21a5bfb7]156 if(ctx.sq.to_submit != 0 || min_comp > 0) {
157
158 __STATS__( true, io.calls.flush++; )
159 int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
160 if( ret < 0 ) {
161 switch((int)errno) {
162 case EAGAIN:
163 case EINTR:
164 case EBUSY:
165 // Update statistics
166 __STATS__( false, io.calls.errors.busy ++; )
167 return false;
168 default:
169 abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
170 }
[61dd73d]171 }
[ece0e80]172
[21a5bfb7]173 __cfadbg_print_safe(io, "Kernel I/O : %u submitted to io_uring %d\n", ret, ctx.fd);
174 __STATS__( true, io.calls.submitted += ret; )
175 /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
176 /* paranoid */ verify( ctx.sq.to_submit >= ret );
[dddb3dd0]177
[21a5bfb7]178 ctx.sq.to_submit -= ret;
[ece0e80]179
[21a5bfb7]180 /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
[5dadc9b7]181
[21a5bfb7]182 // Release the consumed SQEs
183 __release_sqes( ctx );
[ece0e80]184
[21a5bfb7]185 /* paranoid */ verify( ! __preemption_enabled() );
186
[d529ad0]187 __atomic_store_n(&ctx.proc->io.pending, false, __ATOMIC_RELAXED);
[21a5bfb7]188 }
[61dd73d]189
[7ef162b2]190 ready_schedule_lock();
[78a580d]191 bool ret = __cfa_io_drain( &ctx, cltr );
[7ef162b2]192 ready_schedule_unlock();
193 return ret;
[61dd73d]194 }
[f6660520]195
[92976d9]196//=============================================================================================
197// I/O Submissions
198//=============================================================================================
199
[2d8f7b0]200// Submition steps :
[e46c753]201// 1 - Allocate a queue entry. The ring already has memory for all entries but only the ones
[2d8f7b0]202// listed in sq.array are visible by the kernel. For those not listed, the kernel does not
203// offer any assurance that an entry is not being filled by multiple flags. Therefore, we
204// need to write an allocator that allows allocating concurrently.
205//
[e46c753]206// 2 - Actually fill the submit entry, this is the only simple and straightforward step.
[2d8f7b0]207//
[e46c753]208// 3 - Append the entry index to the array and adjust the tail accordingly. This operation
[2d8f7b0]209// needs to arrive to two concensus at the same time:
210// A - The order in which entries are listed in the array: no two threads must pick the
211// same index for their entries
212// B - When can the tail be update for the kernel. EVERY entries in the array between
213// head and tail must be fully filled and shouldn't ever be touched again.
214//
[78da4ab]215 //=============================================================================================
216 // Allocation
217 // for user's convenience fill the sqes from the indexes
218 static inline void __fill(struct io_uring_sqe * out_sqes[], __u32 want, __u32 idxs[], struct $io_context * ctx) {
219 struct io_uring_sqe * sqes = ctx->sq.sqes;
220 for(i; want) {
[dddb3dd0]221 __cfadbg_print_safe(io, "Kernel I/O : filling loop\n");
[78da4ab]222 out_sqes[i] = &sqes[idxs[i]];
223 }
224 }
[2489d31]225
[78da4ab]226 // Try to directly allocate from the a given context
227 // Not thread-safe
228 static inline bool __alloc(struct $io_context * ctx, __u32 idxs[], __u32 want) {
229 __sub_ring_t & sq = ctx->sq;
230 const __u32 mask = *sq.mask;
231 __u32 fhead = sq.free_ring.head; // get the current head of the queue
232 __u32 ftail = sq.free_ring.tail; // get the current tail of the queue
[2489d31]233
[78da4ab]234 // If we don't have enough sqes, fail
235 if((ftail - fhead) < want) { return false; }
[426f60c]236
[78da4ab]237 // copy all the indexes we want from the available list
238 for(i; want) {
[dddb3dd0]239 __cfadbg_print_safe(io, "Kernel I/O : allocating loop\n");
[78da4ab]240 idxs[i] = sq.free_ring.array[(fhead + i) & mask];
[6f121b8]241 }
[2489d31]242
[78da4ab]243 // Advance the head to mark the indexes as consumed
244 __atomic_store_n(&sq.free_ring.head, fhead + want, __ATOMIC_RELEASE);
[df40a56]245
[78da4ab]246 // return success
247 return true;
248 }
[df40a56]249
[78da4ab]250 // Allocate an submit queue entry.
251 // The kernel cannot see these entries until they are submitted, but other threads must be
252 // able to see which entries can be used and which are already un used by an other thread
253 // for convenience, return both the index and the pointer to the sqe
254 // sqe == &sqes[idx]
255 struct $io_context * cfa_io_allocate(struct io_uring_sqe * sqes[], __u32 idxs[], __u32 want) {
256 __cfadbg_print_safe(io, "Kernel I/O : attempting to allocate %u\n", want);
[df40a56]257
[78da4ab]258 disable_interrupts();
259 processor * proc = __cfaabi_tls.this_processor;
[dddb3dd0]260 $io_context * ctx = proc->io.ctx;
[78da4ab]261 /* paranoid */ verify( __cfaabi_tls.this_processor );
[dddb3dd0]262 /* paranoid */ verify( ctx );
[78da4ab]263
[dddb3dd0]264 __cfadbg_print_safe(io, "Kernel I/O : attempting to fast allocation\n");
[78da4ab]265
[dddb3dd0]266 // We can proceed to the fast path
267 if( __alloc(ctx, idxs, want) ) {
268 // Allocation was successful
269 __STATS__( true, io.alloc.fast += 1; )
[a3821fa]270 enable_interrupts();
[df40a56]271
[dddb3dd0]272 __cfadbg_print_safe(io, "Kernel I/O : fast allocation successful from ring %d\n", ctx->fd);
[2fafe7e]273
[dddb3dd0]274 __fill( sqes, want, idxs, ctx );
275 return ctx;
[df40a56]276 }
[dddb3dd0]277 // The fast path failed, fallback
278 __STATS__( true, io.alloc.fail += 1; )
[df40a56]279
[78da4ab]280 // Fast path failed, fallback on arbitration
[d60d30e]281 __STATS__( true, io.alloc.slow += 1; )
[a3821fa]282 enable_interrupts();
[78da4ab]283
[dddb3dd0]284 $io_arbiter * ioarb = proc->cltr->io.arbiter;
285 /* paranoid */ verify( ioarb );
286
[78da4ab]287 __cfadbg_print_safe(io, "Kernel I/O : falling back on arbiter for allocation\n");
288
[11054eb]289 struct $io_context * ret = __ioarbiter_allocate(*ioarb, idxs, want);
[78da4ab]290
[dddb3dd0]291 __cfadbg_print_safe(io, "Kernel I/O : slow allocation completed from ring %d\n", ret->fd);
[df40a56]292
[78da4ab]293 __fill( sqes, want, idxs,ret );
294 return ret;
[df40a56]295 }
296
[78da4ab]297 //=============================================================================================
298 // submission
[2432e8e]299 static inline void __submit_only( struct $io_context * ctx, __u32 idxs[], __u32 have) {
[78da4ab]300 // We can proceed to the fast path
301 // Get the right objects
302 __sub_ring_t & sq = ctx->sq;
303 const __u32 mask = *sq.mask;
[dddb3dd0]304 __u32 tail = *sq.kring.tail;
[78da4ab]305
306 // Add the sqes to the array
307 for( i; have ) {
[dddb3dd0]308 __cfadbg_print_safe(io, "Kernel I/O : __submit loop\n");
[78da4ab]309 sq.kring.array[ (tail + i) & mask ] = idxs[i];
[426f60c]310 }
311
[78da4ab]312 // Make the sqes visible to the submitter
[dddb3dd0]313 __atomic_store_n(sq.kring.tail, tail + have, __ATOMIC_RELEASE);
[e8ac228]314 sq.to_submit += have;
[426f60c]315
[d529ad0]316 __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_RELAXED);
317 __atomic_store_n(&ctx->proc->io.dirty , true, __ATOMIC_RELAXED);
[2432e8e]318 }
319
320 static inline void __submit( struct $io_context * ctx, __u32 idxs[], __u32 have, bool lazy) {
321 __sub_ring_t & sq = ctx->sq;
322 __submit_only(ctx, idxs, have);
323
[70b4aeb9]324 if(sq.to_submit > 30) {
325 __tls_stats()->io.flush.full++;
326 __cfa_io_flush( ctx->proc, 0 );
327 }
328 if(!lazy) {
329 __tls_stats()->io.flush.eager++;
[c7b2215]330 __cfa_io_flush( ctx->proc, 0 );
[dddb3dd0]331 }
[78da4ab]332 }
[2489d31]333
[dddb3dd0]334 void cfa_io_submit( struct $io_context * inctx, __u32 idxs[], __u32 have, bool lazy ) __attribute__((nonnull (1))) {
335 __cfadbg_print_safe(io, "Kernel I/O : attempting to submit %u (%s)\n", have, lazy ? "lazy" : "eager");
[5dadc9b7]336
[78da4ab]337 disable_interrupts();
338 processor * proc = __cfaabi_tls.this_processor;
339 $io_context * ctx = proc->io.ctx;
[dddb3dd0]340 /* paranoid */ verify( __cfaabi_tls.this_processor );
341 /* paranoid */ verify( ctx );
[e46c753]342
[78da4ab]343 // Can we proceed to the fast path
[dddb3dd0]344 if( ctx == inctx ) // We have the right instance?
[78da4ab]345 {
[dddb3dd0]346 __submit(ctx, idxs, have, lazy);
[e46c753]347
[78da4ab]348 // Mark the instance as no longer in-use, re-enable interrupts and return
[d60d30e]349 __STATS__( true, io.submit.fast += 1; )
[a3821fa]350 enable_interrupts();
[ece0e80]351
[78da4ab]352 __cfadbg_print_safe(io, "Kernel I/O : submitted on fast path\n");
353 return;
[e46c753]354 }
[d384787]355
[78da4ab]356 // Fast path failed, fallback on arbitration
[d60d30e]357 __STATS__( true, io.submit.slow += 1; )
[a3821fa]358 enable_interrupts();
[5dadc9b7]359
[78da4ab]360 __cfadbg_print_safe(io, "Kernel I/O : falling back on arbiter for submission\n");
[426f60c]361
[11054eb]362 __ioarbiter_submit(inctx, idxs, have, lazy);
[78da4ab]363 }
[2fab24e3]364
[78da4ab]365 //=============================================================================================
366 // Flushing
[426f60c]367 // Go through the ring's submit queue and release everything that has already been consumed
368 // by io_uring
[78da4ab]369 // This cannot be done by multiple threads
370 static __u32 __release_sqes( struct $io_context & ctx ) {
371 const __u32 mask = *ctx.sq.mask;
[732b406]372
[426f60c]373 __attribute__((unused))
[78da4ab]374 __u32 ctail = *ctx.sq.kring.tail; // get the current tail of the queue
375 __u32 chead = *ctx.sq.kring.head; // get the current head of the queue
376 __u32 phead = ctx.sq.kring.released; // get the head the last time we were here
377
378 __u32 ftail = ctx.sq.free_ring.tail; // get the current tail of the queue
[732b406]379
[426f60c]380 // the 3 fields are organized like this diagram
381 // except it's are ring
382 // ---+--------+--------+----
383 // ---+--------+--------+----
384 // ^ ^ ^
385 // phead chead ctail
386
387 // make sure ctail doesn't wrap around and reach phead
388 /* paranoid */ verify(
389 (ctail >= chead && chead >= phead)
390 || (chead >= phead && phead >= ctail)
391 || (phead >= ctail && ctail >= chead)
392 );
393
394 // find the range we need to clear
[4998155]395 __u32 count = chead - phead;
[426f60c]396
[78da4ab]397 if(count == 0) {
398 return 0;
399 }
400
[426f60c]401 // We acquired an previous-head/current-head range
402 // go through the range and release the sqes
[34b61882]403 for( i; count ) {
[dddb3dd0]404 __cfadbg_print_safe(io, "Kernel I/O : release loop\n");
[78da4ab]405 __u32 idx = ctx.sq.kring.array[ (phead + i) & mask ];
406 ctx.sq.free_ring.array[ (ftail + i) & mask ] = idx;
[34b61882]407 }
[78da4ab]408
409 ctx.sq.kring.released = chead; // note up to were we processed
410 __atomic_store_n(&ctx.sq.free_ring.tail, ftail + count, __ATOMIC_SEQ_CST);
411
412 __ioarbiter_notify(ctx);
413
[34b61882]414 return count;
415 }
[35285fd]416
[78da4ab]417//=============================================================================================
418// I/O Arbiter
419//=============================================================================================
[9f5a71eb]420 static inline bool enqueue(__outstanding_io_queue & queue, __outstanding_io & item) {
421 bool was_empty;
422
[11054eb]423 // Lock the list, it's not thread safe
424 lock( queue.lock __cfaabi_dbg_ctx2 );
425 {
[9f5a71eb]426 was_empty = empty(queue.queue);
427
[11054eb]428 // Add our request to the list
429 add( queue.queue, item );
430
431 // Mark as pending
432 __atomic_store_n( &queue.empty, false, __ATOMIC_SEQ_CST );
433 }
434 unlock( queue.lock );
435
[9f5a71eb]436 return was_empty;
[11054eb]437 }
438
439 static inline bool empty(__outstanding_io_queue & queue ) {
440 return __atomic_load_n( &queue.empty, __ATOMIC_SEQ_CST);
441 }
442
443 static $io_context * __ioarbiter_allocate( $io_arbiter & this, __u32 idxs[], __u32 want ) {
[78da4ab]444 __cfadbg_print_safe(io, "Kernel I/O : arbiter allocating\n");
445
[d60d30e]446 __STATS__( false, io.alloc.block += 1; )
447
[78da4ab]448 // No one has any resources left, wait for something to finish
[11054eb]449 // We need to add ourself to a list of pending allocs and wait for an answer
450 __pending_alloc pa;
451 pa.idxs = idxs;
452 pa.want = want;
[78da4ab]453
[9f5a71eb]454 enqueue(this.pending, (__outstanding_io&)pa);
455
456 wait( pa.sem );
[78da4ab]457
[11054eb]458 return pa.ctx;
[dddb3dd0]459
[78da4ab]460 }
461
[11054eb]462 static void __ioarbiter_notify( $io_arbiter & this, $io_context * ctx ) {
463 /* paranoid */ verify( !empty(this.pending.queue) );
[78da4ab]464
[11054eb]465 lock( this.pending.lock __cfaabi_dbg_ctx2 );
466 {
467 while( !empty(this.pending.queue) ) {
468 __cfadbg_print_safe(io, "Kernel I/O : notifying\n");
469 __u32 have = ctx->sq.free_ring.tail - ctx->sq.free_ring.head;
470 __pending_alloc & pa = (__pending_alloc&)head( this.pending.queue );
[78da4ab]471
[11054eb]472 if( have > pa.want ) goto DONE;
473 drop( this.pending.queue );
[78da4ab]474
[11054eb]475 /* paranoid */__attribute__((unused)) bool ret =
[78da4ab]476
[11054eb]477 __alloc(ctx, pa.idxs, pa.want);
478
479 /* paranoid */ verify( ret );
480
481 pa.ctx = ctx;
482
483 post( pa.sem );
484 }
485
486 this.pending.empty = true;
487 DONE:;
488 }
489 unlock( this.pending.lock );
[78da4ab]490 }
491
492 static void __ioarbiter_notify( $io_context & ctx ) {
[11054eb]493 if(!empty( ctx.arbiter->pending )) {
[78da4ab]494 __ioarbiter_notify( *ctx.arbiter, &ctx );
495 }
496 }
497
498 // Simply append to the pending
[11054eb]499 static void __ioarbiter_submit( $io_context * ctx, __u32 idxs[], __u32 have, bool lazy ) {
[78da4ab]500 __cfadbg_print_safe(io, "Kernel I/O : submitting %u from the arbiter to context %u\n", have, ctx->fd);
501
502 __cfadbg_print_safe(io, "Kernel I/O : waiting to submit %u\n", have);
503
[11054eb]504 __external_io ei;
505 ei.idxs = idxs;
506 ei.have = have;
507 ei.lazy = lazy;
[78da4ab]508
[9f5a71eb]509 bool we = enqueue(ctx->ext_sq, (__outstanding_io&)ei);
510
[d529ad0]511 __atomic_store_n(&ctx->proc->io.pending, true, __ATOMIC_SEQ_CST);
[9f5a71eb]512
513 if( we ) {
514 sigval_t value = { PREEMPT_IO };
515 pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
516 }
517
518 wait( ei.sem );
[78da4ab]519
520 __cfadbg_print_safe(io, "Kernel I/O : %u submitted from arbiter\n", have);
521 }
522
[11054eb]523 static void __ioarbiter_flush( $io_context & ctx ) {
524 if(!empty( ctx.ext_sq )) {
525 __STATS__( false, io.flush.external += 1; )
[78da4ab]526
[11054eb]527 __cfadbg_print_safe(io, "Kernel I/O : arbiter flushing\n");
[d60d30e]528
[11054eb]529 lock( ctx.ext_sq.lock __cfaabi_dbg_ctx2 );
530 {
531 while( !empty(ctx.ext_sq.queue) ) {
532 __external_io & ei = (__external_io&)drop( ctx.ext_sq.queue );
[78da4ab]533
[2432e8e]534 __submit_only(&ctx, ei.idxs, ei.have);
[78da4ab]535
[11054eb]536 post( ei.sem );
537 }
538
539 ctx.ext_sq.empty = true;
540 }
541 unlock(ctx.ext_sq.lock );
542 }
[78da4ab]543 }
[7ef162b2]544
[d3605f8]545 #if defined(CFA_WITH_IO_URING_IDLE)
546 bool __kernel_read(processor * proc, io_future_t & future, iovec & iov, int fd) {
[6ddef36]547 $io_context * ctx = proc->io.ctx;
548 /* paranoid */ verify( ! __preemption_enabled() );
549 /* paranoid */ verify( proc == __cfaabi_tls.this_processor );
550 /* paranoid */ verify( ctx );
[7ef162b2]551
[6ddef36]552 __u32 idx;
553 struct io_uring_sqe * sqe;
[7ef162b2]554
[6ddef36]555 // We can proceed to the fast path
556 if( !__alloc(ctx, &idx, 1) ) return false;
557
558 // Allocation was successful
559 __fill( &sqe, 1, &idx, ctx );
560
561 sqe->user_data = (uintptr_t)&future;
562 sqe->flags = 0;
[a1f3d93]563 sqe->fd = fd;
[6ddef36]564 sqe->off = 0;
[d3605f8]565 sqe->ioprio = 0;
[6ddef36]566 sqe->fsync_flags = 0;
567 sqe->__pad2[0] = 0;
568 sqe->__pad2[1] = 0;
569 sqe->__pad2[2] = 0;
[d3605f8]570
571 #if defined(CFA_HAVE_IORING_OP_READ)
572 sqe->opcode = IORING_OP_READ;
573 sqe->addr = (uint64_t)iov.iov_base;
574 sqe->len = iov.iov_len;
575 #elif defined(CFA_HAVE_READV) && defined(CFA_HAVE_IORING_OP_READV)
576 sqe->opcode = IORING_OP_READV;
577 sqe->addr = (uintptr_t)&iov;
578 sqe->len = 1;
579 #else
580 #error CFA_WITH_IO_URING_IDLE but none of CFA_HAVE_READV, CFA_HAVE_IORING_OP_READV or CFA_HAVE_IORING_OP_READ defined
581 #endif
[6ddef36]582
583 asm volatile("": : :"memory");
584
585 /* paranoid */ verify( sqe->user_data == (uintptr_t)&future );
586 __submit( ctx, &idx, 1, true );
587
588 /* paranoid */ verify( proc == __cfaabi_tls.this_processor );
589 /* paranoid */ verify( ! __preemption_enabled() );
[078fb05]590
591 return true;
[6ddef36]592 }
593 #endif
[47746a2]594#endif
Note: See TracBrowser for help on using the repository browser.