[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" |
---|
[454f478] | 24 | #include "kernel/fwd.hfa" |
---|
[3e2b9c9] | 25 | |
---|
[930e57e] | 26 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
[78da4ab] | 27 | #include "bits/sequence.hfa" |
---|
| 28 | #include "monitor.hfa" |
---|
[2fafe7e] | 29 | |
---|
[78da4ab] | 30 | struct processor; |
---|
| 31 | monitor $io_arbiter; |
---|
[2fafe7e] | 32 | |
---|
[3e2b9c9] | 33 | //----------------------------------------------------------------------- |
---|
| 34 | // Ring Data structure |
---|
[78da4ab] | 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; |
---|
[3e2b9c9] | 57 | |
---|
| 58 | // number of entries and mask to go with it |
---|
[4998155] | 59 | const __u32 * num; |
---|
| 60 | const __u32 * mask; |
---|
[3e2b9c9] | 61 | |
---|
[78da4ab] | 62 | // Submission flags, currently only IORING_SETUP_SQPOLL |
---|
[4998155] | 63 | __u32 * flags; |
---|
[3e2b9c9] | 64 | |
---|
[78da4ab] | 65 | // number of sqes not submitted |
---|
| 66 | // From documentation : [dropped] is incremented for each invalid submission queue entry encountered in the ring buffer. |
---|
[4998155] | 67 | __u32 * dropped; |
---|
[3e2b9c9] | 68 | |
---|
| 69 | // A buffer of sqes (not the actual ring) |
---|
[78da4ab] | 70 | struct io_uring_sqe * sqes; |
---|
[3e2b9c9] | 71 | |
---|
| 72 | // The location and size of the mmaped area |
---|
| 73 | void * ring_ptr; |
---|
| 74 | size_t ring_sz; |
---|
| 75 | }; |
---|
| 76 | |
---|
[78da4ab] | 77 | struct __cmp_ring_t { |
---|
[3e2b9c9] | 78 | // Head and tail of the ring |
---|
[4998155] | 79 | volatile __u32 * head; |
---|
| 80 | volatile __u32 * tail; |
---|
[3e2b9c9] | 81 | |
---|
| 82 | // number of entries and mask to go with it |
---|
[4998155] | 83 | const __u32 * mask; |
---|
| 84 | const __u32 * num; |
---|
[3e2b9c9] | 85 | |
---|
[78da4ab] | 86 | // I don't know what this value is for |
---|
[4998155] | 87 | __u32 * overflow; |
---|
[3e2b9c9] | 88 | |
---|
| 89 | // the kernel ring |
---|
[426f60c] | 90 | volatile struct io_uring_cqe * cqes; |
---|
[3e2b9c9] | 91 | |
---|
| 92 | // The location and size of the mmaped area |
---|
| 93 | void * ring_ptr; |
---|
| 94 | size_t ring_sz; |
---|
| 95 | }; |
---|
| 96 | |
---|
[78da4ab] | 97 | struct __attribute__((aligned(128))) $io_context { |
---|
| 98 | $io_arbiter * arbiter; |
---|
[dddb3dd0] | 99 | processor * proc; |
---|
[78da4ab] | 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; |
---|
[4998155] | 108 | __u32 ring_flags; |
---|
[3e2b9c9] | 109 | int fd; |
---|
[78da4ab] | 110 | }; |
---|
| 111 | |
---|
| 112 | monitor __attribute__((aligned(128))) $io_arbiter { |
---|
| 113 | struct { |
---|
| 114 | condition blocked; |
---|
| 115 | $io_context * ctx; |
---|
| 116 | volatile bool flag; |
---|
| 117 | } pending; |
---|
[3e2b9c9] | 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 | |
---|
[dddb3dd0] | 149 | // void __ioctx_prepare_block($io_context & ctx); |
---|
[930e57e] | 150 | #endif |
---|
| 151 | |
---|
| 152 | //----------------------------------------------------------------------- |
---|
| 153 | // IO user data |
---|
| 154 | struct io_future_t { |
---|
| 155 | future_t self; |
---|
| 156 | __s32 result; |
---|
| 157 | }; |
---|
| 158 | |
---|
| 159 | static 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 | } |
---|