source: libcfa/src/concurrency/io/types.hfa @ a55472cc

ADTast-experimental
Last change on this file since a55472cc was a55472cc, checked in by Thierry Delisle <tdelisle@…>, 19 months ago

Removed use of single_sem in io since oneshot is sufficient and used more consistently

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[3e2b9c9]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//
[454f478]7// io/types.hfa -- PRIVATE
8// Types used by the I/O subsystem
[3e2b9c9]9//
10// Author           : Thierry Delisle
11// Created On       : Fri Jul 31 16:22:47 2020
12// Last Modified By :
13// Last Modified On :
14// Update Count     :
15//
16
17#pragma once
18
[b035046]19#include <limits.h>
20
[930e57e]21extern "C" {
22        #include <linux/types.h>
23}
[4998155]24
[9db2c92]25#include "bits/locks.hfa"
[11054eb]26#include "bits/queue.hfa"
[40a606d2]27#include "iofwd.hfa"
[454f478]28#include "kernel/fwd.hfa"
[3e2b9c9]29
[930e57e]30#if defined(CFA_HAVE_LINUX_IO_URING_H)
[78da4ab]31        #include "bits/sequence.hfa"
32        #include "monitor.hfa"
[2fafe7e]33
[78da4ab]34        struct processor;
[8bee858]35        monitor io_arbiter$;
[2fafe7e]36
[3e2b9c9]37        //-----------------------------------------------------------------------
38        // Ring Data structure
[78da4ab]39      struct __sub_ring_t {
40                struct {
41                        // Head and tail of the ring (associated with array)
42                        volatile __u32 * head;   // one passed last index consumed by the kernel
43                        volatile __u32 * tail;   // one passed last index visible to the kernel
44                        volatile __u32 released; // one passed last index released back to the free list
45
46                        // The actual kernel ring which uses head/tail
47                        // indexes into the sqes arrays
48                        __u32 * array;
49                } kring;
50
51                struct {
52                        volatile __u32 head;
53                        volatile __u32 tail;
54                        // The ring which contains free allocations
55                        // indexes into the sqes arrays
56                        __u32 * array;
57                } free_ring;
58
59                // number of sqes to submit on next system call.
60                __u32 to_submit;
[3e2b9c9]61
62                // number of entries and mask to go with it
[4998155]63                const __u32 * num;
64                const __u32 * mask;
[3e2b9c9]65
[78da4ab]66                // Submission flags, currently only IORING_SETUP_SQPOLL
[4998155]67                __u32 * flags;
[3e2b9c9]68
[78da4ab]69                // number of sqes not submitted
70                // From documentation : [dropped] is incremented for each invalid submission queue entry encountered in the ring buffer.
[4998155]71                __u32 * dropped;
[3e2b9c9]72
73                // A buffer of sqes (not the actual ring)
[78da4ab]74                struct io_uring_sqe * sqes;
[3e2b9c9]75
76                // The location and size of the mmaped area
77                void * ring_ptr;
78                size_t ring_sz;
79        };
80
[78da4ab]81        struct __cmp_ring_t {
[4ecc35a]82                volatile bool lock;
83
[78a580d]84                unsigned id;
85
86                unsigned long long ts;
87
[3e2b9c9]88                // Head and tail of the ring
[4998155]89                volatile __u32 * head;
90                volatile __u32 * tail;
[3e2b9c9]91
92                // number of entries and mask to go with it
[4998155]93                const __u32 * mask;
94                const __u32 * num;
[3e2b9c9]95
[78da4ab]96                // I don't know what this value is for
[4998155]97                __u32 * overflow;
[3e2b9c9]98
99                // the kernel ring
[426f60c]100                volatile struct io_uring_cqe * cqes;
[3e2b9c9]101
102                // The location and size of the mmaped area
103                void * ring_ptr;
104                size_t ring_sz;
105        };
106
[11054eb]107        struct __outstanding_io {
108                inline Colable;
[a55472cc]109                oneshot waitctx;
[11054eb]110        };
111        static inline __outstanding_io *& Next( __outstanding_io * n ) { return (__outstanding_io *)Next( (Colable *)n ); }
112
113        struct __outstanding_io_queue {
114                __spinlock_t lock;
115                Queue(__outstanding_io) queue;
116                volatile bool empty;
117        };
118
119        struct __external_io {
120                inline __outstanding_io;
121                __u32 * idxs;
122                __u32 have;
123                bool lazy;
124        };
125
126
[8bee858]127        struct __attribute__((aligned(64))) io_context$ {
128                io_arbiter$ * arbiter;
[1756e08]129                struct processor * proc;
[78da4ab]130
[11054eb]131                __outstanding_io_queue ext_sq;
[78da4ab]132
133                struct __sub_ring_t sq;
134                struct __cmp_ring_t cq;
[4998155]135                __u32 ring_flags;
[3e2b9c9]136                int fd;
[78da4ab]137        };
138
[8bee858]139        static inline unsigned long long ts(io_context$ *& this) {
[e71e94a]140                const __u32 head = *this->cq.head;
141                const __u32 tail = *this->cq.tail;
142
[b035046]143                if(head == tail) return ULLONG_MAX;
[e71e94a]144
[4479890]145                return this->cq.ts;
146        }
147
[11054eb]148        struct __pending_alloc {
149                inline __outstanding_io;
150                __u32 * idxs;
151                __u32 want;
[8bee858]152                io_context$ * ctx;
[11054eb]153        };
154
[8bee858]155        monitor __attribute__((aligned(64))) io_arbiter$ {
[11054eb]156                __outstanding_io_queue pending;
[3e2b9c9]157        };
158
159        //-----------------------------------------------------------------------
160        // Misc
161        // Weirdly, some systems that do support io_uring don't actually define these
162        #ifdef __alpha__
163                /*
164                * alpha is the only exception, all other architectures
165                * have common numbers for new system calls.
166                */
167                #ifndef __NR_io_uring_setup
168                        #define __NR_io_uring_setup           535
169                #endif
170                #ifndef __NR_io_uring_enter
171                        #define __NR_io_uring_enter           536
172                #endif
173                #ifndef __NR_io_uring_register
174                        #define __NR_io_uring_register        537
175                #endif
176        #else /* !__alpha__ */
177                #ifndef __NR_io_uring_setup
178                        #define __NR_io_uring_setup           425
179                #endif
180                #ifndef __NR_io_uring_enter
181                        #define __NR_io_uring_enter           426
182                #endif
183                #ifndef __NR_io_uring_register
184                        #define __NR_io_uring_register        427
185                #endif
186        #endif
187
[8bee858]188        // void __ioctx_prepare_block(io_context$ & ctx);
[40a606d2]189#endif
Note: See TracBrowser for help on using the repository browser.