source: libcfa/src/concurrency/io.cfa @ 2f1cb37

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 2f1cb37 was 2f1cb37, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Merge branch 'master' into relaxed_ready

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