[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) |
---|
[d2b5d2d] | 27 | #define LEADER_LOCK |
---|
[2fafe7e] | 28 | struct __leaderlock_t { |
---|
| 29 | struct $thread * volatile value; // ($thread) next_leader | (bool:1) is_locked |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | static inline void ?{}( __leaderlock_t & this ) { this.value = 0p; } |
---|
| 33 | |
---|
[3e2b9c9] | 34 | //----------------------------------------------------------------------- |
---|
| 35 | // Ring Data structure |
---|
| 36 | struct __submition_data { |
---|
| 37 | // Head and tail of the ring (associated with array) |
---|
[4998155] | 38 | volatile __u32 * head; |
---|
| 39 | volatile __u32 * tail; |
---|
| 40 | volatile __u32 prev_head; |
---|
[3e2b9c9] | 41 | |
---|
| 42 | // The actual kernel ring which uses head/tail |
---|
| 43 | // indexes into the sqes arrays |
---|
[4998155] | 44 | __u32 * array; |
---|
[3e2b9c9] | 45 | |
---|
| 46 | // number of entries and mask to go with it |
---|
[4998155] | 47 | const __u32 * num; |
---|
| 48 | const __u32 * mask; |
---|
[3e2b9c9] | 49 | |
---|
| 50 | // Submission flags (Not sure what for) |
---|
[4998155] | 51 | __u32 * flags; |
---|
[3e2b9c9] | 52 | |
---|
| 53 | // number of sqes not submitted (whatever that means) |
---|
[4998155] | 54 | __u32 * dropped; |
---|
[3e2b9c9] | 55 | |
---|
| 56 | // Like head/tail but not seen by the kernel |
---|
[4998155] | 57 | volatile __u32 * ready; |
---|
| 58 | __u32 ready_cnt; |
---|
[1095ccd] | 59 | __u32 prev_ready; |
---|
[3e2b9c9] | 60 | |
---|
[2fafe7e] | 61 | #if defined(LEADER_LOCK) |
---|
| 62 | __leaderlock_t submit_lock; |
---|
| 63 | #else |
---|
| 64 | __spinlock_t submit_lock; |
---|
| 65 | #endif |
---|
| 66 | __spinlock_t release_lock; |
---|
[3e2b9c9] | 67 | |
---|
| 68 | // A buffer of sqes (not the actual ring) |
---|
[426f60c] | 69 | volatile struct io_uring_sqe * sqes; |
---|
[3e2b9c9] | 70 | |
---|
| 71 | // The location and size of the mmaped area |
---|
| 72 | void * ring_ptr; |
---|
| 73 | size_t ring_sz; |
---|
| 74 | }; |
---|
| 75 | |
---|
| 76 | struct __completion_data { |
---|
| 77 | // Head and tail of the ring |
---|
[4998155] | 78 | volatile __u32 * head; |
---|
| 79 | volatile __u32 * tail; |
---|
[3e2b9c9] | 80 | |
---|
| 81 | // number of entries and mask to go with it |
---|
[4998155] | 82 | const __u32 * mask; |
---|
| 83 | const __u32 * num; |
---|
[3e2b9c9] | 84 | |
---|
| 85 | // number of cqes not submitted (whatever that means) |
---|
[4998155] | 86 | __u32 * overflow; |
---|
[3e2b9c9] | 87 | |
---|
| 88 | // the kernel ring |
---|
[426f60c] | 89 | volatile struct io_uring_cqe * cqes; |
---|
[3e2b9c9] | 90 | |
---|
| 91 | // The location and size of the mmaped area |
---|
| 92 | void * ring_ptr; |
---|
| 93 | size_t ring_sz; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | struct __io_data { |
---|
| 97 | struct __submition_data submit_q; |
---|
| 98 | struct __completion_data completion_q; |
---|
[4998155] | 99 | __u32 ring_flags; |
---|
[3e2b9c9] | 100 | int fd; |
---|
[426f60c] | 101 | int efd; |
---|
[3e2b9c9] | 102 | bool eager_submits:1; |
---|
| 103 | bool poller_submits:1; |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | //----------------------------------------------------------------------- |
---|
| 107 | // Misc |
---|
| 108 | // Weirdly, some systems that do support io_uring don't actually define these |
---|
| 109 | #ifdef __alpha__ |
---|
| 110 | /* |
---|
| 111 | * alpha is the only exception, all other architectures |
---|
| 112 | * have common numbers for new system calls. |
---|
| 113 | */ |
---|
| 114 | #ifndef __NR_io_uring_setup |
---|
| 115 | #define __NR_io_uring_setup 535 |
---|
| 116 | #endif |
---|
| 117 | #ifndef __NR_io_uring_enter |
---|
| 118 | #define __NR_io_uring_enter 536 |
---|
| 119 | #endif |
---|
| 120 | #ifndef __NR_io_uring_register |
---|
| 121 | #define __NR_io_uring_register 537 |
---|
| 122 | #endif |
---|
| 123 | #else /* !__alpha__ */ |
---|
| 124 | #ifndef __NR_io_uring_setup |
---|
| 125 | #define __NR_io_uring_setup 425 |
---|
| 126 | #endif |
---|
| 127 | #ifndef __NR_io_uring_enter |
---|
| 128 | #define __NR_io_uring_enter 426 |
---|
| 129 | #endif |
---|
| 130 | #ifndef __NR_io_uring_register |
---|
| 131 | #define __NR_io_uring_register 427 |
---|
| 132 | #endif |
---|
| 133 | #endif |
---|
| 134 | |
---|
| 135 | struct $io_ctx_thread; |
---|
[d48b174] | 136 | void __ioctx_register($io_ctx_thread & ctx); |
---|
[d611995] | 137 | void __ioctx_unregister($io_ctx_thread & ctx); |
---|
[d48b174] | 138 | void __ioctx_prepare_block($io_ctx_thread & ctx); |
---|
[35285fd] | 139 | void __sqe_clean( volatile struct io_uring_sqe * sqe ); |
---|
[930e57e] | 140 | #endif |
---|
| 141 | |
---|
| 142 | //----------------------------------------------------------------------- |
---|
| 143 | // IO user data |
---|
| 144 | struct io_future_t { |
---|
| 145 | future_t self; |
---|
| 146 | __s32 result; |
---|
| 147 | }; |
---|
| 148 | |
---|
| 149 | static inline { |
---|
| 150 | bool fulfil( io_future_t & this, __s32 result ) { |
---|
| 151 | this.result = result; |
---|
| 152 | return fulfil(this.self); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | // Wait for the future to be fulfilled |
---|
| 156 | bool wait( io_future_t & this ) { |
---|
| 157 | return wait(this.self); |
---|
| 158 | } |
---|
| 159 | } |
---|