FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
vhost_user_output.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * vhost-user-output
4  *
5  * Copyright (c) 2014-2018 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <fcntl.h> /* for open */
21 #include <sys/ioctl.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 #include <sys/uio.h> /* for iovec */
27 #include <netinet/in.h>
28 #include <sys/vfs.h>
29 
30 #include <linux/if_arp.h>
31 #include <linux/if_tun.h>
32 
33 #include <vlib/vlib.h>
34 #include <vlib/unix/unix.h>
35 
36 #include <vnet/ip/ip.h>
37 
38 #include <vnet/ethernet/ethernet.h>
39 #include <vnet/devices/devices.h>
40 #include <vnet/feature/feature.h>
41 
44 
45 /*
46  * On the transmit side, we keep processing the buffers from vlib in the while
47  * loop and prepare the copy order to be executed later. However, the static
48  * array which we keep the copy order is limited to VHOST_USER_COPY_ARRAY_N
49  * entries. In order to not corrupt memory, we have to do the copy when the
50  * static array reaches the copy threshold. We subtract 40 in case the code
51  * goes into the inner loop for a maximum of 64k frames which may require
52  * more array entries. We subtract 200 because our default buffer size is
53  * 2048 and the default desc len is likely 1536. While it takes less than 40
54  * vlib buffers for the jumbo frame, it may take twice as much descriptors
55  * for the same jumbo frame. Use 200 for the extra head room.
56  */
57 #define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 200)
58 
60 
61 #define foreach_vhost_user_tx_func_error \
62  _(NONE, "no error") \
63  _(NOT_READY, "vhost vring not ready") \
64  _(DOWN, "vhost interface is down") \
65  _(PKT_DROP_NOBUF, "tx packet drops (no available descriptors)") \
66  _(PKT_DROP_NOMRG, "tx packet drops (cannot merge descriptors)") \
67  _(MMAP_FAIL, "mmap failure") \
68  _(INDIRECT_OVERFLOW, "indirect descriptor table overflow")
69 
70 typedef enum
71 {
72 #define _(f,s) VHOST_USER_TX_FUNC_ERROR_##f,
74 #undef _
77 
78 static __clib_unused char *vhost_user_tx_func_error_strings[] = {
79 #define _(n,s) s,
81 #undef _
82 };
83 
84 static __clib_unused u8 *
85 format_vhost_user_interface_name (u8 * s, va_list * args)
86 {
87  u32 i = va_arg (*args, u32);
88  u32 show_dev_instance = ~0;
90 
92  show_dev_instance = vum->show_dev_instance_by_real_dev_instance[i];
93 
94  if (show_dev_instance != ~0)
95  i = show_dev_instance;
96 
97  s = format (s, "VirtualEthernet0/0/%d", i);
98  return s;
99 }
100 
101 static __clib_unused int
103 {
104  // FIXME: check if the new dev instance is already used
107  hi->dev_instance);
108 
110  hi->dev_instance, ~0);
111 
113  new_dev_instance;
114 
115  vu_log_debug (vui, "renumbered vhost-user interface dev_instance %d to %d",
116  hi->dev_instance, new_dev_instance);
117 
118  return 0;
119 }
120 
121 /**
122  * @brief Try once to lock the vring
123  * @return 0 on success, non-zero on failure.
124  */
127 {
128  return clib_atomic_test_and_set (vui->vring_locks[qid]);
129 }
130 
131 /**
132  * @brief Spin until the vring is successfully locked
133  */
136 {
137  while (vhost_user_vring_try_lock (vui, qid))
138  ;
139 }
140 
141 /**
142  * @brief Unlock the vring lock
143  */
146 {
147  clib_atomic_release (vui->vring_locks[qid]);
148 }
149 
152  vhost_user_intf_t * vui, u16 qid,
153  vlib_buffer_t * b, vhost_user_vring_t * rxvq)
154 {
156  u32 last_avail_idx = rxvq->last_avail_idx;
157  u32 desc_current = rxvq->avail->ring[last_avail_idx & rxvq->qsz_mask];
158  vring_desc_t *hdr_desc = 0;
159  u32 hint = 0;
160 
161  clib_memset (t, 0, sizeof (*t));
162  t->device_index = vui - vum->vhost_user_interfaces;
163  t->qid = qid;
164 
165  hdr_desc = &rxvq->desc[desc_current];
166  if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT)
167  {
168  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_INDIRECT;
169  /* Header is the first here */
170  hdr_desc = map_guest_mem (vui, rxvq->desc[desc_current].addr, &hint);
171  }
172  if (rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT)
173  {
174  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SIMPLE_CHAINED;
175  }
176  if (!(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_NEXT) &&
177  !(rxvq->desc[desc_current].flags & VIRTQ_DESC_F_INDIRECT))
178  {
179  t->virtio_ring_flags |= 1 << VIRTIO_TRACE_F_SINGLE_DESC;
180  }
181 
182  t->first_desc_len = hdr_desc ? hdr_desc->len : 0;
183 }
184 
187  u16 copy_len, u32 * map_hint)
188 {
189  void *dst0, *dst1, *dst2, *dst3;
190  if (PREDICT_TRUE (copy_len >= 4))
191  {
192  if (PREDICT_FALSE (!(dst2 = map_guest_mem (vui, cpy[0].dst, map_hint))))
193  return 1;
194  if (PREDICT_FALSE (!(dst3 = map_guest_mem (vui, cpy[1].dst, map_hint))))
195  return 1;
196  while (PREDICT_TRUE (copy_len >= 4))
197  {
198  dst0 = dst2;
199  dst1 = dst3;
200 
201  if (PREDICT_FALSE
202  (!(dst2 = map_guest_mem (vui, cpy[2].dst, map_hint))))
203  return 1;
204  if (PREDICT_FALSE
205  (!(dst3 = map_guest_mem (vui, cpy[3].dst, map_hint))))
206  return 1;
207 
208  CLIB_PREFETCH ((void *) cpy[2].src, 64, LOAD);
209  CLIB_PREFETCH ((void *) cpy[3].src, 64, LOAD);
210 
211  clib_memcpy_fast (dst0, (void *) cpy[0].src, cpy[0].len);
212  clib_memcpy_fast (dst1, (void *) cpy[1].src, cpy[1].len);
213 
214  vhost_user_log_dirty_pages_2 (vui, cpy[0].dst, cpy[0].len, 1);
215  vhost_user_log_dirty_pages_2 (vui, cpy[1].dst, cpy[1].len, 1);
216  copy_len -= 2;
217  cpy += 2;
218  }
219  }
220  while (copy_len)
221  {
222  if (PREDICT_FALSE (!(dst0 = map_guest_mem (vui, cpy->dst, map_hint))))
223  return 1;
224  clib_memcpy_fast (dst0, (void *) cpy->src, cpy->len);
225  vhost_user_log_dirty_pages_2 (vui, cpy->dst, cpy->len, 1);
226  copy_len -= 1;
227  cpy += 1;
228  }
229  return 0;
230 }
231 
234  node, vlib_frame_t * frame)
235 {
236  u32 *buffers = vlib_frame_vector_args (frame);
237  u32 n_left = frame->n_vectors;
239  vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
240  vhost_user_intf_t *vui =
242  u32 qid = ~0;
243  vhost_user_vring_t *rxvq;
244  u8 error;
245  u32 thread_index = vm->thread_index;
246  vhost_cpu_t *cpu = &vum->cpus[thread_index];
247  u32 map_hint = 0;
248  u8 retry = 8;
249  u16 copy_len;
250  u16 tx_headers_len;
251 
252  if (PREDICT_FALSE (!vui->admin_up))
253  {
254  error = VHOST_USER_TX_FUNC_ERROR_DOWN;
255  goto done3;
256  }
257 
258  if (PREDICT_FALSE (!vui->is_ready))
259  {
260  error = VHOST_USER_TX_FUNC_ERROR_NOT_READY;
261  goto done3;
262  }
263 
264  qid = VHOST_VRING_IDX_RX (*vec_elt_at_index (vui->per_cpu_tx_qid,
265  thread_index));
266  rxvq = &vui->vrings[qid];
267  if (PREDICT_FALSE (rxvq->avail == 0))
268  {
269  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
270  goto done3;
271  }
272 
273  if (PREDICT_FALSE (vui->use_tx_spinlock))
274  vhost_user_vring_lock (vui, qid);
275 
276 retry:
277  error = VHOST_USER_TX_FUNC_ERROR_NONE;
278  tx_headers_len = 0;
279  copy_len = 0;
280  while (n_left > 0)
281  {
282  vlib_buffer_t *b0, *current_b0;
283  u16 desc_head, desc_index, desc_len;
284  vring_desc_t *desc_table;
285  uword buffer_map_addr;
286  u32 buffer_len;
287  u16 bytes_left;
288 
289  if (PREDICT_TRUE (n_left > 1))
290  vlib_prefetch_buffer_with_index (vm, buffers[1], LOAD);
291 
292  b0 = vlib_get_buffer (vm, buffers[0]);
293 
294  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
295  {
296  cpu->current_trace = vlib_add_trace (vm, node, b0,
297  sizeof (*cpu->current_trace));
298  vhost_user_tx_trace (cpu->current_trace, vui, qid / 2, b0, rxvq);
299  }
300 
301  if (PREDICT_FALSE (rxvq->last_avail_idx == rxvq->avail->idx))
302  {
303  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
304  goto done;
305  }
306 
307  desc_table = rxvq->desc;
308  desc_head = desc_index =
309  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
310 
311  /* Go deeper in case of indirect descriptor
312  * I don't know of any driver providing indirect for RX. */
313  if (PREDICT_FALSE (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
314  {
315  if (PREDICT_FALSE
316  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
317  {
318  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
319  goto done;
320  }
321  if (PREDICT_FALSE
322  (!(desc_table =
323  map_guest_mem (vui, rxvq->desc[desc_index].addr,
324  &map_hint))))
325  {
326  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
327  goto done;
328  }
329  desc_index = 0;
330  }
331 
332  desc_len = vui->virtio_net_hdr_sz;
333  buffer_map_addr = desc_table[desc_index].addr;
334  buffer_len = desc_table[desc_index].len;
335 
336  {
337  // Get a header from the header array
338  virtio_net_hdr_mrg_rxbuf_t *hdr = &cpu->tx_headers[tx_headers_len];
339  tx_headers_len++;
340  hdr->hdr.flags = 0;
341  hdr->hdr.gso_type = 0;
342  hdr->num_buffers = 1; //This is local, no need to check
343 
344  // Prepare a copy order executed later for the header
345  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
346  vhost_copy_t *cpy = &cpu->copy[copy_len];
347  copy_len++;
348  cpy->len = vui->virtio_net_hdr_sz;
349  cpy->dst = buffer_map_addr;
350  cpy->src = (uword) hdr;
351  }
352 
353  buffer_map_addr += vui->virtio_net_hdr_sz;
354  buffer_len -= vui->virtio_net_hdr_sz;
355  bytes_left = b0->current_length;
356  current_b0 = b0;
357  while (1)
358  {
359  if (buffer_len == 0)
360  { //Get new output
361  if (desc_table[desc_index].flags & VIRTQ_DESC_F_NEXT)
362  {
363  //Next one is chained
364  desc_index = desc_table[desc_index].next;
365  buffer_map_addr = desc_table[desc_index].addr;
366  buffer_len = desc_table[desc_index].len;
367  }
368  else if (vui->virtio_net_hdr_sz == 12) //MRG is available
369  {
370  virtio_net_hdr_mrg_rxbuf_t *hdr =
371  &cpu->tx_headers[tx_headers_len - 1];
372 
373  //Move from available to used buffer
374  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id =
375  desc_head;
376  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len =
377  desc_len;
378  vhost_user_log_dirty_ring (vui, rxvq,
379  ring[rxvq->last_used_idx &
380  rxvq->qsz_mask]);
381 
382  rxvq->last_avail_idx++;
383  rxvq->last_used_idx++;
384  hdr->num_buffers++;
385  desc_len = 0;
386 
387  if (PREDICT_FALSE
388  (rxvq->last_avail_idx == rxvq->avail->idx))
389  {
390  //Dequeue queued descriptors for this packet
391  rxvq->last_used_idx -= hdr->num_buffers - 1;
392  rxvq->last_avail_idx -= hdr->num_buffers - 1;
393  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF;
394  goto done;
395  }
396 
397  desc_table = rxvq->desc;
398  desc_head = desc_index =
399  rxvq->avail->ring[rxvq->last_avail_idx & rxvq->qsz_mask];
400  if (PREDICT_FALSE
401  (rxvq->desc[desc_head].flags & VIRTQ_DESC_F_INDIRECT))
402  {
403  //It is seriously unlikely that a driver will put indirect descriptor
404  //after non-indirect descriptor.
405  if (PREDICT_FALSE
406  (rxvq->desc[desc_head].len < sizeof (vring_desc_t)))
407  {
408  error = VHOST_USER_TX_FUNC_ERROR_INDIRECT_OVERFLOW;
409  goto done;
410  }
411  if (PREDICT_FALSE
412  (!(desc_table =
413  map_guest_mem (vui,
414  rxvq->desc[desc_index].addr,
415  &map_hint))))
416  {
417  error = VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL;
418  goto done;
419  }
420  desc_index = 0;
421  }
422  buffer_map_addr = desc_table[desc_index].addr;
423  buffer_len = desc_table[desc_index].len;
424  }
425  else
426  {
427  error = VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOMRG;
428  goto done;
429  }
430  }
431 
432  {
433  ASSERT (copy_len < VHOST_USER_COPY_ARRAY_N);
434  vhost_copy_t *cpy = &cpu->copy[copy_len];
435  copy_len++;
436  cpy->len = bytes_left;
437  cpy->len = (cpy->len > buffer_len) ? buffer_len : cpy->len;
438  cpy->dst = buffer_map_addr;
439  cpy->src = (uword) vlib_buffer_get_current (current_b0) +
440  current_b0->current_length - bytes_left;
441 
442  bytes_left -= cpy->len;
443  buffer_len -= cpy->len;
444  buffer_map_addr += cpy->len;
445  desc_len += cpy->len;
446 
447  CLIB_PREFETCH (&rxvq->desc, CLIB_CACHE_LINE_BYTES, LOAD);
448  }
449 
450  // Check if vlib buffer has more data. If not, get more or break.
451  if (PREDICT_TRUE (!bytes_left))
452  {
453  if (PREDICT_FALSE
454  (current_b0->flags & VLIB_BUFFER_NEXT_PRESENT))
455  {
456  current_b0 = vlib_get_buffer (vm, current_b0->next_buffer);
457  bytes_left = current_b0->current_length;
458  }
459  else
460  {
461  //End of packet
462  break;
463  }
464  }
465  }
466 
467  //Move from available to used ring
468  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].id = desc_head;
469  rxvq->used->ring[rxvq->last_used_idx & rxvq->qsz_mask].len = desc_len;
470  vhost_user_log_dirty_ring (vui, rxvq,
471  ring[rxvq->last_used_idx & rxvq->qsz_mask]);
472  rxvq->last_avail_idx++;
473  rxvq->last_used_idx++;
474 
475  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
476  {
477  cpu->current_trace->hdr = cpu->tx_headers[tx_headers_len - 1];
478  }
479 
480  n_left--; //At the end for error counting when 'goto done' is invoked
481 
482  /*
483  * Do the copy periodically to prevent
484  * cpu->copy array overflow and corrupt memory
485  */
487  {
488  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
489  &map_hint)))
490  {
491  vlib_error_count (vm, node->node_index,
492  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
493  }
494  copy_len = 0;
495 
496  /* give buffers back to driver */
498  rxvq->used->idx = rxvq->last_used_idx;
499  vhost_user_log_dirty_ring (vui, rxvq, idx);
500  }
501  buffers++;
502  }
503 
504 done:
505  //Do the memory copies
506  if (PREDICT_FALSE (vhost_user_tx_copy (vui, cpu->copy, copy_len,
507  &map_hint)))
508  {
509  vlib_error_count (vm, node->node_index,
510  VHOST_USER_TX_FUNC_ERROR_MMAP_FAIL, 1);
511  }
512 
514  rxvq->used->idx = rxvq->last_used_idx;
515  vhost_user_log_dirty_ring (vui, rxvq, idx);
516 
517  /*
518  * When n_left is set, error is always set to something too.
519  * In case error is due to lack of remaining buffers, we go back up and
520  * retry.
521  * The idea is that it is better to waste some time on packets
522  * that have been processed already than dropping them and get
523  * more fresh packets with a good likelyhood that they will be dropped too.
524  * This technique also gives more time to VM driver to pick-up packets.
525  * In case the traffic flows from physical to virtual interfaces, this
526  * technique will end-up leveraging the physical NIC buffer in order to
527  * absorb the VM's CPU jitter.
528  */
529  if (n_left && (error == VHOST_USER_TX_FUNC_ERROR_PKT_DROP_NOBUF) && retry)
530  {
531  retry--;
532  goto retry;
533  }
534 
535  /* interrupt (call) handling */
536  if ((rxvq->callfd_idx != ~0) &&
538  {
539  rxvq->n_since_last_int += frame->n_vectors - n_left;
540 
541  if (rxvq->n_since_last_int > vum->coalesce_frames)
542  vhost_user_send_call (vm, rxvq);
543  }
544 
545  vhost_user_vring_unlock (vui, qid);
546 
547 done3:
548  if (PREDICT_FALSE (n_left && error != VHOST_USER_TX_FUNC_ERROR_NONE))
549  {
550  vlib_error_count (vm, node->node_index, error, n_left);
554  thread_index, vui->sw_if_index, n_left);
555  }
556 
557  vlib_buffer_free (vm, vlib_frame_vector_args (frame), frame->n_vectors);
558  return frame->n_vectors;
559 }
560 
561 static __clib_unused clib_error_t *
564 {
565  vlib_main_t *vm = vnm->vlib_main;
566  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
568  vhost_user_intf_t *vui =
570  vhost_user_vring_t *txvq = &vui->vrings[VHOST_VRING_IDX_TX (qid)];
571 
572  if ((mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
574  {
575  if (txvq->kickfd_idx == ~0)
576  {
577  // We cannot support interrupt mode if the driver opts out
578  return clib_error_return (0, "Driver does not support interrupt");
579  }
581  {
582  vum->ifq_count++;
583  // Start the timer if this is the first encounter on interrupt
584  // interface/queue
585  if ((vum->ifq_count == 1) &&
586  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
590  }
591  }
592  else if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
593  {
594  if (((txvq->mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) ||
596  vum->ifq_count)
597  {
598  vum->ifq_count--;
599  // Stop the timer if there is no more interrupt interface/queue
600  if ((vum->ifq_count == 0) &&
601  (vum->coalesce_time > 0.0) && (vum->coalesce_frames > 0))
605  }
606  }
607 
608  txvq->mode = mode;
611  else if ((mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE) ||
613  txvq->used->flags = 0;
614  else
615  {
616  vu_log_err (vui, "unhandled mode %d changed for if %d queue %d", mode,
617  hw_if_index, qid);
618  return clib_error_return (0, "unsupported");
619  }
620 
621  return 0;
622 }
623 
624 static __clib_unused clib_error_t *
626  u32 flags)
627 {
628  vnet_hw_interface_t *hif = vnet_get_hw_interface (vnm, hw_if_index);
630  vhost_user_intf_t *vui =
632  u8 link_old, link_new;
633 
634  link_old = vui_is_link_up (vui);
635 
636  vui->admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
637 
638  link_new = vui_is_link_up (vui);
639 
640  if (link_old != link_new)
641  vnet_hw_interface_set_flags (vnm, vui->hw_if_index, link_new ?
643 
644  return /* no error */ 0;
645 }
646 
647 /* *INDENT-OFF* */
649  .name = "vhost-user",
650  .tx_function_n_errors = VHOST_USER_TX_FUNC_N_ERROR,
651  .tx_function_error_strings = vhost_user_tx_func_error_strings,
652  .format_device_name = format_vhost_user_interface_name,
653  .name_renumber = vhost_user_name_renumber,
654  .admin_up_down_function = vhost_user_interface_admin_up_down,
655  .rx_mode_change_function = vhost_user_interface_rx_mode_change,
656  .format_tx_trace = format_vhost_trace,
657 };
658 
659 /* *INDENT-ON* */
660 
661 /*
662  * fd.io coding-style-patch-verification: ON
663  *
664  * Local Variables:
665  * eval: (c-set-style "gnu")
666  * End:
667  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
u32 len
Definition: pci.h:200
static __clib_unused u8 * format_vhost_user_interface_name(u8 *s, va_list *args)
static __clib_unused int vhost_user_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
vmrglw vmrglh hi
static __clib_unused clib_error_t * vhost_user_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static_always_inline int vhost_user_vring_try_lock(vhost_user_intf_t *vui, u32 qid)
Try once to lock the vring.
u32 flags
Definition: vhost_user.h:115
vring_desc_t * desc
Definition: vhost_user.h:237
u32 virtio_ring_flags
The device index.
Definition: vhost_user.h:320
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
Definition: vhost_user.h:322
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
Definition: vhost_user.h:353
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
Definition: buffer_funcs.h:865
vhost_user_tx_func_error_t
#define foreach_vhost_user_tx_func_error
vnet_interface_main_t interface_main
Definition: vnet.h:56
#define PREDICT_TRUE(x)
Definition: clib.h:112
static __clib_unused char * vhost_user_tx_func_error_strings[]
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
Definition: error_funcs.h:57
#define VHOST_USER_TX_COPY_THRESHOLD
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
vring_used_elem_t ring[0]
Definition: pci.h:223
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]
Definition: vhost_user.h:335
u16 next
Definition: pci.h:202
vring_avail_t * avail
Definition: vhost_user.h:238
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 thread_index
Definition: main.h:197
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
int i
#define VHOST_USER_EVENT_START_TIMER
Definition: vhost_user.h:266
#define VRING_AVAIL_F_NO_INTERRUPT
Definition: vhost_user.h:46
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
Definition: counter.h:78
vl_api_ip4_address_t dst
Definition: ipsec_gre.api:39
u16 idx
Definition: pci.h:208
static_always_inline void vhost_user_vring_lock(vhost_user_intf_t *vui, u32 qid)
Spin until the vring is successfully locked.
u16 flags
Definition: pci.h:221
struct _vnet_device_class vnet_device_class_t
vring_used_t * used
Definition: vhost_user.h:239
vhost_trace_t * current_trace
Definition: vhost_user.h:339
unsigned char u8
Definition: types.h:56
#define vu_log_debug(dev, f,...)
Definition: vhost_user.h:48
u64 addr
Definition: pci.h:199
vnet_hw_interface_rx_mode
Definition: interface.h:52
#define static_always_inline
Definition: clib.h:99
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
Definition: buffer_funcs.h:440
static_always_inline u32 vhost_user_tx_copy(vhost_user_intf_t *vui, vhost_copy_t *cpy, u16 copy_len, u32 *map_hint)
static_always_inline void * map_guest_mem(vhost_user_intf_t *vui, uword addr, u32 *hint)
#define VHOST_VRING_IDX_TX(qid)
Definition: vhost_user.h:24
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define VRING_USED_F_NO_NOTIFY
Definition: vhost_user.h:45
#define clib_error_return(e, args...)
Definition: error.h:99
static_always_inline u8 * format_vhost_trace(u8 *s, va_list *va)
#define VNET_DEVICE_CLASS_TX_FN(devclass)
Definition: interface.h:287
unsigned int u32
Definition: types.h:88
#define clib_atomic_test_and_set(a)
Definition: atomics.h:40
VNET_DEVICE_CLASS(vhost_user_device_class)
#define VHOST_USER_COPY_ARRAY_N
Definition: vhost_user.h:327
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
vlib_main_t * vlib_main
Definition: vnet.h:80
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
#define clib_atomic_release(a)
Definition: atomics.h:41
unsigned short u16
Definition: types.h:57
#define VIRTQ_DESC_F_INDIRECT
Definition: vhost_user.h:28
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:111
vhost_user_main_t vhost_user_main
Definition: vhost_user.c:56
vnet_main_t vnet_main
Definition: misc.c:43
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:823
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
static_always_inline void vhost_user_vring_unlock(vhost_user_intf_t *vui, u32 qid)
Unlock the vring lock.
static_always_inline u8 vui_is_link_up(vhost_user_intf_t *vui)
u8 len
Definition: ip_types.api:49
#define VHOST_VRING_IDX_RX(qid)
Definition: vhost_user.h:23
vnet_device_class_t vhost_user_device_class
u32 * show_dev_instance_by_real_dev_instance
Definition: vhost_user.h:347
u16 device_index
The interface queue index (Not the virtio vring idx)
Definition: vhost_user.h:319
vhost_user_intf_t * vhost_user_interfaces
Definition: vhost_user.h:346
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:312
static __clib_unused clib_error_t * vhost_user_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_interface_rx_mode mode)
#define VHOST_USER_EVENT_STOP_TIMER
Definition: vhost_user.h:267
u16 first_desc_len
Runtime queue flags.
Definition: vhost_user.h:321
vl_api_vxlan_gbp_api_tunnel_mode_t mode
Definition: vxlan_gbp.api:44
u16 flags
Definition: pci.h:207
#define ASSERT(truth)
#define vu_log_err(dev, f,...)
Definition: vhost_user.h:61
#define VIRTQ_DESC_F_NEXT
Definition: vhost_user.h:27
static_always_inline void vhost_user_send_call(vlib_main_t *vm, vhost_user_vring_t *vq)
volatile u32 * vring_locks[VHOST_VRING_MAX_N]
Definition: vhost_user.h:296
vlib_node_registration_t vhost_user_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (vhost_user_send_interrupt_node)
Definition: vhost_user.c:53
static_always_inline void vhost_user_tx_trace(vhost_trace_t *t, vhost_user_intf_t *vui, u16 qid, vlib_buffer_t *b, vhost_user_vring_t *rxvq)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
u16 ring[0]
Definition: pci.h:209
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:140
vhost_user_vring_t vrings[VHOST_VRING_MAX_N]
Definition: vhost_user.h:295
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:504
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
static_always_inline void vhost_user_log_dirty_pages_2(vhost_user_intf_t *vui, u64 addr, u64 len, u8 is_host_address)
#define vhost_user_log_dirty_ring(vui, vq, member)
u16 idx
Definition: pci.h:222
u16 flags
Definition: pci.h:201
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:115
virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE]
Definition: vhost_user.h:334
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:486
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85