FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
devices.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 #ifndef included_vnet_vnet_device_h
17 #define included_vnet_vnet_device_h
18 
19 #include <vnet/unix/pcap.h>
20 #include <vnet/l3_types.h>
21 
22 typedef enum
23 {
32 
33 #define VNET_DEVICE_INPUT_NEXT_NODES { \
34  [VNET_DEVICE_INPUT_NEXT_DROP] = "error-drop", \
35  [VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT] = "ethernet-input", \
36  [VNET_DEVICE_INPUT_NEXT_IP4_NCS_INPUT] = "ip4-input-no-checksum", \
37  [VNET_DEVICE_INPUT_NEXT_IP4_INPUT] = "ip4-input", \
38  [VNET_DEVICE_INPUT_NEXT_IP6_INPUT] = "ip6-input", \
39  [VNET_DEVICE_INPUT_NEXT_MPLS_INPUT] = "mpls-input", \
40 }
41 
42 typedef struct
43 {
44  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
45 
46  /* total input packet counter */
49 
50 typedef struct
51 {
57 
58 typedef struct
59 {
66 
67 typedef struct
68 {
72 
75 extern const u32 device_input_next_node_advance[];
76 extern const u32 device_input_next_node_flags[];
77 
78 static inline void
80  u32 node_index)
81 {
82  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
83  hw->input_node_index = node_index;
84 }
85 
86 void vnet_hw_interface_assign_rx_thread (vnet_main_t * vnm, u32 hw_if_index,
87  u16 queue_id, uword thread_index);
89  u16 queue_id);
90 int vnet_hw_interface_set_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
91  u16 queue_id,
93 int vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
94  u16 queue_id,
96 
97 static inline u64
99 {
101  u64 sum = 0;
103 
104  vec_foreach (pwd, vdm->workers) sum += pwd->aggregate_rx_packets;
105 
106  return sum;
107 }
108 
109 static inline void
111 {
114 
115  pwd = vec_elt_at_index (vdm->workers, thread_index);
116  pwd->aggregate_rx_packets += count;
117 }
118 
121 {
122  vnet_device_input_runtime_t *rt = (void *) node->runtime_data;
123  return rt->devices_and_queues;
124 }
125 
128  u16 queue_id)
129 {
130  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
132  return hw->input_node_thread_index_by_queue[queue_id];
133 }
134 
137  u16 queue_id)
138 {
139  vlib_main_t *vm;
143  uword idx;
144 
145  hw = vnet_get_hw_interface (vnm, hw_if_index);
146  idx = vnet_get_device_input_thread_index (vnm, hw_if_index, queue_id);
147  vm = vlib_mains[idx];
149  idx = hw->dq_runtime_index_by_queue[queue_id];
150  dq = vec_elt_at_index (rt->devices_and_queues, idx);
151  dq->interrupt_pending = 1;
152 
154 }
155 
156 #define foreach_device_and_queue(var,vec) \
157  for (var = (vec); var < vec_end (vec); var++) \
158  if ((var->mode == VNET_HW_INTERFACE_RX_MODE_POLLING) \
159  || clib_smp_swap (&((var)->interrupt_pending), 0))
160 
161 
162 #endif /* included_vnet_vnet_device_h */
163 
164 /*
165  * fd.io coding-style-patch-verification: ON
166  *
167  * Local Variables:
168  * eval: (c-set-style "gnu")
169  * End:
170  */
static void vnet_device_increment_rx_packets(u32 thread_index, u64 count)
Definition: devices.h:110
vlib_node_registration_t device_input_node
(constructor) VLIB_REGISTER_NODE (device_input_node)
Definition: devices.c:32
vnet_device_and_queue_t * devices_and_queues
Definition: devices.h:69
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:63
uword first_worker_thread_index
Definition: devices.h:53
u8 runtime_data[0]
Function dependent node-runtime data.
Definition: node.h:500
static u64 vnet_get_aggregate_rx_packets(void)
Definition: devices.h:98
unsigned long u64
Definition: types.h:89
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:196
PCAP utility definitions.
u32 * input_node_thread_index_by_queue
Definition: interface.h:560
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
vnet_device_per_worker_data_t * workers
Definition: devices.h:52
uword next_worker_thread_index
Definition: devices.h:55
static_always_inline vnet_device_and_queue_t * vnet_get_device_and_queue(vlib_main_t *vm, vlib_node_runtime_t *node)
Definition: devices.h:120
int vnet_hw_interface_set_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode mode)
Definition: devices.c:252
uword * dq_runtime_index_by_queue
Definition: interface.h:567
vlib_main_t ** vlib_mains
Definition: buffer.c:303
uword last_worker_thread_index
Definition: devices.h:54
vlib_node_state_t enabled_node_state
Definition: devices.h:70
vnet_hw_interface_rx_mode
Definition: interface.h:51
#define static_always_inline
Definition: clib.h:93
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:136
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
unsigned int u32
Definition: types.h:88
static_always_inline uword vnet_get_device_input_thread_index(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:127
unsigned short u16
Definition: types.h:57
vnet_device_input_next_t
Definition: devices.h:22
static void * vlib_node_get_runtime_data(vlib_main_t *vm, u32 node_index)
Get node runtime private data by node index.
Definition: node_funcs.h:110
const u32 device_input_next_node_flags[]
Definition: devices.c:57
int vnet_hw_interface_get_rx_mode(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, vnet_hw_interface_rx_mode *mode)
Definition: devices.c:312
vnet_hw_interface_rx_mode mode
Definition: devices.h:63
vlib_main_t * vm
Definition: buffer.c:294
#define ASSERT(truth)
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:138
size_t count
Definition: vapi.c:46
struct _vlib_node_registration vlib_node_registration_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
vnet_device_main_t vnet_device_main
Definition: devices.c:22
vlib_node_state_t
Definition: node.h:243
#define vec_foreach(var, vec)
Vector iterator.
const u32 device_input_next_node_advance[]
Definition: devices.c:47
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:187