Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | c5df8c7 | 2019-04-08 07:42:30 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 Cisco and/or its affiliates. |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 3 | * Copyright (c) 2019 Arm Limited |
| 4 | * Copyright (c) 2010-2017 Intel Corporation and/or its affiliates. |
| 5 | * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org |
| 6 | * Inspired from DPDK rte_ring.h (SPSC only) (derived from freebsd bufring.h). |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at: |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 20 | #include <svm/svm_fifo.h> |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame] | 21 | #include <vppinfra/cpu.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 23 | CLIB_MARCH_FN (svm_fifo_copy_to_chunk, void, svm_fifo_t * f, |
| 24 | svm_fifo_chunk_t * c, u32 tail_idx, const u8 * src, u32 len, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 25 | svm_fifo_chunk_t ** last) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 26 | { |
| 27 | u32 n_chunk; |
| 28 | |
| 29 | ASSERT (tail_idx >= c->start_byte && tail_idx < c->start_byte + c->length); |
| 30 | |
| 31 | tail_idx -= c->start_byte; |
| 32 | n_chunk = c->length - tail_idx; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 33 | if (n_chunk <= len) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 34 | { |
| 35 | u32 to_copy = len; |
| 36 | clib_memcpy_fast (&c->data[tail_idx], src, n_chunk); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 37 | c = c->next; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 38 | while ((to_copy -= n_chunk)) |
| 39 | { |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 40 | n_chunk = clib_min (c->length, to_copy); |
| 41 | clib_memcpy_fast (&c->data[0], src + (len - to_copy), n_chunk); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 42 | c = c->length <= to_copy ? c->next : c; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 43 | } |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 44 | if (*last) |
| 45 | *last = c; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 46 | } |
| 47 | else |
| 48 | { |
| 49 | clib_memcpy_fast (&c->data[tail_idx], src, len); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | CLIB_MARCH_FN (svm_fifo_copy_from_chunk, void, svm_fifo_t * f, |
| 54 | svm_fifo_chunk_t * c, u32 head_idx, u8 * dst, u32 len, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 55 | svm_fifo_chunk_t ** last) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 56 | { |
| 57 | u32 n_chunk; |
| 58 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 59 | ASSERT (head_idx >= c->start_byte && head_idx < c->start_byte + c->length); |
| 60 | |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 61 | head_idx -= c->start_byte; |
| 62 | n_chunk = c->length - head_idx; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 63 | if (n_chunk <= len) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 64 | { |
| 65 | u32 to_copy = len; |
| 66 | clib_memcpy_fast (dst, &c->data[head_idx], n_chunk); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 67 | c = c->next; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 68 | while ((to_copy -= n_chunk)) |
| 69 | { |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 70 | n_chunk = clib_min (c->length, to_copy); |
| 71 | clib_memcpy_fast (dst + (len - to_copy), &c->data[0], n_chunk); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 72 | c = c->length <= to_copy ? c->next : c; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 73 | } |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 74 | if (*last) |
| 75 | *last = c; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 76 | } |
| 77 | else |
| 78 | { |
| 79 | clib_memcpy_fast (dst, &c->data[head_idx], len); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | #ifndef CLIB_MARCH_VARIANT |
| 84 | |
| 85 | static inline void |
| 86 | svm_fifo_copy_to_chunk (svm_fifo_t * f, svm_fifo_chunk_t * c, u32 tail_idx, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 87 | const u8 * src, u32 len, svm_fifo_chunk_t ** last) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 88 | { |
| 89 | CLIB_MARCH_FN_SELECT (svm_fifo_copy_to_chunk) (f, c, tail_idx, src, len, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 90 | last); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void |
| 94 | svm_fifo_copy_from_chunk (svm_fifo_t * f, svm_fifo_chunk_t * c, u32 head_idx, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 95 | u8 * dst, u32 len, svm_fifo_chunk_t ** last) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 96 | { |
| 97 | CLIB_MARCH_FN_SELECT (svm_fifo_copy_from_chunk) (f, c, head_idx, dst, len, |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 98 | last); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 101 | static inline u8 |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 102 | position_lt (svm_fifo_t * f, u32 a, u32 b, u32 tail) |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 103 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 104 | return (f_distance_to (f, a, tail) < f_distance_to (f, b, tail)); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static inline u8 |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 108 | position_leq (svm_fifo_t * f, u32 a, u32 b, u32 tail) |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 109 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 110 | return (f_distance_to (f, a, tail) <= f_distance_to (f, b, tail)); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static inline u8 |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 114 | position_gt (svm_fifo_t * f, u32 a, u32 b, u32 tail) |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 115 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 116 | return (f_distance_to (f, a, tail) > f_distance_to (f, b, tail)); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static inline u32 |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 120 | position_diff (svm_fifo_t * f, u32 a, u32 b, u32 tail) |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 121 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 122 | return f_distance_to (f, a, tail) - f_distance_to (f, b, tail); |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static inline u32 |
| 126 | ooo_segment_end_pos (svm_fifo_t * f, ooo_segment_t * s) |
| 127 | { |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 128 | return (s->start + s->length) % f->size; |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 129 | } |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 130 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 131 | void |
| 132 | svm_fifo_free_ooo_data (svm_fifo_t * f) |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 133 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 134 | pool_free (f->ooo_segments); |
| 135 | } |
| 136 | |
| 137 | static inline ooo_segment_t * |
| 138 | ooo_segment_get_prev (svm_fifo_t * f, ooo_segment_t * s) |
| 139 | { |
| 140 | if (s->prev == OOO_SEGMENT_INVALID_INDEX) |
| 141 | return 0; |
| 142 | return pool_elt_at_index (f->ooo_segments, s->prev); |
| 143 | } |
| 144 | |
| 145 | static inline ooo_segment_t * |
| 146 | ooo_segment_next (svm_fifo_t * f, ooo_segment_t * s) |
| 147 | { |
| 148 | if (s->next == OOO_SEGMENT_INVALID_INDEX) |
| 149 | return 0; |
| 150 | return pool_elt_at_index (f->ooo_segments, s->next); |
| 151 | } |
| 152 | |
| 153 | static inline ooo_segment_t * |
| 154 | ooo_segment_alloc (svm_fifo_t * f, u32 start, u32 length) |
| 155 | { |
| 156 | ooo_segment_t *s; |
| 157 | |
| 158 | pool_get (f->ooo_segments, s); |
| 159 | |
| 160 | s->start = start; |
| 161 | s->length = length; |
| 162 | s->prev = s->next = OOO_SEGMENT_INVALID_INDEX; |
| 163 | |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 164 | return s; |
| 165 | } |
| 166 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 167 | static inline void |
| 168 | ooo_segment_free (svm_fifo_t * f, u32 index) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 169 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 170 | ooo_segment_t *cur, *prev = 0, *next = 0; |
| 171 | cur = pool_elt_at_index (f->ooo_segments, index); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 172 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 173 | if (cur->next != OOO_SEGMENT_INVALID_INDEX) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 174 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 175 | next = pool_elt_at_index (f->ooo_segments, cur->next); |
| 176 | next->prev = cur->prev; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 177 | } |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 178 | |
| 179 | if (cur->prev != OOO_SEGMENT_INVALID_INDEX) |
| 180 | { |
| 181 | prev = pool_elt_at_index (f->ooo_segments, cur->prev); |
| 182 | prev->next = cur->next; |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | f->ooos_list_head = cur->next; |
| 187 | } |
| 188 | |
| 189 | pool_put (f->ooo_segments, cur); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Add segment to fifo's out-of-order segment list. Takes care of merging |
| 194 | * adjacent segments and removing overlapping ones. |
| 195 | */ |
| 196 | static void |
| 197 | ooo_segment_add (svm_fifo_t * f, u32 offset, u32 head, u32 tail, u32 length) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 198 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 199 | ooo_segment_t *s, *new_s, *prev, *next, *it; |
| 200 | u32 new_index, s_end_pos, s_index; |
| 201 | u32 offset_pos, offset_end_pos; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 202 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 203 | ASSERT (offset + length <= f_distance_to (f, head, tail) || head == tail); |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 204 | |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 205 | offset_pos = (tail + offset) % f->size; |
| 206 | offset_end_pos = (tail + offset + length) % f->size; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 207 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 208 | f->ooos_newest = OOO_SEGMENT_INVALID_INDEX; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 209 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 210 | if (f->ooos_list_head == OOO_SEGMENT_INVALID_INDEX) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 211 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 212 | s = ooo_segment_alloc (f, offset_pos, length); |
| 213 | f->ooos_list_head = s - f->ooo_segments; |
| 214 | f->ooos_newest = f->ooos_list_head; |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | /* Find first segment that starts after new segment */ |
| 219 | s = pool_elt_at_index (f->ooo_segments, f->ooos_list_head); |
| 220 | while (s->next != OOO_SEGMENT_INVALID_INDEX |
| 221 | && position_lt (f, s->start, offset_pos, tail)) |
| 222 | s = pool_elt_at_index (f->ooo_segments, s->next); |
| 223 | |
| 224 | /* If we have a previous and we overlap it, use it as starting point */ |
| 225 | prev = ooo_segment_get_prev (f, s); |
| 226 | if (prev |
| 227 | && position_leq (f, offset_pos, ooo_segment_end_pos (f, prev), tail)) |
| 228 | { |
| 229 | s = prev; |
| 230 | s_end_pos = ooo_segment_end_pos (f, s); |
| 231 | |
| 232 | /* Since we have previous, offset start position cannot be smaller |
| 233 | * than prev->start. Check tail */ |
| 234 | ASSERT (position_lt (f, s->start, offset_pos, tail)); |
| 235 | goto check_tail; |
| 236 | } |
| 237 | |
| 238 | s_index = s - f->ooo_segments; |
| 239 | s_end_pos = ooo_segment_end_pos (f, s); |
| 240 | |
| 241 | /* No overlap, add before current segment */ |
| 242 | if (position_lt (f, offset_end_pos, s->start, tail)) |
| 243 | { |
| 244 | new_s = ooo_segment_alloc (f, offset_pos, length); |
| 245 | new_index = new_s - f->ooo_segments; |
| 246 | |
| 247 | /* Pool might've moved, get segment again */ |
| 248 | s = pool_elt_at_index (f->ooo_segments, s_index); |
| 249 | if (s->prev != OOO_SEGMENT_INVALID_INDEX) |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 250 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 251 | new_s->prev = s->prev; |
| 252 | prev = pool_elt_at_index (f->ooo_segments, new_s->prev); |
| 253 | prev->next = new_index; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 254 | } |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 255 | else |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 256 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 257 | /* New head */ |
| 258 | f->ooos_list_head = new_index; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 259 | } |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 260 | |
| 261 | new_s->next = s_index; |
| 262 | s->prev = new_index; |
| 263 | f->ooos_newest = new_index; |
| 264 | return; |
| 265 | } |
| 266 | /* No overlap, add after current segment */ |
| 267 | else if (position_gt (f, offset_pos, s_end_pos, tail)) |
| 268 | { |
| 269 | new_s = ooo_segment_alloc (f, offset_pos, length); |
| 270 | new_index = new_s - f->ooo_segments; |
| 271 | |
| 272 | /* Pool might've moved, get segment again */ |
| 273 | s = pool_elt_at_index (f->ooo_segments, s_index); |
| 274 | |
| 275 | /* Needs to be last */ |
| 276 | ASSERT (s->next == OOO_SEGMENT_INVALID_INDEX); |
| 277 | |
| 278 | new_s->prev = s_index; |
| 279 | s->next = new_index; |
| 280 | f->ooos_newest = new_index; |
| 281 | |
| 282 | return; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 285 | /* |
| 286 | * Merge needed |
| 287 | */ |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 288 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 289 | /* Merge at head */ |
| 290 | if (position_lt (f, offset_pos, s->start, tail)) |
| 291 | { |
| 292 | s->start = offset_pos; |
| 293 | s->length = position_diff (f, s_end_pos, s->start, tail); |
| 294 | f->ooos_newest = s - f->ooo_segments; |
| 295 | } |
| 296 | |
| 297 | check_tail: |
| 298 | |
| 299 | /* Overlapping tail */ |
| 300 | if (position_gt (f, offset_end_pos, s_end_pos, tail)) |
| 301 | { |
| 302 | s->length = position_diff (f, offset_end_pos, s->start, tail); |
| 303 | |
| 304 | /* Remove the completely overlapped segments in the tail */ |
| 305 | it = ooo_segment_next (f, s); |
| 306 | while (it && position_leq (f, ooo_segment_end_pos (f, it), |
| 307 | offset_end_pos, tail)) |
| 308 | { |
| 309 | next = ooo_segment_next (f, it); |
| 310 | ooo_segment_free (f, it - f->ooo_segments); |
| 311 | it = next; |
| 312 | } |
| 313 | |
| 314 | /* If partial overlap with last, merge */ |
| 315 | if (it && position_leq (f, it->start, offset_end_pos, tail)) |
| 316 | { |
| 317 | s->length = position_diff (f, ooo_segment_end_pos (f, it), |
| 318 | s->start, tail); |
| 319 | ooo_segment_free (f, it - f->ooo_segments); |
| 320 | } |
| 321 | f->ooos_newest = s - f->ooo_segments; |
| 322 | } |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 325 | /** |
| 326 | * Removes segments that can now be enqueued because the fifo's tail has |
| 327 | * advanced. Returns the number of bytes added to tail. |
| 328 | */ |
| 329 | static int |
| 330 | ooo_segment_try_collect (svm_fifo_t * f, u32 n_bytes_enqueued, u32 * tail) |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 331 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 332 | u32 s_index, bytes = 0; |
| 333 | ooo_segment_t *s; |
| 334 | i32 diff; |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 335 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 336 | s = pool_elt_at_index (f->ooo_segments, f->ooos_list_head); |
| 337 | diff = f_distance_from (f, s->start, *tail); |
| 338 | |
| 339 | ASSERT (diff != n_bytes_enqueued); |
| 340 | |
| 341 | if (diff > n_bytes_enqueued) |
| 342 | return 0; |
| 343 | |
| 344 | /* If last tail update overlaps one/multiple ooo segments, remove them */ |
| 345 | while (0 <= diff && diff < n_bytes_enqueued) |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 346 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 347 | s_index = s - f->ooo_segments; |
| 348 | |
| 349 | /* Segment end is beyond the tail. Advance tail and remove segment */ |
| 350 | if (s->length > diff) |
| 351 | { |
| 352 | bytes = s->length - diff; |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 353 | *tail = (*tail + bytes) % f->size; |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 354 | ooo_segment_free (f, s_index); |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | /* If we have next go on */ |
| 359 | if (s->next != OOO_SEGMENT_INVALID_INDEX) |
| 360 | { |
| 361 | s = pool_elt_at_index (f->ooo_segments, s->next); |
| 362 | diff = f_distance_from (f, s->start, *tail); |
| 363 | ooo_segment_free (f, s_index); |
| 364 | } |
| 365 | /* End of search */ |
| 366 | else |
| 367 | { |
| 368 | ooo_segment_free (f, s_index); |
| 369 | break; |
| 370 | } |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 371 | } |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 372 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 373 | ASSERT (bytes <= f->nitems); |
| 374 | return bytes; |
Florin Coras | b59a705 | 2017-04-18 22:07:29 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 377 | void |
| 378 | svm_fifo_init (svm_fifo_t * f, u32 size) |
| 379 | { |
| 380 | f->size = size; |
| 381 | /* |
| 382 | * usable size of the fifo set to rounded_data_size - 1 |
| 383 | * to differentiate between free fifo and empty fifo. |
| 384 | */ |
| 385 | f->nitems = f->size - 1; |
| 386 | f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 387 | f->segment_index = SVM_FIFO_INVALID_INDEX; |
| 388 | f->refcnt = 1; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 389 | f->default_chunk.start_byte = 0; |
| 390 | f->default_chunk.length = f->size; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 391 | f->default_chunk.next = f->start_chunk = f->end_chunk = &f->default_chunk; |
| 392 | f->head_chunk = f->tail_chunk = f->ooo_enq = f->ooo_deq = f->start_chunk; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Florin Coras | b095a3c | 2019-04-25 12:58:46 -0700 | [diff] [blame] | 395 | /** |
| 396 | * Creates a fifo in the current heap. Fails vs blow up the process |
| 397 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 398 | svm_fifo_t * |
| 399 | svm_fifo_create (u32 data_size_in_bytes) |
| 400 | { |
| 401 | svm_fifo_t *f; |
Dave Barach | 818eb54 | 2017-08-02 13:56:13 -0400 | [diff] [blame] | 402 | u32 rounded_data_size; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 403 | |
Dave Barach | 818eb54 | 2017-08-02 13:56:13 -0400 | [diff] [blame] | 404 | /* always round fifo data size to the next highest power-of-two */ |
| 405 | rounded_data_size = (1 << (max_log2 (data_size_in_bytes))); |
| 406 | f = clib_mem_alloc_aligned_or_null (sizeof (*f) + rounded_data_size, |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 407 | CLIB_CACHE_LINE_BYTES); |
| 408 | if (f == 0) |
| 409 | return 0; |
| 410 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 411 | clib_memset (f, 0, sizeof (*f)); |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 412 | svm_fifo_init (f, data_size_in_bytes); |
| 413 | return f; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Florin Coras | b095a3c | 2019-04-25 12:58:46 -0700 | [diff] [blame] | 416 | /** |
| 417 | * Creates a fifo chunk in the current heap |
| 418 | */ |
| 419 | svm_fifo_chunk_t * |
| 420 | svm_fifo_chunk_alloc (u32 size) |
| 421 | { |
| 422 | svm_fifo_chunk_t *c; |
| 423 | u32 rounded_size; |
| 424 | |
| 425 | /* round chunk size to the next highest power-of-two */ |
| 426 | rounded_size = (1 << (max_log2 (size))); |
| 427 | c = clib_mem_alloc_aligned_or_null (sizeof (*c) + rounded_size, |
| 428 | CLIB_CACHE_LINE_BYTES); |
| 429 | if (c == 0) |
| 430 | return 0; |
| 431 | |
| 432 | clib_memset (c, 0, sizeof (*c)); |
| 433 | c->length = rounded_size; |
| 434 | return c; |
| 435 | } |
| 436 | |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 437 | static inline void |
| 438 | svm_fifo_size_update (svm_fifo_t * f, svm_fifo_chunk_t * c) |
| 439 | { |
| 440 | svm_fifo_chunk_t *prev; |
| 441 | u32 add_bytes = 0; |
| 442 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 443 | if (!c) |
| 444 | return; |
| 445 | |
| 446 | f->end_chunk->next = c; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 447 | while (c) |
| 448 | { |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 449 | add_bytes += c->length; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 450 | prev = c; |
| 451 | c = c->next; |
| 452 | } |
| 453 | f->end_chunk = prev; |
| 454 | prev->next = f->start_chunk; |
| 455 | f->size += add_bytes; |
| 456 | f->nitems = f->size - 1; |
| 457 | f->new_chunks = 0; |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | svm_fifo_try_size_update (svm_fifo_t * f, u32 new_head) |
| 462 | { |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 463 | if (new_head > f->tail) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 464 | return; |
| 465 | |
| 466 | svm_fifo_size_update (f, f->new_chunks); |
| 467 | f->flags &= ~SVM_FIFO_F_SIZE_UPDATE; |
| 468 | } |
| 469 | |
| 470 | void |
| 471 | svm_fifo_add_chunk (svm_fifo_t * f, svm_fifo_chunk_t * c) |
| 472 | { |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 473 | svm_fifo_chunk_t *cur, *prev; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 474 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 475 | /* Initialize rbtree if needed and add default chunk to it */ |
| 476 | if (!(f->flags & SVM_FIFO_F_MULTI_CHUNK)) |
| 477 | { |
| 478 | rb_tree_init (&f->chunk_lookup); |
| 479 | rb_tree_add2 (&f->chunk_lookup, 0, pointer_to_uword (f->start_chunk)); |
| 480 | f->flags |= SVM_FIFO_F_MULTI_CHUNK; |
| 481 | } |
| 482 | |
| 483 | /* Initialize chunks and add to lookup rbtree. Expectation is that this is |
| 484 | * called with the heap where the rbtree's pool is pushed. */ |
| 485 | cur = c; |
| 486 | if (f->new_chunks) |
| 487 | { |
| 488 | prev = f->new_chunks; |
| 489 | while (prev->next) |
| 490 | prev = prev->next; |
| 491 | prev->next = c; |
| 492 | } |
| 493 | else |
| 494 | prev = f->end_chunk; |
| 495 | |
| 496 | while (cur) |
| 497 | { |
| 498 | cur->start_byte = prev->start_byte + prev->length; |
| 499 | rb_tree_add2 (&f->chunk_lookup, cur->start_byte, |
| 500 | pointer_to_uword (cur)); |
| 501 | prev = cur; |
| 502 | cur = cur->next; |
| 503 | } |
| 504 | |
| 505 | /* If fifo is not wrapped, update the size now */ |
| 506 | if (!svm_fifo_is_wrapped (f)) |
| 507 | { |
| 508 | ASSERT (!f->new_chunks); |
| 509 | svm_fifo_size_update (f, c); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 510 | return; |
| 511 | } |
| 512 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 513 | /* Postpone size update */ |
| 514 | if (!f->new_chunks) |
| 515 | { |
| 516 | f->new_chunks = c; |
| 517 | f->flags |= SVM_FIFO_F_SIZE_UPDATE; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | static inline u8 |
| 522 | svm_fifo_chunk_includes_pos (svm_fifo_chunk_t * c, u32 pos) |
| 523 | { |
| 524 | return (pos >= c->start_byte && pos < c->start_byte + c->length); |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Find chunk for given byte position |
| 529 | * |
| 530 | * @param f fifo |
| 531 | * @param pos normalized position in fifo |
| 532 | * |
| 533 | * @return chunk that includes given position or 0 |
| 534 | */ |
| 535 | static svm_fifo_chunk_t * |
| 536 | svm_fifo_find_chunk (svm_fifo_t * f, u32 pos) |
| 537 | { |
| 538 | rb_tree_t *rt = &f->chunk_lookup; |
| 539 | rb_node_t *cur, *prev; |
| 540 | svm_fifo_chunk_t *c; |
| 541 | |
| 542 | cur = rb_node (rt, rt->root); |
| 543 | while (pos != cur->key) |
| 544 | { |
| 545 | prev = cur; |
| 546 | if (pos < cur->key) |
| 547 | cur = rb_node_left (rt, cur); |
| 548 | else |
| 549 | cur = rb_node_right (rt, cur); |
| 550 | |
| 551 | if (rb_node_is_tnil (rt, cur)) |
| 552 | { |
| 553 | /* Hit tnil as a left child. Find predecessor */ |
| 554 | if (pos < prev->key) |
| 555 | { |
| 556 | cur = rb_tree_predecessor (rt, prev); |
| 557 | c = uword_to_pointer (cur->opaque, svm_fifo_chunk_t *); |
| 558 | if (svm_fifo_chunk_includes_pos (c, pos)) |
| 559 | return c; |
| 560 | return 0; |
| 561 | } |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 562 | /* Hit tnil as a right child. Check if this is the one */ |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 563 | c = uword_to_pointer (prev->opaque, svm_fifo_chunk_t *); |
| 564 | if (svm_fifo_chunk_includes_pos (c, pos)) |
| 565 | return c; |
| 566 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | if (!rb_node_is_tnil (rt, cur)) |
| 572 | return uword_to_pointer (cur->opaque, svm_fifo_chunk_t *); |
| 573 | return 0; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 576 | void |
Florin Coras | b095a3c | 2019-04-25 12:58:46 -0700 | [diff] [blame] | 577 | svm_fifo_free_chunk_lookup (svm_fifo_t * f) |
| 578 | { |
| 579 | rb_tree_free_nodes (&f->chunk_lookup); |
| 580 | } |
| 581 | |
| 582 | void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 583 | svm_fifo_free (svm_fifo_t * f) |
| 584 | { |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 585 | ASSERT (f->refcnt > 0); |
| 586 | |
| 587 | if (--f->refcnt == 0) |
| 588 | { |
Florin Coras | b095a3c | 2019-04-25 12:58:46 -0700 | [diff] [blame] | 589 | /* ooo data is not allocated on segment heap */ |
| 590 | svm_fifo_free_chunk_lookup (f); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 591 | clib_mem_free (f); |
| 592 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 595 | void |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 596 | svm_fifo_overwrite_head (svm_fifo_t * f, u8 * src, u32 len) |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 597 | { |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 598 | u32 n_chunk; |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 599 | u32 head, tail, head_idx; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 600 | svm_fifo_chunk_t *c; |
| 601 | |
| 602 | ASSERT (len <= f->nitems); |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 603 | |
| 604 | f_load_head_tail_cons (f, &head, &tail); |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 605 | c = f->head_chunk; |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 606 | head_idx = head - c->start_byte; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 607 | n_chunk = c->length - head_idx; |
| 608 | if (len <= n_chunk) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 609 | clib_memcpy_fast (&c->data[head_idx], src, len); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 610 | else |
| 611 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 612 | clib_memcpy_fast (&c->data[head_idx], src, n_chunk); |
| 613 | clib_memcpy_fast (&c->next->data[0], src + n_chunk, len - n_chunk); |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 614 | } |
| 615 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 616 | |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 617 | int |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 618 | svm_fifo_enqueue (svm_fifo_t * f, u32 len, const u8 * src) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 619 | { |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 620 | u32 tail, head, free_count; |
| 621 | |
| 622 | f_load_head_tail_prod (f, &head, &tail); |
| 623 | |
| 624 | /* free space in fifo can only increase during enqueue: SPSC */ |
| 625 | free_count = f_free_count (f, head, tail); |
| 626 | |
| 627 | f->ooos_newest = OOO_SEGMENT_INVALID_INDEX; |
| 628 | |
| 629 | if (PREDICT_FALSE (free_count == 0)) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 630 | return SVM_FIFO_EFULL; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 631 | |
| 632 | /* number of bytes we're going to copy */ |
| 633 | len = clib_min (free_count, len); |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 634 | svm_fifo_copy_to_chunk (f, f->tail_chunk, tail, src, len, &f->tail_chunk); |
| 635 | tail = (tail + len) % f->size; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 636 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 637 | svm_fifo_trace_add (f, head, len, 2); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 638 | |
| 639 | /* collect out-of-order segments */ |
| 640 | if (PREDICT_FALSE (f->ooos_list_head != OOO_SEGMENT_INVALID_INDEX)) |
| 641 | len += ooo_segment_try_collect (f, len, &tail); |
| 642 | |
| 643 | /* store-rel: producer owned index (paired with load-acq in consumer) */ |
| 644 | clib_atomic_store_rel_n (&f->tail, tail); |
| 645 | |
| 646 | return len; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Enqueue a future segment. |
| 651 | * |
| 652 | * Two choices: either copies the entire segment, or copies nothing |
| 653 | * Returns 0 of the entire segment was copied |
| 654 | * Returns -1 if none of the segment was copied due to lack of space |
| 655 | */ |
| 656 | int |
| 657 | svm_fifo_enqueue_with_offset (svm_fifo_t * f, u32 offset, u32 len, u8 * src) |
| 658 | { |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 659 | u32 tail, head, free_count, tail_idx; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 660 | |
| 661 | f_load_head_tail_prod (f, &head, &tail); |
| 662 | |
| 663 | /* free space in fifo can only increase during enqueue: SPSC */ |
| 664 | free_count = f_free_count (f, head, tail); |
| 665 | |
| 666 | /* will this request fit? */ |
| 667 | if ((len + offset) > free_count) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 668 | return SVM_FIFO_EFULL; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 669 | |
| 670 | f->ooos_newest = OOO_SEGMENT_INVALID_INDEX; |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 671 | svm_fifo_trace_add (f, offset, len, 1); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 672 | ooo_segment_add (f, offset, head, tail, len); |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 673 | tail_idx = (tail + offset) % f->size; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 674 | |
| 675 | if (!svm_fifo_chunk_includes_pos (f->ooo_enq, tail_idx)) |
| 676 | f->ooo_enq = svm_fifo_find_chunk (f, tail_idx); |
| 677 | |
| 678 | svm_fifo_copy_to_chunk (f, f->ooo_enq, tail_idx, src, len, &f->ooo_enq); |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | int |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 684 | svm_fifo_dequeue (svm_fifo_t * f, u32 len, u8 * dst) |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 685 | { |
| 686 | u32 tail, head, cursize; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 687 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 688 | f_load_head_tail_cons (f, &head, &tail); |
| 689 | |
| 690 | /* current size of fifo can only increase during dequeue: SPSC */ |
| 691 | cursize = f_cursize (f, head, tail); |
| 692 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 693 | if (PREDICT_FALSE (cursize == 0)) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 694 | return SVM_FIFO_EEMPTY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 695 | |
Florin Coras | 99ad2fc | 2019-04-18 21:25:49 -0700 | [diff] [blame] | 696 | len = clib_min (cursize, len); |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 697 | svm_fifo_copy_from_chunk (f, f->head_chunk, head, dst, len, &f->head_chunk); |
| 698 | head = (head + len) % f->size; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 699 | |
Florin Coras | 2309e7a | 2019-04-18 18:58:10 -0700 | [diff] [blame] | 700 | if (PREDICT_FALSE (f->flags & SVM_FIFO_F_SIZE_UPDATE)) |
| 701 | svm_fifo_try_size_update (f, head); |
| 702 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 703 | /* store-rel: consumer owned index (paired with load-acq in producer) */ |
| 704 | clib_atomic_store_rel_n (&f->head, head); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 705 | |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 706 | return len; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 707 | } |
| 708 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 709 | int |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 710 | svm_fifo_peek (svm_fifo_t * f, u32 offset, u32 len, u8 * dst) |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame] | 711 | { |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 712 | u32 tail, head, cursize, head_idx; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 713 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 714 | f_load_head_tail_cons (f, &head, &tail); |
| 715 | |
| 716 | /* current size of fifo can only increase during peek: SPSC */ |
| 717 | cursize = f_cursize (f, head, tail); |
| 718 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 719 | if (PREDICT_FALSE (cursize < offset)) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 720 | return SVM_FIFO_EEMPTY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 721 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 722 | len = clib_min (cursize - offset, len); |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 723 | head_idx = (head + offset) % f->size; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 724 | if (!svm_fifo_chunk_includes_pos (f->ooo_deq, head_idx)) |
| 725 | f->ooo_deq = svm_fifo_find_chunk (f, head_idx); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 726 | |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 727 | svm_fifo_copy_from_chunk (f, f->ooo_deq, head_idx, dst, len, &f->ooo_deq); |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 728 | return len; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | int |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 732 | svm_fifo_dequeue_drop (svm_fifo_t * f, u32 len) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 733 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 734 | u32 total_drop_bytes, tail, head, cursize; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 735 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 736 | f_load_head_tail_cons (f, &head, &tail); |
| 737 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 738 | /* number of bytes available */ |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 739 | cursize = f_cursize (f, head, tail); |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 740 | if (PREDICT_FALSE (cursize == 0)) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 741 | return SVM_FIFO_EEMPTY; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 742 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 743 | svm_fifo_trace_add (f, tail, total_drop_bytes, 3); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 744 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 745 | /* number of bytes we're going to drop */ |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 746 | total_drop_bytes = clib_min (cursize, len); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 747 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 748 | /* move head */ |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 749 | head = (head + total_drop_bytes) % f->size; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 750 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 751 | /* store-rel: consumer owned index (paired with load-acq in producer) */ |
| 752 | clib_atomic_store_rel_n (&f->head, head); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 753 | |
| 754 | return total_drop_bytes; |
| 755 | } |
| 756 | |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 757 | void |
| 758 | svm_fifo_dequeue_drop_all (svm_fifo_t * f) |
| 759 | { |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 760 | /* consumer foreign index */ |
| 761 | u32 tail = clib_atomic_load_acq_n (&f->tail); |
| 762 | /* store-rel: consumer owned index (paired with load-acq in producer) */ |
| 763 | clib_atomic_store_rel_n (&f->head, tail); |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 766 | int |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 767 | svm_fifo_segments (svm_fifo_t * f, svm_fifo_seg_t * fs) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 768 | { |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 769 | u32 cursize, head, tail, head_idx; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 770 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 771 | f_load_head_tail_cons (f, &head, &tail); |
| 772 | |
| 773 | /* consumer function, cursize can only increase while we're working */ |
| 774 | cursize = f_cursize (f, head, tail); |
| 775 | |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 776 | if (PREDICT_FALSE (cursize == 0)) |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 777 | return SVM_FIFO_EEMPTY; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 778 | |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 779 | head_idx = head; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 780 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 781 | if (tail < head) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 782 | { |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 783 | fs[0].len = f->size - head_idx; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 784 | fs[0].data = f->head_chunk->data + head_idx; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 785 | fs[1].len = cursize - fs[0].len; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 786 | fs[1].data = f->head_chunk->data; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 787 | } |
| 788 | else |
| 789 | { |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 790 | fs[0].len = cursize; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 791 | fs[0].data = f->head_chunk->data + head_idx; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 792 | fs[1].len = 0; |
| 793 | fs[1].data = 0; |
| 794 | } |
| 795 | return cursize; |
| 796 | } |
| 797 | |
| 798 | void |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 799 | svm_fifo_segments_free (svm_fifo_t * f, svm_fifo_seg_t * fs) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 800 | { |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 801 | u32 head; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 802 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 803 | /* consumer owned index */ |
| 804 | head = f->head; |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 805 | |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 806 | ASSERT (fs[0].data == f->head_chunk->data + head); |
| 807 | head = (head + fs[0].len + fs[1].len) % f->size; |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 808 | /* store-rel: consumer owned index (paired with load-acq in producer) */ |
| 809 | clib_atomic_store_rel_n (&f->head, head); |
| 810 | } |
| 811 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 812 | /** |
| 813 | * Clones fifo |
| 814 | * |
| 815 | * Assumptions: |
| 816 | * - no prod and cons are accessing either dest or src fifo |
| 817 | * - fifo is not multi chunk |
| 818 | */ |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 819 | void |
| 820 | svm_fifo_clone (svm_fifo_t * df, svm_fifo_t * sf) |
| 821 | { |
| 822 | u32 head, tail; |
Florin Coras | 0a84680 | 2019-04-09 18:29:14 -0700 | [diff] [blame] | 823 | clib_memcpy_fast (df->head_chunk->data, sf->head_chunk->data, sf->size); |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 824 | |
| 825 | f_load_head_tail_all_acq (sf, &head, &tail); |
| 826 | clib_atomic_store_rel_n (&df->head, head); |
| 827 | clib_atomic_store_rel_n (&df->tail, tail); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 830 | u32 |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 831 | svm_fifo_n_ooo_segments (svm_fifo_t * f) |
Dave Barach | 1f75cfd | 2017-04-14 16:46:44 -0400 | [diff] [blame] | 832 | { |
| 833 | return pool_elts (f->ooo_segments); |
| 834 | } |
| 835 | |
| 836 | ooo_segment_t * |
| 837 | svm_fifo_first_ooo_segment (svm_fifo_t * f) |
| 838 | { |
| 839 | return pool_elt_at_index (f->ooo_segments, f->ooos_list_head); |
| 840 | } |
| 841 | |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 842 | /** |
| 843 | * Set fifo pointers to requested offset |
| 844 | */ |
| 845 | void |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 846 | svm_fifo_init_pointers (svm_fifo_t * f, u32 head, u32 tail) |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 847 | { |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 848 | head = head % f->size; |
| 849 | tail = tail % f->size; |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 850 | clib_atomic_store_rel_n (&f->head, head); |
| 851 | clib_atomic_store_rel_n (&f->tail, tail); |
| 852 | if (f->flags & SVM_FIFO_F_MULTI_CHUNK) |
| 853 | { |
| 854 | svm_fifo_chunk_t *c; |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 855 | c = svm_fifo_find_chunk (f, head); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 856 | ASSERT (c != 0); |
| 857 | f->head_chunk = f->ooo_deq = c; |
Florin Coras | 29a59c3 | 2019-05-02 12:52:19 -0700 | [diff] [blame^] | 858 | c = svm_fifo_find_chunk (f, tail); |
Florin Coras | 4375fa3 | 2019-04-19 15:56:00 -0700 | [diff] [blame] | 859 | ASSERT (c != 0); |
| 860 | f->tail_chunk = f->ooo_enq = c; |
| 861 | } |
Florin Coras | c28764f | 2017-04-26 00:08:42 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Florin Coras | 72b0428 | 2019-01-14 17:23:11 -0800 | [diff] [blame] | 864 | void |
| 865 | svm_fifo_add_subscriber (svm_fifo_t * f, u8 subscriber) |
| 866 | { |
| 867 | if (f->n_subscribers >= SVM_FIFO_MAX_EVT_SUBSCRIBERS) |
| 868 | return; |
| 869 | f->subscribers[f->n_subscribers++] = subscriber; |
| 870 | } |
| 871 | |
| 872 | void |
| 873 | svm_fifo_del_subscriber (svm_fifo_t * f, u8 subscriber) |
| 874 | { |
| 875 | int i; |
| 876 | |
| 877 | for (i = 0; i < f->n_subscribers; i++) |
| 878 | { |
| 879 | if (f->subscribers[i] != subscriber) |
| 880 | continue; |
| 881 | f->subscribers[i] = f->subscribers[f->n_subscribers - 1]; |
| 882 | f->n_subscribers--; |
| 883 | break; |
| 884 | } |
| 885 | } |
| 886 | |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 887 | u8 * |
| 888 | format_ooo_segment (u8 * s, va_list * args) |
| 889 | { |
| 890 | svm_fifo_t *f = va_arg (*args, svm_fifo_t *); |
| 891 | ooo_segment_t *seg = va_arg (*args, ooo_segment_t *); |
| 892 | u32 normalized_start = (seg->start + f->nitems - f->tail) % f->size; |
| 893 | s = format (s, "[%u, %u], len %u, next %d, prev %d", normalized_start, |
| 894 | (normalized_start + seg->length) % f->size, seg->length, |
| 895 | seg->next, seg->prev); |
| 896 | return s; |
| 897 | } |
| 898 | |
| 899 | u8 * |
| 900 | svm_fifo_dump_trace (u8 * s, svm_fifo_t * f) |
| 901 | { |
| 902 | #if SVM_FIFO_TRACE |
| 903 | svm_fifo_trace_elem_t *seg = 0; |
| 904 | int i = 0; |
| 905 | |
| 906 | if (f->trace) |
| 907 | { |
| 908 | vec_foreach (seg, f->trace) |
| 909 | { |
| 910 | s = format (s, "{%u, %u, %u}, ", seg->offset, seg->len, seg->action); |
| 911 | i++; |
| 912 | if (i % 5 == 0) |
| 913 | s = format (s, "\n"); |
| 914 | } |
| 915 | s = format (s, "\n"); |
| 916 | } |
| 917 | return s; |
| 918 | #else |
| 919 | return 0; |
| 920 | #endif |
| 921 | } |
| 922 | |
| 923 | u8 * |
| 924 | svm_fifo_replay (u8 * s, svm_fifo_t * f, u8 no_read, u8 verbose) |
| 925 | { |
| 926 | int i, trace_len; |
| 927 | u8 *data = 0; |
| 928 | svm_fifo_trace_elem_t *trace; |
| 929 | u32 offset; |
| 930 | svm_fifo_t *dummy_fifo; |
| 931 | |
| 932 | if (!f) |
| 933 | return s; |
| 934 | |
| 935 | #if SVM_FIFO_TRACE |
| 936 | trace = f->trace; |
| 937 | trace_len = vec_len (trace); |
| 938 | #else |
| 939 | trace = 0; |
| 940 | trace_len = 0; |
| 941 | #endif |
| 942 | |
| 943 | dummy_fifo = svm_fifo_create (f->size); |
| 944 | clib_memset (f->head_chunk->data, 0xFF, f->nitems); |
| 945 | vec_validate (data, f->nitems); |
| 946 | for (i = 0; i < vec_len (data); i++) |
| 947 | data[i] = i; |
| 948 | |
| 949 | for (i = 0; i < trace_len; i++) |
| 950 | { |
| 951 | offset = trace[i].offset; |
| 952 | if (trace[i].action == 1) |
| 953 | { |
| 954 | if (verbose) |
| 955 | s = format (s, "adding [%u, %u]:", trace[i].offset, |
| 956 | (trace[i].offset + trace[i].len) % dummy_fifo->size); |
| 957 | svm_fifo_enqueue_with_offset (dummy_fifo, trace[i].offset, |
| 958 | trace[i].len, &data[offset]); |
| 959 | } |
| 960 | else if (trace[i].action == 2) |
| 961 | { |
| 962 | if (verbose) |
| 963 | s = format (s, "adding [%u, %u]:", 0, trace[i].len); |
| 964 | svm_fifo_enqueue (dummy_fifo, trace[i].len, &data[offset]); |
| 965 | } |
| 966 | else if (!no_read) |
| 967 | { |
| 968 | if (verbose) |
| 969 | s = format (s, "read: %u", trace[i].len); |
| 970 | svm_fifo_dequeue_drop (dummy_fifo, trace[i].len); |
| 971 | } |
| 972 | if (verbose) |
| 973 | s = format (s, "%U", format_svm_fifo, dummy_fifo, 1); |
| 974 | } |
| 975 | |
| 976 | s = format (s, "result: %U", format_svm_fifo, dummy_fifo, 1); |
| 977 | |
| 978 | return s; |
| 979 | } |
| 980 | |
| 981 | u8 * |
| 982 | format_ooo_list (u8 * s, va_list * args) |
| 983 | { |
| 984 | svm_fifo_t *f = va_arg (*args, svm_fifo_t *); |
| 985 | u32 indent = va_arg (*args, u32); |
| 986 | u32 ooo_segment_index = f->ooos_list_head; |
| 987 | ooo_segment_t *seg; |
| 988 | |
| 989 | while (ooo_segment_index != OOO_SEGMENT_INVALID_INDEX) |
| 990 | { |
| 991 | seg = pool_elt_at_index (f->ooo_segments, ooo_segment_index); |
| 992 | s = format (s, "%U%U\n", format_white_space, indent, format_ooo_segment, |
| 993 | f, seg); |
| 994 | ooo_segment_index = seg->next; |
| 995 | } |
| 996 | |
| 997 | return s; |
| 998 | } |
| 999 | |
| 1000 | u8 * |
| 1001 | format_svm_fifo (u8 * s, va_list * args) |
| 1002 | { |
| 1003 | svm_fifo_t *f = va_arg (*args, svm_fifo_t *); |
| 1004 | int verbose = va_arg (*args, int); |
| 1005 | u32 indent; |
| 1006 | |
| 1007 | if (!s) |
| 1008 | return s; |
| 1009 | |
| 1010 | indent = format_get_indent (s); |
| 1011 | s = format (s, "cursize %u nitems %u has_event %d\n", |
| 1012 | svm_fifo_max_dequeue (f), f->nitems, f->has_event); |
| 1013 | s = format (s, "%Uhead %u tail %u segment manager %u\n", format_white_space, |
| 1014 | indent, (f->head % f->size), (f->tail % f->size), |
| 1015 | f->segment_manager); |
| 1016 | |
| 1017 | if (verbose > 1) |
| 1018 | s = format (s, "%Uvpp session %d thread %d app session %d thread %d\n", |
| 1019 | format_white_space, indent, f->master_session_index, |
| 1020 | f->master_thread_index, f->client_session_index, |
| 1021 | f->client_thread_index); |
| 1022 | |
| 1023 | if (verbose) |
| 1024 | { |
| 1025 | s = format (s, "%Uooo pool %d active elts newest %u\n", |
| 1026 | format_white_space, indent, pool_elts (f->ooo_segments), |
| 1027 | f->ooos_newest); |
| 1028 | if (svm_fifo_has_ooo_data (f)) |
| 1029 | s = format (s, " %U", format_ooo_list, f, indent, verbose); |
| 1030 | } |
| 1031 | return s; |
| 1032 | } |
| 1033 | |
Florin Coras | 3aa7af3 | 2018-06-29 08:44:31 -0700 | [diff] [blame] | 1034 | #endif |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1035 | /* |
| 1036 | * fd.io coding-style-patch-verification: ON |
| 1037 | * |
| 1038 | * Local Variables: |
| 1039 | * eval: (c-set-style "gnu") |
| 1040 | * End: |
| 1041 | */ |