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
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/types.hfa -- PRIVATE
8// Types used by the I/O subsystem
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
19#include <limits.h>
20
21extern "C" {
22        #include <linux/types.h>
23}
24
25#include "bits/locks.hfa"
26#include "bits/queue.hfa"
27#include "iofwd.hfa"
28#include "kernel/fwd.hfa"
29
30#if defined(CFA_HAVE_LINUX_IO_URING_H)
31        #include "bits/sequence.hfa"
32        #include "monitor.hfa"
33
34        struct processor;
35        monitor io_arbiter$;
36
37        //-----------------------------------------------------------------------
38        // Ring Data structure
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;
61
62                // number of entries and mask to go with it
63                const __u32 * num;
64                const __u32 * mask;
65
66                // Submission flags, currently only IORING_SETUP_SQPOLL
67                __u32 * flags;
68
69                // number of sqes not submitted
70                // From documentation : [dropped] is incremented for each invalid submission queue entry encountered in the ring buffer.
71                __u32 * dropped;
72
73                // A buffer of sqes (not the actual ring)
74                struct io_uring_sqe * sqes;
75
76                // The location and size of the mmaped area
77                void * ring_ptr;
78                size_t ring_sz;
79        };
80
81        struct __cmp_ring_t {
82                volatile bool lock;
83
84                unsigned id;
85
86                unsigned long long ts;
87
88                // Head and tail of the ring
89                volatile __u32 * head;
90                volatile __u32 * tail;
91
92                // number of entries and mask to go with it
93                const __u32 * mask;
94                const __u32 * num;
95
96                // I don't know what this value is for
97                __u32 * overflow;
98
99                // the kernel ring
100                volatile struct io_uring_cqe * cqes;
101
102                // The location and size of the mmaped area
103                void * ring_ptr;
104                size_t ring_sz;
105        };
106
107        struct __outstanding_io {
108                inline Colable;
109                oneshot waitctx;
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
127        struct __attribute__((aligned(64))) io_context$ {
128                io_arbiter$ * arbiter;
129                struct processor * proc;
130
131                __outstanding_io_queue ext_sq;
132
133                struct __sub_ring_t sq;
134                struct __cmp_ring_t cq;
135                __u32 ring_flags;
136                int fd;
137        };
138
139        static inline unsigned long long ts(io_context$ *& this) {
140                const __u32 head = *this->cq.head;
141                const __u32 tail = *this->cq.tail;
142
143                if(head == tail) return ULLONG_MAX;
144
145                return this->cq.ts;
146        }
147
148        struct __pending_alloc {
149                inline __outstanding_io;
150                __u32 * idxs;
151                __u32 want;
152                io_context$ * ctx;
153        };
154
155        monitor __attribute__((aligned(64))) io_arbiter$ {
156                __outstanding_io_queue pending;
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
188        // void __ioctx_prepare_block(io_context$ & ctx);
189#endif
Note: See TracBrowser for help on using the repository browser.