[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" |
---|
[3e2b9c9] | 27 | |
---|
[930e57e] | 28 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
[78da4ab] | 29 | #include "bits/sequence.hfa" |
---|
| 30 | #include "monitor.hfa" |
---|
[2fafe7e] | 31 | |
---|
[78da4ab] | 32 | struct processor; |
---|
| 33 | monitor $io_arbiter; |
---|
[2fafe7e] | 34 | |
---|
[3e2b9c9] | 35 | //----------------------------------------------------------------------- |
---|
| 36 | // Ring Data structure |
---|
[78da4ab] | 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; |
---|
[3e2b9c9] | 59 | |
---|
| 60 | // number of entries and mask to go with it |
---|
[4998155] | 61 | const __u32 * num; |
---|
| 62 | const __u32 * mask; |
---|
[3e2b9c9] | 63 | |
---|
[78da4ab] | 64 | // Submission flags, currently only IORING_SETUP_SQPOLL |
---|
[4998155] | 65 | __u32 * flags; |
---|
[3e2b9c9] | 66 | |
---|
[78da4ab] | 67 | // number of sqes not submitted |
---|
| 68 | // From documentation : [dropped] is incremented for each invalid submission queue entry encountered in the ring buffer. |
---|
[4998155] | 69 | __u32 * dropped; |
---|
[3e2b9c9] | 70 | |
---|
| 71 | // A buffer of sqes (not the actual ring) |
---|
[78da4ab] | 72 | struct io_uring_sqe * sqes; |
---|
[3e2b9c9] | 73 | |
---|
| 74 | // The location and size of the mmaped area |
---|
| 75 | void * ring_ptr; |
---|
| 76 | size_t ring_sz; |
---|
| 77 | }; |
---|
| 78 | |
---|
[78da4ab] | 79 | struct __cmp_ring_t { |
---|
[4ecc35a] | 80 | volatile bool lock; |
---|
| 81 | |
---|
[78a580d] | 82 | unsigned id; |
---|
| 83 | |
---|
| 84 | unsigned long long ts; |
---|
| 85 | |
---|
[3e2b9c9] | 86 | // Head and tail of the ring |
---|
[4998155] | 87 | volatile __u32 * head; |
---|
| 88 | volatile __u32 * tail; |
---|
[3e2b9c9] | 89 | |
---|
| 90 | // number of entries and mask to go with it |
---|
[4998155] | 91 | const __u32 * mask; |
---|
| 92 | const __u32 * num; |
---|
[3e2b9c9] | 93 | |
---|
[78da4ab] | 94 | // I don't know what this value is for |
---|
[4998155] | 95 | __u32 * overflow; |
---|
[3e2b9c9] | 96 | |
---|
| 97 | // the kernel ring |
---|
[426f60c] | 98 | volatile struct io_uring_cqe * cqes; |
---|
[3e2b9c9] | 99 | |
---|
| 100 | // The location and size of the mmaped area |
---|
| 101 | void * ring_ptr; |
---|
| 102 | size_t ring_sz; |
---|
| 103 | }; |
---|
| 104 | |
---|
[11054eb] | 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 | |
---|
[78da4ab] | 125 | struct __attribute__((aligned(128))) $io_context { |
---|
| 126 | $io_arbiter * arbiter; |
---|
[dddb3dd0] | 127 | processor * proc; |
---|
[78da4ab] | 128 | |
---|
[11054eb] | 129 | __outstanding_io_queue ext_sq; |
---|
[78da4ab] | 130 | |
---|
| 131 | struct __sub_ring_t sq; |
---|
| 132 | struct __cmp_ring_t cq; |
---|
[4998155] | 133 | __u32 ring_flags; |
---|
[3e2b9c9] | 134 | int fd; |
---|
[78da4ab] | 135 | }; |
---|
| 136 | |
---|
[11054eb] | 137 | struct __pending_alloc { |
---|
| 138 | inline __outstanding_io; |
---|
| 139 | __u32 * idxs; |
---|
| 140 | __u32 want; |
---|
| 141 | $io_context * ctx; |
---|
| 142 | }; |
---|
| 143 | |
---|
| 144 | struct __attribute__((aligned(128))) $io_arbiter { |
---|
| 145 | __outstanding_io_queue pending; |
---|
[3e2b9c9] | 146 | }; |
---|
| 147 | |
---|
| 148 | //----------------------------------------------------------------------- |
---|
| 149 | // Misc |
---|
| 150 | // Weirdly, some systems that do support io_uring don't actually define these |
---|
| 151 | #ifdef __alpha__ |
---|
| 152 | /* |
---|
| 153 | * alpha is the only exception, all other architectures |
---|
| 154 | * have common numbers for new system calls. |
---|
| 155 | */ |
---|
| 156 | #ifndef __NR_io_uring_setup |
---|
| 157 | #define __NR_io_uring_setup 535 |
---|
| 158 | #endif |
---|
| 159 | #ifndef __NR_io_uring_enter |
---|
| 160 | #define __NR_io_uring_enter 536 |
---|
| 161 | #endif |
---|
| 162 | #ifndef __NR_io_uring_register |
---|
| 163 | #define __NR_io_uring_register 537 |
---|
| 164 | #endif |
---|
| 165 | #else /* !__alpha__ */ |
---|
| 166 | #ifndef __NR_io_uring_setup |
---|
| 167 | #define __NR_io_uring_setup 425 |
---|
| 168 | #endif |
---|
| 169 | #ifndef __NR_io_uring_enter |
---|
| 170 | #define __NR_io_uring_enter 426 |
---|
| 171 | #endif |
---|
| 172 | #ifndef __NR_io_uring_register |
---|
| 173 | #define __NR_io_uring_register 427 |
---|
| 174 | #endif |
---|
| 175 | #endif |
---|
| 176 | |
---|
[dddb3dd0] | 177 | // void __ioctx_prepare_block($io_context & ctx); |
---|
[40a606d2] | 178 | #endif |
---|