Commit 1a21cc50 authored by David S. Miller's avatar David S. Miller

Merge branch 'nfp-flower-speed-up-stats-update-loop'

Jakub Kicinski says:

====================
nfp: flower: speed up stats update loop

This set from Pieter improves performance of processing FW stats
update notifications.  The FW seems to send those at relatively
high rate (roughly ten per second per flow), therefore if we want
to approach the million flows mark we have to be very careful
about our data structures.

We tried rhashtable for stat updates, but according to our experiments
rhashtable lookup on a u32 takes roughly 60ns on an Xeon E5-2670 v3.
Which translate to a hard limit of 16M lookups per second on this CPU,
and, according to perf record jhash and memcmp account for 60% of CPU
usage on the core handling the updates.

Given that our statistic IDs are already array indices, and considering
each statistic is only 24B in size, we decided to forego the use
of hashtables and use a directly indexed array.  The CPU savings are
considerable.

With the recent improvements in TC core and with our own bottlenecks
out of the way Pieter removes the artificial limit of 128 flows, and
allows the driver to install as many flows as FW supports.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 7579d84b 12ecf615
...@@ -509,11 +509,6 @@ static int nfp_bpf_init(struct nfp_app *app) ...@@ -509,11 +509,6 @@ static int nfp_bpf_init(struct nfp_app *app)
return err; return err;
} }
static void nfp_check_rhashtable_empty(void *ptr, void *arg)
{
WARN_ON_ONCE(1);
}
static void nfp_bpf_clean(struct nfp_app *app) static void nfp_bpf_clean(struct nfp_app *app)
{ {
struct nfp_app_bpf *bpf = app->priv; struct nfp_app_bpf *bpf = app->priv;
......
...@@ -518,8 +518,8 @@ static int nfp_flower_vnic_init(struct nfp_app *app, struct nfp_net *nn) ...@@ -518,8 +518,8 @@ static int nfp_flower_vnic_init(struct nfp_app *app, struct nfp_net *nn)
static int nfp_flower_init(struct nfp_app *app) static int nfp_flower_init(struct nfp_app *app)
{ {
const struct nfp_pf *pf = app->pf; const struct nfp_pf *pf = app->pf;
u64 version, features, ctx_count;
struct nfp_flower_priv *app_priv; struct nfp_flower_priv *app_priv;
u64 version, features;
int err; int err;
if (!pf->eth_tbl) { if (!pf->eth_tbl) {
...@@ -543,6 +543,16 @@ static int nfp_flower_init(struct nfp_app *app) ...@@ -543,6 +543,16 @@ static int nfp_flower_init(struct nfp_app *app)
return err; return err;
} }
ctx_count = nfp_rtsym_read_le(app->pf->rtbl, "CONFIG_FC_HOST_CTX_COUNT",
&err);
if (err) {
nfp_warn(app->cpp,
"FlowerNIC: unsupported host context count: %d\n",
err);
err = 0;
ctx_count = BIT(17);
}
/* We need to ensure hardware has enough flower capabilities. */ /* We need to ensure hardware has enough flower capabilities. */
if (version != NFP_FLOWER_ALLOWED_VER) { if (version != NFP_FLOWER_ALLOWED_VER) {
nfp_warn(app->cpp, "FlowerNIC: unsupported firmware version\n"); nfp_warn(app->cpp, "FlowerNIC: unsupported firmware version\n");
...@@ -553,6 +563,7 @@ static int nfp_flower_init(struct nfp_app *app) ...@@ -553,6 +563,7 @@ static int nfp_flower_init(struct nfp_app *app)
if (!app_priv) if (!app_priv)
return -ENOMEM; return -ENOMEM;
app_priv->stats_ring_size = roundup_pow_of_two(ctx_count);
app->priv = app_priv; app->priv = app_priv;
app_priv->app = app; app_priv->app = app;
skb_queue_head_init(&app_priv->cmsg_skbs_high); skb_queue_head_init(&app_priv->cmsg_skbs_high);
...@@ -563,7 +574,7 @@ static int nfp_flower_init(struct nfp_app *app) ...@@ -563,7 +574,7 @@ static int nfp_flower_init(struct nfp_app *app)
init_waitqueue_head(&app_priv->mtu_conf.wait_q); init_waitqueue_head(&app_priv->mtu_conf.wait_q);
spin_lock_init(&app_priv->mtu_conf.lock); spin_lock_init(&app_priv->mtu_conf.lock);
err = nfp_flower_metadata_init(app); err = nfp_flower_metadata_init(app, ctx_count);
if (err) if (err)
goto err_free_app_priv; goto err_free_app_priv;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <linux/circ_buf.h> #include <linux/circ_buf.h>
#include <linux/hashtable.h> #include <linux/hashtable.h>
#include <linux/rhashtable.h>
#include <linux/time64.h> #include <linux/time64.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/pkt_cls.h> #include <net/pkt_cls.h>
...@@ -50,10 +51,8 @@ struct net_device; ...@@ -50,10 +51,8 @@ struct net_device;
struct nfp_app; struct nfp_app;
#define NFP_FL_STATS_CTX_DONT_CARE cpu_to_be32(0xffffffff) #define NFP_FL_STATS_CTX_DONT_CARE cpu_to_be32(0xffffffff)
#define NFP_FL_STATS_ENTRY_RS BIT(20) #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
#define NFP_FL_STATS_ELEM_RS 4 init_unalloc)
#define NFP_FL_REPEATED_HASH_MAX BIT(17)
#define NFP_FLOWER_HASH_BITS 19
#define NFP_FLOWER_MASK_ENTRY_RS 256 #define NFP_FLOWER_MASK_ENTRY_RS 256
#define NFP_FLOWER_MASK_ELEMENT_RS 1 #define NFP_FLOWER_MASK_ELEMENT_RS 1
#define NFP_FLOWER_MASK_HASH_BITS 10 #define NFP_FLOWER_MASK_HASH_BITS 10
...@@ -138,7 +137,10 @@ struct nfp_fl_lag { ...@@ -138,7 +137,10 @@ struct nfp_fl_lag {
* @stats_ids: List of free stats ids * @stats_ids: List of free stats ids
* @mask_ids: List of free mask ids * @mask_ids: List of free mask ids
* @mask_table: Hash table used to store masks * @mask_table: Hash table used to store masks
* @stats_ring_size: Maximum number of allowed stats ids
* @flow_table: Hash table used to store flower rules * @flow_table: Hash table used to store flower rules
* @stats: Stored stats updates for flower rules
* @stats_lock: Lock for flower rule stats updates
* @cmsg_work: Workqueue for control messages processing * @cmsg_work: Workqueue for control messages processing
* @cmsg_skbs_high: List of higher priority skbs for control message * @cmsg_skbs_high: List of higher priority skbs for control message
* processing * processing
...@@ -171,7 +173,10 @@ struct nfp_flower_priv { ...@@ -171,7 +173,10 @@ struct nfp_flower_priv {
struct nfp_fl_stats_id stats_ids; struct nfp_fl_stats_id stats_ids;
struct nfp_fl_mask_id mask_ids; struct nfp_fl_mask_id mask_ids;
DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS); DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS); u32 stats_ring_size;
struct rhashtable flow_table;
struct nfp_fl_stats *stats;
spinlock_t stats_lock; /* lock stats */
struct work_struct cmsg_work; struct work_struct cmsg_work;
struct sk_buff_head cmsg_skbs_high; struct sk_buff_head cmsg_skbs_high;
struct sk_buff_head cmsg_skbs_low; struct sk_buff_head cmsg_skbs_low;
...@@ -227,10 +232,8 @@ struct nfp_fl_stats { ...@@ -227,10 +232,8 @@ struct nfp_fl_stats {
struct nfp_fl_payload { struct nfp_fl_payload {
struct nfp_fl_rule_metadata meta; struct nfp_fl_rule_metadata meta;
unsigned long tc_flower_cookie; unsigned long tc_flower_cookie;
struct hlist_node link; struct rhash_head fl_node;
struct rcu_head rcu; struct rcu_head rcu;
spinlock_t lock; /* lock stats */
struct nfp_fl_stats stats;
__be32 nfp_tun_ipv4_addr; __be32 nfp_tun_ipv4_addr;
struct net_device *ingress_dev; struct net_device *ingress_dev;
char *unmasked_data; char *unmasked_data;
...@@ -239,6 +242,8 @@ struct nfp_fl_payload { ...@@ -239,6 +242,8 @@ struct nfp_fl_payload {
bool ingress_offload; bool ingress_offload;
}; };
extern const struct rhashtable_params nfp_flower_table_params;
struct nfp_fl_stats_frame { struct nfp_fl_stats_frame {
__be32 stats_con_id; __be32 stats_con_id;
__be32 pkt_count; __be32 pkt_count;
...@@ -246,7 +251,7 @@ struct nfp_fl_stats_frame { ...@@ -246,7 +251,7 @@ struct nfp_fl_stats_frame {
__be64 stats_cookie; __be64 stats_cookie;
}; };
int nfp_flower_metadata_init(struct nfp_app *app); int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count);
void nfp_flower_metadata_cleanup(struct nfp_app *app); void nfp_flower_metadata_cleanup(struct nfp_app *app);
int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev, int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
......
...@@ -48,6 +48,12 @@ struct nfp_mask_id_table { ...@@ -48,6 +48,12 @@ struct nfp_mask_id_table {
u8 mask_id; u8 mask_id;
}; };
struct nfp_fl_flow_table_cmp_arg {
struct net_device *netdev;
unsigned long cookie;
__be32 host_ctx;
};
static int nfp_release_stats_entry(struct nfp_app *app, u32 stats_context_id) static int nfp_release_stats_entry(struct nfp_app *app, u32 stats_context_id)
{ {
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
...@@ -55,14 +61,14 @@ static int nfp_release_stats_entry(struct nfp_app *app, u32 stats_context_id) ...@@ -55,14 +61,14 @@ static int nfp_release_stats_entry(struct nfp_app *app, u32 stats_context_id)
ring = &priv->stats_ids.free_list; ring = &priv->stats_ids.free_list;
/* Check if buffer is full. */ /* Check if buffer is full. */
if (!CIRC_SPACE(ring->head, ring->tail, NFP_FL_STATS_ENTRY_RS * if (!CIRC_SPACE(ring->head, ring->tail,
NFP_FL_STATS_ELEM_RS - priv->stats_ring_size * NFP_FL_STATS_ELEM_RS -
NFP_FL_STATS_ELEM_RS + 1)) NFP_FL_STATS_ELEM_RS + 1))
return -ENOBUFS; return -ENOBUFS;
memcpy(&ring->buf[ring->head], &stats_context_id, NFP_FL_STATS_ELEM_RS); memcpy(&ring->buf[ring->head], &stats_context_id, NFP_FL_STATS_ELEM_RS);
ring->head = (ring->head + NFP_FL_STATS_ELEM_RS) % ring->head = (ring->head + NFP_FL_STATS_ELEM_RS) %
(NFP_FL_STATS_ENTRY_RS * NFP_FL_STATS_ELEM_RS); (priv->stats_ring_size * NFP_FL_STATS_ELEM_RS);
return 0; return 0;
} }
...@@ -74,7 +80,7 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id) ...@@ -74,7 +80,7 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id)
struct circ_buf *ring; struct circ_buf *ring;
ring = &priv->stats_ids.free_list; ring = &priv->stats_ids.free_list;
freed_stats_id = NFP_FL_STATS_ENTRY_RS; freed_stats_id = priv->stats_ring_size;
/* Check for unallocated entries first. */ /* Check for unallocated entries first. */
if (priv->stats_ids.init_unalloc > 0) { if (priv->stats_ids.init_unalloc > 0) {
*stats_context_id = priv->stats_ids.init_unalloc - 1; *stats_context_id = priv->stats_ids.init_unalloc - 1;
...@@ -92,7 +98,7 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id) ...@@ -92,7 +98,7 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id)
*stats_context_id = temp_stats_id; *stats_context_id = temp_stats_id;
memcpy(&ring->buf[ring->tail], &freed_stats_id, NFP_FL_STATS_ELEM_RS); memcpy(&ring->buf[ring->tail], &freed_stats_id, NFP_FL_STATS_ELEM_RS);
ring->tail = (ring->tail + NFP_FL_STATS_ELEM_RS) % ring->tail = (ring->tail + NFP_FL_STATS_ELEM_RS) %
(NFP_FL_STATS_ENTRY_RS * NFP_FL_STATS_ELEM_RS); (priv->stats_ring_size * NFP_FL_STATS_ELEM_RS);
return 0; return 0;
} }
...@@ -102,56 +108,37 @@ struct nfp_fl_payload * ...@@ -102,56 +108,37 @@ struct nfp_fl_payload *
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie, nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
struct net_device *netdev, __be32 host_ctx) struct net_device *netdev, __be32 host_ctx)
{ {
struct nfp_fl_flow_table_cmp_arg flower_cmp_arg;
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
struct nfp_fl_payload *flower_entry;
hash_for_each_possible_rcu(priv->flow_table, flower_entry, link, flower_cmp_arg.netdev = netdev;
tc_flower_cookie) flower_cmp_arg.cookie = tc_flower_cookie;
if (flower_entry->tc_flower_cookie == tc_flower_cookie && flower_cmp_arg.host_ctx = host_ctx;
(!netdev || flower_entry->ingress_dev == netdev) &&
(host_ctx == NFP_FL_STATS_CTX_DONT_CARE ||
flower_entry->meta.host_ctx_id == host_ctx))
return flower_entry;
return NULL; return rhashtable_lookup_fast(&priv->flow_table, &flower_cmp_arg,
} nfp_flower_table_params);
static void
nfp_flower_update_stats(struct nfp_app *app, struct nfp_fl_stats_frame *stats)
{
struct nfp_fl_payload *nfp_flow;
unsigned long flower_cookie;
flower_cookie = be64_to_cpu(stats->stats_cookie);
rcu_read_lock();
nfp_flow = nfp_flower_search_fl_table(app, flower_cookie, NULL,
stats->stats_con_id);
if (!nfp_flow)
goto exit_rcu_unlock;
spin_lock(&nfp_flow->lock);
nfp_flow->stats.pkts += be32_to_cpu(stats->pkt_count);
nfp_flow->stats.bytes += be64_to_cpu(stats->byte_count);
nfp_flow->stats.used = jiffies;
spin_unlock(&nfp_flow->lock);
exit_rcu_unlock:
rcu_read_unlock();
} }
void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb) void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb)
{ {
unsigned int msg_len = nfp_flower_cmsg_get_data_len(skb); unsigned int msg_len = nfp_flower_cmsg_get_data_len(skb);
struct nfp_fl_stats_frame *stats_frame; struct nfp_flower_priv *priv = app->priv;
struct nfp_fl_stats_frame *stats;
unsigned char *msg; unsigned char *msg;
u32 ctx_id;
int i; int i;
msg = nfp_flower_cmsg_get_data(skb); msg = nfp_flower_cmsg_get_data(skb);
stats_frame = (struct nfp_fl_stats_frame *)msg; spin_lock(&priv->stats_lock);
for (i = 0; i < msg_len / sizeof(*stats_frame); i++) for (i = 0; i < msg_len / sizeof(*stats); i++) {
nfp_flower_update_stats(app, stats_frame + i); stats = (struct nfp_fl_stats_frame *)msg + i;
ctx_id = be32_to_cpu(stats->stats_con_id);
priv->stats[ctx_id].pkts += be32_to_cpu(stats->pkt_count);
priv->stats[ctx_id].bytes += be64_to_cpu(stats->byte_count);
priv->stats[ctx_id].used = jiffies;
}
spin_unlock(&priv->stats_lock);
} }
static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id) static int nfp_release_mask_id(struct nfp_app *app, u8 mask_id)
...@@ -345,9 +332,9 @@ int nfp_compile_flow_metadata(struct nfp_app *app, ...@@ -345,9 +332,9 @@ int nfp_compile_flow_metadata(struct nfp_app *app,
/* Update flow payload with mask ids. */ /* Update flow payload with mask ids. */
nfp_flow->unmasked_data[NFP_FL_MASK_ID_LOCATION] = new_mask_id; nfp_flow->unmasked_data[NFP_FL_MASK_ID_LOCATION] = new_mask_id;
nfp_flow->stats.pkts = 0; priv->stats[stats_cxt].pkts = 0;
nfp_flow->stats.bytes = 0; priv->stats[stats_cxt].bytes = 0;
nfp_flow->stats.used = jiffies; priv->stats[stats_cxt].used = jiffies;
check_entry = nfp_flower_search_fl_table(app, flow->cookie, netdev, check_entry = nfp_flower_search_fl_table(app, flow->cookie, netdev,
NFP_FL_STATS_CTX_DONT_CARE); NFP_FL_STATS_CTX_DONT_CARE);
...@@ -389,12 +376,56 @@ int nfp_modify_flow_metadata(struct nfp_app *app, ...@@ -389,12 +376,56 @@ int nfp_modify_flow_metadata(struct nfp_app *app,
return nfp_release_stats_entry(app, temp_ctx_id); return nfp_release_stats_entry(app, temp_ctx_id);
} }
int nfp_flower_metadata_init(struct nfp_app *app) static int nfp_fl_obj_cmpfn(struct rhashtable_compare_arg *arg,
const void *obj)
{
const struct nfp_fl_flow_table_cmp_arg *cmp_arg = arg->key;
const struct nfp_fl_payload *flow_entry = obj;
if ((!cmp_arg->netdev || flow_entry->ingress_dev == cmp_arg->netdev) &&
(cmp_arg->host_ctx == NFP_FL_STATS_CTX_DONT_CARE ||
flow_entry->meta.host_ctx_id == cmp_arg->host_ctx))
return flow_entry->tc_flower_cookie != cmp_arg->cookie;
return 1;
}
static u32 nfp_fl_obj_hashfn(const void *data, u32 len, u32 seed)
{
const struct nfp_fl_payload *flower_entry = data;
return jhash2((u32 *)&flower_entry->tc_flower_cookie,
sizeof(flower_entry->tc_flower_cookie) / sizeof(u32),
seed);
}
static u32 nfp_fl_key_hashfn(const void *data, u32 len, u32 seed)
{
const struct nfp_fl_flow_table_cmp_arg *cmp_arg = data;
return jhash2((u32 *)&cmp_arg->cookie,
sizeof(cmp_arg->cookie) / sizeof(u32), seed);
}
const struct rhashtable_params nfp_flower_table_params = {
.head_offset = offsetof(struct nfp_fl_payload, fl_node),
.hashfn = nfp_fl_key_hashfn,
.obj_cmpfn = nfp_fl_obj_cmpfn,
.obj_hashfn = nfp_fl_obj_hashfn,
.automatic_shrinking = true,
};
int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count)
{ {
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
int err;
hash_init(priv->mask_table); hash_init(priv->mask_table);
hash_init(priv->flow_table);
err = rhashtable_init(&priv->flow_table, &nfp_flower_table_params);
if (err)
return err;
get_random_bytes(&priv->mask_id_seed, sizeof(priv->mask_id_seed)); get_random_bytes(&priv->mask_id_seed, sizeof(priv->mask_id_seed));
/* Init ring buffer and unallocated mask_ids. */ /* Init ring buffer and unallocated mask_ids. */
...@@ -402,7 +433,7 @@ int nfp_flower_metadata_init(struct nfp_app *app) ...@@ -402,7 +433,7 @@ int nfp_flower_metadata_init(struct nfp_app *app)
kmalloc_array(NFP_FLOWER_MASK_ENTRY_RS, kmalloc_array(NFP_FLOWER_MASK_ENTRY_RS,
NFP_FLOWER_MASK_ELEMENT_RS, GFP_KERNEL); NFP_FLOWER_MASK_ELEMENT_RS, GFP_KERNEL);
if (!priv->mask_ids.mask_id_free_list.buf) if (!priv->mask_ids.mask_id_free_list.buf)
return -ENOMEM; goto err_free_flow_table;
priv->mask_ids.init_unallocated = NFP_FLOWER_MASK_ENTRY_RS - 1; priv->mask_ids.init_unallocated = NFP_FLOWER_MASK_ENTRY_RS - 1;
...@@ -416,18 +447,29 @@ int nfp_flower_metadata_init(struct nfp_app *app) ...@@ -416,18 +447,29 @@ int nfp_flower_metadata_init(struct nfp_app *app)
/* Init ring buffer and unallocated stats_ids. */ /* Init ring buffer and unallocated stats_ids. */
priv->stats_ids.free_list.buf = priv->stats_ids.free_list.buf =
vmalloc(array_size(NFP_FL_STATS_ELEM_RS, vmalloc(array_size(NFP_FL_STATS_ELEM_RS,
NFP_FL_STATS_ENTRY_RS)); priv->stats_ring_size));
if (!priv->stats_ids.free_list.buf) if (!priv->stats_ids.free_list.buf)
goto err_free_last_used; goto err_free_last_used;
priv->stats_ids.init_unalloc = NFP_FL_REPEATED_HASH_MAX; priv->stats_ids.init_unalloc = host_ctx_count;
priv->stats = kvmalloc_array(priv->stats_ring_size,
sizeof(struct nfp_fl_stats), GFP_KERNEL);
if (!priv->stats)
goto err_free_ring_buf;
spin_lock_init(&priv->stats_lock);
return 0; return 0;
err_free_ring_buf:
vfree(priv->stats_ids.free_list.buf);
err_free_last_used: err_free_last_used:
kfree(priv->mask_ids.last_used); kfree(priv->mask_ids.last_used);
err_free_mask_id: err_free_mask_id:
kfree(priv->mask_ids.mask_id_free_list.buf); kfree(priv->mask_ids.mask_id_free_list.buf);
err_free_flow_table:
rhashtable_destroy(&priv->flow_table);
return -ENOMEM; return -ENOMEM;
} }
...@@ -438,6 +480,9 @@ void nfp_flower_metadata_cleanup(struct nfp_app *app) ...@@ -438,6 +480,9 @@ void nfp_flower_metadata_cleanup(struct nfp_app *app)
if (!priv) if (!priv)
return; return;
rhashtable_free_and_destroy(&priv->flow_table,
nfp_check_rhashtable_empty, NULL);
kvfree(priv->stats);
kfree(priv->mask_ids.mask_id_free_list.buf); kfree(priv->mask_ids.mask_id_free_list.buf);
kfree(priv->mask_ids.last_used); kfree(priv->mask_ids.last_used);
vfree(priv->stats_ids.free_list.buf); vfree(priv->stats_ids.free_list.buf);
......
...@@ -428,8 +428,6 @@ nfp_flower_allocate_new(struct nfp_fl_key_ls *key_layer, bool egress) ...@@ -428,8 +428,6 @@ nfp_flower_allocate_new(struct nfp_fl_key_ls *key_layer, bool egress)
flow_pay->nfp_tun_ipv4_addr = 0; flow_pay->nfp_tun_ipv4_addr = 0;
flow_pay->meta.flags = 0; flow_pay->meta.flags = 0;
spin_lock_init(&flow_pay->lock);
flow_pay->ingress_offload = !egress; flow_pay->ingress_offload = !egress;
return flow_pay; return flow_pay;
...@@ -513,9 +511,12 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev, ...@@ -513,9 +511,12 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
if (err) if (err)
goto err_destroy_flow; goto err_destroy_flow;
INIT_HLIST_NODE(&flow_pay->link);
flow_pay->tc_flower_cookie = flow->cookie; flow_pay->tc_flower_cookie = flow->cookie;
hash_add_rcu(priv->flow_table, &flow_pay->link, flow->cookie); err = rhashtable_insert_fast(&priv->flow_table, &flow_pay->fl_node,
nfp_flower_table_params);
if (err)
goto err_destroy_flow;
port->tc_offload_cnt++; port->tc_offload_cnt++;
/* Deallocate flow payload when flower rule has been destroyed. */ /* Deallocate flow payload when flower rule has been destroyed. */
...@@ -550,6 +551,7 @@ nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev, ...@@ -550,6 +551,7 @@ nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev,
struct tc_cls_flower_offload *flow, bool egress) struct tc_cls_flower_offload *flow, bool egress)
{ {
struct nfp_port *port = nfp_port_from_netdev(netdev); struct nfp_port *port = nfp_port_from_netdev(netdev);
struct nfp_flower_priv *priv = app->priv;
struct nfp_fl_payload *nfp_flow; struct nfp_fl_payload *nfp_flow;
struct net_device *ingr_dev; struct net_device *ingr_dev;
int err; int err;
...@@ -573,11 +575,13 @@ nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev, ...@@ -573,11 +575,13 @@ nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev,
goto err_free_flow; goto err_free_flow;
err_free_flow: err_free_flow:
hash_del_rcu(&nfp_flow->link);
port->tc_offload_cnt--; port->tc_offload_cnt--;
kfree(nfp_flow->action_data); kfree(nfp_flow->action_data);
kfree(nfp_flow->mask_data); kfree(nfp_flow->mask_data);
kfree(nfp_flow->unmasked_data); kfree(nfp_flow->unmasked_data);
WARN_ON_ONCE(rhashtable_remove_fast(&priv->flow_table,
&nfp_flow->fl_node,
nfp_flower_table_params));
kfree_rcu(nfp_flow, rcu); kfree_rcu(nfp_flow, rcu);
return err; return err;
} }
...@@ -598,8 +602,10 @@ static int ...@@ -598,8 +602,10 @@ static int
nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev, nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev,
struct tc_cls_flower_offload *flow, bool egress) struct tc_cls_flower_offload *flow, bool egress)
{ {
struct nfp_flower_priv *priv = app->priv;
struct nfp_fl_payload *nfp_flow; struct nfp_fl_payload *nfp_flow;
struct net_device *ingr_dev; struct net_device *ingr_dev;
u32 ctx_id;
ingr_dev = egress ? NULL : netdev; ingr_dev = egress ? NULL : netdev;
nfp_flow = nfp_flower_search_fl_table(app, flow->cookie, ingr_dev, nfp_flow = nfp_flower_search_fl_table(app, flow->cookie, ingr_dev,
...@@ -610,13 +616,16 @@ nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev, ...@@ -610,13 +616,16 @@ nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev,
if (nfp_flow->ingress_offload && egress) if (nfp_flow->ingress_offload && egress)
return 0; return 0;
spin_lock_bh(&nfp_flow->lock); ctx_id = be32_to_cpu(nfp_flow->meta.host_ctx_id);
tcf_exts_stats_update(flow->exts, nfp_flow->stats.bytes,
nfp_flow->stats.pkts, nfp_flow->stats.used); spin_lock_bh(&priv->stats_lock);
tcf_exts_stats_update(flow->exts, priv->stats[ctx_id].bytes,
priv->stats[ctx_id].pkts,
priv->stats[ctx_id].used);
nfp_flow->stats.pkts = 0; priv->stats[ctx_id].pkts = 0;
nfp_flow->stats.bytes = 0; priv->stats[ctx_id].bytes = 0;
spin_unlock_bh(&nfp_flow->lock); spin_unlock_bh(&priv->stats_lock);
return 0; return 0;
} }
......
...@@ -60,6 +60,11 @@ static const struct nfp_app_type *apps[] = { ...@@ -60,6 +60,11 @@ static const struct nfp_app_type *apps[] = {
#endif #endif
}; };
void nfp_check_rhashtable_empty(void *ptr, void *arg)
{
WARN_ON_ONCE(1);
}
struct nfp_app *nfp_app_from_netdev(struct net_device *netdev) struct nfp_app *nfp_app_from_netdev(struct net_device *netdev)
{ {
if (nfp_netdev_is_nfp_net(netdev)) { if (nfp_netdev_is_nfp_net(netdev)) {
......
...@@ -196,6 +196,7 @@ struct nfp_app { ...@@ -196,6 +196,7 @@ struct nfp_app {
void *priv; void *priv;
}; };
void nfp_check_rhashtable_empty(void *ptr, void *arg);
bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment