summaryrefslogtreecommitdiffstats
path: root/src/vnet/interface/rx_queue.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2020-11-24 18:15:07 +0100
committerDave Barach <openvpp@barachs.net>2021-01-29 16:33:35 +0000
commit64177a3ed84125fac21758fc60e62548c5cbdfaa (patch)
tree46a9f3f8ef345378f89e3d496fec0fdd366856c9 /src/vnet/interface/rx_queue.c
parent150bf5ac6b067a9051bcce7f6126bbededbc4c1b (diff)
interface: fix interface name overflow in logs
hi->name is a non-NULL-terminated vector. Type: fix Change-Id: I1a9f128f24f137b43cb47169677cc4288043fbd7 Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/interface/rx_queue.c')
-rw-r--r--src/vnet/interface/rx_queue.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/vnet/interface/rx_queue.c b/src/vnet/interface/rx_queue.c
index c0492dd555e..9c73351184d 100644
--- a/src/vnet/interface/rx_queue.c
+++ b/src/vnet/interface/rx_queue.c
@@ -89,7 +89,7 @@ vnet_hw_if_register_rx_queue (vnet_main_t *vnm, u32 hw_if_index, u32 queue_id,
rxq->mode = VNET_HW_IF_RX_MODE_POLLING;
rxq->file_index = ~0;
- log_debug ("register: interface %s queue-id %u thread %u", hi->name,
+ log_debug ("register: interface %v queue-id %u thread %u", hi->name,
queue_id, thread_index);
return queue_index;
@@ -114,7 +114,7 @@ vnet_hw_if_unregister_rx_queue (vnet_main_t *vnm, u32 queue_index)
break;
}
- log_debug ("unregister: interface %s queue-id %u", hi->name, rxq->queue_id);
+ log_debug ("unregister: interface %v queue-id %u", hi->name, rxq->queue_id);
pool_put_index (im->hw_if_rx_queues, queue_index);
}
@@ -123,7 +123,7 @@ vnet_hw_if_unregister_all_rx_queues (vnet_main_t *vnm, u32 hw_if_index)
{
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
- log_debug ("unregister_all: interface %s", hi->name);
+ log_debug ("unregister_all: interface %v", hi->name);
for (int i = 0; i < vec_len (hi->rx_queue_indices); i++)
vnet_hw_if_unregister_rx_queue (vnm, hi->rx_queue_indices[i]);
@@ -140,7 +140,7 @@ vnet_hw_if_set_rx_queue_file_index (vnet_main_t *vnm, u32 queue_index,
rxq->file_index = file_index;
clib_file_set_polling_thread (&file_main, file_index, rxq->thread_index);
- log_debug ("set_file_index: interface %s queue-id %u file-index %u",
+ log_debug ("set_file_index: interface %v queue-id %u file-index %u",
hi->name, rxq->queue_id, file_index);
}
@@ -150,7 +150,7 @@ vnet_hw_if_set_input_node (vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
vlib_main_t *vm = vlib_get_main ();
vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
hi->input_node_index = node_index;
- log_debug ("set_input_node: node %U for interface %s", format_vlib_node_name,
+ log_debug ("set_input_node: node %U for interface %v", format_vlib_node_name,
vm, node_index, hi->name);
}
@@ -169,7 +169,7 @@ vnet_hw_if_set_rx_queue_mode (vnet_main_t *vnm, u32 queue_index,
if (rxq->mode == mode)
{
- log_debug ("set_rx_queue_mode: interface %s queue-id %u mode "
+ log_debug ("set_rx_queue_mode: interface %v queue-id %u mode "
"unchanged (%U)",
hi->name, rxq->queue_id, format_vnet_hw_if_rx_mode, mode);
return 0;
@@ -181,7 +181,7 @@ vnet_hw_if_set_rx_queue_mode (vnet_main_t *vnm, u32 queue_index,
rxq->queue_id, mode);
if (err)
{
- log_err ("setting rx mode on the interface %s queue-id %u failed.\n"
+ log_err ("setting rx mode on the interface %v queue-id %u failed.\n"
" %U",
hi->name, rxq->queue_id, format_clib_error, err);
clib_error_free (err);
@@ -190,7 +190,7 @@ vnet_hw_if_set_rx_queue_mode (vnet_main_t *vnm, u32 queue_index,
}
rxq->mode = mode;
- log_debug ("set_rx_queue_mode: interface %s queue-id %u mode set to %U",
+ log_debug ("set_rx_queue_mode: interface %v queue-id %u mode set to %U",
hi->name, rxq->queue_id, format_vnet_hw_if_rx_mode, mode);
return 0;
}
@@ -214,7 +214,7 @@ vnet_hw_if_set_rx_queue_thread_index (vnet_main_t *vnm, u32 queue_index,
if (rxq->file_index != ~0)
clib_file_set_polling_thread (&file_main, rxq->file_index, thread_index);
- log_debug ("set_rx_queue_thread_index: interface %s queue-id %u "
+ log_debug ("set_rx_queue_thread_index: interface %v queue-id %u "
"thread-index set to %u",
hi->name, rxq->queue_id, thread_index);
}
.highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 *------------------------------------------------------------------
 * Copyright (c) 2020 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#ifndef _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_
#define _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_

#define VIRTIO_BUFFERING_DEFAULT_SIZE 1024
#define VIRTIO_BUFFERING_TIMEOUT 1e-5

typedef struct
{
  f64 timeout_ts;
  u32 *buffers;
  u32 node_index;
  u16 size;
  u16 free_size;
  u16 front;
  u16 back;
  u8 is_enable;
} virtio_vring_buffering_t;

static_always_inline clib_error_t *
virtio_vring_buffering_init (virtio_vring_buffering_t ** buffering,
			     u32 node_index, u16 size)
{
  if (*buffering)
    return clib_error_return (0, "buffering: already initialized");

  if (!is_pow2 (size))
    return clib_error_return (0, "buffering: size must be power of 2");

  if (size > 32768)
    return clib_error_return (0, "buffering: size must be 32768 or lower");

  if (size == 0)
    size = VIRTIO_BUFFERING_DEFAULT_SIZE;

  virtio_vring_buffering_t *b_temp = 0;
  b_temp =
    (virtio_vring_buffering_t *)
    clib_mem_alloc (sizeof (virtio_vring_buffering_t));
  if (!b_temp)
    return clib_error_return (0, "buffering: memory allocation failed");

  clib_memset (b_temp, 0, sizeof (virtio_vring_buffering_t));

  b_temp->node_index = node_index;
  b_temp->free_size = size;
  b_temp->size = size;

  vec_validate_aligned (b_temp->buffers, size, CLIB_CACHE_LINE_BYTES);
  b_temp->is_enable = 1;

  *buffering = b_temp;
  return 0;
}

static_always_inline void
virtio_vring_buffering_buffers_free (vlib_main_t * vm,
				     virtio_vring_buffering_t * buffering)
{
  u16 n_buffers = buffering->size - buffering->free_size;
  if (n_buffers)
    {
      vlib_buffer_free_from_ring (vm, buffering->buffers, buffering->front,
				  buffering->size, n_buffers);
      buffering->free_size += n_buffers;
    }
}

static_always_inline void
virtio_vring_buffering_free (vlib_main_t * vm,
			     virtio_vring_buffering_t * buffering)
{
  if (buffering)
    {
      virtio_vring_buffering_buffers_free (vm, buffering);
      vec_free (buffering->buffers);
      clib_mem_free (buffering);
    }
}

static_always_inline u8
virtio_vring_buffering_is_enable (virtio_vring_buffering_t * buffering)
{
  if (buffering)
    return buffering->is_enable;

  return 0;
}

static_always_inline void
virtio_vring_buffering_set_is_enable (virtio_vring_buffering_t * buffering,
				      u8 is_enable)
{
  if (buffering)
    buffering->is_enable = is_enable;
}

static_always_inline void
virtio_vring_buffering_set_timeout (vlib_main_t * vm,
				    virtio_vring_buffering_t * buffering,
				    f64 timeout_expire)
{
  if (buffering)
    buffering->timeout_ts = vlib_time_now (vm) + timeout_expire;
}

static_always_inline u8
virtio_vring_buffering_is_timeout (vlib_main_t * vm,
				   virtio_vring_buffering_t * buffering)
{
  if (buffering && (buffering->timeout_ts < vlib_time_now (vm)))
    return 1;
  return 0;
}

static_always_inline u8
virtio_vring_buffering_is_empty (virtio_vring_buffering_t * buffering)
{
  if (buffering->size == buffering->free_size)
    return 1;
  return 0;
}

static_always_inline u8
virtio_vring_buffering_is_full (virtio_vring_buffering_t * buffering)
{
  if (buffering->free_size == 0)
    return 1;
  return 0;
}

static_always_inline u16
virtio_vring_n_buffers (virtio_vring_buffering_t * buffering)
{
  return (buffering->size - buffering->free_size);
}

static_always_inline u16
virtio_vring_buffering_store_packets (virtio_vring_buffering_t * buffering,
				      u32 * bi, u16 n_store)
{
  u16 mask, n_s = 0, i = 0;

  if (!virtio_vring_buffering_is_enable (buffering)
      || virtio_vring_buffering_is_full (buffering))
    return 0;

  mask = buffering->size - 1;
  n_s = clib_min (n_store, buffering->free_size);

  while (i < n_s)
    {
      buffering->buffers[buffering->back] = bi[i];
      buffering->back = (buffering->back + 1) & mask;
      buffering->free_size--;
      i++;
    }
  return n_s;
}

static_always_inline u32
virtio_vring_buffering_read_from_front (virtio_vring_buffering_t * buffering)
{
  u32 bi = ~0;
  u16 mask = buffering->size - 1;
  if (virtio_vring_buffering_is_empty (buffering))
    return bi;

  bi = buffering->buffers[buffering->front];
  buffering->buffers[buffering->front] = ~0;
  buffering->front = (buffering->front + 1) & mask;
  buffering->free_size++;
  return bi;
}

static_always_inline u32
virtio_vring_buffering_read_from_back (virtio_vring_buffering_t * buffering)
{
  u32 bi = ~0;
  u16 mask = buffering->size - 1;
  if (virtio_vring_buffering_is_empty (buffering))
    return bi;

  buffering->back = (buffering->back - 1) & mask;
  bi = buffering->buffers[buffering->back];
  buffering->buffers[buffering->back] = ~0;
  buffering->free_size++;
  return bi;
}

static_always_inline void
virtio_vring_buffering_schedule_node_on_dispatcher (vlib_main_t * vm,
						    virtio_vring_buffering_t *
						    buffering)
{
  if (buffering && virtio_vring_buffering_is_timeout (vm, buffering)
      && virtio_vring_n_buffers (buffering))
    {
      vlib_frame_t *f = vlib_get_frame_to_node (vm, buffering->node_index);
      u32 *f_to = vlib_frame_vector_args (f);
      f_to[f->n_vectors] = virtio_vring_buffering_read_from_back (buffering);
      f->n_vectors++;
      vlib_put_frame_to_node (vm, buffering->node_index, f);
      virtio_vring_buffering_set_timeout (vm, buffering,
					  VIRTIO_BUFFERING_TIMEOUT);
    }
}

static_always_inline u8 *
virtio_vring_buffering_format (u8 * s, va_list * args)
{
  virtio_vring_buffering_t *buffering =
    va_arg (*args, virtio_vring_buffering_t *);
  u32 indent = format_get_indent (s);

  if (!buffering)
    return s;

  indent += 2;

  if (buffering->is_enable)
    s = format (s, "packet-buffering: enable\n");
  else
    s = format (s, "packet-buffering: disable\n");
  s =
    format (s,
	    "%Usize %u n_buffers %u front %u back %u",
	    format_white_space, indent, buffering->size,
	    virtio_vring_n_buffers (buffering), buffering->front,
	    buffering->back);

  return s;
}

#endif /* _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */