|
|
|
|
@@ -32,13 +32,11 @@
|
|
|
|
|
|
|
|
|
|
#include <linux/mlx5/driver.h>
|
|
|
|
|
#include <linux/mlx5/fs.h>
|
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
|
#include "mlx5_core.h"
|
|
|
|
|
#include "fs_core.h"
|
|
|
|
|
#include "fs_cmd.h"
|
|
|
|
|
|
|
|
|
|
#define MLX5_FC_STATS_PERIOD msecs_to_jiffies(1000)
|
|
|
|
|
#define MLX5_FC_BULK_QUERY_ALLOC_PERIOD msecs_to_jiffies(180 * 1000)
|
|
|
|
|
/* Max number of counters to query in bulk read is 32K */
|
|
|
|
|
#define MLX5_SW_MAX_COUNTERS_BULK BIT(15)
|
|
|
|
|
#define MLX5_INIT_COUNTERS_BULK 8
|
|
|
|
|
@@ -52,21 +50,37 @@ struct mlx5_fc_cache {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc {
|
|
|
|
|
struct list_head list;
|
|
|
|
|
struct llist_node addlist;
|
|
|
|
|
struct llist_node dellist;
|
|
|
|
|
|
|
|
|
|
/* last{packets,bytes} members are used when calculating the delta since
|
|
|
|
|
* last reading
|
|
|
|
|
*/
|
|
|
|
|
u64 lastpackets;
|
|
|
|
|
u64 lastbytes;
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc_bulk *bulk;
|
|
|
|
|
u32 id;
|
|
|
|
|
bool aging;
|
|
|
|
|
struct mlx5_fc_bulk *bulk;
|
|
|
|
|
struct mlx5_fc_cache cache;
|
|
|
|
|
/* last{packets,bytes} are used for calculating deltas since last reading. */
|
|
|
|
|
u64 lastpackets;
|
|
|
|
|
u64 lastbytes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc_cache cache ____cacheline_aligned_in_smp;
|
|
|
|
|
struct mlx5_fc_pool {
|
|
|
|
|
struct mlx5_core_dev *dev;
|
|
|
|
|
struct mutex pool_lock; /* protects pool lists */
|
|
|
|
|
struct list_head fully_used;
|
|
|
|
|
struct list_head partially_used;
|
|
|
|
|
struct list_head unused;
|
|
|
|
|
int available_fcs;
|
|
|
|
|
int used_fcs;
|
|
|
|
|
int threshold;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc_stats {
|
|
|
|
|
struct xarray counters;
|
|
|
|
|
|
|
|
|
|
struct workqueue_struct *wq;
|
|
|
|
|
struct delayed_work work;
|
|
|
|
|
unsigned long sampling_interval; /* jiffies */
|
|
|
|
|
u32 *bulk_query_out;
|
|
|
|
|
int bulk_query_len;
|
|
|
|
|
bool bulk_query_alloc_failed;
|
|
|
|
|
unsigned long next_bulk_query_alloc;
|
|
|
|
|
struct mlx5_fc_pool fc_pool;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_pool_init(struct mlx5_fc_pool *fc_pool, struct mlx5_core_dev *dev);
|
|
|
|
|
@@ -74,78 +88,6 @@ static void mlx5_fc_pool_cleanup(struct mlx5_fc_pool *fc_pool);
|
|
|
|
|
static struct mlx5_fc *mlx5_fc_pool_acquire_counter(struct mlx5_fc_pool *fc_pool);
|
|
|
|
|
static void mlx5_fc_pool_release_counter(struct mlx5_fc_pool *fc_pool, struct mlx5_fc *fc);
|
|
|
|
|
|
|
|
|
|
/* locking scheme:
|
|
|
|
|
*
|
|
|
|
|
* It is the responsibility of the user to prevent concurrent calls or bad
|
|
|
|
|
* ordering to mlx5_fc_create(), mlx5_fc_destroy() and accessing a reference
|
|
|
|
|
* to struct mlx5_fc.
|
|
|
|
|
* e.g en_tc.c is protected by RTNL lock of its caller, and will never call a
|
|
|
|
|
* dump (access to struct mlx5_fc) after a counter is destroyed.
|
|
|
|
|
*
|
|
|
|
|
* access to counter list:
|
|
|
|
|
* - create (user context)
|
|
|
|
|
* - mlx5_fc_create() only adds to an addlist to be used by
|
|
|
|
|
* mlx5_fc_stats_work(). addlist is a lockless single linked list
|
|
|
|
|
* that doesn't require any additional synchronization when adding single
|
|
|
|
|
* node.
|
|
|
|
|
* - spawn thread to do the actual destroy
|
|
|
|
|
*
|
|
|
|
|
* - destroy (user context)
|
|
|
|
|
* - add a counter to lockless dellist
|
|
|
|
|
* - spawn thread to do the actual del
|
|
|
|
|
*
|
|
|
|
|
* - dump (user context)
|
|
|
|
|
* user should not call dump after destroy
|
|
|
|
|
*
|
|
|
|
|
* - query (single thread workqueue context)
|
|
|
|
|
* destroy/dump - no conflict (see destroy)
|
|
|
|
|
* query/dump - packets and bytes might be inconsistent (since update is not
|
|
|
|
|
* atomic)
|
|
|
|
|
* query/create - no conflict (see create)
|
|
|
|
|
* since every create/destroy spawn the work, only after necessary time has
|
|
|
|
|
* elapsed, the thread will actually query the hardware.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct list_head *mlx5_fc_counters_lookup_next(struct mlx5_core_dev *dev,
|
|
|
|
|
u32 id)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
unsigned long next_id = (unsigned long)id + 1;
|
|
|
|
|
struct mlx5_fc *counter;
|
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
/* skip counters that are in idr, but not yet in counters list */
|
|
|
|
|
idr_for_each_entry_continue_ul(&fc_stats->counters_idr,
|
|
|
|
|
counter, tmp, next_id) {
|
|
|
|
|
if (!list_empty(&counter->list))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
|
|
return counter ? &counter->list : &fc_stats->counters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_stats_insert(struct mlx5_core_dev *dev,
|
|
|
|
|
struct mlx5_fc *counter)
|
|
|
|
|
{
|
|
|
|
|
struct list_head *next = mlx5_fc_counters_lookup_next(dev, counter->id);
|
|
|
|
|
|
|
|
|
|
list_add_tail(&counter->list, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_stats_remove(struct mlx5_core_dev *dev,
|
|
|
|
|
struct mlx5_fc *counter)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
list_del(&counter->list);
|
|
|
|
|
|
|
|
|
|
spin_lock(&fc_stats->counters_idr_lock);
|
|
|
|
|
WARN_ON(!idr_remove(&fc_stats->counters_idr, counter->id));
|
|
|
|
|
spin_unlock(&fc_stats->counters_idr_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int get_init_bulk_query_len(struct mlx5_core_dev *dev)
|
|
|
|
|
{
|
|
|
|
|
return min_t(int, MLX5_INIT_COUNTERS_BULK,
|
|
|
|
|
@@ -174,47 +116,64 @@ static void update_counter_cache(int index, u32 *bulk_raw_data,
|
|
|
|
|
cache->lastuse = jiffies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_stats_query_counter_range(struct mlx5_core_dev *dev,
|
|
|
|
|
struct mlx5_fc *first,
|
|
|
|
|
u32 last_id)
|
|
|
|
|
/* Synchronization notes
|
|
|
|
|
*
|
|
|
|
|
* Access to counter array:
|
|
|
|
|
* - create - mlx5_fc_create() (user context)
|
|
|
|
|
* - inserts the counter into the xarray.
|
|
|
|
|
*
|
|
|
|
|
* - destroy - mlx5_fc_destroy() (user context)
|
|
|
|
|
* - erases the counter from the xarray and releases it.
|
|
|
|
|
*
|
|
|
|
|
* - query mlx5_fc_query(), mlx5_fc_query_cached{,_raw}() (user context)
|
|
|
|
|
* - user should not access a counter after destroy.
|
|
|
|
|
*
|
|
|
|
|
* - bulk query (single thread workqueue context)
|
|
|
|
|
* - create: query relies on 'lastuse' to avoid updating counters added
|
|
|
|
|
* around the same time as the current bulk cmd.
|
|
|
|
|
* - destroy: destroyed counters will not be accessed, even if they are
|
|
|
|
|
* destroyed during a bulk query command.
|
|
|
|
|
*/
|
|
|
|
|
static void mlx5_fc_stats_query_all_counters(struct mlx5_core_dev *dev)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
bool query_more_counters = (first->id <= last_id);
|
|
|
|
|
int cur_bulk_len = fc_stats->bulk_query_len;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
u32 bulk_len = fc_stats->bulk_query_len;
|
|
|
|
|
XA_STATE(xas, &fc_stats->counters, 0);
|
|
|
|
|
u32 *data = fc_stats->bulk_query_out;
|
|
|
|
|
struct mlx5_fc *counter = first;
|
|
|
|
|
struct mlx5_fc *counter;
|
|
|
|
|
u32 last_bulk_id = 0;
|
|
|
|
|
u64 bulk_query_time;
|
|
|
|
|
u32 bulk_base_id;
|
|
|
|
|
int bulk_len;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
while (query_more_counters) {
|
|
|
|
|
/* first id must be aligned to 4 when using bulk query */
|
|
|
|
|
bulk_base_id = counter->id & ~0x3;
|
|
|
|
|
|
|
|
|
|
/* number of counters to query inc. the last counter */
|
|
|
|
|
bulk_len = min_t(int, cur_bulk_len,
|
|
|
|
|
ALIGN(last_id - bulk_base_id + 1, 4));
|
|
|
|
|
|
|
|
|
|
err = mlx5_cmd_fc_bulk_query(dev, bulk_base_id, bulk_len,
|
|
|
|
|
data);
|
|
|
|
|
if (err) {
|
|
|
|
|
mlx5_core_err(dev, "Error doing bulk query: %d\n", err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
query_more_counters = false;
|
|
|
|
|
|
|
|
|
|
list_for_each_entry_from(counter, &fc_stats->counters, list) {
|
|
|
|
|
int counter_index = counter->id - bulk_base_id;
|
|
|
|
|
struct mlx5_fc_cache *cache = &counter->cache;
|
|
|
|
|
|
|
|
|
|
if (counter->id >= bulk_base_id + bulk_len) {
|
|
|
|
|
query_more_counters = true;
|
|
|
|
|
break;
|
|
|
|
|
xas_lock(&xas);
|
|
|
|
|
xas_for_each(&xas, counter, U32_MAX) {
|
|
|
|
|
if (xas_retry(&xas, counter))
|
|
|
|
|
continue;
|
|
|
|
|
if (unlikely(counter->id >= last_bulk_id)) {
|
|
|
|
|
/* Start new bulk query. */
|
|
|
|
|
/* First id must be aligned to 4 when using bulk query. */
|
|
|
|
|
bulk_base_id = counter->id & ~0x3;
|
|
|
|
|
last_bulk_id = bulk_base_id + bulk_len;
|
|
|
|
|
/* The lock is released while querying the hw and reacquired after. */
|
|
|
|
|
xas_unlock(&xas);
|
|
|
|
|
/* The same id needs to be processed again in the next loop iteration. */
|
|
|
|
|
xas_reset(&xas);
|
|
|
|
|
bulk_query_time = jiffies;
|
|
|
|
|
err = mlx5_cmd_fc_bulk_query(dev, bulk_base_id, bulk_len, data);
|
|
|
|
|
if (err) {
|
|
|
|
|
mlx5_core_err(dev, "Error doing bulk query: %d\n", err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_counter_cache(counter_index, data, cache);
|
|
|
|
|
xas_lock(&xas);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* Do not update counters added after bulk query was started. */
|
|
|
|
|
if (time_after64(bulk_query_time, counter->cache.lastuse))
|
|
|
|
|
update_counter_cache(counter->id - bulk_base_id, data,
|
|
|
|
|
&counter->cache);
|
|
|
|
|
}
|
|
|
|
|
xas_unlock(&xas);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
|
|
|
|
|
@@ -225,7 +184,7 @@ static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
if (counter->bulk)
|
|
|
|
|
mlx5_fc_pool_release_counter(&fc_stats->fc_pool, counter);
|
|
|
|
|
@@ -233,85 +192,55 @@ static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
|
|
|
|
|
mlx5_fc_free(dev, counter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_stats_bulk_query_size_increase(struct mlx5_core_dev *dev)
|
|
|
|
|
static void mlx5_fc_stats_bulk_query_buf_realloc(struct mlx5_core_dev *dev,
|
|
|
|
|
int bulk_query_len)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
int max_bulk_len = get_max_bulk_query_len(dev);
|
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
u32 *bulk_query_out_tmp;
|
|
|
|
|
int max_out_len;
|
|
|
|
|
int out_len;
|
|
|
|
|
|
|
|
|
|
if (fc_stats->bulk_query_alloc_failed &&
|
|
|
|
|
time_before(now, fc_stats->next_bulk_query_alloc))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
max_out_len = mlx5_cmd_fc_get_bulk_query_out_len(max_bulk_len);
|
|
|
|
|
bulk_query_out_tmp = kzalloc(max_out_len, GFP_KERNEL);
|
|
|
|
|
out_len = mlx5_cmd_fc_get_bulk_query_out_len(bulk_query_len);
|
|
|
|
|
bulk_query_out_tmp = kvzalloc(out_len, GFP_KERNEL);
|
|
|
|
|
if (!bulk_query_out_tmp) {
|
|
|
|
|
mlx5_core_warn_once(dev,
|
|
|
|
|
"Can't increase flow counters bulk query buffer size, insufficient memory, bulk_size(%d)\n",
|
|
|
|
|
max_bulk_len);
|
|
|
|
|
fc_stats->bulk_query_alloc_failed = true;
|
|
|
|
|
fc_stats->next_bulk_query_alloc =
|
|
|
|
|
now + MLX5_FC_BULK_QUERY_ALLOC_PERIOD;
|
|
|
|
|
"Can't increase flow counters bulk query buffer size, alloc failed, bulk_query_len(%d)\n",
|
|
|
|
|
bulk_query_len);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kfree(fc_stats->bulk_query_out);
|
|
|
|
|
kvfree(fc_stats->bulk_query_out);
|
|
|
|
|
fc_stats->bulk_query_out = bulk_query_out_tmp;
|
|
|
|
|
fc_stats->bulk_query_len = max_bulk_len;
|
|
|
|
|
if (fc_stats->bulk_query_alloc_failed) {
|
|
|
|
|
mlx5_core_info(dev,
|
|
|
|
|
"Flow counters bulk query buffer size increased, bulk_size(%d)\n",
|
|
|
|
|
max_bulk_len);
|
|
|
|
|
fc_stats->bulk_query_alloc_failed = false;
|
|
|
|
|
}
|
|
|
|
|
fc_stats->bulk_query_len = bulk_query_len;
|
|
|
|
|
mlx5_core_info(dev,
|
|
|
|
|
"Flow counters bulk query buffer size increased, bulk_query_len(%d)\n",
|
|
|
|
|
bulk_query_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int mlx5_fc_num_counters(struct mlx5_fc_stats *fc_stats)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc *counter;
|
|
|
|
|
int num_counters = 0;
|
|
|
|
|
unsigned long id;
|
|
|
|
|
|
|
|
|
|
xa_for_each(&fc_stats->counters, id, counter)
|
|
|
|
|
num_counters++;
|
|
|
|
|
return num_counters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mlx5_fc_stats_work(struct work_struct *work)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_core_dev *dev = container_of(work, struct mlx5_core_dev,
|
|
|
|
|
priv.fc_stats.work.work);
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
/* Take dellist first to ensure that counters cannot be deleted before
|
|
|
|
|
* they are inserted.
|
|
|
|
|
*/
|
|
|
|
|
struct llist_node *dellist = llist_del_all(&fc_stats->dellist);
|
|
|
|
|
struct llist_node *addlist = llist_del_all(&fc_stats->addlist);
|
|
|
|
|
struct mlx5_fc *counter = NULL, *last = NULL, *tmp;
|
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = container_of(work, struct mlx5_fc_stats,
|
|
|
|
|
work.work);
|
|
|
|
|
struct mlx5_core_dev *dev = fc_stats->fc_pool.dev;
|
|
|
|
|
|
|
|
|
|
if (addlist || !list_empty(&fc_stats->counters))
|
|
|
|
|
queue_delayed_work(fc_stats->wq, &fc_stats->work,
|
|
|
|
|
fc_stats->sampling_interval);
|
|
|
|
|
queue_delayed_work(fc_stats->wq, &fc_stats->work, fc_stats->sampling_interval);
|
|
|
|
|
|
|
|
|
|
llist_for_each_entry(counter, addlist, addlist) {
|
|
|
|
|
mlx5_fc_stats_insert(dev, counter);
|
|
|
|
|
fc_stats->num_counters++;
|
|
|
|
|
}
|
|
|
|
|
/* Grow the bulk query buffer to max if not maxed and enough counters are present. */
|
|
|
|
|
if (unlikely(fc_stats->bulk_query_len < get_max_bulk_query_len(dev) &&
|
|
|
|
|
mlx5_fc_num_counters(fc_stats) > get_init_bulk_query_len(dev)))
|
|
|
|
|
mlx5_fc_stats_bulk_query_buf_realloc(dev, get_max_bulk_query_len(dev));
|
|
|
|
|
|
|
|
|
|
llist_for_each_entry_safe(counter, tmp, dellist, dellist) {
|
|
|
|
|
mlx5_fc_stats_remove(dev, counter);
|
|
|
|
|
|
|
|
|
|
mlx5_fc_release(dev, counter);
|
|
|
|
|
fc_stats->num_counters--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fc_stats->bulk_query_len < get_max_bulk_query_len(dev) &&
|
|
|
|
|
fc_stats->num_counters > get_init_bulk_query_len(dev))
|
|
|
|
|
mlx5_fc_stats_bulk_query_size_increase(dev);
|
|
|
|
|
|
|
|
|
|
if (time_before(now, fc_stats->next_query) ||
|
|
|
|
|
list_empty(&fc_stats->counters))
|
|
|
|
|
return;
|
|
|
|
|
last = list_last_entry(&fc_stats->counters, struct mlx5_fc, list);
|
|
|
|
|
|
|
|
|
|
counter = list_first_entry(&fc_stats->counters, struct mlx5_fc,
|
|
|
|
|
list);
|
|
|
|
|
if (counter)
|
|
|
|
|
mlx5_fc_stats_query_counter_range(dev, counter, last->id);
|
|
|
|
|
|
|
|
|
|
fc_stats->next_query = now + fc_stats->sampling_interval;
|
|
|
|
|
mlx5_fc_stats_query_all_counters(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev)
|
|
|
|
|
@@ -334,7 +263,7 @@ static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev)
|
|
|
|
|
|
|
|
|
|
static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc *counter;
|
|
|
|
|
|
|
|
|
|
if (aging && MLX5_CAP_GEN(dev, flow_counter_bulk_alloc) != 0) {
|
|
|
|
|
@@ -346,16 +275,15 @@ static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
return mlx5_fc_single_alloc(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc *counter = mlx5_fc_acquire(dev, aging);
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (IS_ERR(counter))
|
|
|
|
|
return counter;
|
|
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&counter->list);
|
|
|
|
|
counter->aging = aging;
|
|
|
|
|
|
|
|
|
|
if (aging) {
|
|
|
|
|
@@ -365,18 +293,9 @@ struct mlx5_fc *mlx5_fc_create_ex(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
counter->lastbytes = counter->cache.bytes;
|
|
|
|
|
counter->lastpackets = counter->cache.packets;
|
|
|
|
|
|
|
|
|
|
idr_preload(GFP_KERNEL);
|
|
|
|
|
spin_lock(&fc_stats->counters_idr_lock);
|
|
|
|
|
|
|
|
|
|
err = idr_alloc_u32(&fc_stats->counters_idr, counter, &id, id,
|
|
|
|
|
GFP_NOWAIT);
|
|
|
|
|
|
|
|
|
|
spin_unlock(&fc_stats->counters_idr_lock);
|
|
|
|
|
idr_preload_end();
|
|
|
|
|
if (err)
|
|
|
|
|
err = xa_err(xa_store(&fc_stats->counters, id, counter, GFP_KERNEL));
|
|
|
|
|
if (err != 0)
|
|
|
|
|
goto err_out_alloc;
|
|
|
|
|
|
|
|
|
|
llist_add(&counter->addlist, &fc_stats->addlist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return counter;
|
|
|
|
|
@@ -385,16 +304,6 @@ err_out_alloc:
|
|
|
|
|
mlx5_fc_release(dev, counter);
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc *counter = mlx5_fc_create_ex(dev, aging);
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
if (aging)
|
|
|
|
|
mod_delayed_work(fc_stats->wq, &fc_stats->work, 0);
|
|
|
|
|
return counter;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(mlx5_fc_create);
|
|
|
|
|
|
|
|
|
|
u32 mlx5_fc_id(struct mlx5_fc *counter)
|
|
|
|
|
@@ -405,39 +314,32 @@ EXPORT_SYMBOL(mlx5_fc_id);
|
|
|
|
|
|
|
|
|
|
void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
if (!counter)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (counter->aging) {
|
|
|
|
|
llist_add(&counter->dellist, &fc_stats->dellist);
|
|
|
|
|
mod_delayed_work(fc_stats->wq, &fc_stats->work, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (counter->aging)
|
|
|
|
|
xa_erase(&fc_stats->counters, counter->id);
|
|
|
|
|
mlx5_fc_release(dev, counter);
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(mlx5_fc_destroy);
|
|
|
|
|
|
|
|
|
|
int mlx5_init_fc_stats(struct mlx5_core_dev *dev)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
int init_bulk_len;
|
|
|
|
|
int init_out_len;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats;
|
|
|
|
|
|
|
|
|
|
spin_lock_init(&fc_stats->counters_idr_lock);
|
|
|
|
|
idr_init(&fc_stats->counters_idr);
|
|
|
|
|
INIT_LIST_HEAD(&fc_stats->counters);
|
|
|
|
|
init_llist_head(&fc_stats->addlist);
|
|
|
|
|
init_llist_head(&fc_stats->dellist);
|
|
|
|
|
|
|
|
|
|
init_bulk_len = get_init_bulk_query_len(dev);
|
|
|
|
|
init_out_len = mlx5_cmd_fc_get_bulk_query_out_len(init_bulk_len);
|
|
|
|
|
fc_stats->bulk_query_out = kzalloc(init_out_len, GFP_KERNEL);
|
|
|
|
|
if (!fc_stats->bulk_query_out)
|
|
|
|
|
fc_stats = kzalloc(sizeof(*fc_stats), GFP_KERNEL);
|
|
|
|
|
if (!fc_stats)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
fc_stats->bulk_query_len = init_bulk_len;
|
|
|
|
|
dev->priv.fc_stats = fc_stats;
|
|
|
|
|
|
|
|
|
|
xa_init(&fc_stats->counters);
|
|
|
|
|
|
|
|
|
|
/* Allocate initial (small) bulk query buffer. */
|
|
|
|
|
mlx5_fc_stats_bulk_query_buf_realloc(dev, get_init_bulk_query_len(dev));
|
|
|
|
|
if (!fc_stats->bulk_query_out)
|
|
|
|
|
goto err_bulk;
|
|
|
|
|
|
|
|
|
|
fc_stats->wq = create_singlethread_workqueue("mlx5_fc");
|
|
|
|
|
if (!fc_stats->wq)
|
|
|
|
|
@@ -447,34 +349,35 @@ int mlx5_init_fc_stats(struct mlx5_core_dev *dev)
|
|
|
|
|
INIT_DELAYED_WORK(&fc_stats->work, mlx5_fc_stats_work);
|
|
|
|
|
|
|
|
|
|
mlx5_fc_pool_init(&fc_stats->fc_pool, dev);
|
|
|
|
|
queue_delayed_work(fc_stats->wq, &fc_stats->work, MLX5_FC_STATS_PERIOD);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err_wq_create:
|
|
|
|
|
kfree(fc_stats->bulk_query_out);
|
|
|
|
|
kvfree(fc_stats->bulk_query_out);
|
|
|
|
|
err_bulk:
|
|
|
|
|
kfree(fc_stats);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mlx5_cleanup_fc_stats(struct mlx5_core_dev *dev)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct llist_node *tmplist;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc *counter;
|
|
|
|
|
struct mlx5_fc *tmp;
|
|
|
|
|
unsigned long id;
|
|
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&dev->priv.fc_stats.work);
|
|
|
|
|
destroy_workqueue(dev->priv.fc_stats.wq);
|
|
|
|
|
dev->priv.fc_stats.wq = NULL;
|
|
|
|
|
cancel_delayed_work_sync(&fc_stats->work);
|
|
|
|
|
destroy_workqueue(fc_stats->wq);
|
|
|
|
|
fc_stats->wq = NULL;
|
|
|
|
|
|
|
|
|
|
tmplist = llist_del_all(&fc_stats->addlist);
|
|
|
|
|
llist_for_each_entry_safe(counter, tmp, tmplist, addlist)
|
|
|
|
|
mlx5_fc_release(dev, counter);
|
|
|
|
|
|
|
|
|
|
list_for_each_entry_safe(counter, tmp, &fc_stats->counters, list)
|
|
|
|
|
xa_for_each(&fc_stats->counters, id, counter) {
|
|
|
|
|
xa_erase(&fc_stats->counters, id);
|
|
|
|
|
mlx5_fc_release(dev, counter);
|
|
|
|
|
}
|
|
|
|
|
xa_destroy(&fc_stats->counters);
|
|
|
|
|
|
|
|
|
|
mlx5_fc_pool_cleanup(&fc_stats->fc_pool);
|
|
|
|
|
idr_destroy(&fc_stats->counters_idr);
|
|
|
|
|
kfree(fc_stats->bulk_query_out);
|
|
|
|
|
kvfree(fc_stats->bulk_query_out);
|
|
|
|
|
kfree(fc_stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int mlx5_fc_query(struct mlx5_core_dev *dev, struct mlx5_fc *counter,
|
|
|
|
|
@@ -518,7 +421,7 @@ void mlx5_fc_queue_stats_work(struct mlx5_core_dev *dev,
|
|
|
|
|
struct delayed_work *dwork,
|
|
|
|
|
unsigned long delay)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
queue_delayed_work(fc_stats->wq, dwork, delay);
|
|
|
|
|
}
|
|
|
|
|
@@ -526,7 +429,7 @@ void mlx5_fc_queue_stats_work(struct mlx5_core_dev *dev,
|
|
|
|
|
void mlx5_fc_update_sampling_interval(struct mlx5_core_dev *dev,
|
|
|
|
|
unsigned long interval)
|
|
|
|
|
{
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;
|
|
|
|
|
struct mlx5_fc_stats *fc_stats = dev->priv.fc_stats;
|
|
|
|
|
|
|
|
|
|
fc_stats->sampling_interval = min_t(unsigned long, interval,
|
|
|
|
|
fc_stats->sampling_interval);
|
|
|
|
|
|