| 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 -- PRIVATE
|
|---|
| 8 | // Types used by the I/O subsystem
|
|---|
| 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 |
|
|---|
| 19 | extern "C" {
|
|---|
| 20 | #include <linux/types.h>
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | #include "bits/locks.hfa"
|
|---|
| 24 | #include "bits/queue.hfa"
|
|---|
| 25 | #include "iofwd.hfa"
|
|---|
| 26 | #include "kernel/fwd.hfa"
|
|---|
| 27 | #include "limits.hfa"
|
|---|
| 28 |
|
|---|
| 29 | #if defined(CFA_HAVE_LINUX_IO_URING_H)
|
|---|
| 30 | #include "bits/sequence.hfa"
|
|---|
| 31 | #include "monitor.hfa"
|
|---|
| 32 |
|
|---|
| 33 | struct processor;
|
|---|
| 34 | monitor $io_arbiter;
|
|---|
| 35 |
|
|---|
| 36 | //-----------------------------------------------------------------------
|
|---|
| 37 | // Ring Data structure
|
|---|
| 38 | struct __sub_ring_t {
|
|---|
| 39 | struct {
|
|---|
| 40 | // Head and tail of the ring (associated with array)
|
|---|
| 41 | volatile __u32 * head; // one passed last index consumed by the kernel
|
|---|
| 42 | volatile __u32 * tail; // one passed last index visible to the kernel
|
|---|
| 43 | volatile __u32 released; // one passed last index released back to the free list
|
|---|
| 44 |
|
|---|
| 45 | // The actual kernel ring which uses head/tail
|
|---|
| 46 | // indexes into the sqes arrays
|
|---|
| 47 | __u32 * array;
|
|---|
| 48 | } kring;
|
|---|
| 49 |
|
|---|
| 50 | struct {
|
|---|
| 51 | volatile __u32 head;
|
|---|
| 52 | volatile __u32 tail;
|
|---|
| 53 | // The ring which contains free allocations
|
|---|
| 54 | // indexes into the sqes arrays
|
|---|
| 55 | __u32 * array;
|
|---|
| 56 | } free_ring;
|
|---|
| 57 |
|
|---|
| 58 | // number of sqes to submit on next system call.
|
|---|
| 59 | __u32 to_submit;
|
|---|
| 60 |
|
|---|
| 61 | // number of entries and mask to go with it
|
|---|
| 62 | const __u32 * num;
|
|---|
| 63 | const __u32 * mask;
|
|---|
| 64 |
|
|---|
| 65 | // Submission flags, currently only IORING_SETUP_SQPOLL
|
|---|
| 66 | __u32 * flags;
|
|---|
| 67 |
|
|---|
| 68 | // number of sqes not submitted
|
|---|
| 69 | // From documentation : [dropped] is incremented for each invalid submission queue entry encountered in the ring buffer.
|
|---|
| 70 | __u32 * dropped;
|
|---|
| 71 |
|
|---|
| 72 | // A buffer of sqes (not the actual ring)
|
|---|
| 73 | struct io_uring_sqe * sqes;
|
|---|
| 74 |
|
|---|
| 75 | // The location and size of the mmaped area
|
|---|
| 76 | void * ring_ptr;
|
|---|
| 77 | size_t ring_sz;
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | struct __cmp_ring_t {
|
|---|
| 81 | volatile bool lock;
|
|---|
| 82 |
|
|---|
| 83 | unsigned id;
|
|---|
| 84 |
|
|---|
| 85 | unsigned long long ts;
|
|---|
| 86 |
|
|---|
| 87 | // Head and tail of the ring
|
|---|
| 88 | volatile __u32 * head;
|
|---|
| 89 | volatile __u32 * tail;
|
|---|
| 90 |
|
|---|
| 91 | // number of entries and mask to go with it
|
|---|
| 92 | const __u32 * mask;
|
|---|
| 93 | const __u32 * num;
|
|---|
| 94 |
|
|---|
| 95 | // I don't know what this value is for
|
|---|
| 96 | __u32 * overflow;
|
|---|
| 97 |
|
|---|
| 98 | // the kernel ring
|
|---|
| 99 | volatile struct io_uring_cqe * cqes;
|
|---|
| 100 |
|
|---|
| 101 | // The location and size of the mmaped area
|
|---|
| 102 | void * ring_ptr;
|
|---|
| 103 | size_t ring_sz;
|
|---|
| 104 | };
|
|---|
| 105 |
|
|---|
| 106 | struct __outstanding_io {
|
|---|
| 107 | inline Colable;
|
|---|
| 108 | single_sem sem;
|
|---|
| 109 | };
|
|---|
| 110 | static inline __outstanding_io *& Next( __outstanding_io * n ) { return (__outstanding_io *)Next( (Colable *)n ); }
|
|---|
| 111 |
|
|---|
| 112 | struct __outstanding_io_queue {
|
|---|
| 113 | __spinlock_t lock;
|
|---|
| 114 | Queue(__outstanding_io) queue;
|
|---|
| 115 | volatile bool empty;
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | struct __external_io {
|
|---|
| 119 | inline __outstanding_io;
|
|---|
| 120 | __u32 * idxs;
|
|---|
| 121 | __u32 have;
|
|---|
| 122 | bool lazy;
|
|---|
| 123 | };
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | struct __attribute__((aligned(128))) $io_context {
|
|---|
| 127 | $io_arbiter * arbiter;
|
|---|
| 128 | processor * proc;
|
|---|
| 129 |
|
|---|
| 130 | __outstanding_io_queue ext_sq;
|
|---|
| 131 |
|
|---|
| 132 | struct __sub_ring_t sq;
|
|---|
| 133 | struct __cmp_ring_t cq;
|
|---|
| 134 | __u32 ring_flags;
|
|---|
| 135 | int fd;
|
|---|
| 136 | };
|
|---|
| 137 |
|
|---|
| 138 | static inline unsigned long long ts($io_context *& this) {
|
|---|
| 139 | const __u32 head = *this->cq.head;
|
|---|
| 140 | const __u32 tail = *this->cq.tail;
|
|---|
| 141 |
|
|---|
| 142 | if(head == tail) return MAX;
|
|---|
| 143 |
|
|---|
| 144 | return this->cq.ts;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | struct __pending_alloc {
|
|---|
| 148 | inline __outstanding_io;
|
|---|
| 149 | __u32 * idxs;
|
|---|
| 150 | __u32 want;
|
|---|
| 151 | $io_context * ctx;
|
|---|
| 152 | };
|
|---|
| 153 |
|
|---|
| 154 | struct __attribute__((aligned(128))) $io_arbiter {
|
|---|
| 155 | __outstanding_io_queue pending;
|
|---|
| 156 | };
|
|---|
| 157 |
|
|---|
| 158 | //-----------------------------------------------------------------------
|
|---|
| 159 | // Misc
|
|---|
| 160 | // Weirdly, some systems that do support io_uring don't actually define these
|
|---|
| 161 | #ifdef __alpha__
|
|---|
| 162 | /*
|
|---|
| 163 | * alpha is the only exception, all other architectures
|
|---|
| 164 | * have common numbers for new system calls.
|
|---|
| 165 | */
|
|---|
| 166 | #ifndef __NR_io_uring_setup
|
|---|
| 167 | #define __NR_io_uring_setup 535
|
|---|
| 168 | #endif
|
|---|
| 169 | #ifndef __NR_io_uring_enter
|
|---|
| 170 | #define __NR_io_uring_enter 536
|
|---|
| 171 | #endif
|
|---|
| 172 | #ifndef __NR_io_uring_register
|
|---|
| 173 | #define __NR_io_uring_register 537
|
|---|
| 174 | #endif
|
|---|
| 175 | #else /* !__alpha__ */
|
|---|
| 176 | #ifndef __NR_io_uring_setup
|
|---|
| 177 | #define __NR_io_uring_setup 425
|
|---|
| 178 | #endif
|
|---|
| 179 | #ifndef __NR_io_uring_enter
|
|---|
| 180 | #define __NR_io_uring_enter 426
|
|---|
| 181 | #endif
|
|---|
| 182 | #ifndef __NR_io_uring_register
|
|---|
| 183 | #define __NR_io_uring_register 427
|
|---|
| 184 | #endif
|
|---|
| 185 | #endif
|
|---|
| 186 |
|
|---|
| 187 | // void __ioctx_prepare_block($io_context & ctx);
|
|---|
| 188 | #endif
|
|---|