From: Ophir Munk <[email protected]> Refactor mark allocation to offload layer, with API to be used by upper layers (dpif-netdev), as a pre-step towards allocating marks by offload layer.
Co-authored-by: Eli Britstein <[email protected]> Signed-off-by: Ophir Munk <[email protected]> Reviewed-by: Roni Bar Yanai <[email protected]> Signed-off-by: Eli Britstein <[email protected]> --- lib/dpif-netdev.c | 33 +++------------------------------ lib/netdev-offload.c | 33 +++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 4 ++++ 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 8e6b14d35..bd937f300 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2146,9 +2146,6 @@ dp_netdev_pmd_find_dpcls(struct dp_netdev_pmd_thread *pmd, return cls; } -#define MAX_FLOW_MARK (UINT32_MAX - 1) -#define INVALID_FLOW_MARK (UINT32_MAX) - struct megaflow_to_mark_data { const struct cmap_node node; ovs_u128 mega_ufid; @@ -2158,7 +2155,6 @@ struct megaflow_to_mark_data { struct flow_mark { struct cmap megaflow_to_mark; struct cmap mark_to_flow; - struct id_pool *pool; }; static struct flow_mark flow_mark = { @@ -2166,29 +2162,6 @@ static struct flow_mark flow_mark = { .mark_to_flow = CMAP_INITIALIZER, }; -static uint32_t -flow_mark_alloc(void) -{ - uint32_t mark; - - if (!flow_mark.pool) { - /* Haven't initiated yet, do it here */ - flow_mark.pool = id_pool_create(0, MAX_FLOW_MARK); - } - - if (id_pool_alloc_id(flow_mark.pool, &mark)) { - return mark; - } - - return INVALID_FLOW_MARK; -} - -static void -flow_mark_free(uint32_t mark) -{ - id_pool_free_id(flow_mark.pool, mark); -} - /* associate megaflow with a mark, which is a 1:1 mapping */ static void megaflow_to_mark_associate(const ovs_u128 *mega_ufid, uint32_t mark) @@ -2300,7 +2273,7 @@ mark_to_flow_disassociate(struct dp_netdev_pmd_thread *pmd, netdev_close(port); } - flow_mark_free(mark); + netdev_offload_flow_mark_free(mark); VLOG_DBG("Freed flow mark %u\n", mark); megaflow_to_mark_disassociate(&flow->mega_ufid); @@ -2429,7 +2402,7 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) return 0; } - mark = flow_mark_alloc(); + mark = netdev_offload_flow_mark_alloc(); if (mark == INVALID_FLOW_MARK) { VLOG_ERR("Failed to allocate flow mark!\n"); } @@ -2462,7 +2435,7 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) err_free: if (!modification) { - flow_mark_free(mark); + netdev_offload_flow_mark_free(mark); } else { mark_to_flow_disassociate(pmd, flow); } diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index 1612fe6b8..008c46d50 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -33,6 +33,7 @@ #include "openvswitch/dynamic-string.h" #include "fatal-signal.h" #include "hash.h" +#include "id-pool.h" #include "openvswitch/list.h" #include "netdev-offload-provider.h" #include "netdev-provider.h" @@ -59,6 +60,8 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload); static bool netdev_flow_api_enabled = false; +static struct id_pool *mark_pool = NULL; +static struct ovs_mutex mark_pool_mutex = OVS_MUTEX_INITIALIZER; /* Protects 'netdev_flow_apis'. */ static struct ovs_mutex netdev_flow_api_provider_mutex = OVS_MUTEX_INITIALIZER; @@ -279,6 +282,36 @@ netdev_flow_del(struct netdev *netdev, const ovs_u128 *ufid, : EOPNOTSUPP; } +#define MAX_FLOW_MARK (UINT32_MAX - 1) + +uint32_t +netdev_offload_flow_mark_alloc(void) +{ + uint32_t mark; + + ovs_mutex_lock(&mark_pool_mutex); + if (!mark_pool) { + /* Haven't initiated yet, do it here */ + mark_pool = id_pool_create(0, MAX_FLOW_MARK); + } + + if (id_pool_alloc_id(mark_pool, &mark)) { + ovs_mutex_unlock(&mark_pool_mutex); + return mark; + } + + ovs_mutex_unlock(&mark_pool_mutex); + return INVALID_FLOW_MARK; +} + +void +netdev_offload_flow_mark_free(uint32_t mark) +{ + ovs_mutex_lock(&mark_pool_mutex); + id_pool_free_id(mark_pool, mark); + ovs_mutex_unlock(&mark_pool_mutex); +} + int netdev_init_flow_api(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 66ab75f82..b5488d00e 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -75,6 +75,8 @@ struct offload_info { uint32_t flow_mark; }; +#define INVALID_FLOW_MARK (UINT32_MAX) + int netdev_flow_flush(struct netdev *); int netdev_flow_dump_create(struct netdev *, struct netdev_flow_dump **dump); int netdev_flow_dump_destroy(struct netdev_flow_dump *); @@ -119,6 +121,8 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, struct dpif_flow_stats *stats, struct dpif_flow_attrs *attrs, struct ofpbuf *buf); +uint32_t netdev_offload_flow_mark_alloc(void); +void netdev_offload_flow_mark_free(uint32_t mark); #ifdef __cplusplus } -- 2.14.5 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
