Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <svm/message_queue.h> |
| 17 | #include <vppinfra/mem.h> |
Nathan Skrzypczak | cfdb109 | 2019-12-02 16:44:42 +0100 | [diff] [blame] | 18 | #include <vppinfra/format.h> |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 19 | #include <vppinfra/time.h> |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 20 | #include <sys/eventfd.h> |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 21 | #include <sys/socket.h> |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 22 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 23 | static inline svm_msg_q_ring_t * |
| 24 | svm_msg_q_ring_inline (svm_msg_q_t * mq, u32 ring_index) |
| 25 | { |
| 26 | return vec_elt_at_index (mq->rings, ring_index); |
| 27 | } |
| 28 | |
| 29 | svm_msg_q_ring_t * |
| 30 | svm_msg_q_ring (svm_msg_q_t * mq, u32 ring_index) |
| 31 | { |
| 32 | return svm_msg_q_ring_inline (mq, ring_index); |
| 33 | } |
| 34 | |
| 35 | static inline void * |
| 36 | svm_msg_q_ring_data (svm_msg_q_ring_t * ring, u32 elt_index) |
| 37 | { |
| 38 | ASSERT (elt_index < ring->nitems); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 39 | return (ring->shr->data + elt_index * ring->elsize); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 42 | static void |
| 43 | svm_msg_q_init_mutex (svm_msg_q_shared_queue_t *sq) |
| 44 | { |
| 45 | pthread_mutexattr_t attr; |
| 46 | pthread_condattr_t cattr; |
| 47 | |
| 48 | clib_memset (&attr, 0, sizeof (attr)); |
| 49 | clib_memset (&cattr, 0, sizeof (cattr)); |
| 50 | |
| 51 | if (pthread_mutexattr_init (&attr)) |
| 52 | clib_unix_warning ("mutexattr_init"); |
| 53 | if (pthread_mutexattr_setpshared (&attr, PTHREAD_PROCESS_SHARED)) |
| 54 | clib_unix_warning ("pthread_mutexattr_setpshared"); |
| 55 | if (pthread_mutexattr_setrobust (&attr, PTHREAD_MUTEX_ROBUST)) |
| 56 | clib_unix_warning ("setrobust"); |
| 57 | if (pthread_mutex_init (&sq->mutex, &attr)) |
| 58 | clib_unix_warning ("mutex_init"); |
| 59 | if (pthread_mutexattr_destroy (&attr)) |
| 60 | clib_unix_warning ("mutexattr_destroy"); |
| 61 | if (pthread_condattr_init (&cattr)) |
| 62 | clib_unix_warning ("condattr_init"); |
| 63 | if (pthread_condattr_setpshared (&cattr, PTHREAD_PROCESS_SHARED)) |
| 64 | clib_unix_warning ("condattr_setpshared"); |
| 65 | if (pthread_cond_init (&sq->condvar, &cattr)) |
| 66 | clib_unix_warning ("cond_init1"); |
| 67 | if (pthread_condattr_destroy (&cattr)) |
| 68 | clib_unix_warning ("cond_init2"); |
| 69 | } |
| 70 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 71 | svm_msg_q_shared_t * |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 72 | svm_msg_q_init (void *base, svm_msg_q_cfg_t *cfg) |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 73 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 74 | svm_msg_q_ring_shared_t *ring; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 75 | svm_msg_q_shared_queue_t *sq; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 76 | svm_msg_q_shared_t *smq; |
| 77 | u32 q_sz, offset; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 78 | int i; |
| 79 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 80 | q_sz = sizeof (*sq) + cfg->q_nitems * sizeof (svm_msg_q_msg_t); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 81 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 82 | smq = (svm_msg_q_shared_t *) base; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 83 | sq = smq->q; |
| 84 | clib_memset (sq, 0, sizeof (*sq)); |
| 85 | sq->elsize = sizeof (svm_msg_q_msg_t); |
| 86 | sq->maxsize = cfg->q_nitems; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 87 | smq->n_rings = cfg->n_rings; |
| 88 | ring = (void *) ((u8 *) smq->q + q_sz); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 89 | for (i = 0; i < cfg->n_rings; i++) |
| 90 | { |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 91 | ring->elsize = cfg->ring_cfgs[i].elsize; |
| 92 | ring->nitems = cfg->ring_cfgs[i].nitems; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 93 | ring->cursize = ring->head = ring->tail = 0; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 94 | offset = sizeof (*ring) + ring->nitems * ring->elsize; |
| 95 | ring = (void *) ((u8 *) ring + offset); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 98 | svm_msg_q_init_mutex (sq); |
| 99 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 100 | return smq; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 103 | uword |
| 104 | svm_msg_q_size_to_alloc (svm_msg_q_cfg_t *cfg) |
| 105 | { |
| 106 | svm_msg_q_ring_cfg_t *ring_cfg; |
| 107 | uword rings_sz = 0, mq_sz; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 108 | u32 q_sz; |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 109 | int i; |
| 110 | |
| 111 | ASSERT (cfg); |
| 112 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 113 | rings_sz = sizeof (svm_msg_q_ring_shared_t) * cfg->n_rings; |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 114 | for (i = 0; i < cfg->n_rings; i++) |
| 115 | { |
| 116 | if (cfg->ring_cfgs[i].data) |
| 117 | continue; |
| 118 | ring_cfg = &cfg->ring_cfgs[i]; |
| 119 | rings_sz += (uword) ring_cfg->nitems * ring_cfg->elsize; |
| 120 | } |
| 121 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 122 | q_sz = sizeof (svm_msg_q_shared_queue_t) + |
| 123 | cfg->q_nitems * sizeof (svm_msg_q_msg_t); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 124 | mq_sz = sizeof (svm_msg_q_shared_t) + q_sz + rings_sz; |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 125 | |
| 126 | return mq_sz; |
| 127 | } |
| 128 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 129 | svm_msg_q_shared_t * |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 130 | svm_msg_q_alloc (svm_msg_q_cfg_t *cfg) |
| 131 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 132 | uword mq_sz; |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 133 | u8 *base; |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 134 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 135 | mq_sz = svm_msg_q_size_to_alloc (cfg); |
Florin Coras | 213b1bb | 2020-12-07 14:33:58 -0800 | [diff] [blame] | 136 | base = clib_mem_alloc_aligned (mq_sz, CLIB_CACHE_LINE_BYTES); |
| 137 | if (!base) |
| 138 | return 0; |
| 139 | |
| 140 | return svm_msg_q_init (base, cfg); |
| 141 | } |
| 142 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 143 | void |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 144 | svm_msg_q_attach (svm_msg_q_t *mq, void *smq_base) |
| 145 | { |
| 146 | svm_msg_q_ring_shared_t *ring; |
| 147 | svm_msg_q_shared_t *smq; |
| 148 | u32 i, n_rings, q_sz, offset; |
| 149 | |
| 150 | smq = (svm_msg_q_shared_t *) smq_base; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 151 | mq->q.shr = smq->q; |
| 152 | mq->q.evtfd = -1; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 153 | n_rings = smq->n_rings; |
| 154 | vec_validate (mq->rings, n_rings - 1); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 155 | q_sz = sizeof (svm_msg_q_shared_queue_t) + |
| 156 | mq->q.shr->maxsize * sizeof (svm_msg_q_msg_t); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 157 | ring = (void *) ((u8 *) smq->q + q_sz); |
| 158 | for (i = 0; i < n_rings; i++) |
| 159 | { |
| 160 | mq->rings[i].nitems = ring->nitems; |
| 161 | mq->rings[i].elsize = ring->elsize; |
| 162 | mq->rings[i].shr = ring; |
| 163 | offset = sizeof (*ring) + ring->nitems * ring->elsize; |
| 164 | ring = (void *) ((u8 *) ring + offset); |
| 165 | } |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 166 | clib_spinlock_init (&mq->q.lock); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void |
Florin Coras | 8c517c8 | 2021-03-30 00:23:54 -0700 | [diff] [blame] | 170 | svm_msg_q_cleanup (svm_msg_q_t *mq) |
| 171 | { |
| 172 | vec_free (mq->rings); |
| 173 | clib_spinlock_free (&mq->q.lock); |
| 174 | if (mq->q.evtfd != -1) |
| 175 | close (mq->q.evtfd); |
| 176 | } |
| 177 | |
| 178 | void |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 179 | svm_msg_q_free (svm_msg_q_t * mq) |
| 180 | { |
Florin Coras | 8c517c8 | 2021-03-30 00:23:54 -0700 | [diff] [blame] | 181 | svm_msg_q_cleanup (mq); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 182 | clib_mem_free (mq->q.shr); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 183 | clib_mem_free (mq); |
| 184 | } |
| 185 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 186 | static void |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 187 | svm_msg_q_send_signal (svm_msg_q_t *mq, u8 is_consumer) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 188 | { |
| 189 | if (mq->q.evtfd == -1) |
| 190 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 191 | if (is_consumer) |
| 192 | { |
| 193 | int rv = pthread_mutex_lock (&mq->q.shr->mutex); |
| 194 | if (PREDICT_FALSE (rv == EOWNERDEAD)) |
| 195 | { |
| 196 | rv = pthread_mutex_consistent (&mq->q.shr->mutex); |
| 197 | return; |
| 198 | } |
| 199 | } |
| 200 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 201 | (void) pthread_cond_broadcast (&mq->q.shr->condvar); |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 202 | |
| 203 | if (is_consumer) |
| 204 | pthread_mutex_unlock (&mq->q.shr->mutex); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 205 | } |
| 206 | else |
| 207 | { |
| 208 | int __clib_unused rv; |
| 209 | u64 data = 1; |
| 210 | |
| 211 | if (mq->q.evtfd < 0) |
| 212 | return; |
| 213 | |
| 214 | rv = write (mq->q.evtfd, &data, sizeof (data)); |
| 215 | if (PREDICT_FALSE (rv < 0)) |
| 216 | clib_unix_warning ("signal write on %d returned %d", mq->q.evtfd, rv); |
| 217 | } |
| 218 | } |
| 219 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 220 | svm_msg_q_msg_t |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 221 | svm_msg_q_alloc_msg_w_ring (svm_msg_q_t * mq, u32 ring_index) |
| 222 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 223 | svm_msg_q_ring_shared_t *sr; |
| 224 | svm_msg_q_ring_t *ring; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 225 | svm_msg_q_msg_t msg; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 226 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 227 | ring = svm_msg_q_ring_inline (mq, ring_index); |
| 228 | sr = ring->shr; |
| 229 | |
| 230 | ASSERT (sr->cursize < ring->nitems); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 231 | msg.ring_index = ring - mq->rings; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 232 | msg.elt_index = sr->tail; |
| 233 | sr->tail = (sr->tail + 1) % ring->nitems; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 234 | clib_atomic_fetch_add_rel (&sr->cursize, 1); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 235 | return msg; |
| 236 | } |
| 237 | |
| 238 | int |
| 239 | svm_msg_q_lock_and_alloc_msg_w_ring (svm_msg_q_t * mq, u32 ring_index, |
| 240 | u8 noblock, svm_msg_q_msg_t * msg) |
| 241 | { |
| 242 | if (noblock) |
| 243 | { |
| 244 | if (svm_msg_q_try_lock (mq)) |
| 245 | return -1; |
Florin Coras | 80d100c | 2022-04-19 18:57:24 -0700 | [diff] [blame] | 246 | if (PREDICT_FALSE (svm_msg_q_or_ring_is_full (mq, ring_index))) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 247 | { |
| 248 | svm_msg_q_unlock (mq); |
| 249 | return -2; |
| 250 | } |
| 251 | *msg = svm_msg_q_alloc_msg_w_ring (mq, ring_index); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 252 | } |
| 253 | else |
| 254 | { |
| 255 | svm_msg_q_lock (mq); |
Florin Coras | 80d100c | 2022-04-19 18:57:24 -0700 | [diff] [blame] | 256 | while (svm_msg_q_or_ring_is_full (mq, ring_index)) |
| 257 | svm_msg_q_or_ring_wait_prod (mq, ring_index); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 258 | *msg = svm_msg_q_alloc_msg_w_ring (mq, ring_index); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | svm_msg_q_msg_t |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 264 | svm_msg_q_alloc_msg (svm_msg_q_t * mq, u32 nbytes) |
| 265 | { |
| 266 | svm_msg_q_msg_t msg = {.as_u64 = ~0 }; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 267 | svm_msg_q_ring_shared_t *sr; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 268 | svm_msg_q_ring_t *ring; |
| 269 | |
| 270 | vec_foreach (ring, mq->rings) |
| 271 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 272 | sr = ring->shr; |
| 273 | if (ring->elsize < nbytes || sr->cursize == ring->nitems) |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 274 | continue; |
| 275 | msg.ring_index = ring - mq->rings; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 276 | msg.elt_index = sr->tail; |
| 277 | sr->tail = (sr->tail + 1) % ring->nitems; |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 278 | clib_atomic_fetch_add_relax (&sr->cursize, 1); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 279 | break; |
| 280 | } |
| 281 | return msg; |
| 282 | } |
| 283 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 284 | void * |
| 285 | svm_msg_q_msg_data (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) |
| 286 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 287 | svm_msg_q_ring_t *ring = svm_msg_q_ring_inline (mq, msg->ring_index); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 288 | return svm_msg_q_ring_data (ring, msg->elt_index); |
| 289 | } |
| 290 | |
| 291 | void |
| 292 | svm_msg_q_free_msg (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) |
| 293 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 294 | svm_msg_q_ring_shared_t *sr; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 295 | svm_msg_q_ring_t *ring; |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 296 | u32 need_signal; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 297 | |
Florin Coras | 41c9e04 | 2018-09-11 00:10:41 -0700 | [diff] [blame] | 298 | ASSERT (vec_len (mq->rings) > msg->ring_index); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 299 | ring = svm_msg_q_ring_inline (mq, msg->ring_index); |
| 300 | sr = ring->shr; |
| 301 | if (msg->elt_index == sr->head) |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 302 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 303 | sr->head = (sr->head + 1) % ring->nitems; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 304 | } |
| 305 | else |
| 306 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 307 | clib_warning ("message out of order: elt %u head %u ring %u", |
| 308 | msg->elt_index, sr->head, msg->ring_index); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 309 | /* for now, expect messages to be processed in order */ |
| 310 | ASSERT (0); |
| 311 | } |
Florin Coras | fea813a | 2019-12-27 10:26:56 -0800 | [diff] [blame] | 312 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 313 | need_signal = clib_atomic_load_relax_n (&sr->cursize) == ring->nitems; |
| 314 | clib_atomic_fetch_sub_relax (&sr->cursize, 1); |
Florin Coras | fea813a | 2019-12-27 10:26:56 -0800 | [diff] [blame] | 315 | |
| 316 | if (PREDICT_FALSE (need_signal)) |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 317 | svm_msg_q_send_signal (mq, 1 /* is consumer */); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static int |
| 321 | svm_msq_q_msg_is_valid (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) |
| 322 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 323 | u32 dist1, dist2, tail, head; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 324 | svm_msg_q_ring_shared_t *sr; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 325 | svm_msg_q_ring_t *ring; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 326 | |
| 327 | if (vec_len (mq->rings) <= msg->ring_index) |
| 328 | return 0; |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 329 | |
| 330 | ring = svm_msg_q_ring_inline (mq, msg->ring_index); |
| 331 | sr = ring->shr; |
| 332 | tail = sr->tail; |
| 333 | head = sr->head; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 334 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 335 | dist1 = ((ring->nitems + msg->elt_index) - head) % ring->nitems; |
| 336 | if (tail == head) |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 337 | dist2 = (sr->cursize == 0) ? 0 : ring->nitems; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 338 | else |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 339 | dist2 = ((ring->nitems + tail) - head) % ring->nitems; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 340 | return (dist1 < dist2); |
| 341 | } |
| 342 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 343 | void |
| 344 | svm_msg_q_add_raw (svm_msg_q_t *mq, svm_msg_q_msg_t *msg) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 345 | { |
| 346 | svm_msg_q_shared_queue_t *sq = mq->q.shr; |
| 347 | i8 *tailp; |
| 348 | u32 sz; |
| 349 | |
| 350 | tailp = (i8 *) (&sq->data[0] + sq->elsize * sq->tail); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 351 | clib_memcpy_fast (tailp, msg, sq->elsize); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 352 | |
| 353 | sq->tail = (sq->tail + 1) % sq->maxsize; |
| 354 | |
| 355 | sz = clib_atomic_fetch_add_rel (&sq->cursize, 1); |
| 356 | if (!sz) |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 357 | svm_msg_q_send_signal (mq, 0 /* is consumer */); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 360 | int |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 361 | svm_msg_q_add (svm_msg_q_t * mq, svm_msg_q_msg_t * msg, int nowait) |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 362 | { |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 363 | ASSERT (svm_msq_q_msg_is_valid (mq, msg)); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 364 | |
| 365 | if (nowait) |
| 366 | { |
| 367 | /* zero on success */ |
| 368 | if (svm_msg_q_try_lock (mq)) |
| 369 | { |
| 370 | return (-1); |
| 371 | } |
| 372 | } |
| 373 | else |
| 374 | svm_msg_q_lock (mq); |
| 375 | |
| 376 | if (PREDICT_FALSE (svm_msg_q_is_full (mq))) |
| 377 | { |
| 378 | if (nowait) |
| 379 | return (-2); |
| 380 | while (svm_msg_q_is_full (mq)) |
Florin Coras | 89c98a4 | 2021-03-25 11:24:33 -0700 | [diff] [blame] | 381 | svm_msg_q_wait_prod (mq); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 384 | svm_msg_q_add_raw (mq, msg); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 385 | |
| 386 | svm_msg_q_unlock (mq); |
| 387 | |
| 388 | return 0; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 392 | svm_msg_q_add_and_unlock (svm_msg_q_t * mq, svm_msg_q_msg_t * msg) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 393 | { |
| 394 | ASSERT (svm_msq_q_msg_is_valid (mq, msg)); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 395 | svm_msg_q_add_raw (mq, msg); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 396 | svm_msg_q_unlock (mq); |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 399 | int |
| 400 | svm_msg_q_sub_raw (svm_msg_q_t *mq, svm_msg_q_msg_t *elem) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 401 | { |
| 402 | svm_msg_q_shared_queue_t *sq = mq->q.shr; |
| 403 | i8 *headp; |
| 404 | u32 sz; |
| 405 | |
| 406 | ASSERT (!svm_msg_q_is_empty (mq)); |
| 407 | |
| 408 | headp = (i8 *) (&sq->data[0] + sq->elsize * sq->head); |
| 409 | clib_memcpy_fast (elem, headp, sq->elsize); |
| 410 | |
| 411 | sq->head = (sq->head + 1) % sq->maxsize; |
| 412 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 413 | sz = clib_atomic_fetch_sub_relax (&sq->cursize, 1); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 414 | if (PREDICT_FALSE (sz == sq->maxsize)) |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 415 | svm_msg_q_send_signal (mq, 1 /* is consumer */); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 420 | int |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 421 | svm_msg_q_sub_raw_batch (svm_msg_q_t *mq, svm_msg_q_msg_t *msg_buf, u32 n_msgs) |
| 422 | { |
| 423 | svm_msg_q_shared_queue_t *sq = mq->q.shr; |
| 424 | u32 sz, to_deq; |
| 425 | i8 *headp; |
| 426 | |
| 427 | sz = svm_msg_q_size (mq); |
| 428 | ASSERT (sz); |
| 429 | to_deq = clib_min (sz, n_msgs); |
| 430 | |
| 431 | headp = (i8 *) (&sq->data[0] + sq->elsize * sq->head); |
| 432 | |
| 433 | if (sq->head + to_deq < sq->maxsize) |
| 434 | { |
| 435 | clib_memcpy_fast (msg_buf, headp, sq->elsize * to_deq); |
| 436 | sq->head += to_deq; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | u32 first_batch = sq->maxsize - sq->head; |
| 441 | clib_memcpy_fast (msg_buf, headp, sq->elsize * first_batch); |
| 442 | clib_memcpy_fast (msg_buf + first_batch, sq->data, |
| 443 | sq->elsize * (to_deq - first_batch)); |
| 444 | sq->head = (sq->head + to_deq) % sq->maxsize; |
| 445 | } |
| 446 | |
| 447 | clib_atomic_fetch_sub_relax (&sq->cursize, to_deq); |
| 448 | if (PREDICT_FALSE (sz == sq->maxsize)) |
| 449 | svm_msg_q_send_signal (mq, 1 /* is consumer */); |
| 450 | |
| 451 | return to_deq; |
| 452 | } |
| 453 | |
| 454 | int |
| 455 | svm_msg_q_sub (svm_msg_q_t *mq, svm_msg_q_msg_t *msg, |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 456 | svm_q_conditional_wait_t cond, u32 time) |
| 457 | { |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 458 | int rc = 0; |
| 459 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 460 | if (svm_msg_q_is_empty (mq)) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 461 | { |
| 462 | if (cond == SVM_Q_NOWAIT) |
| 463 | { |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 464 | return (-2); |
| 465 | } |
| 466 | else if (cond == SVM_Q_TIMEDWAIT) |
| 467 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 468 | if ((rc = svm_msg_q_timedwait (mq, time))) |
| 469 | return rc; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 470 | } |
| 471 | else |
| 472 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 473 | svm_msg_q_wait (mq, SVM_MQ_WAIT_EMPTY); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 477 | svm_msg_q_sub_raw (mq, msg); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 478 | |
| 479 | return 0; |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 482 | void |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 483 | svm_msg_q_set_eventfd (svm_msg_q_t *mq, int fd) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 484 | { |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 485 | mq->q.evtfd = fd; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | int |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 489 | svm_msg_q_alloc_eventfd (svm_msg_q_t *mq) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 490 | { |
| 491 | int fd; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 492 | if ((fd = eventfd (0, 0)) < 0) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 493 | return -1; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 494 | svm_msg_q_set_eventfd (mq, fd); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 498 | int |
| 499 | svm_msg_q_wait (svm_msg_q_t *mq, svm_msg_q_wait_type_t type) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 500 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 501 | u8 (*fn) (svm_msg_q_t *); |
| 502 | int rv; |
| 503 | |
| 504 | fn = (type == SVM_MQ_WAIT_EMPTY) ? svm_msg_q_is_empty : svm_msg_q_is_full; |
| 505 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 506 | if (mq->q.evtfd == -1) |
| 507 | { |
Florin Coras | 89c98a4 | 2021-03-25 11:24:33 -0700 | [diff] [blame] | 508 | rv = pthread_mutex_lock (&mq->q.shr->mutex); |
| 509 | if (PREDICT_FALSE (rv == EOWNERDEAD)) |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 510 | { |
Florin Coras | 89c98a4 | 2021-03-25 11:24:33 -0700 | [diff] [blame] | 511 | rv = pthread_mutex_consistent (&mq->q.shr->mutex); |
| 512 | return rv; |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | while (fn (mq)) |
| 516 | pthread_cond_wait (&mq->q.shr->condvar, &mq->q.shr->mutex); |
| 517 | |
Florin Coras | 89c98a4 | 2021-03-25 11:24:33 -0700 | [diff] [blame] | 518 | pthread_mutex_unlock (&mq->q.shr->mutex); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 519 | } |
| 520 | else |
| 521 | { |
| 522 | u64 buf; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 523 | |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 524 | while (fn (mq)) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 525 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 526 | while ((rv = read (mq->q.evtfd, &buf, sizeof (buf))) < 0) |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 527 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 528 | if (errno != EAGAIN) |
| 529 | { |
| 530 | clib_unix_warning ("read error"); |
| 531 | return rv; |
| 532 | } |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 535 | } |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 536 | |
| 537 | return 0; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | int |
Florin Coras | 89c98a4 | 2021-03-25 11:24:33 -0700 | [diff] [blame] | 541 | svm_msg_q_wait_prod (svm_msg_q_t *mq) |
| 542 | { |
| 543 | if (mq->q.evtfd == -1) |
| 544 | { |
| 545 | while (svm_msg_q_is_full (mq)) |
| 546 | pthread_cond_wait (&mq->q.shr->condvar, &mq->q.shr->mutex); |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | u64 buf; |
| 551 | int rv; |
| 552 | |
| 553 | while (svm_msg_q_is_full (mq)) |
| 554 | { |
| 555 | while ((rv = read (mq->q.evtfd, &buf, sizeof (buf))) < 0) |
| 556 | { |
| 557 | if (errno != EAGAIN) |
| 558 | { |
| 559 | clib_unix_warning ("read error"); |
| 560 | return rv; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | int |
Florin Coras | 80d100c | 2022-04-19 18:57:24 -0700 | [diff] [blame] | 570 | svm_msg_q_or_ring_wait_prod (svm_msg_q_t *mq, u32 ring_index) |
| 571 | { |
| 572 | if (mq->q.evtfd == -1) |
| 573 | { |
| 574 | while (svm_msg_q_or_ring_is_full (mq, ring_index)) |
| 575 | pthread_cond_wait (&mq->q.shr->condvar, &mq->q.shr->mutex); |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | u64 buf; |
| 580 | int rv; |
| 581 | |
| 582 | while (svm_msg_q_or_ring_is_full (mq, ring_index)) |
| 583 | { |
| 584 | while ((rv = read (mq->q.evtfd, &buf, sizeof (buf))) < 0) |
| 585 | { |
| 586 | if (errno != EAGAIN) |
| 587 | { |
| 588 | clib_unix_warning ("read error"); |
| 589 | return rv; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | int |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 599 | svm_msg_q_timedwait (svm_msg_q_t *mq, double timeout) |
| 600 | { |
| 601 | if (mq->q.evtfd == -1) |
| 602 | { |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 603 | svm_msg_q_shared_queue_t *sq = mq->q.shr; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 604 | struct timespec ts; |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 605 | u32 sz; |
| 606 | int rv; |
| 607 | |
| 608 | rv = pthread_mutex_lock (&sq->mutex); |
| 609 | if (PREDICT_FALSE (rv == EOWNERDEAD)) |
| 610 | { |
| 611 | rv = pthread_mutex_consistent (&sq->mutex); |
| 612 | return rv; |
| 613 | } |
| 614 | |
| 615 | /* check if we're still in a signalable state after grabbing lock */ |
| 616 | sz = svm_msg_q_size (mq); |
| 617 | if (sz != 0 && sz != sq->maxsize) |
| 618 | { |
| 619 | pthread_mutex_unlock (&sq->mutex); |
| 620 | return 0; |
| 621 | } |
| 622 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 623 | ts.tv_sec = unix_time_now () + (u32) timeout; |
| 624 | ts.tv_nsec = (timeout - (u32) timeout) * 1e9; |
Florin Coras | 5398dfb | 2021-01-25 20:31:27 -0800 | [diff] [blame] | 625 | rv = pthread_cond_timedwait (&sq->condvar, &sq->mutex, &ts); |
| 626 | |
| 627 | pthread_mutex_unlock (&sq->mutex); |
| 628 | return rv; |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 629 | } |
| 630 | else |
| 631 | { |
| 632 | struct timeval tv; |
| 633 | u64 buf; |
| 634 | int rv; |
| 635 | |
| 636 | tv.tv_sec = (u64) timeout; |
| 637 | tv.tv_usec = ((u64) timeout - (u64) timeout) * 1e9; |
Florin Coras | f9db7f0 | 2021-02-15 11:56:46 -0800 | [diff] [blame] | 638 | rv = setsockopt (mq->q.evtfd, SOL_SOCKET, SO_RCVTIMEO, |
| 639 | (const char *) &tv, sizeof tv); |
| 640 | if (rv < 0) |
| 641 | { |
| 642 | clib_unix_warning ("setsockopt"); |
| 643 | return -1; |
| 644 | } |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 645 | |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 646 | rv = read (mq->q.evtfd, &buf, sizeof (buf)); |
| 647 | if (rv < 0) |
| 648 | clib_warning ("read %u", errno); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 649 | |
| 650 | return rv < 0 ? errno : 0; |
| 651 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Nathan Skrzypczak | cfdb109 | 2019-12-02 16:44:42 +0100 | [diff] [blame] | 654 | u8 * |
| 655 | format_svm_msg_q (u8 * s, va_list * args) |
| 656 | { |
| 657 | svm_msg_q_t *mq = va_arg (*args, svm_msg_q_t *); |
Florin Coras | 86f1232 | 2021-01-22 15:05:14 -0800 | [diff] [blame] | 658 | s = format (s, " [Q:%d/%d]", mq->q.shr->cursize, mq->q.shr->maxsize); |
Nathan Skrzypczak | cfdb109 | 2019-12-02 16:44:42 +0100 | [diff] [blame] | 659 | for (u32 i = 0; i < vec_len (mq->rings); i++) |
| 660 | { |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 661 | s = format (s, " [R%d:%d/%d]", i, mq->rings[i].shr->cursize, |
Nathan Skrzypczak | cfdb109 | 2019-12-02 16:44:42 +0100 | [diff] [blame] | 662 | mq->rings[i].nitems); |
| 663 | } |
| 664 | return s; |
| 665 | } |
| 666 | |
Florin Coras | 65784c1 | 2018-07-04 04:17:41 -0700 | [diff] [blame] | 667 | /* |
| 668 | * fd.io coding-style-patch-verification: ON |
| 669 | * |
| 670 | * Local Variables: |
| 671 | * eval: (c-set-style "gnu") |
| 672 | * End: |
| 673 | */ |