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