FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
tx_queue.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright(c) 2021 Cisco Systems, Inc.
3  */
4 
5 #include <vnet/vnet.h>
6 #include <vnet/devices/devices.h>
8 #include <vlib/unix/unix.h>
9 
10 VLIB_REGISTER_LOG_CLASS (if_txq_log, static) = {
11  .class_name = "interface",
12  .subclass_name = "tx-queue",
13 };
14 
15 #define log_debug(fmt, ...) vlib_log_debug (if_txq_log.class, fmt, __VA_ARGS__)
16 #define log_err(fmt, ...) vlib_log_err (if_txq_log.class, fmt, __VA_ARGS__)
17 
18 static u64
19 tx_queue_key (u32 hw_if_index, u32 queue_id)
20 {
21  return ((u64) hw_if_index << 32) | queue_id;
22 }
23 
24 u32
26  u32 queue_id)
27 {
29  u64 key = tx_queue_key (hw_if_index, queue_id);
31  return p ? p[0] : ~0;
32 }
33 
34 u32
35 vnet_hw_if_register_tx_queue (vnet_main_t *vnm, u32 hw_if_index, u32 queue_id)
36 {
38  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
40  u64 key = tx_queue_key (hw_if_index, queue_id);
41  u32 queue_index;
42 
44  clib_panic ("Trying to register already registered queue id (%u) in the "
45  "interface %v\n",
46  queue_id, hi->name);
47 
49  queue_index = txq - im->hw_if_tx_queues;
50  vec_add1 (hi->tx_queue_indices, queue_index);
52  queue_index);
53  txq->hw_if_index = hw_if_index;
54  txq->queue_id = queue_id;
55 
56  log_debug ("register: interface %v queue-id %u", hi->name, queue_id);
57 
58  return queue_index;
59 }
60 
61 void
63 {
66  txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
68  u64 key;
69 
70  key = tx_queue_key (txq->hw_if_index, txq->queue_id);
72 
73  for (int i = 0; i < vec_len (hi->tx_queue_indices); i++)
74  if (hi->tx_queue_indices[i] == queue_index)
75  {
76  vec_del1 (hi->tx_queue_indices, i);
77  break;
78  }
79 
80  log_debug ("unregister: interface %v queue-id %u", hi->name, txq->queue_id);
82  pool_put_index (im->hw_if_tx_queues, queue_index);
83 }
84 
85 void
87 {
88  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
91  u64 key;
92 
93  log_debug ("unregister_all: interface %v", hi->name);
94 
95  for (int i = 0; i < vec_len (hi->tx_queue_indices); i++)
96  {
97  txq = vnet_hw_if_get_tx_queue (vnm, hi->tx_queue_indices[i]);
98  key = tx_queue_key (txq->hw_if_index, txq->queue_id);
100 
101  clib_bitmap_free (txq->threads);
102  pool_put_index (im->hw_if_tx_queues, hi->tx_queue_indices[i]);
103  }
104 
105  vec_free (hi->tx_queue_indices);
106 }
107 
108 void
111 {
112  vnet_hw_if_tx_queue_t *txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
114  txq->threads = clib_bitmap_set (txq->threads, thread_index, 1);
115  log_debug ("assign_thread: interface %v queue-id %u thread %u", hi->name,
116  txq->queue_id, thread_index);
117 }
118 
119 void
122 {
123  vnet_hw_if_tx_queue_t *txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
125  txq->threads = clib_bitmap_set (txq->threads, thread_index, 0);
126  log_debug ("unassign_thread: interface %v queue-id %u thread %u", hi->name,
127  txq->queue_id, thread_index);
128 }
im
vnet_interface_main_t * im
Definition: interface_output.c:395
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
vnet_hw_if_unregister_all_tx_queues
void vnet_hw_if_unregister_all_tx_queues(vnet_main_t *vnm, u32 hw_if_index)
Definition: tx_queue.c:86
vnet_hw_if_get_tx_queue_index_by_id
u32 vnet_hw_if_get_tx_queue_index_by_id(vnet_main_t *vnm, u32 hw_if_index, u32 queue_id)
Definition: tx_queue.c:25
vnet_interface_main_t
Definition: interface.h:989
vnet_hw_if_tx_queue_assign_thread
void vnet_hw_if_tx_queue_assign_thread(vnet_main_t *vnm, u32 queue_index, u32 thread_index)
Definition: tx_queue.c:109
vnet_hw_if_unregister_tx_queue
void vnet_hw_if_unregister_tx_queue(vnet_main_t *vnm, u32 queue_index)
Definition: tx_queue.c:62
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
vnet_hw_if_tx_queue_unassign_thread
void vnet_hw_if_tx_queue_unassign_thread(vnet_main_t *vnm, u32 queue_index, u32 thread_index)
Definition: tx_queue.c:120
pool_put_index
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:337
key
typedef key
Definition: ipsec_types.api:88
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
clib_bitmap_free
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
uword
u64 uword
Definition: types.h:112
hash_unset_mem_free
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
vnet_hw_if_tx_queue_t::queue_id
u32 queue_id
Definition: interface.h:609
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
vnet_hw_if_get_tx_queue
static_always_inline vnet_hw_if_tx_queue_t * vnet_hw_if_get_tx_queue(vnet_main_t *vnm, u32 queue_index)
Definition: tx_queue_funcs.h:23
hash_set_mem_alloc
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279
clib_bitmap_set
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap.
Definition: bitmap.h:167
vnet_interface_main_t::txq_index_by_hw_if_index_and_queue_id
uword * txq_index_by_hw_if_index_and_queue_id
Definition: interface.h:1000
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
VLIB_REGISTER_LOG_CLASS
VLIB_REGISTER_LOG_CLASS(if_txq_log, static)
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
u64
unsigned long u64
Definition: types.h:89
u32
unsigned int u32
Definition: types.h:88
vnet_hw_if_tx_queue_t
Definition: interface.h:602
vnet_interface_main_t::hw_if_tx_queues
vnet_hw_if_tx_queue_t * hw_if_tx_queues
Definition: interface.h:999
tx_queue_key
static u64 tx_queue_key(u32 hw_if_index, u32 queue_id)
Definition: tx_queue.c:19
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
unix.h
log_debug
#define log_debug(fmt,...)
Definition: tx_queue.c:15
vnet_hw_if_tx_queue_t::threads
clib_bitmap_t * threads
Definition: interface.h:612
vnet_hw_if_tx_queue_t::hw_if_index
u32 hw_if_index
Definition: interface.h:606
devices.h
tx_queue_funcs.h
vnet.h
clib_panic
#define clib_panic(format, args...)
Definition: error.h:72
vnet_hw_if_register_tx_queue
u32 vnet_hw_if_register_tx_queue(vnet_main_t *vnm, u32 hw_if_index, u32 queue_id)
Definition: tx_queue.c:35
vec_del1
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:896
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81