source: libcfa/src/concurrency/io.cfa@ 13c5e19

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum stuck-waitfor-destruct
Last change on this file since 13c5e19 was 13c5e19, checked in by Thierry Delisle <tdelisle@…>, 6 years ago
  • Moved snzi and subqueues outside of ready_queue.cfa.
  • Added random.hfa with multiple prng.
  • Minor optimizations to ready-queue
  • Stats now track number of local pops( bias pops )
  • Fixed stats for io
  • Fixed calculaton of nprocessors
  • Fixed IO to work with new ready-queue
  • Property mode set to 100644
File size: 37.1 KB
Line 
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
16// #define __CFA_DEBUG_PRINT_IO__
17// #define __CFA_DEBUG_PRINT_IO_CORE__
18
19#include "kernel.hfa"
20#include "bitmanip.hfa"
21
22#if !defined(HAVE_LINUX_IO_URING_H)
23 void __kernel_io_startup( cluster &, unsigned, bool ) {
24 // Nothing to do without io_uring
25 }
26
27 void __kernel_io_finish_start( cluster & ) {
28 // Nothing to do without io_uring
29 }
30
31 void __kernel_io_prepare_stop( cluster & ) {
32 // Nothing to do without io_uring
33 }
34
35 void __kernel_io_shutdown( cluster &, bool ) {
36 // Nothing to do without io_uring
37 }
38
39#else
40 extern "C" {
41 #define _GNU_SOURCE /* See feature_test_macros(7) */
42 #include <errno.h>
43 #include <stdint.h>
44 #include <string.h>
45 #include <unistd.h>
46 #include <sys/mman.h>
47 #include <sys/syscall.h>
48
49 #include <linux/io_uring.h>
50 }
51
52 #include "bits/signal.hfa"
53 #include "kernel_private.hfa"
54 #include "thread.hfa"
55
56 uint32_t entries_per_cluster() {
57 return 256;
58 }
59
60 static void * __io_poller_slow( void * arg );
61
62 // Weirdly, some systems that do support io_uring don't actually define these
63 #ifdef __alpha__
64 /*
65 * alpha is the only exception, all other architectures
66 * have common numbers for new system calls.
67 */
68 #ifndef __NR_io_uring_setup
69 #define __NR_io_uring_setup 535
70 #endif
71 #ifndef __NR_io_uring_enter
72 #define __NR_io_uring_enter 536
73 #endif
74 #ifndef __NR_io_uring_register
75 #define __NR_io_uring_register 537
76 #endif
77 #else /* !__alpha__ */
78 #ifndef __NR_io_uring_setup
79 #define __NR_io_uring_setup 425
80 #endif
81 #ifndef __NR_io_uring_enter
82 #define __NR_io_uring_enter 426
83 #endif
84 #ifndef __NR_io_uring_register
85 #define __NR_io_uring_register 427
86 #endif
87 #endif
88
89 // Fast poller user-thread
90 // Not using the "thread" keyword because we want to control
91 // more carefully when to start/stop it
92 struct __io_poller_fast {
93 struct __io_data * ring;
94 $thread thrd;
95 };
96
97 void ?{}( __io_poller_fast & this, struct cluster & cltr ) {
98 this.ring = cltr.io;
99 (this.thrd){ "Fast I/O Poller", cltr };
100 }
101 void ^?{}( __io_poller_fast & mutex this );
102 void main( __io_poller_fast & this );
103 static inline $thread * get_thread( __io_poller_fast & this ) { return &this.thrd; }
104 void ^?{}( __io_poller_fast & mutex this ) {}
105
106 struct __submition_data {
107 // Head and tail of the ring (associated with array)
108 volatile uint32_t * head;
109 volatile uint32_t * tail;
110
111 // The actual kernel ring which uses head/tail
112 // indexes into the sqes arrays
113 uint32_t * array;
114
115 // number of entries and mask to go with it
116 const uint32_t * num;
117 const uint32_t * mask;
118
119 // Submission flags (Not sure what for)
120 uint32_t * flags;
121
122 // number of sqes not submitted (whatever that means)
123 uint32_t * dropped;
124
125 // Like head/tail but not seen by the kernel
126 volatile uint32_t * ready;
127 uint32_t ready_cnt;
128
129 __spinlock_t lock;
130
131 // A buffer of sqes (not the actual ring)
132 struct io_uring_sqe * sqes;
133
134 // The location and size of the mmaped area
135 void * ring_ptr;
136 size_t ring_sz;
137 };
138
139 struct __completion_data {
140 // Head and tail of the ring
141 volatile uint32_t * head;
142 volatile uint32_t * tail;
143
144 // number of entries and mask to go with it
145 const uint32_t * mask;
146 const uint32_t * num;
147
148 // number of cqes not submitted (whatever that means)
149 uint32_t * overflow;
150
151 // the kernel ring
152 struct io_uring_cqe * cqes;
153
154 // The location and size of the mmaped area
155 void * ring_ptr;
156 size_t ring_sz;
157 };
158
159 struct __io_data {
160 struct __submition_data submit_q;
161 struct __completion_data completion_q;
162 uint32_t ring_flags;
163 int cltr_flags;
164 int fd;
165 semaphore submit;
166 volatile bool done;
167 struct {
168 struct {
169 __processor_id_t id;
170 void * stack;
171 pthread_t kthrd;
172 volatile bool blocked;
173 } slow;
174 __io_poller_fast fast;
175 __bin_sem_t sem;
176 } poller;
177 };
178
179//=============================================================================================
180// I/O Startup / Shutdown logic
181//=============================================================================================
182 void __kernel_io_startup( cluster & this, unsigned io_flags, bool main_cluster ) {
183 this.io = malloc();
184
185 // Step 1 : call to setup
186 struct io_uring_params params;
187 memset(&params, 0, sizeof(params));
188
189 uint32_t nentries = entries_per_cluster();
190
191 int fd = syscall(__NR_io_uring_setup, nentries, &params );
192 if(fd < 0) {
193 abort("KERNEL ERROR: IO_URING SETUP - %s\n", strerror(errno));
194 }
195
196 // Step 2 : mmap result
197 memset( this.io, 0, sizeof(struct __io_data) );
198 struct __submition_data & sq = this.io->submit_q;
199 struct __completion_data & cq = this.io->completion_q;
200
201 // calculate the right ring size
202 sq.ring_sz = params.sq_off.array + (params.sq_entries * sizeof(unsigned) );
203 cq.ring_sz = params.cq_off.cqes + (params.cq_entries * sizeof(struct io_uring_cqe));
204
205 // Requires features
206 #if defined(IORING_FEAT_SINGLE_MMAP)
207 // adjust the size according to the parameters
208 if ((params.features & IORING_FEAT_SINGLE_MMAP) != 0) {
209 cq->ring_sz = sq->ring_sz = max(cq->ring_sz, sq->ring_sz);
210 }
211 #endif
212
213 // mmap the Submit Queue into existence
214 sq.ring_ptr = mmap(0, sq.ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQ_RING);
215 if (sq.ring_ptr == (void*)MAP_FAILED) {
216 abort("KERNEL ERROR: IO_URING MMAP1 - %s\n", strerror(errno));
217 }
218
219 // Requires features
220 #if defined(IORING_FEAT_SINGLE_MMAP)
221 // mmap the Completion Queue into existence (may or may not be needed)
222 if ((params.features & IORING_FEAT_SINGLE_MMAP) != 0) {
223 cq->ring_ptr = sq->ring_ptr;
224 }
225 else
226 #endif
227 {
228 // We need multiple call to MMAP
229 cq.ring_ptr = mmap(0, cq.ring_sz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_CQ_RING);
230 if (cq.ring_ptr == (void*)MAP_FAILED) {
231 munmap(sq.ring_ptr, sq.ring_sz);
232 abort("KERNEL ERROR: IO_URING MMAP2 - %s\n", strerror(errno));
233 }
234 }
235
236 // mmap the submit queue entries
237 size_t size = params.sq_entries * sizeof(struct io_uring_sqe);
238 sq.sqes = (struct io_uring_sqe *)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, IORING_OFF_SQES);
239 if (sq.sqes == (struct io_uring_sqe *)MAP_FAILED) {
240 munmap(sq.ring_ptr, sq.ring_sz);
241 if (cq.ring_ptr != sq.ring_ptr) munmap(cq.ring_ptr, cq.ring_sz);
242 abort("KERNEL ERROR: IO_URING MMAP3 - %s\n", strerror(errno));
243 }
244
245 // Get the pointers from the kernel to fill the structure
246 // submit queue
247 sq.head = (volatile uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.head);
248 sq.tail = (volatile uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.tail);
249 sq.mask = ( const uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_mask);
250 sq.num = ( const uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.ring_entries);
251 sq.flags = ( uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.flags);
252 sq.dropped = ( uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.dropped);
253 sq.array = ( uint32_t *)(((intptr_t)sq.ring_ptr) + params.sq_off.array);
254
255 {
256 const uint32_t num = *sq.num;
257 for( i; num ) {
258 sq.sqes[i].user_data = 0ul64;
259 }
260 }
261
262 if( io_flags & CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS ) {
263 /* paranoid */ verify( is_pow2( io_flags >> CFA_CLUSTER_IO_BUFFLEN_OFFSET ) || ((io_flags >> CFA_CLUSTER_IO_BUFFLEN_OFFSET) < 8) );
264 sq.ready_cnt = max(io_flags >> CFA_CLUSTER_IO_BUFFLEN_OFFSET, 8);
265 sq.ready = alloc_align( 64, sq.ready_cnt );
266 for(i; sq.ready_cnt) {
267 sq.ready[i] = -1ul32;
268 }
269 }
270 else {
271 sq.ready_cnt = 0;
272 sq.ready = 0p;
273 }
274
275 // completion queue
276 cq.head = (volatile uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.head);
277 cq.tail = (volatile uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.tail);
278 cq.mask = ( const uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_mask);
279 cq.num = ( const uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.ring_entries);
280 cq.overflow = ( uint32_t *)(((intptr_t)cq.ring_ptr) + params.cq_off.overflow);
281 cq.cqes = (struct io_uring_cqe *)(((intptr_t)cq.ring_ptr) + params.cq_off.cqes);
282
283 // some paranoid checks
284 /* paranoid */ verifyf( (*cq.mask) == ((*cq.num) - 1ul32), "IO_URING Expected mask to be %u (%u entries), was %u", (*cq.num) - 1ul32, *cq.num, *cq.mask );
285 /* paranoid */ verifyf( (*cq.num) >= nentries, "IO_URING Expected %u entries, got %u", nentries, *cq.num );
286 /* paranoid */ verifyf( (*cq.head) == 0, "IO_URING Expected head to be 0, got %u", *cq.head );
287 /* paranoid */ verifyf( (*cq.tail) == 0, "IO_URING Expected tail to be 0, got %u", *cq.tail );
288
289 /* paranoid */ verifyf( (*sq.mask) == ((*sq.num) - 1ul32), "IO_URING Expected mask to be %u (%u entries), was %u", (*sq.num) - 1ul32, *sq.num, *sq.mask );
290 /* paranoid */ verifyf( (*sq.num) >= nentries, "IO_URING Expected %u entries, got %u", nentries, *sq.num );
291 /* paranoid */ verifyf( (*sq.head) == 0, "IO_URING Expected head to be 0, got %u", *sq.head );
292 /* paranoid */ verifyf( (*sq.tail) == 0, "IO_URING Expected tail to be 0, got %u", *sq.tail );
293
294 // Update the global ring info
295 this.io->ring_flags = params.flags;
296 this.io->cltr_flags = io_flags;
297 this.io->fd = fd;
298 this.io->done = false;
299 (this.io->submit){ min(*sq.num, *cq.num) };
300
301 if(!main_cluster) {
302 __kernel_io_finish_start( this );
303 }
304 }
305
306 void __kernel_io_finish_start( cluster & this ) {
307 if( this.io->cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD ) {
308 __cfadbg_print_safe(io_core, "Kernel I/O : Creating fast poller for cluter %p\n", &this);
309 (this.io->poller.fast){ this };
310 __thrd_start( this.io->poller.fast, main );
311 }
312
313 // Create the poller thread
314 __cfadbg_print_safe(io_core, "Kernel I/O : Creating slow poller for cluter %p\n", &this);
315 this.io->poller.slow.blocked = false;
316 this.io->poller.slow.stack = __create_pthread( &this.io->poller.slow.kthrd, __io_poller_slow, &this );
317 }
318
319 void __kernel_io_prepare_stop( cluster & this ) {
320 __cfadbg_print_safe(io_core, "Kernel I/O : Stopping pollers for cluster\n", &this);
321 // Notify the poller thread of the shutdown
322 __atomic_store_n(&this.io->done, true, __ATOMIC_SEQ_CST);
323
324 // Stop the IO Poller
325 sigval val = { 1 };
326 pthread_sigqueue( this.io->poller.slow.kthrd, SIGUSR1, val );
327 post( this.io->poller.sem );
328
329 // Wait for the poller thread to finish
330 pthread_join( this.io->poller.slow.kthrd, 0p );
331 free( this.io->poller.slow.stack );
332
333 __cfadbg_print_safe(io_core, "Kernel I/O : Slow poller stopped for cluster\n", &this);
334
335 if( this.io->cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD ) {
336 with( this.io->poller.fast ) {
337 /* paranoid */ verify( this.nprocessors == 0 || &this == mainCluster );
338 /* paranoid */ verify( !ready_mutate_islocked() );
339
340 // We need to adjust the clean-up based on where the thread is
341 if( thrd.state == Ready || thrd.preempted != __NO_PREEMPTION ) {
342
343 ready_schedule_lock( (struct __processor_id_t *)active_processor() );
344
345 // This is the tricky case
346 // The thread was preempted and now it is on the ready queue
347 // The thread should be the last on the list
348 /* paranoid */ verify( thrd.link.next != 0p );
349
350 // Remove the thread from the ready queue of this cluster
351 __attribute__((unused)) bool removed = remove_head( &this, &thrd );
352 /* paranoid */ verify( removed );
353 thrd.link.next = 0p;
354 thrd.link.prev = 0p;
355 __cfaabi_dbg_debug_do( thrd.unpark_stale = true );
356
357 // Fixup the thread state
358 thrd.state = Blocked;
359 thrd.ticket = 0;
360 thrd.preempted = __NO_PREEMPTION;
361
362 ready_schedule_unlock( (struct __processor_id_t *)active_processor() );
363
364 // Pretend like the thread was blocked all along
365 }
366 // !!! This is not an else if !!!
367 if( thrd.state == Blocked ) {
368
369 // This is the "easy case"
370 // The thread is parked and can easily be moved to active cluster
371 verify( thrd.curr_cluster != active_cluster() || thrd.curr_cluster == mainCluster );
372 thrd.curr_cluster = active_cluster();
373
374 // unpark the fast io_poller
375 unpark( &thrd __cfaabi_dbg_ctx2 );
376 }
377 else {
378
379 // The thread is in a weird state
380 // I don't know what to do here
381 abort("Fast poller thread is in unexpected state, cannot clean-up correctly\n");
382 }
383
384 }
385
386 ^(this.io->poller.fast){};
387
388 __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller stopped for cluster\n", &this);
389 }
390 }
391
392 void __kernel_io_shutdown( cluster & this, bool main_cluster ) {
393 if(!main_cluster) {
394 __kernel_io_prepare_stop( this );
395 }
396
397 // Shutdown the io rings
398 struct __submition_data & sq = this.io->submit_q;
399 struct __completion_data & cq = this.io->completion_q;
400
401 // unmap the submit queue entries
402 munmap(sq.sqes, (*sq.num) * sizeof(struct io_uring_sqe));
403
404 // unmap the Submit Queue ring
405 munmap(sq.ring_ptr, sq.ring_sz);
406
407 // unmap the Completion Queue ring, if it is different
408 if (cq.ring_ptr != sq.ring_ptr) {
409 munmap(cq.ring_ptr, cq.ring_sz);
410 }
411
412 // close the file descriptor
413 close(this.io->fd);
414
415 free( this.io->submit_q.ready ); // Maybe null, doesn't matter
416 free( this.io );
417 }
418
419//=============================================================================================
420// I/O Polling
421//=============================================================================================
422 struct io_user_data {
423 int32_t result;
424 $thread * thrd;
425 };
426
427 // Process a single completion message from the io_uring
428 // This is NOT thread-safe
429 static [int, bool] __drain_io( & struct __io_data ring, * sigset_t mask, int waitcnt, bool in_kernel ) {
430 unsigned to_submit = 0;
431 if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS ) {
432
433 // If the poller thread also submits, then we need to aggregate the submissions which are ready
434 uint32_t tail = *ring.submit_q.tail;
435 const uint32_t mask = *ring.submit_q.mask;
436
437 // Go through the list of ready submissions
438 for( i; ring.submit_q.ready_cnt ) {
439 // replace any submission with the sentinel, to consume it.
440 uint32_t idx = __atomic_exchange_n( &ring.submit_q.ready[i], -1ul32, __ATOMIC_RELAXED);
441
442 // If it was already the sentinel, then we are done
443 if( idx == -1ul32 ) continue;
444
445 // If we got a real submission, append it to the list
446 ring.submit_q.array[ (tail + to_submit) & mask ] = idx & mask;
447 to_submit++;
448 }
449
450 // Increment the tail based on how many we are ready to submit
451 __atomic_fetch_add(ring.submit_q.tail, to_submit, __ATOMIC_SEQ_CST);
452 }
453
454 const uint32_t smask = *ring.submit_q.mask;
455 uint32_t shead = *ring.submit_q.head;
456 int ret = syscall( __NR_io_uring_enter, ring.fd, to_submit, waitcnt, IORING_ENTER_GETEVENTS, mask, _NSIG / 8);
457 if( ret < 0 ) {
458 switch((int)errno) {
459 case EAGAIN:
460 case EINTR:
461 return -EAGAIN;
462 default:
463 abort( "KERNEL ERROR: IO_URING WAIT - %s\n", strerror(errno) );
464 }
465 }
466
467 uint32_t nhead = *ring.submit_q.head;
468 verifyf( (shead + ret) == nhead, "Expected %u got %u\n", (shead + ret), nhead );
469
470 // Release the consumed SQEs
471 for( i; ret ) {
472 uint32_t idx = ring.submit_q.array[ (i + shead) & smask ];
473 ring.submit_q.sqes[ idx ].user_data = 0;
474 }
475
476 uint32_t avail = 0;
477 uint32_t sqe_num = *ring.submit_q.num;
478 for(i; sqe_num) {
479 if( ring.submit_q.sqes[ i ].user_data == 0 ) avail++;
480 }
481
482 // update statistics
483 #if !defined(__CFA_NO_STATISTICS__)
484 __tls_stats()->io.submit_q.submit_avg.rdy += to_submit;
485 __tls_stats()->io.submit_q.submit_avg.csm += ret;
486 __tls_stats()->io.submit_q.submit_avg.avl += avail;
487 __tls_stats()->io.submit_q.submit_avg.cnt += 1;
488 #endif
489
490 // Drain the queue
491 unsigned head = *ring.completion_q.head;
492 unsigned tail = *ring.completion_q.tail;
493 const uint32_t mask = *ring.completion_q.mask;
494
495 // Memory barrier
496 __atomic_thread_fence( __ATOMIC_SEQ_CST );
497
498 // Nothing was new return 0
499 if (head == tail) {
500 return 0;
501 }
502
503 uint32_t count = tail - head;
504 for(i; count) {
505 unsigned idx = (head + i) & mask;
506 struct io_uring_cqe & cqe = ring.completion_q.cqes[idx];
507
508 /* paranoid */ verify(&cqe);
509
510 struct io_user_data * data = (struct io_user_data *)cqe.user_data;
511 __cfadbg_print_safe( io, "Kernel I/O : Performed reading io cqe %p, result %d for %p\n", data, cqe.res, data->thrd );
512
513 data->result = cqe.res;
514 if(!in_kernel) { unpark( data->thrd __cfaabi_dbg_ctx2 ); }
515 else { __unpark( &ring.poller.slow.id, data->thrd __cfaabi_dbg_ctx2 ); }
516 }
517
518 // Allow new submissions to happen
519 // V(ring.submit, count);
520
521 // Mark to the kernel that the cqe has been seen
522 // Ensure that the kernel only sees the new value of the head index after the CQEs have been read.
523 __atomic_thread_fence( __ATOMIC_SEQ_CST );
524 __atomic_fetch_add( ring.completion_q.head, count, __ATOMIC_RELAXED );
525
526 return [count, count > 0 || to_submit > 0];
527 }
528
529 static void * __io_poller_slow( void * arg ) {
530 #if !defined( __CFA_NO_STATISTICS__ )
531 __stats_t local_stats;
532 __init_stats( &local_stats );
533 kernelTLS.this_stats = &local_stats;
534 #endif
535
536 cluster * cltr = (cluster *)arg;
537 struct __io_data & ring = *cltr->io;
538
539 ring.poller.slow.id.id = doregister( &ring.poller.slow.id );
540
541 sigset_t mask;
542 sigfillset(&mask);
543 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
544 abort( "KERNEL ERROR: IO_URING - pthread_sigmask" );
545 }
546
547 sigdelset( &mask, SIGUSR1 );
548
549 verify( (*ring.submit_q.head) == (*ring.submit_q.tail) );
550 verify( (*ring.completion_q.head) == (*ring.completion_q.tail) );
551
552 __cfadbg_print_safe(io_core, "Kernel I/O : Slow poller for ring %p ready\n", &ring);
553
554 if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD ) {
555 while(!__atomic_load_n(&ring.done, __ATOMIC_SEQ_CST)) {
556
557 __atomic_store_n( &ring.poller.slow.blocked, true, __ATOMIC_SEQ_CST );
558
559 // In the user-thread approach drain and if anything was drained,
560 // batton pass to the user-thread
561 int count;
562 bool again;
563 [count, again] = __drain_io( ring, &mask, 1, true );
564
565 __atomic_store_n( &ring.poller.slow.blocked, false, __ATOMIC_SEQ_CST );
566
567 // Update statistics
568 #if !defined(__CFA_NO_STATISTICS__)
569 __tls_stats()->io.complete_q.completed_avg.val += count;
570 __tls_stats()->io.complete_q.completed_avg.slow_cnt += 1;
571 #endif
572
573 if(again) {
574 __cfadbg_print_safe(io_core, "Kernel I/O : Moving to ring %p to fast poller\n", &ring);
575 __unpark( &ring.poller.slow.id, &ring.poller.fast.thrd __cfaabi_dbg_ctx2 );
576 wait( ring.poller.sem );
577 }
578 }
579 }
580 else {
581 while(!__atomic_load_n(&ring.done, __ATOMIC_SEQ_CST)) {
582 //In the naive approach, just poll the io completion queue directly
583 int count;
584 bool again;
585 [count, again] = __drain_io( ring, &mask, 1, true );
586
587 // Update statistics
588 #if !defined(__CFA_NO_STATISTICS__)
589 __tls_stats()->io.complete_q.completed_avg.val += count;
590 __tls_stats()->io.complete_q.completed_avg.slow_cnt += 1;
591 #endif
592 }
593 }
594
595 __cfadbg_print_safe(io_core, "Kernel I/O : Slow poller for ring %p stopping\n", &ring);
596
597 unregister( &ring.poller.slow.id );
598
599 return 0p;
600 }
601
602 void main( __io_poller_fast & this ) {
603 verify( this.ring->cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD );
604
605 // Start parked
606 park( __cfaabi_dbg_ctx );
607
608 __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller for ring %p ready\n", &this.ring);
609
610 int reset = 0;
611
612 // Then loop until we need to start
613 while(!__atomic_load_n(&this.ring->done, __ATOMIC_SEQ_CST)) {
614
615 // Drain the io
616 int count;
617 bool again;
618 disable_interrupts();
619 [count, again] = __drain_io( *this.ring, 0p, 0, false );
620
621 if(!again) reset++;
622
623 // Update statistics
624 #if !defined(__CFA_NO_STATISTICS__)
625 __tls_stats()->io.complete_q.completed_avg.val += count;
626 __tls_stats()->io.complete_q.completed_avg.fast_cnt += 1;
627 #endif
628 enable_interrupts( __cfaabi_dbg_ctx );
629
630 // If we got something, just yield and check again
631 if(reset < 5) {
632 yield();
633 }
634 // We didn't get anything baton pass to the slow poller
635 else {
636 __cfadbg_print_safe(io_core, "Kernel I/O : Moving to ring %p to slow poller\n", &this.ring);
637 reset = 0;
638
639 // wake up the slow poller
640 post( this.ring->poller.sem );
641
642 // park this thread
643 park( __cfaabi_dbg_ctx );
644 }
645 }
646
647 __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller for ring %p stopping\n", &this.ring);
648 }
649
650 static inline void __wake_poller( struct __io_data & ring ) __attribute__((artificial));
651 static inline void __wake_poller( struct __io_data & ring ) {
652 if(!__atomic_load_n( &ring.poller.slow.blocked, __ATOMIC_SEQ_CST)) return;
653
654 sigval val = { 1 };
655 pthread_sigqueue( ring.poller.slow.kthrd, SIGUSR1, val );
656 }
657
658//=============================================================================================
659// I/O Submissions
660//=============================================================================================
661
662// Submition steps :
663// 1 - We need to make sure we don't overflow any of the buffer, P(ring.submit) to make sure
664// entries are available. The semaphore make sure that there is no more operations in
665// progress then the number of entries in the buffer. This probably limits concurrency
666// more than necessary since submitted but not completed operations don't need any
667// entries in user space. However, I don't know what happens if we overflow the buffers
668// because too many requests completed at once. This is a safe approach in all cases.
669// Furthermore, with hundreds of entries, this may be okay.
670//
671// 2 - Allocate a queue entry. The ring already has memory for all entries but only the ones
672// listed in sq.array are visible by the kernel. For those not listed, the kernel does not
673// offer any assurance that an entry is not being filled by multiple flags. Therefore, we
674// need to write an allocator that allows allocating concurrently.
675//
676// 3 - Actually fill the submit entry, this is the only simple and straightforward step.
677//
678// 4 - Append the entry index to the array and adjust the tail accordingly. This operation
679// needs to arrive to two concensus at the same time:
680// A - The order in which entries are listed in the array: no two threads must pick the
681// same index for their entries
682// B - When can the tail be update for the kernel. EVERY entries in the array between
683// head and tail must be fully filled and shouldn't ever be touched again.
684//
685
686 static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
687 verify( data != 0 );
688
689 disable_interrupts();
690
691 // Prepare the data we need
692 __attribute((unused)) int len = 0;
693 __attribute((unused)) int block = 0;
694 uint32_t cnt = *ring.submit_q.num;
695 uint32_t mask = *ring.submit_q.mask;
696 uint32_t off = __tls_rand();
697
698 // Loop around looking for an available spot
699 for() {
700 // Look through the list starting at some offset
701 for(i; cnt) {
702 uint64_t expected = 0;
703 uint32_t idx = (i + off) & mask;
704 struct io_uring_sqe * sqe = &ring.submit_q.sqes[idx];
705 volatile uint64_t * udata = &sqe->user_data;
706
707 if( *udata == expected &&
708 __atomic_compare_exchange_n( udata, &expected, data, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) )
709 {
710 // update statistics
711 #if !defined(__CFA_NO_STATISTICS__)
712 __tls_stats()->io.submit_q.alloc_avg.val += len;
713 __tls_stats()->io.submit_q.alloc_avg.block += block;
714 __tls_stats()->io.submit_q.alloc_avg.cnt += 1;
715 #endif
716
717 enable_interrupts( __cfaabi_dbg_ctx );
718
719 // Success return the data
720 return [sqe, idx];
721 }
722 verify(expected != data);
723
724 len ++;
725 }
726
727 block++;
728 yield();
729 }
730 }
731
732 static inline void __submit( struct __io_data & ring, uint32_t idx ) {
733 // Get now the data we definetely need
734 uint32_t * const tail = ring.submit_q.tail;
735 const uint32_t mask = *ring.submit_q.mask;
736
737 disable_interrupts();
738
739 // There are 2 submission schemes, check which one we are using
740 if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS ) {
741 // If the poller thread submits, then we just need to add this to the ready array
742
743 /* paranoid */ verify( idx <= mask );
744 /* paranoid */ verify( idx != -1ul32 );
745
746 // We need to find a spot in the ready array
747 __attribute((unused)) int len = 0;
748 __attribute((unused)) int block = 0;
749 uint32_t ready_mask = ring.submit_q.ready_cnt - 1;
750 uint32_t off = __tls_rand();
751 LOOKING: for() {
752 for(i; ring.submit_q.ready_cnt) {
753 uint32_t ii = (i + off) & ready_mask;
754 uint32_t expected = -1ul32;
755 if( __atomic_compare_exchange_n( &ring.submit_q.ready[ii], &expected, idx, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) ) {
756 break LOOKING;
757 }
758 verify(expected != idx);
759
760 len ++;
761 }
762
763 block++;
764 yield();
765 }
766
767 __wake_poller( ring );
768
769 // update statistics
770 #if !defined(__CFA_NO_STATISTICS__)
771 __tls_stats()->io.submit_q.look_avg.val += len;
772 __tls_stats()->io.submit_q.look_avg.block += block;
773 __tls_stats()->io.submit_q.look_avg.cnt += 1;
774 #endif
775
776 __cfadbg_print_safe( io, "Kernel I/O : Added %u to ready for %p\n", idx, active_thread() );
777 }
778 else {
779 // get mutual exclusion
780 lock(ring.submit_q.lock __cfaabi_dbg_ctx2);
781
782 // Append to the list of ready entries
783
784 /* paranoid */ verify( idx <= mask );
785
786 ring.submit_q.array[ (*tail) & mask ] = idx & mask;
787 __atomic_fetch_add(tail, 1ul32, __ATOMIC_SEQ_CST);
788
789 // Submit however, many entries need to be submitted
790 int ret = syscall( __NR_io_uring_enter, ring.fd, 1, 0, 0, 0p, 0);
791 if( ret < 0 ) {
792 switch((int)errno) {
793 default:
794 abort( "KERNEL ERROR: IO_URING SUBMIT - %s\n", strerror(errno) );
795 }
796 }
797
798 // update statistics
799 #if !defined(__CFA_NO_STATISTICS__)
800 __tls_stats()->io.submit_q.submit_avg.csm += 1;
801 __tls_stats()->io.submit_q.submit_avg.cnt += 1;
802 #endif
803
804 unlock(ring.submit_q.lock);
805
806 __cfadbg_print_safe( io, "Kernel I/O : Performed io_submit for %p, returned %d\n", active_thread(), ret );
807 }
808
809 enable_interrupts( __cfaabi_dbg_ctx );
810 }
811
812 static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
813 this.opcode = opcode;
814 #if !defined(IOSQE_ASYNC)
815 this.flags = 0;
816 #else
817 this.flags = IOSQE_ASYNC;
818 #endif
819 this.ioprio = 0;
820 this.fd = fd;
821 this.off = 0;
822 this.addr = 0;
823 this.len = 0;
824 this.rw_flags = 0;
825 this.__pad2[0] = this.__pad2[1] = this.__pad2[2] = 0;
826 }
827
828 static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
829 (this){ opcode, fd };
830 this.off = off;
831 this.addr = (uint64_t)addr;
832 this.len = len;
833 }
834
835
836//=============================================================================================
837// I/O Interface
838//=============================================================================================
839
840 #define __submit_prelude \
841 io_user_data data = { 0, active_thread() }; \
842 struct __io_data & ring = *data.thrd->curr_cluster->io; \
843 struct io_uring_sqe * sqe; \
844 uint32_t idx; \
845 [sqe, idx] = __submit_alloc( ring, (uint64_t)&data );
846
847 #define __submit_wait \
848 /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
849 verify( sqe->user_data == (uint64_t)&data ); \
850 __submit( ring, idx ); \
851 park( __cfaabi_dbg_ctx ); \
852 return data.result;
853#endif
854
855// Some forward declarations
856extern "C" {
857 #include <unistd.h>
858 #include <sys/types.h>
859 #include <sys/socket.h>
860 #include <sys/syscall.h>
861
862#if defined(HAVE_PREADV2)
863 struct iovec;
864 extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
865#endif
866#if defined(HAVE_PWRITEV2)
867 struct iovec;
868 extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
869#endif
870
871 extern int fsync(int fd);
872 extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
873
874 struct msghdr;
875 struct sockaddr;
876 extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
877 extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
878 extern ssize_t send(int sockfd, const void *buf, size_t len, int flags);
879 extern ssize_t recv(int sockfd, void *buf, size_t len, int flags);
880 extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
881 extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
882
883 extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
884 extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
885 extern int madvise(void *addr, size_t length, int advice);
886
887 extern int openat(int dirfd, const char *pathname, int flags, mode_t mode);
888 extern int close(int fd);
889
890 extern ssize_t read (int fd, void *buf, size_t count);
891}
892
893//-----------------------------------------------------------------------------
894// Asynchronous operations
895#if defined(HAVE_PREADV2)
896 ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
897 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV)
898 return preadv2(fd, iov, iovcnt, offset, flags);
899 #else
900 __submit_prelude
901
902 (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
903
904 __submit_wait
905 #endif
906 }
907#endif
908
909#if defined(HAVE_PWRITEV2)
910 ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
911 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITEV)
912 return pwritev2(fd, iov, iovcnt, offset, flags);
913 #else
914 __submit_prelude
915
916 (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
917
918 __submit_wait
919 #endif
920 }
921#endif
922
923int cfa_fsync(int fd) {
924 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FSYNC)
925 return fsync(fd);
926 #else
927 __submit_prelude
928
929 (*sqe){ IORING_OP_FSYNC, fd };
930
931 __submit_wait
932 #endif
933}
934
935int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
936 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SYNC_FILE_RANGE)
937 return sync_file_range(fd, offset, nbytes, flags);
938 #else
939 __submit_prelude
940
941 (*sqe){ IORING_OP_SYNC_FILE_RANGE, fd };
942 sqe->off = offset;
943 sqe->len = nbytes;
944 sqe->sync_range_flags = flags;
945
946 __submit_wait
947 #endif
948}
949
950
951ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
952 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SENDMSG)
953 return sendmsg(sockfd, msg, flags);
954 #else
955 __submit_prelude
956
957 (*sqe){ IORING_OP_SENDMSG, sockfd, msg, 1, 0 };
958 sqe->msg_flags = flags;
959
960 __submit_wait
961 #endif
962}
963
964ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) {
965 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECVMSG)
966 return recvmsg(sockfd, msg, flags);
967 #else
968 __submit_prelude
969
970 (*sqe){ IORING_OP_RECVMSG, sockfd, msg, 1, 0 };
971 sqe->msg_flags = flags;
972
973 __submit_wait
974 #endif
975}
976
977ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) {
978 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SEND)
979 return send( sockfd, buf, len, flags );
980 #else
981 __submit_prelude
982
983 (*sqe){ IORING_OP_SEND, sockfd };
984 sqe->addr = (uint64_t)buf;
985 sqe->len = len;
986 sqe->msg_flags = flags;
987
988 __submit_wait
989 #endif
990}
991
992ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) {
993 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECV)
994 return recv( sockfd, buf, len, flags );
995 #else
996 __submit_prelude
997
998 (*sqe){ IORING_OP_RECV, sockfd };
999 sqe->addr = (uint64_t)buf;
1000 sqe->len = len;
1001 sqe->msg_flags = flags;
1002
1003 __submit_wait
1004 #endif
1005}
1006
1007int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
1008 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_ACCEPT)
1009 return accept4( sockfd, addr, addrlen, flags );
1010 #else
1011 __submit_prelude
1012
1013 (*sqe){ IORING_OP_ACCEPT, sockfd };
1014 sqe->addr = addr;
1015 sqe->addr2 = addrlen;
1016 sqe->accept_flags = flags;
1017
1018 __submit_wait
1019 #endif
1020}
1021
1022int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
1023 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CONNECT)
1024 return connect( sockfd, addr, addrlen );
1025 #else
1026 __submit_prelude
1027
1028 (*sqe){ IORING_OP_CONNECT, sockfd };
1029 sqe->addr = (uint64_t)addr;
1030 sqe->off = addrlen;
1031
1032 __submit_wait
1033 #endif
1034}
1035
1036int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
1037 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FALLOCATE)
1038 return fallocate( fd, mode, offset, len );
1039 #else
1040 __submit_prelude
1041
1042 (*sqe){ IORING_OP_FALLOCATE, fd };
1043 sqe->off = offset;
1044 sqe->len = length;
1045 sqe->mode = mode;
1046
1047 __submit_wait
1048 #endif
1049}
1050
1051int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
1052 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FADVISE)
1053 return posix_fadvise( fd, offset, len, advice );
1054 #else
1055 __submit_prelude
1056
1057 (*sqe){ IORING_OP_FADVISE, fd };
1058 sqe->off = (uint64_t)offset;
1059 sqe->len = length;
1060 sqe->fadvise_advice = advice;
1061
1062 __submit_wait
1063 #endif
1064}
1065
1066int cfa_madvise(void *addr, size_t length, int advice) {
1067 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_MADVISE)
1068 return madvise( addr, length, advice );
1069 #else
1070 __submit_prelude
1071
1072 (*sqe){ IORING_OP_MADVISE, 0 };
1073 sqe->addr = (uint64_t)addr;
1074 sqe->len = length;
1075 sqe->fadvise_advice = advice;
1076
1077 __submit_wait
1078 #endif
1079}
1080
1081int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
1082 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_OPENAT)
1083 return openat( dirfd, pathname, flags, mode );
1084 #else
1085 __submit_prelude
1086
1087 (*sqe){ IORING_OP_OPENAT, dirfd };
1088 sqe->addr = (uint64_t)pathname;
1089 sqe->open_flags = flags;
1090 sqe->mode = mode;
1091
1092 __submit_wait
1093 #endif
1094}
1095
1096int cfa_close(int fd) {
1097 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CLOSE)
1098 return close( fd );
1099 #else
1100 __submit_prelude
1101
1102 (*sqe){ IORING_OP_CLOSE, fd };
1103
1104 __submit_wait
1105 #endif
1106}
1107
1108
1109ssize_t cfa_read(int fd, void *buf, size_t count) {
1110 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READ)
1111 return read( fd, buf, count );
1112 #else
1113 __submit_prelude
1114
1115 (*sqe){ IORING_OP_READ, fd, buf, count, 0 };
1116
1117 __submit_wait
1118 #endif
1119}
1120
1121ssize_t cfa_write(int fd, void *buf, size_t count) {
1122 #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITE)
1123 return read( fd, buf, count );
1124 #else
1125 __submit_prelude
1126
1127 (*sqe){ IORING_OP_WRITE, fd, buf, count, 0 };
1128
1129 __submit_wait
1130 #endif
1131}
1132
1133//-----------------------------------------------------------------------------
1134// Check if a function is asynchronous
1135
1136// Macro magic to reduce the size of the following switch case
1137#define IS_DEFINED_APPLY(f, ...) f(__VA_ARGS__)
1138#define IS_DEFINED_SECOND(first, second, ...) second
1139#define IS_DEFINED_TEST(expansion) _CFA_IO_FEATURE_##expansion
1140#define IS_DEFINED(macro) IS_DEFINED_APPLY( IS_DEFINED_SECOND,IS_DEFINED_TEST(macro) false, true)
1141
1142bool has_user_level_blocking( fptr_t func ) {
1143 #if defined(HAVE_LINUX_IO_URING_H)
1144 #if defined(HAVE_PREADV2)
1145 if( /*func == (fptr_t)preadv2 || */
1146 func == (fptr_t)cfa_preadv2 )
1147 #define _CFA_IO_FEATURE_IORING_OP_READV ,
1148 return IS_DEFINED(IORING_OP_READV);
1149 #endif
1150
1151 #if defined(HAVE_PWRITEV2)
1152 if( /*func == (fptr_t)pwritev2 || */
1153 func == (fptr_t)cfa_pwritev2 )
1154 #define _CFA_IO_FEATURE_IORING_OP_WRITEV ,
1155 return IS_DEFINED(IORING_OP_WRITEV);
1156 #endif
1157
1158 if( /*func == (fptr_t)fsync || */
1159 func == (fptr_t)cfa_fsync )
1160 #define _CFA_IO_FEATURE_IORING_OP_FSYNC ,
1161 return IS_DEFINED(IORING_OP_FSYNC);
1162
1163 if( /*func == (fptr_t)ync_file_range || */
1164 func == (fptr_t)cfa_sync_file_range )
1165 #define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE ,
1166 return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE);
1167
1168 if( /*func == (fptr_t)sendmsg || */
1169 func == (fptr_t)cfa_sendmsg )
1170 #define _CFA_IO_FEATURE_IORING_OP_SENDMSG ,
1171 return IS_DEFINED(IORING_OP_SENDMSG);
1172
1173 if( /*func == (fptr_t)recvmsg || */
1174 func == (fptr_t)cfa_recvmsg )
1175 #define _CFA_IO_FEATURE_IORING_OP_RECVMSG ,
1176 return IS_DEFINED(IORING_OP_RECVMSG);
1177
1178 if( /*func == (fptr_t)send || */
1179 func == (fptr_t)cfa_send )
1180 #define _CFA_IO_FEATURE_IORING_OP_SEND ,
1181 return IS_DEFINED(IORING_OP_SEND);
1182
1183 if( /*func == (fptr_t)recv || */
1184 func == (fptr_t)cfa_recv )
1185 #define _CFA_IO_FEATURE_IORING_OP_RECV ,
1186 return IS_DEFINED(IORING_OP_RECV);
1187
1188 if( /*func == (fptr_t)accept4 || */
1189 func == (fptr_t)cfa_accept4 )
1190 #define _CFA_IO_FEATURE_IORING_OP_ACCEPT ,
1191 return IS_DEFINED(IORING_OP_ACCEPT);
1192
1193 if( /*func == (fptr_t)connect || */
1194 func == (fptr_t)cfa_connect )
1195 #define _CFA_IO_FEATURE_IORING_OP_CONNECT ,
1196 return IS_DEFINED(IORING_OP_CONNECT);
1197
1198 if( /*func == (fptr_t)fallocate || */
1199 func == (fptr_t)cfa_fallocate )
1200 #define _CFA_IO_FEATURE_IORING_OP_FALLOCATE ,
1201 return IS_DEFINED(IORING_OP_FALLOCATE);
1202
1203 if( /*func == (fptr_t)posix_fadvise || */
1204 func == (fptr_t)cfa_fadvise )
1205 #define _CFA_IO_FEATURE_IORING_OP_FADVISE ,
1206 return IS_DEFINED(IORING_OP_FADVISE);
1207
1208 if( /*func == (fptr_t)madvise || */
1209 func == (fptr_t)cfa_madvise )
1210 #define _CFA_IO_FEATURE_IORING_OP_MADVISE ,
1211 return IS_DEFINED(IORING_OP_MADVISE);
1212
1213 if( /*func == (fptr_t)openat || */
1214 func == (fptr_t)cfa_openat )
1215 #define _CFA_IO_FEATURE_IORING_OP_OPENAT ,
1216 return IS_DEFINED(IORING_OP_OPENAT);
1217
1218 if( /*func == (fptr_t)close || */
1219 func == (fptr_t)cfa_close )
1220 #define _CFA_IO_FEATURE_IORING_OP_CLOSE ,
1221 return IS_DEFINED(IORING_OP_CLOSE);
1222
1223 if( /*func == (fptr_t)read || */
1224 func == (fptr_t)cfa_read )
1225 #define _CFA_IO_FEATURE_IORING_OP_READ ,
1226 return IS_DEFINED(IORING_OP_READ);
1227
1228 if( /*func == (fptr_t)write || */
1229 func == (fptr_t)cfa_write )
1230 #define _CFA_IO_FEATURE_IORING_OP_WRITE ,
1231 return IS_DEFINED(IORING_OP_WRITE);
1232 #endif
1233
1234 return false;
1235}
Note: See TracBrowser for help on using the repository browser.