source: libcfa/src/concurrency/io.cfa @ de917da3

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since de917da3 was de917da3, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Removed flaky verify in io

  • Property mode set to 100644
File size: 37.0 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                // Release the consumed SQEs
468                for( i; ret ) {
469                        uint32_t idx = ring.submit_q.array[ (i + shead) & smask ];
470                        ring.submit_q.sqes[ idx ].user_data = 0;
471                }
472
473                uint32_t avail = 0;
474                uint32_t sqe_num = *ring.submit_q.num;
475                for(i; sqe_num) {
476                        if( ring.submit_q.sqes[ i ].user_data == 0 ) avail++;
477                }
478
479                // update statistics
480                #if !defined(__CFA_NO_STATISTICS__)
481                        __tls_stats()->io.submit_q.submit_avg.rdy += to_submit;
482                        __tls_stats()->io.submit_q.submit_avg.csm += ret;
483                        __tls_stats()->io.submit_q.submit_avg.avl += avail;
484                        __tls_stats()->io.submit_q.submit_avg.cnt += 1;
485                #endif
486
487                // Drain the queue
488                unsigned head = *ring.completion_q.head;
489                unsigned tail = *ring.completion_q.tail;
490                const uint32_t mask = *ring.completion_q.mask;
491
492                // Memory barrier
493                __atomic_thread_fence( __ATOMIC_SEQ_CST );
494
495                // Nothing was new return 0
496                if (head == tail) {
497                        return 0;
498                }
499
500                uint32_t count = tail - head;
501                for(i; count) {
502                        unsigned idx = (head + i) & mask;
503                        struct io_uring_cqe & cqe = ring.completion_q.cqes[idx];
504
505                        /* paranoid */ verify(&cqe);
506
507                        struct io_user_data * data = (struct io_user_data *)cqe.user_data;
508                        __cfadbg_print_safe( io, "Kernel I/O : Performed reading io cqe %p, result %d for %p\n", data, cqe.res, data->thrd );
509
510                        data->result = cqe.res;
511                        if(!in_kernel) { unpark( data->thrd __cfaabi_dbg_ctx2 ); }
512                        else         { __unpark( &ring.poller.slow.id, data->thrd __cfaabi_dbg_ctx2 ); }
513                }
514
515                // Allow new submissions to happen
516                // V(ring.submit, count);
517
518                // Mark to the kernel that the cqe has been seen
519                // Ensure that the kernel only sees the new value of the head index after the CQEs have been read.
520                __atomic_thread_fence( __ATOMIC_SEQ_CST );
521                __atomic_fetch_add( ring.completion_q.head, count, __ATOMIC_RELAXED );
522
523                return [count, count > 0 || to_submit > 0];
524        }
525
526        static void * __io_poller_slow( void * arg ) {
527                #if !defined( __CFA_NO_STATISTICS__ )
528                        __stats_t local_stats;
529                        __init_stats( &local_stats );
530                        kernelTLS.this_stats = &local_stats;
531                #endif
532
533                cluster * cltr = (cluster *)arg;
534                struct __io_data & ring = *cltr->io;
535
536                ring.poller.slow.id.id = doregister( &ring.poller.slow.id );
537
538                sigset_t mask;
539                sigfillset(&mask);
540                if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
541                        abort( "KERNEL ERROR: IO_URING - pthread_sigmask" );
542                }
543
544                sigdelset( &mask, SIGUSR1 );
545
546                verify( (*ring.submit_q.head) == (*ring.submit_q.tail) );
547                verify( (*ring.completion_q.head) == (*ring.completion_q.tail) );
548
549                __cfadbg_print_safe(io_core, "Kernel I/O : Slow poller for ring %p ready\n", &ring);
550
551                if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD ) {
552                        while(!__atomic_load_n(&ring.done, __ATOMIC_SEQ_CST)) {
553
554                                __atomic_store_n( &ring.poller.slow.blocked, true, __ATOMIC_SEQ_CST );
555
556                                // In the user-thread approach drain and if anything was drained,
557                                // batton pass to the user-thread
558                                int count;
559                                bool again;
560                                [count, again] = __drain_io( ring, &mask, 1, true );
561
562                                __atomic_store_n( &ring.poller.slow.blocked, false, __ATOMIC_SEQ_CST );
563
564                                // Update statistics
565                                #if !defined(__CFA_NO_STATISTICS__)
566                                        __tls_stats()->io.complete_q.completed_avg.val += count;
567                                        __tls_stats()->io.complete_q.completed_avg.slow_cnt += 1;
568                                #endif
569
570                                if(again) {
571                                        __cfadbg_print_safe(io_core, "Kernel I/O : Moving to ring %p to fast poller\n", &ring);
572                                        __unpark( &ring.poller.slow.id, &ring.poller.fast.thrd __cfaabi_dbg_ctx2 );
573                                        wait( ring.poller.sem );
574                                }
575                        }
576                }
577                else {
578                        while(!__atomic_load_n(&ring.done, __ATOMIC_SEQ_CST)) {
579                                //In the naive approach, just poll the io completion queue directly
580                                int count;
581                                bool again;
582                                [count, again] = __drain_io( ring, &mask, 1, true );
583
584                                // Update statistics
585                                #if !defined(__CFA_NO_STATISTICS__)
586                                        __tls_stats()->io.complete_q.completed_avg.val += count;
587                                        __tls_stats()->io.complete_q.completed_avg.slow_cnt += 1;
588                                #endif
589                        }
590                }
591
592                __cfadbg_print_safe(io_core, "Kernel I/O : Slow poller for ring %p stopping\n", &ring);
593
594                unregister( &ring.poller.slow.id );
595
596                return 0p;
597        }
598
599        void main( __io_poller_fast & this ) {
600                verify( this.ring->cltr_flags & CFA_CLUSTER_IO_POLLER_USER_THREAD );
601
602                // Start parked
603                park( __cfaabi_dbg_ctx );
604
605                __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller for ring %p ready\n", &this.ring);
606
607                int reset = 0;
608
609                // Then loop until we need to start
610                while(!__atomic_load_n(&this.ring->done, __ATOMIC_SEQ_CST)) {
611
612                        // Drain the io
613                        int count;
614                        bool again;
615                        disable_interrupts();
616                                [count, again] = __drain_io( *this.ring, 0p, 0, false );
617
618                                if(!again) reset++;
619
620                                // Update statistics
621                                #if !defined(__CFA_NO_STATISTICS__)
622                                        __tls_stats()->io.complete_q.completed_avg.val += count;
623                                        __tls_stats()->io.complete_q.completed_avg.fast_cnt += 1;
624                                #endif
625                        enable_interrupts( __cfaabi_dbg_ctx );
626
627                        // If we got something, just yield and check again
628                        if(reset < 5) {
629                                yield();
630                        }
631                        // We didn't get anything baton pass to the slow poller
632                        else {
633                                __cfadbg_print_safe(io_core, "Kernel I/O : Moving to ring %p to slow poller\n", &this.ring);
634                                reset = 0;
635
636                                // wake up the slow poller
637                                post( this.ring->poller.sem );
638
639                                // park this thread
640                                park( __cfaabi_dbg_ctx );
641                        }
642                }
643
644                __cfadbg_print_safe(io_core, "Kernel I/O : Fast poller for ring %p stopping\n", &this.ring);
645        }
646
647        static inline void __wake_poller( struct __io_data & ring ) __attribute__((artificial));
648        static inline void __wake_poller( struct __io_data & ring ) {
649                if(!__atomic_load_n( &ring.poller.slow.blocked, __ATOMIC_SEQ_CST)) return;
650
651                sigval val = { 1 };
652                pthread_sigqueue( ring.poller.slow.kthrd, SIGUSR1, val );
653        }
654
655//=============================================================================================
656// I/O Submissions
657//=============================================================================================
658
659// Submition steps :
660// 1 - We need to make sure we don't overflow any of the buffer, P(ring.submit) to make sure
661//     entries are available. The semaphore make sure that there is no more operations in
662//     progress then the number of entries in the buffer. This probably limits concurrency
663//     more than necessary since submitted but not completed operations don't need any
664//     entries in user space. However, I don't know what happens if we overflow the buffers
665//     because too many requests completed at once. This is a safe approach in all cases.
666//     Furthermore, with hundreds of entries, this may be okay.
667//
668// 2 - Allocate a queue entry. The ring already has memory for all entries but only the ones
669//     listed in sq.array are visible by the kernel. For those not listed, the kernel does not
670//     offer any assurance that an entry is not being filled by multiple flags. Therefore, we
671//     need to write an allocator that allows allocating concurrently.
672//
673// 3 - Actually fill the submit entry, this is the only simple and straightforward step.
674//
675// 4 - Append the entry index to the array and adjust the tail accordingly. This operation
676//     needs to arrive to two concensus at the same time:
677//     A - The order in which entries are listed in the array: no two threads must pick the
678//         same index for their entries
679//     B - When can the tail be update for the kernel. EVERY entries in the array between
680//         head and tail must be fully filled and shouldn't ever be touched again.
681//
682
683        static inline [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ) {
684                verify( data != 0 );
685
686                disable_interrupts();
687
688                // Prepare the data we need
689                __attribute((unused)) int len   = 0;
690                __attribute((unused)) int block = 0;
691                uint32_t cnt = *ring.submit_q.num;
692                uint32_t mask = *ring.submit_q.mask;
693                uint32_t off = __tls_rand();
694
695                // Loop around looking for an available spot
696                for() {
697                        // Look through the list starting at some offset
698                        for(i; cnt) {
699                                uint64_t expected = 0;
700                                uint32_t idx = (i + off) & mask;
701                                struct io_uring_sqe * sqe = &ring.submit_q.sqes[idx];
702                                volatile uint64_t * udata = &sqe->user_data;
703
704                                if( *udata == expected &&
705                                        __atomic_compare_exchange_n( udata, &expected, data, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) )
706                                {
707                                        // update statistics
708                                        #if !defined(__CFA_NO_STATISTICS__)
709                                                __tls_stats()->io.submit_q.alloc_avg.val   += len;
710                                                __tls_stats()->io.submit_q.alloc_avg.block += block;
711                                                __tls_stats()->io.submit_q.alloc_avg.cnt   += 1;
712                                        #endif
713
714                                        enable_interrupts( __cfaabi_dbg_ctx );
715
716                                        // Success return the data
717                                        return [sqe, idx];
718                                }
719                                verify(expected != data);
720
721                                len ++;
722                        }
723
724                        block++;
725                        yield();
726                }
727        }
728
729        static inline void __submit( struct __io_data & ring, uint32_t idx ) {
730                // Get now the data we definetely need
731                uint32_t * const tail = ring.submit_q.tail;
732                const uint32_t mask = *ring.submit_q.mask;
733
734                disable_interrupts();
735
736                // There are 2 submission schemes, check which one we are using
737                if( ring.cltr_flags & CFA_CLUSTER_IO_POLLER_THREAD_SUBMITS ) {
738                        // If the poller thread submits, then we just need to add this to the ready array
739
740                        /* paranoid */ verify( idx <= mask   );
741                        /* paranoid */ verify( idx != -1ul32 );
742
743                        // We need to find a spot in the ready array
744                        __attribute((unused)) int len   = 0;
745                        __attribute((unused)) int block = 0;
746                        uint32_t ready_mask = ring.submit_q.ready_cnt - 1;
747                        uint32_t off = __tls_rand();
748                        LOOKING: for() {
749                                for(i; ring.submit_q.ready_cnt) {
750                                        uint32_t ii = (i + off) & ready_mask;
751                                        uint32_t expected = -1ul32;
752                                        if( __atomic_compare_exchange_n( &ring.submit_q.ready[ii], &expected, idx, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED ) ) {
753                                                break LOOKING;
754                                        }
755                                        verify(expected != idx);
756
757                                        len ++;
758                                }
759
760                                block++;
761                                yield();
762                        }
763
764                        __wake_poller( ring );
765
766                        // update statistics
767                        #if !defined(__CFA_NO_STATISTICS__)
768                                __tls_stats()->io.submit_q.look_avg.val   += len;
769                                __tls_stats()->io.submit_q.look_avg.block += block;
770                                __tls_stats()->io.submit_q.look_avg.cnt   += 1;
771                        #endif
772
773                        __cfadbg_print_safe( io, "Kernel I/O : Added %u to ready for %p\n", idx, active_thread() );
774                }
775                else {
776                        // get mutual exclusion
777                        lock(ring.submit_q.lock __cfaabi_dbg_ctx2);
778
779                        // Append to the list of ready entries
780
781                        /* paranoid */ verify( idx <= mask );
782
783                        ring.submit_q.array[ (*tail) & mask ] = idx & mask;
784                        __atomic_fetch_add(tail, 1ul32, __ATOMIC_SEQ_CST);
785
786                        // Submit however, many entries need to be submitted
787                        int ret = syscall( __NR_io_uring_enter, ring.fd, 1, 0, 0, 0p, 0);
788                        if( ret < 0 ) {
789                                switch((int)errno) {
790                                default:
791                                        abort( "KERNEL ERROR: IO_URING SUBMIT - %s\n", strerror(errno) );
792                                }
793                        }
794
795                        // update statistics
796                        #if !defined(__CFA_NO_STATISTICS__)
797                                __tls_stats()->io.submit_q.submit_avg.csm += 1;
798                                __tls_stats()->io.submit_q.submit_avg.cnt += 1;
799                        #endif
800
801                        unlock(ring.submit_q.lock);
802
803                        __cfadbg_print_safe( io, "Kernel I/O : Performed io_submit for %p, returned %d\n", active_thread(), ret );
804                }
805
806                enable_interrupts( __cfaabi_dbg_ctx );
807        }
808
809        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) {
810                this.opcode = opcode;
811                #if !defined(IOSQE_ASYNC)
812                        this.flags = 0;
813                #else
814                        this.flags = IOSQE_ASYNC;
815                #endif
816                this.ioprio = 0;
817                this.fd = fd;
818                this.off = 0;
819                this.addr = 0;
820                this.len = 0;
821                this.rw_flags = 0;
822                this.__pad2[0] = this.__pad2[1] = this.__pad2[2] = 0;
823        }
824
825        static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) {
826                (this){ opcode, fd };
827                this.off = off;
828                this.addr = (uint64_t)addr;
829                this.len = len;
830        }
831
832
833//=============================================================================================
834// I/O Interface
835//=============================================================================================
836
837        #define __submit_prelude \
838                io_user_data data = { 0, active_thread() }; \
839                struct __io_data & ring = *data.thrd->curr_cluster->io; \
840                struct io_uring_sqe * sqe; \
841                uint32_t idx; \
842                [sqe, idx] = __submit_alloc( ring, (uint64_t)&data );
843
844        #define __submit_wait \
845                /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \
846                verify( sqe->user_data == (uint64_t)&data ); \
847                __submit( ring, idx ); \
848                park( __cfaabi_dbg_ctx ); \
849                return data.result;
850#endif
851
852// Some forward declarations
853extern "C" {
854        #include <unistd.h>
855        #include <sys/types.h>
856        #include <sys/socket.h>
857        #include <sys/syscall.h>
858
859#if defined(HAVE_PREADV2)
860        struct iovec;
861        extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
862#endif
863#if defined(HAVE_PWRITEV2)
864        struct iovec;
865        extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags);
866#endif
867
868        extern int fsync(int fd);
869        extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags);
870
871        struct msghdr;
872        struct sockaddr;
873        extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
874        extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
875        extern ssize_t send(int sockfd, const void *buf, size_t len, int flags);
876        extern ssize_t recv(int sockfd, void *buf, size_t len, int flags);
877        extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
878        extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
879
880        extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len);
881        extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice);
882        extern int madvise(void *addr, size_t length, int advice);
883
884        extern int openat(int dirfd, const char *pathname, int flags, mode_t mode);
885        extern int close(int fd);
886
887        extern ssize_t read (int fd, void *buf, size_t count);
888}
889
890//-----------------------------------------------------------------------------
891// Asynchronous operations
892#if defined(HAVE_PREADV2)
893        ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
894                #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV)
895                        return preadv2(fd, iov, iovcnt, offset, flags);
896                #else
897                        __submit_prelude
898
899                        (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset };
900
901                        __submit_wait
902                #endif
903        }
904#endif
905
906#if defined(HAVE_PWRITEV2)
907        ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) {
908                #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITEV)
909                        return pwritev2(fd, iov, iovcnt, offset, flags);
910                #else
911                        __submit_prelude
912
913                        (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset };
914
915                        __submit_wait
916                #endif
917        }
918#endif
919
920int cfa_fsync(int fd) {
921        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FSYNC)
922                return fsync(fd);
923        #else
924                __submit_prelude
925
926                (*sqe){ IORING_OP_FSYNC, fd };
927
928                __submit_wait
929        #endif
930}
931
932int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) {
933        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SYNC_FILE_RANGE)
934                return sync_file_range(fd, offset, nbytes, flags);
935        #else
936                __submit_prelude
937
938                (*sqe){ IORING_OP_SYNC_FILE_RANGE, fd };
939                sqe->off = offset;
940                sqe->len = nbytes;
941                sqe->sync_range_flags = flags;
942
943                __submit_wait
944        #endif
945}
946
947
948ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
949        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SENDMSG)
950                return sendmsg(sockfd, msg, flags);
951        #else
952                __submit_prelude
953
954                (*sqe){ IORING_OP_SENDMSG, sockfd, msg, 1, 0 };
955                sqe->msg_flags = flags;
956
957                __submit_wait
958        #endif
959}
960
961ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) {
962        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECVMSG)
963                return recvmsg(sockfd, msg, flags);
964        #else
965                __submit_prelude
966
967                (*sqe){ IORING_OP_RECVMSG, sockfd, msg, 1, 0 };
968                sqe->msg_flags = flags;
969
970                __submit_wait
971        #endif
972}
973
974ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) {
975        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SEND)
976                return send( sockfd, buf, len, flags );
977        #else
978                __submit_prelude
979
980                (*sqe){ IORING_OP_SEND, sockfd };
981                sqe->addr = (uint64_t)buf;
982                sqe->len = len;
983                sqe->msg_flags = flags;
984
985                __submit_wait
986        #endif
987}
988
989ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) {
990        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECV)
991                return recv( sockfd, buf, len, flags );
992        #else
993                __submit_prelude
994
995                (*sqe){ IORING_OP_RECV, sockfd };
996                sqe->addr = (uint64_t)buf;
997                sqe->len = len;
998                sqe->msg_flags = flags;
999
1000                __submit_wait
1001        #endif
1002}
1003
1004int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
1005        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_ACCEPT)
1006                return accept4( sockfd, addr, addrlen, flags );
1007        #else
1008                __submit_prelude
1009
1010                (*sqe){ IORING_OP_ACCEPT, sockfd };
1011                sqe->addr = addr;
1012                sqe->addr2 = addrlen;
1013                sqe->accept_flags = flags;
1014
1015                __submit_wait
1016        #endif
1017}
1018
1019int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
1020        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CONNECT)
1021                return connect( sockfd, addr, addrlen );
1022        #else
1023                __submit_prelude
1024
1025                (*sqe){ IORING_OP_CONNECT, sockfd };
1026                sqe->addr = (uint64_t)addr;
1027                sqe->off = addrlen;
1028
1029                __submit_wait
1030        #endif
1031}
1032
1033int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) {
1034        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FALLOCATE)
1035                return fallocate( fd, mode, offset, len );
1036        #else
1037                __submit_prelude
1038
1039                (*sqe){ IORING_OP_FALLOCATE, fd };
1040                sqe->off = offset;
1041                sqe->len = length;
1042                sqe->mode = mode;
1043
1044                __submit_wait
1045        #endif
1046}
1047
1048int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
1049        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FADVISE)
1050                return posix_fadvise( fd, offset, len, advice );
1051        #else
1052                __submit_prelude
1053
1054                (*sqe){ IORING_OP_FADVISE, fd };
1055                sqe->off = (uint64_t)offset;
1056                sqe->len = length;
1057                sqe->fadvise_advice = advice;
1058
1059                __submit_wait
1060        #endif
1061}
1062
1063int cfa_madvise(void *addr, size_t length, int advice) {
1064        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_MADVISE)
1065                return madvise( addr, length, advice );
1066        #else
1067                __submit_prelude
1068
1069                (*sqe){ IORING_OP_MADVISE, 0 };
1070                sqe->addr = (uint64_t)addr;
1071                sqe->len = length;
1072                sqe->fadvise_advice = advice;
1073
1074                __submit_wait
1075        #endif
1076}
1077
1078int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) {
1079        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_OPENAT)
1080                return openat( dirfd, pathname, flags, mode );
1081        #else
1082                __submit_prelude
1083
1084                (*sqe){ IORING_OP_OPENAT, dirfd };
1085                sqe->addr = (uint64_t)pathname;
1086                sqe->open_flags = flags;
1087                sqe->mode = mode;
1088
1089                __submit_wait
1090        #endif
1091}
1092
1093int cfa_close(int fd) {
1094        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CLOSE)
1095                return close( fd );
1096        #else
1097                __submit_prelude
1098
1099                (*sqe){ IORING_OP_CLOSE, fd };
1100
1101                __submit_wait
1102        #endif
1103}
1104
1105
1106ssize_t cfa_read(int fd, void *buf, size_t count) {
1107        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READ)
1108                return read( fd, buf, count );
1109        #else
1110                __submit_prelude
1111
1112                (*sqe){ IORING_OP_READ, fd, buf, count, 0 };
1113
1114                __submit_wait
1115        #endif
1116}
1117
1118ssize_t cfa_write(int fd, void *buf, size_t count) {
1119        #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITE)
1120                return read( fd, buf, count );
1121        #else
1122                __submit_prelude
1123
1124                (*sqe){ IORING_OP_WRITE, fd, buf, count, 0 };
1125
1126                __submit_wait
1127        #endif
1128}
1129
1130//-----------------------------------------------------------------------------
1131// Check if a function is asynchronous
1132
1133// Macro magic to reduce the size of the following switch case
1134#define IS_DEFINED_APPLY(f, ...) f(__VA_ARGS__)
1135#define IS_DEFINED_SECOND(first, second, ...) second
1136#define IS_DEFINED_TEST(expansion) _CFA_IO_FEATURE_##expansion
1137#define IS_DEFINED(macro) IS_DEFINED_APPLY( IS_DEFINED_SECOND,IS_DEFINED_TEST(macro) false, true)
1138
1139bool has_user_level_blocking( fptr_t func ) {
1140        #if defined(HAVE_LINUX_IO_URING_H)
1141                #if defined(HAVE_PREADV2)
1142                        if( /*func == (fptr_t)preadv2 || */
1143                                func == (fptr_t)cfa_preadv2 )
1144                                #define _CFA_IO_FEATURE_IORING_OP_READV ,
1145                                return IS_DEFINED(IORING_OP_READV);
1146                #endif
1147
1148                #if defined(HAVE_PWRITEV2)
1149                        if( /*func == (fptr_t)pwritev2 || */
1150                                func == (fptr_t)cfa_pwritev2 )
1151                                #define _CFA_IO_FEATURE_IORING_OP_WRITEV ,
1152                                return IS_DEFINED(IORING_OP_WRITEV);
1153                #endif
1154
1155                if( /*func == (fptr_t)fsync || */
1156                        func == (fptr_t)cfa_fsync )
1157                        #define _CFA_IO_FEATURE_IORING_OP_FSYNC ,
1158                        return IS_DEFINED(IORING_OP_FSYNC);
1159
1160                if( /*func == (fptr_t)ync_file_range || */
1161                        func == (fptr_t)cfa_sync_file_range )
1162                        #define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE ,
1163                        return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE);
1164
1165                if( /*func == (fptr_t)sendmsg || */
1166                        func == (fptr_t)cfa_sendmsg )
1167                        #define _CFA_IO_FEATURE_IORING_OP_SENDMSG ,
1168                        return IS_DEFINED(IORING_OP_SENDMSG);
1169
1170                if( /*func == (fptr_t)recvmsg || */
1171                        func == (fptr_t)cfa_recvmsg )
1172                        #define _CFA_IO_FEATURE_IORING_OP_RECVMSG ,
1173                        return IS_DEFINED(IORING_OP_RECVMSG);
1174
1175                if( /*func == (fptr_t)send || */
1176                        func == (fptr_t)cfa_send )
1177                        #define _CFA_IO_FEATURE_IORING_OP_SEND ,
1178                        return IS_DEFINED(IORING_OP_SEND);
1179
1180                if( /*func == (fptr_t)recv || */
1181                        func == (fptr_t)cfa_recv )
1182                        #define _CFA_IO_FEATURE_IORING_OP_RECV ,
1183                        return IS_DEFINED(IORING_OP_RECV);
1184
1185                if( /*func == (fptr_t)accept4 || */
1186                        func == (fptr_t)cfa_accept4 )
1187                        #define _CFA_IO_FEATURE_IORING_OP_ACCEPT ,
1188                        return IS_DEFINED(IORING_OP_ACCEPT);
1189
1190                if( /*func == (fptr_t)connect || */
1191                        func == (fptr_t)cfa_connect )
1192                        #define _CFA_IO_FEATURE_IORING_OP_CONNECT ,
1193                        return IS_DEFINED(IORING_OP_CONNECT);
1194
1195                if( /*func == (fptr_t)fallocate || */
1196                        func == (fptr_t)cfa_fallocate )
1197                        #define _CFA_IO_FEATURE_IORING_OP_FALLOCATE ,
1198                        return IS_DEFINED(IORING_OP_FALLOCATE);
1199
1200                if( /*func == (fptr_t)posix_fadvise || */
1201                        func == (fptr_t)cfa_fadvise )
1202                        #define _CFA_IO_FEATURE_IORING_OP_FADVISE ,
1203                        return IS_DEFINED(IORING_OP_FADVISE);
1204
1205                if( /*func == (fptr_t)madvise || */
1206                        func == (fptr_t)cfa_madvise )
1207                        #define _CFA_IO_FEATURE_IORING_OP_MADVISE ,
1208                        return IS_DEFINED(IORING_OP_MADVISE);
1209
1210                if( /*func == (fptr_t)openat || */
1211                        func == (fptr_t)cfa_openat )
1212                        #define _CFA_IO_FEATURE_IORING_OP_OPENAT ,
1213                        return IS_DEFINED(IORING_OP_OPENAT);
1214
1215                if( /*func == (fptr_t)close || */
1216                        func == (fptr_t)cfa_close )
1217                        #define _CFA_IO_FEATURE_IORING_OP_CLOSE ,
1218                        return IS_DEFINED(IORING_OP_CLOSE);
1219
1220                if( /*func == (fptr_t)read || */
1221                        func == (fptr_t)cfa_read )
1222                        #define _CFA_IO_FEATURE_IORING_OP_READ ,
1223                        return IS_DEFINED(IORING_OP_READ);
1224
1225                if( /*func == (fptr_t)write || */
1226                        func == (fptr_t)cfa_write )
1227                        #define _CFA_IO_FEATURE_IORING_OP_WRITE ,
1228                        return IS_DEFINED(IORING_OP_WRITE);
1229        #endif
1230
1231        return false;
1232}
Note: See TracBrowser for help on using the repository browser.