policer: add api to bind policer to worker 21/31221/3
authorBrian Russell <brian@graphiant.com>
Wed, 10 Feb 2021 13:53:42 +0000 (13:53 +0000)
committerNeale Ranns <neale@graphiant.com>
Mon, 15 Feb 2021 12:15:32 +0000 (12:15 +0000)
Add a new api to allow a policer to be bound to
a specific worker thread for thread handoff.

Type: improvement
Signed-off-by: Brian Russell <brian@graphiant.com>
Change-Id: I2623a6827843c3d93c0d7b4ad7c2e13611ec1696

src/vnet/policer/policer.api
src/vnet/policer/policer.c
src/vnet/policer/policer.h
src/vnet/policer/policer_api.c

index 946cc35..c3b8d7c 100644 (file)
@@ -17,6 +17,23 @@ option version = "2.0.0";
 
 import "vnet/policer/policer_types.api";
 
+/** \brief policer bind: Associate/disassociate a policer with a worker thread.
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param name - policer name to bind
+    @param worker_index - the worker thread to bind to
+    @param bind_enable - Associate/disassociate
+*/
+autoreply define policer_bind
+{
+  u32 client_index;
+  u32 context;
+
+  string name[64];
+  u32 worker_index;
+  bool bind_enable;
+};
+
 /** \brief Add/del policer
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
index 2c05ae2..8146d4b 100644 (file)
@@ -13,6 +13,7 @@
  * limitations under the License.
  */
 #include <stdint.h>
+#include <stdbool.h>
 #include <vnet/policer/policer.h>
 #include <vnet/policer/police_inlines.h>
 #include <vnet/classify/vnet_classify.h>
@@ -133,6 +134,37 @@ policer_add_del (vlib_main_t *vm, u8 *name, qos_pol_cfg_params_st *cfg,
   return 0;
 }
 
+int
+policer_bind_worker (u8 *name, u32 worker, bool bind)
+{
+  vnet_policer_main_t *pm = &vnet_policer_main;
+  policer_read_response_type_st *policer;
+  uword *p;
+
+  p = hash_get_mem (pm->policer_index_by_name, name);
+  if (p == 0)
+    {
+      return VNET_API_ERROR_NO_SUCH_ENTRY;
+    }
+
+  policer = &pm->policers[p[0]];
+
+  if (bind)
+    {
+      if (worker >= vlib_num_workers ())
+       {
+         return VNET_API_ERROR_INVALID_WORKER;
+       }
+
+      policer->thread_index = vlib_get_worker_thread_index (worker);
+    }
+  else
+    {
+      policer->thread_index = ~0;
+    }
+  return 0;
+}
+
 u8 *
 format_policer_instance (u8 * s, va_list * va)
 {
index 4d253f7..4c2c741 100644 (file)
@@ -15,6 +15,8 @@
 #ifndef __included_policer_h__
 #define __included_policer_h__
 
+#include <stdbool.h>
+
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
 
@@ -68,6 +70,7 @@ u8 *format_policer_instance (u8 * s, va_list * va);
 clib_error_t *policer_add_del (vlib_main_t *vm, u8 *name,
                               qos_pol_cfg_params_st *cfg, u32 *policer_index,
                               u8 is_add);
+int policer_bind_worker (u8 *name, u32 worker, bool bind);
 
 #endif /* __included_policer_h__ */
 
index fb66667..17ed737 100644 (file)
 
 #include <vlibapi/api_helper_macros.h>
 
-#define foreach_vpe_api_msg                             \
-_(POLICER_ADD_DEL, policer_add_del)                     \
-_(POLICER_DUMP, policer_dump)
+#define foreach_vpe_api_msg                                                   \
+  _ (POLICER_ADD_DEL, policer_add_del)                                        \
+  _ (POLICER_BIND, policer_bind)                                              \
+  _ (POLICER_DUMP, policer_dump)
 
 static void
 vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
@@ -95,6 +96,26 @@ vl_api_policer_add_del_t_handler (vl_api_policer_add_del_t * mp)
   /* *INDENT-ON* */
 }
 
+static void
+vl_api_policer_bind_t_handler (vl_api_policer_bind_t *mp)
+{
+  vl_api_policer_bind_reply_t *rmp;
+  u8 *name;
+  u32 worker_index;
+  u8 bind_enable;
+  int rv;
+
+  name = format (0, "%s", mp->name);
+  vec_terminate_c_string (name);
+
+  worker_index = ntohl (mp->worker_index);
+  bind_enable = mp->bind_enable;
+
+  rv = policer_bind_worker (name, worker_index, bind_enable);
+  vec_free (name);
+  REPLY_MACRO (VL_API_POLICER_BIND_REPLY);
+}
+
 static void
 send_policer_details (u8 *name, qos_pol_cfg_params_st *config,
                      policer_read_response_type_st *templ,