source: libcfa/src/concurrency/io/types.hfa @ 11054eb

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

Fix io to no longer use monitors since some usages aren't in threads

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