[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 | // |
---|
| 7 | // io/types.hfa -- |
---|
| 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Fri Jul 31 16:22:47 2020 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
| 18 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
[4998155] | 19 | extern "C" { |
---|
| 20 | #include <linux/types.h> |
---|
| 21 | } |
---|
| 22 | |
---|
[3e2b9c9] | 23 | #include "bits/locks.hfa" |
---|
| 24 | |
---|
[d2b5d2d] | 25 | #define LEADER_LOCK |
---|
[2fafe7e] | 26 | struct __leaderlock_t { |
---|
| 27 | struct $thread * volatile value; // ($thread) next_leader | (bool:1) is_locked |
---|
| 28 | }; |
---|
| 29 | |
---|
| 30 | static inline void ?{}( __leaderlock_t & this ) { this.value = 0p; } |
---|
| 31 | |
---|
[3e2b9c9] | 32 | //----------------------------------------------------------------------- |
---|
| 33 | // Ring Data structure |
---|
| 34 | struct __submition_data { |
---|
| 35 | // Head and tail of the ring (associated with array) |
---|
[4998155] | 36 | volatile __u32 * head; |
---|
| 37 | volatile __u32 * tail; |
---|
| 38 | volatile __u32 prev_head; |
---|
[3e2b9c9] | 39 | |
---|
| 40 | // The actual kernel ring which uses head/tail |
---|
| 41 | // indexes into the sqes arrays |
---|
[4998155] | 42 | __u32 * array; |
---|
[3e2b9c9] | 43 | |
---|
| 44 | // number of entries and mask to go with it |
---|
[4998155] | 45 | const __u32 * num; |
---|
| 46 | const __u32 * mask; |
---|
[3e2b9c9] | 47 | |
---|
| 48 | // Submission flags (Not sure what for) |
---|
[4998155] | 49 | __u32 * flags; |
---|
[3e2b9c9] | 50 | |
---|
| 51 | // number of sqes not submitted (whatever that means) |
---|
[4998155] | 52 | __u32 * dropped; |
---|
[3e2b9c9] | 53 | |
---|
| 54 | // Like head/tail but not seen by the kernel |
---|
[4998155] | 55 | volatile __u32 * ready; |
---|
| 56 | __u32 ready_cnt; |
---|
[1095ccd] | 57 | __u32 prev_ready; |
---|
[3e2b9c9] | 58 | |
---|
[2fafe7e] | 59 | #if defined(LEADER_LOCK) |
---|
| 60 | __leaderlock_t submit_lock; |
---|
| 61 | #else |
---|
| 62 | __spinlock_t submit_lock; |
---|
| 63 | #endif |
---|
| 64 | __spinlock_t release_lock; |
---|
[3e2b9c9] | 65 | |
---|
| 66 | // A buffer of sqes (not the actual ring) |
---|
| 67 | struct io_uring_sqe * sqes; |
---|
| 68 | |
---|
| 69 | // The location and size of the mmaped area |
---|
| 70 | void * ring_ptr; |
---|
| 71 | size_t ring_sz; |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | struct __completion_data { |
---|
| 75 | // Head and tail of the ring |
---|
[4998155] | 76 | volatile __u32 * head; |
---|
| 77 | volatile __u32 * tail; |
---|
[3e2b9c9] | 78 | |
---|
| 79 | // number of entries and mask to go with it |
---|
[4998155] | 80 | const __u32 * mask; |
---|
| 81 | const __u32 * num; |
---|
[3e2b9c9] | 82 | |
---|
| 83 | // number of cqes not submitted (whatever that means) |
---|
[4998155] | 84 | __u32 * overflow; |
---|
[3e2b9c9] | 85 | |
---|
| 86 | // the kernel ring |
---|
| 87 | struct io_uring_cqe * cqes; |
---|
| 88 | |
---|
| 89 | // The location and size of the mmaped area |
---|
| 90 | void * ring_ptr; |
---|
| 91 | size_t ring_sz; |
---|
| 92 | }; |
---|
| 93 | |
---|
| 94 | struct __io_data { |
---|
| 95 | struct __submition_data submit_q; |
---|
| 96 | struct __completion_data completion_q; |
---|
[4998155] | 97 | __u32 ring_flags; |
---|
[3e2b9c9] | 98 | int fd; |
---|
| 99 | bool eager_submits:1; |
---|
| 100 | bool poller_submits:1; |
---|
| 101 | }; |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | //----------------------------------------------------------------------- |
---|
| 105 | // IO user data |
---|
| 106 | struct __io_user_data_t { |
---|
[4998155] | 107 | __s32 result; |
---|
| 108 | oneshot sem; |
---|
[3e2b9c9] | 109 | }; |
---|
| 110 | |
---|
| 111 | //----------------------------------------------------------------------- |
---|
| 112 | // Misc |
---|
| 113 | // Weirdly, some systems that do support io_uring don't actually define these |
---|
| 114 | #ifdef __alpha__ |
---|
| 115 | /* |
---|
| 116 | * alpha is the only exception, all other architectures |
---|
| 117 | * have common numbers for new system calls. |
---|
| 118 | */ |
---|
| 119 | #ifndef __NR_io_uring_setup |
---|
| 120 | #define __NR_io_uring_setup 535 |
---|
| 121 | #endif |
---|
| 122 | #ifndef __NR_io_uring_enter |
---|
| 123 | #define __NR_io_uring_enter 536 |
---|
| 124 | #endif |
---|
| 125 | #ifndef __NR_io_uring_register |
---|
| 126 | #define __NR_io_uring_register 537 |
---|
| 127 | #endif |
---|
| 128 | #else /* !__alpha__ */ |
---|
| 129 | #ifndef __NR_io_uring_setup |
---|
| 130 | #define __NR_io_uring_setup 425 |
---|
| 131 | #endif |
---|
| 132 | #ifndef __NR_io_uring_enter |
---|
| 133 | #define __NR_io_uring_enter 426 |
---|
| 134 | #endif |
---|
| 135 | #ifndef __NR_io_uring_register |
---|
| 136 | #define __NR_io_uring_register 427 |
---|
| 137 | #endif |
---|
| 138 | #endif |
---|
| 139 | |
---|
| 140 | struct epoll_event; |
---|
| 141 | struct $io_ctx_thread; |
---|
| 142 | void __ioctx_register($io_ctx_thread & ctx, struct epoll_event & ev); |
---|
| 143 | void __ioctx_prepare_block($io_ctx_thread & ctx, struct epoll_event & ev); |
---|
| 144 | #endif |
---|