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

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 7425720 was 4479890, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Implemented helping for io drain based on timestamps.

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