policer: add api to bind policer to worker
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
This commit is contained in:
Brian Russell
committed by
Neale Ranns
parent
fd0b399ff6
commit
48e26367cf
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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__ */
|
||||
|
||||
|
@ -42,9 +42,10 @@
|
||||
|
||||
#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,
|
||||
|
Reference in New Issue
Block a user