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

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

Changed io to use ring per kernel threads.

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