aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/policer/police_inlines.h
diff options
context:
space:
mode:
authorBrian Russell <brian@graphiant.com>2021-02-18 10:25:23 +0000
committerNeale Ranns <neale@graphiant.com>2021-02-19 10:53:15 +0000
commitfce88656cc1b0da8731a71c4a6efa759e0df3fa8 (patch)
tree52d58afa787b5d6b0ffcabc70f99e8313c4875df /src/vnet/policer/police_inlines.h
parent6e6920d4e096bd158a0057ce0f8dd8a08cbabf72 (diff)
policer: move handoff checks into policer code
The IP punt policer currently checks if it needs to do worker thread handoff based on the thread index stored in the policer. Move this functionality into the policer code so it can be common for all users of the policer. Type: improvement Signed-off-by: Brian Russell <brian@graphiant.com> Change-Id: Ia8d11e62898a58b19d7b27b296f8369baa3e5aa1
Diffstat (limited to 'src/vnet/policer/police_inlines.h')
-rw-r--r--src/vnet/policer/police_inlines.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/vnet/policer/police_inlines.h b/src/vnet/policer/police_inlines.h
index fe0c754b7d4..9f56e1134d6 100644
--- a/src/vnet/policer/police_inlines.h
+++ b/src/vnet/policer/police_inlines.h
@@ -56,11 +56,9 @@ vnet_policer_mark (vlib_buffer_t *b, ip_dscp_t dscp)
}
static_always_inline u8
-vnet_policer_police (vlib_main_t * vm,
- vlib_buffer_t * b,
- u32 policer_index,
+vnet_policer_police (vlib_main_t *vm, vlib_buffer_t *b, u32 policer_index,
u64 time_in_policer_periods,
- policer_result_e packet_color)
+ policer_result_e packet_color, bool handoff)
{
qos_action_type_en act;
u32 len;
@@ -72,8 +70,25 @@ vnet_policer_police (vlib_main_t * vm,
vlib_prefetch_combined_counter (&policer_counters[POLICE_CONFORM],
vm->thread_index, policer_index);
- len = vlib_buffer_length_in_chain (vm, b);
pol = &pm->policers[policer_index];
+
+ if (handoff)
+ {
+ if (PREDICT_FALSE (pol->thread_index == ~0))
+ /*
+ * This is the first packet to use this policer. Set the
+ * thread index in the policer to this thread and any
+ * packets seen by this node on other threads will
+ * be handed off to this one.
+ *
+ * This could happen simultaneously on another thread.
+ */
+ clib_atomic_cmp_and_swap (&pol->thread_index, ~0, vm->thread_index);
+ else if (PREDICT_FALSE (pol->thread_index != vm->thread_index))
+ return QOS_ACTION_HANDOFF;
+ }
+
+ len = vlib_buffer_length_in_chain (vm, b);
col = vnet_police_packet (pol, len, packet_color, time_in_policer_periods);
act = pol->action[col];
vlib_increment_combined_counter (&policer_counters[col], vm->thread_index,