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 | extern "C" { |
---|
19 | #include <linux/types.h> |
---|
20 | } |
---|
21 | |
---|
22 | #include "bits/locks.hfa" |
---|
23 | |
---|
24 | #if defined(CFA_HAVE_LINUX_IO_URING_H) |
---|
25 | #define LEADER_LOCK |
---|
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 | |
---|
32 | //----------------------------------------------------------------------- |
---|
33 | // Ring Data structure |
---|
34 | struct __submition_data { |
---|
35 | // Head and tail of the ring (associated with array) |
---|
36 | volatile __u32 * head; |
---|
37 | volatile __u32 * tail; |
---|
38 | volatile __u32 prev_head; |
---|
39 | |
---|
40 | // The actual kernel ring which uses head/tail |
---|
41 | // indexes into the sqes arrays |
---|
42 | __u32 * array; |
---|
43 | |
---|
44 | // number of entries and mask to go with it |
---|
45 | const __u32 * num; |
---|
46 | const __u32 * mask; |
---|
47 | |
---|
48 | // Submission flags (Not sure what for) |
---|
49 | __u32 * flags; |
---|
50 | |
---|
51 | // number of sqes not submitted (whatever that means) |
---|
52 | __u32 * dropped; |
---|
53 | |
---|
54 | // Like head/tail but not seen by the kernel |
---|
55 | volatile __u32 * ready; |
---|
56 | __u32 ready_cnt; |
---|
57 | __u32 prev_ready; |
---|
58 | |
---|
59 | #if defined(LEADER_LOCK) |
---|
60 | __leaderlock_t submit_lock; |
---|
61 | #else |
---|
62 | __spinlock_t submit_lock; |
---|
63 | #endif |
---|
64 | __spinlock_t release_lock; |
---|
65 | |
---|
66 | // A buffer of sqes (not the actual ring) |
---|
67 | volatile 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 |
---|
76 | volatile __u32 * head; |
---|
77 | volatile __u32 * tail; |
---|
78 | |
---|
79 | // number of entries and mask to go with it |
---|
80 | const __u32 * mask; |
---|
81 | const __u32 * num; |
---|
82 | |
---|
83 | // number of cqes not submitted (whatever that means) |
---|
84 | __u32 * overflow; |
---|
85 | |
---|
86 | // the kernel ring |
---|
87 | volatile 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; |
---|
97 | __u32 ring_flags; |
---|
98 | int fd; |
---|
99 | int efd; |
---|
100 | bool eager_submits:1; |
---|
101 | bool poller_submits:1; |
---|
102 | }; |
---|
103 | |
---|
104 | //----------------------------------------------------------------------- |
---|
105 | // Misc |
---|
106 | // Weirdly, some systems that do support io_uring don't actually define these |
---|
107 | #ifdef __alpha__ |
---|
108 | /* |
---|
109 | * alpha is the only exception, all other architectures |
---|
110 | * have common numbers for new system calls. |
---|
111 | */ |
---|
112 | #ifndef __NR_io_uring_setup |
---|
113 | #define __NR_io_uring_setup 535 |
---|
114 | #endif |
---|
115 | #ifndef __NR_io_uring_enter |
---|
116 | #define __NR_io_uring_enter 536 |
---|
117 | #endif |
---|
118 | #ifndef __NR_io_uring_register |
---|
119 | #define __NR_io_uring_register 537 |
---|
120 | #endif |
---|
121 | #else /* !__alpha__ */ |
---|
122 | #ifndef __NR_io_uring_setup |
---|
123 | #define __NR_io_uring_setup 425 |
---|
124 | #endif |
---|
125 | #ifndef __NR_io_uring_enter |
---|
126 | #define __NR_io_uring_enter 426 |
---|
127 | #endif |
---|
128 | #ifndef __NR_io_uring_register |
---|
129 | #define __NR_io_uring_register 427 |
---|
130 | #endif |
---|
131 | #endif |
---|
132 | |
---|
133 | struct $io_ctx_thread; |
---|
134 | void __ioctx_register($io_ctx_thread & ctx); |
---|
135 | void __ioctx_prepare_block($io_ctx_thread & ctx); |
---|
136 | #endif |
---|
137 | |
---|
138 | //----------------------------------------------------------------------- |
---|
139 | // IO user data |
---|
140 | struct io_future_t { |
---|
141 | future_t self; |
---|
142 | __s32 result; |
---|
143 | }; |
---|
144 | |
---|
145 | static inline { |
---|
146 | bool fulfil( io_future_t & this, __s32 result ) { |
---|
147 | this.result = result; |
---|
148 | return fulfil(this.self); |
---|
149 | } |
---|
150 | |
---|
151 | // Wait for the future to be fulfilled |
---|
152 | bool wait( io_future_t & this ) { |
---|
153 | return wait(this.self); |
---|
154 | } |
---|
155 | } |
---|