aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/vxlan-gbp/encap.c
diff options
context:
space:
mode:
authorZhiyong Yang <zhiyong.yang@intel.com>2019-05-16 05:24:17 -0400
committerDamjan Marion <dmarion@me.com>2019-05-29 15:02:19 +0000
commit257573d86bae518736f76ee59066d4200cd55bd2 (patch)
tree7a8e40bfa872188148f55db6c97368d7a2b8100c /src/vnet/vxlan-gbp/encap.c
parent913f4c9a8824c1bd167d3a103aec902a14c08697 (diff)
vxlan-gbp: prefetch encap header memory area
This patch helps save 4.1 clocks/pkt from 62.9 to 58.8 clocks/pkt on Skylake. Change-Id: I749a88a8fa6c78243441a89d6afcd04f106af3da Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
Diffstat (limited to 'src/vnet/vxlan-gbp/encap.c')
-rw-r--r--src/vnet/vxlan-gbp/encap.c136
1 files changed, 70 insertions, 66 deletions
diff --git a/src/vnet/vxlan-gbp/encap.c b/src/vnet/vxlan-gbp/encap.c
index 85d6f7787c4..9766d1c3ca1 100644
--- a/src/vnet/vxlan-gbp/encap.c
+++ b/src/vnet/vxlan-gbp/encap.c
@@ -87,9 +87,11 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
u32 next0 = 0, next1 = 0;
vxlan_gbp_tunnel_t *t0 = NULL, *t1 = NULL;
index_t dpoi_idx0 = INDEX_INVALID, dpoi_idx1 = INDEX_INVALID;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
from = vlib_frame_vector_args (from_frame);
n_left_from = from_frame->n_vectors;
+ vlib_get_buffers (vm, from, bufs, n_left_from);
next_index = node->cached_next_index;
@@ -121,8 +123,10 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
vlib_prefetch_buffer_header (p2, LOAD);
vlib_prefetch_buffer_header (p3, LOAD);
- CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
- CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[2]->data - CLIB_CACHE_LINE_BYTES,
+ 2 * CLIB_CACHE_LINE_BYTES, LOAD);
+ CLIB_PREFETCH (b[3]->data - CLIB_CACHE_LINE_BYTES,
+ 2 * CLIB_CACHE_LINE_BYTES, LOAD);
}
u32 bi0 = to_next[0] = from[0];
@@ -132,15 +136,13 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
n_left_to_next -= 2;
n_left_from -= 2;
- vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
- vlib_buffer_t *b1 = vlib_get_buffer (vm, bi1);
- u32 flow_hash0 = vnet_l2_compute_flow_hash (b0);
- u32 flow_hash1 = vnet_l2_compute_flow_hash (b1);
+ u32 flow_hash0 = vnet_l2_compute_flow_hash (b[0]);
+ u32 flow_hash1 = vnet_l2_compute_flow_hash (b[1]);
/* Get next node index and adj index from tunnel next_dpo */
- if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX])
+ if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX])
{
- sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
+ sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
vnet_hw_interface_t *hi0 =
vnet_get_sup_hw_interface (vnm, sw_if_index0);
t0 = &vxm->tunnels[hi0->dev_instance];
@@ -150,9 +152,9 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
}
/* Get next node index and adj index from tunnel next_dpo */
- if (sw_if_index1 != vnet_buffer (b1)->sw_if_index[VLIB_TX])
+ if (sw_if_index1 != vnet_buffer (b[1])->sw_if_index[VLIB_TX])
{
- if (sw_if_index0 == vnet_buffer (b1)->sw_if_index[VLIB_TX])
+ if (sw_if_index0 == vnet_buffer (b[1])->sw_if_index[VLIB_TX])
{
sw_if_index1 = sw_if_index0;
t1 = t0;
@@ -161,7 +163,7 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
}
else
{
- sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_TX];
+ sw_if_index1 = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
vnet_hw_interface_t *hi1 =
vnet_get_sup_hw_interface (vnm, sw_if_index1);
t1 = &vxm->tunnels[hi1->dev_instance];
@@ -171,25 +173,25 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
}
}
- vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpoi_idx0;
- vnet_buffer (b1)->ip.adj_index[VLIB_TX] = dpoi_idx1;
+ vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpoi_idx0;
+ vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = dpoi_idx1;
ASSERT (t0->rewrite_header.data_bytes == underlay_hdr_len);
ASSERT (t1->rewrite_header.data_bytes == underlay_hdr_len);
- vnet_rewrite_two_headers (*t0, *t1, vlib_buffer_get_current (b0),
- vlib_buffer_get_current (b1),
+ vnet_rewrite_two_headers (*t0, *t1, vlib_buffer_get_current (b[0]),
+ vlib_buffer_get_current (b[1]),
underlay_hdr_len);
- vlib_buffer_advance (b0, -underlay_hdr_len);
- vlib_buffer_advance (b1, -underlay_hdr_len);
+ vlib_buffer_advance (b[0], -underlay_hdr_len);
+ vlib_buffer_advance (b[1], -underlay_hdr_len);
- u32 len0 = vlib_buffer_length_in_chain (vm, b0);
- u32 len1 = vlib_buffer_length_in_chain (vm, b1);
+ u32 len0 = vlib_buffer_length_in_chain (vm, b[0]);
+ u32 len1 = vlib_buffer_length_in_chain (vm, b[1]);
u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len);
u16 payload_l1 = clib_host_to_net_u16 (len1 - l3_len);
- void *underlay0 = vlib_buffer_get_current (b0);
- void *underlay1 = vlib_buffer_get_current (b1);
+ void *underlay0 = vlib_buffer_get_current (b[0]);
+ void *underlay1 = vlib_buffer_get_current (b[1]);
ip4_header_t *ip4_0, *ip4_1;
qos_bits_t ip4_0_tos = 0, ip4_1_tos = 0;
@@ -208,14 +210,14 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
ip4_0->length = clib_host_to_net_u16 (len0);
ip4_1->length = clib_host_to_net_u16 (len1);
- if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_QOS_DATA_VALID))
+ if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_QOS_DATA_VALID))
{
- ip4_0_tos = vnet_buffer2 (b0)->qos.bits;
+ ip4_0_tos = vnet_buffer2 (b[0])->qos.bits;
ip4_0->tos = ip4_0_tos;
}
- if (PREDICT_FALSE (b1->flags & VNET_BUFFER_F_QOS_DATA_VALID))
+ if (PREDICT_FALSE (b[1]->flags & VNET_BUFFER_F_QOS_DATA_VALID))
{
- ip4_1_tos = vnet_buffer2 (b1)->qos.bits;
+ ip4_1_tos = vnet_buffer2 (b[1])->qos.bits;
ip4_1->tos = ip4_1_tos;
}
@@ -252,21 +254,21 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
udp1->src_port = flow_hash1;
/* set source class and gpflags */
- vxlan_gbp0->gpflags = vnet_buffer2 (b0)->gbp.flags;
- vxlan_gbp1->gpflags = vnet_buffer2 (b1)->gbp.flags;
+ vxlan_gbp0->gpflags = vnet_buffer2 (b[0])->gbp.flags;
+ vxlan_gbp1->gpflags = vnet_buffer2 (b[1])->gbp.flags;
vxlan_gbp0->sclass =
- clib_host_to_net_u16 (vnet_buffer2 (b0)->gbp.sclass);
+ clib_host_to_net_u16 (vnet_buffer2 (b[0])->gbp.sclass);
vxlan_gbp1->sclass =
- clib_host_to_net_u16 (vnet_buffer2 (b1)->gbp.sclass);
+ clib_host_to_net_u16 (vnet_buffer2 (b[1])->gbp.sclass);
if (csum_offload)
{
- b0->flags |= csum_flags;
- vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data;
- vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data;
- b1->flags |= csum_flags;
- vnet_buffer (b1)->l3_hdr_offset = l3_1 - b1->data;
- vnet_buffer (b1)->l4_hdr_offset = (u8 *) udp1 - b1->data;
+ b[0]->flags |= csum_flags;
+ vnet_buffer (b[0])->l3_hdr_offset = l3_0 - b[0]->data;
+ vnet_buffer (b[0])->l4_hdr_offset = (u8 *) udp0 - b[0]->data;
+ b[1]->flags |= csum_flags;
+ vnet_buffer (b[1])->l3_hdr_offset = l3_1 - b[1]->data;
+ vnet_buffer (b[1])->l4_hdr_offset = (u8 *) udp1 - b[1]->data;
}
/* IPv4 UDP checksum only if checksum offload is used */
else if (is_ip4)
@@ -296,12 +298,12 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
int bogus = 0;
udp0->checksum = ip6_tcp_udp_icmp_compute_checksum
- (vm, b0, ip6_0, &bogus);
+ (vm, b[0], ip6_0, &bogus);
ASSERT (bogus == 0);
if (udp0->checksum == 0)
udp0->checksum = 0xffff;
udp1->checksum = ip6_tcp_udp_icmp_compute_checksum
- (vm, b1, ip6_1, &bogus);
+ (vm, b[1], ip6_1, &bogus);
ASSERT (bogus == 0);
if (udp1->checksum == 0)
udp1->checksum = 0xffff;
@@ -313,25 +315,26 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
sw_if_index1, 1, len1);
pkts_encapsulated += 2;
- if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
{
vxlan_gbp_encap_trace_t *tr =
- vlib_add_trace (vm, node, b0, sizeof (*tr));
+ vlib_add_trace (vm, node, b[0], sizeof (*tr));
tr->tunnel_index = t0 - vxm->tunnels;
tr->vni = t0->vni;
- tr->sclass = vnet_buffer2 (b0)->gbp.sclass;
- tr->flags = vnet_buffer2 (b0)->gbp.flags;
+ tr->sclass = vnet_buffer2 (b[0])->gbp.sclass;
+ tr->flags = vnet_buffer2 (b[0])->gbp.flags;
}
- if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED))
{
vxlan_gbp_encap_trace_t *tr =
- vlib_add_trace (vm, node, b1, sizeof (*tr));
+ vlib_add_trace (vm, node, b[1], sizeof (*tr));
tr->tunnel_index = t1 - vxm->tunnels;
tr->vni = t1->vni;
- tr->sclass = vnet_buffer2 (b1)->gbp.sclass;
- tr->flags = vnet_buffer2 (b1)->gbp.flags;
+ tr->sclass = vnet_buffer2 (b[1])->gbp.sclass;
+ tr->flags = vnet_buffer2 (b[1])->gbp.flags;
}
+ b += 2;
vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
to_next, n_left_to_next,
@@ -346,13 +349,12 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
n_left_from -= 1;
n_left_to_next -= 1;
- vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0);
- u32 flow_hash0 = vnet_l2_compute_flow_hash (b0);
+ u32 flow_hash0 = vnet_l2_compute_flow_hash (b[0]);
/* Get next node index and adj index from tunnel next_dpo */
- if (sw_if_index0 != vnet_buffer (b0)->sw_if_index[VLIB_TX])
+ if (sw_if_index0 != vnet_buffer (b[0])->sw_if_index[VLIB_TX])
{
- sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
+ sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
vnet_hw_interface_t *hi0 =
vnet_get_sup_hw_interface (vnm, sw_if_index0);
t0 = &vxm->tunnels[hi0->dev_instance];
@@ -360,16 +362,16 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
next0 = t0->next_dpo.dpoi_next_node;
dpoi_idx0 = t0->next_dpo.dpoi_index;
}
- vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpoi_idx0;
+ vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = dpoi_idx0;
ASSERT (t0->rewrite_header.data_bytes == underlay_hdr_len);
- vnet_rewrite_one_header (*t0, vlib_buffer_get_current (b0),
+ vnet_rewrite_one_header (*t0, vlib_buffer_get_current (b[0]),
underlay_hdr_len);
- vlib_buffer_advance (b0, -underlay_hdr_len);
- void *underlay0 = vlib_buffer_get_current (b0);
+ vlib_buffer_advance (b[0], -underlay_hdr_len);
+ void *underlay0 = vlib_buffer_get_current (b[0]);
- u32 len0 = vlib_buffer_length_in_chain (vm, b0);
+ u32 len0 = vlib_buffer_length_in_chain (vm, b[0]);
u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len);
vxlan_gbp_header_t *vxlan_gbp0;
@@ -386,9 +388,9 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
ip4_0 = &hdr->ip4;
ip4_0->length = clib_host_to_net_u16 (len0);
- if (PREDICT_FALSE (b0->flags & VNET_BUFFER_F_QOS_DATA_VALID))
+ if (PREDICT_FALSE (b[0]->flags & VNET_BUFFER_F_QOS_DATA_VALID))
{
- ip4_0_tos = vnet_buffer2 (b0)->qos.bits;
+ ip4_0_tos = vnet_buffer2 (b[0])->qos.bits;
ip4_0->tos = ip4_0_tos;
}
@@ -414,15 +416,15 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
udp0->src_port = flow_hash0;
/* set source class and gpflags */
- vxlan_gbp0->gpflags = vnet_buffer2 (b0)->gbp.flags;
+ vxlan_gbp0->gpflags = vnet_buffer2 (b[0])->gbp.flags;
vxlan_gbp0->sclass =
- clib_host_to_net_u16 (vnet_buffer2 (b0)->gbp.sclass);
+ clib_host_to_net_u16 (vnet_buffer2 (b[0])->gbp.sclass);
if (csum_offload)
{
- b0->flags |= csum_flags;
- vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data;
- vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data;
+ b[0]->flags |= csum_flags;
+ vnet_buffer (b[0])->l3_hdr_offset = l3_0 - b[0]->data;
+ vnet_buffer (b[0])->l4_hdr_offset = (u8 *) udp0 - b[0]->data;
}
/* IPv4 UDP checksum only if checksum offload is used */
else if (is_ip4)
@@ -443,7 +445,7 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
int bogus = 0;
udp0->checksum = ip6_tcp_udp_icmp_compute_checksum
- (vm, b0, ip6_0, &bogus);
+ (vm, b[0], ip6_0, &bogus);
ASSERT (bogus == 0);
if (udp0->checksum == 0)
udp0->checksum = 0xffff;
@@ -453,15 +455,17 @@ vxlan_gbp_encap_inline (vlib_main_t * vm,
sw_if_index0, 1, len0);
pkts_encapsulated++;
- if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
{
vxlan_gbp_encap_trace_t *tr =
- vlib_add_trace (vm, node, b0, sizeof (*tr));
+ vlib_add_trace (vm, node, b[0], sizeof (*tr));
tr->tunnel_index = t0 - vxm->tunnels;
tr->vni = t0->vni;
- tr->sclass = vnet_buffer2 (b0)->gbp.sclass;
- tr->flags = vnet_buffer2 (b0)->gbp.flags;
+ tr->sclass = vnet_buffer2 (b[0])->gbp.sclass;
+ tr->flags = vnet_buffer2 (b[0])->gbp.flags;
}
+ b += 1;
+
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);