Skip to content

Commit c3bdbae

Browse files
msanallaSaeed Mahameed
authored andcommitted
net/mlx5: Store page counters in a single array
Currently, an independent page counter is used for tracking memory usage for each function type such as VF, PF and host PF (DPU). For better code-readibilty, use a single array that stores the number of allocated memory pages for each function type. Signed-off-by: Maher Sanalla <[email protected]> Reviewed-by: Shay Drory <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 8aa5f17 commit c3bdbae

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

drivers/net/ethernet/mellanox/mlx5/core/debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ void mlx5_pages_debugfs_init(struct mlx5_core_dev *dev)
245245
pages = dev->priv.dbg.pages_debugfs;
246246

247247
debugfs_create_u32("fw_pages_total", 0400, pages, &dev->priv.fw_pages);
248-
debugfs_create_u32("fw_pages_vfs", 0400, pages, &dev->priv.vfs_pages);
249-
debugfs_create_u32("fw_pages_host_pf", 0400, pages, &dev->priv.host_pf_pages);
248+
debugfs_create_u32("fw_pages_vfs", 0400, pages, &dev->priv.page_counters[MLX5_VF]);
249+
debugfs_create_u32("fw_pages_host_pf", 0400, pages, &dev->priv.page_counters[MLX5_HOST_PF]);
250250
debugfs_create_u32("fw_pages_alloc_failed", 0400, pages, &dev->priv.fw_pages_alloc_failed);
251251
debugfs_create_u32("fw_pages_give_dropped", 0400, pages, &dev->priv.give_pages_dropped);
252252
debugfs_create_u32("fw_pages_reclaim_discard", 0400, pages,

drivers/net/ethernet/mellanox/mlx5/core/ecpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void mlx5_ec_cleanup(struct mlx5_core_dev *dev)
8787

8888
mlx5_host_pf_cleanup(dev);
8989

90-
err = mlx5_wait_for_pages(dev, &dev->priv.host_pf_pages);
90+
err = mlx5_wait_for_pages(dev, &dev->priv.page_counters[MLX5_HOST_PF]);
9191
if (err)
9292
mlx5_core_warn(dev, "Timeout reclaiming external host PF pages err(%d)\n", err);
9393
}

drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ static u32 get_function(u16 func_id, bool ec_function)
7474
return (u32)func_id | (ec_function << 16);
7575
}
7676

77+
static u16 func_id_to_type(struct mlx5_core_dev *dev, u16 func_id, bool ec_function)
78+
{
79+
if (!func_id)
80+
return mlx5_core_is_ecpf(dev) && !ec_function ? MLX5_HOST_PF : MLX5_PF;
81+
82+
return MLX5_VF;
83+
}
84+
7785
static struct rb_root *page_root_per_function(struct mlx5_core_dev *dev, u32 function)
7886
{
7987
struct rb_root *root;
@@ -332,6 +340,7 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
332340
u32 out[MLX5_ST_SZ_DW(manage_pages_out)] = {0};
333341
int inlen = MLX5_ST_SZ_BYTES(manage_pages_in);
334342
int notify_fail = event;
343+
u16 func_type;
335344
u64 addr;
336345
int err;
337346
u32 *in;
@@ -383,11 +392,9 @@ static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
383392
goto out_dropped;
384393
}
385394

395+
func_type = func_id_to_type(dev, func_id, ec_function);
396+
dev->priv.page_counters[func_type] += npages;
386397
dev->priv.fw_pages += npages;
387-
if (func_id)
388-
dev->priv.vfs_pages += npages;
389-
else if (mlx5_core_is_ecpf(dev) && !ec_function)
390-
dev->priv.host_pf_pages += npages;
391398

392399
mlx5_core_dbg(dev, "npages %d, ec_function %d, func_id 0x%x, err %d\n",
393400
npages, ec_function, func_id, err);
@@ -414,6 +421,7 @@ static void release_all_pages(struct mlx5_core_dev *dev, u16 func_id,
414421
struct rb_root *root;
415422
struct rb_node *p;
416423
int npages = 0;
424+
u16 func_type;
417425

418426
root = xa_load(&dev->priv.page_root_xa, function);
419427
if (WARN_ON_ONCE(!root))
@@ -428,11 +436,9 @@ static void release_all_pages(struct mlx5_core_dev *dev, u16 func_id,
428436
free_fwp(dev, fwp, fwp->free_count);
429437
}
430438

439+
func_type = func_id_to_type(dev, func_id, ec_function);
440+
dev->priv.page_counters[func_type] -= npages;
431441
dev->priv.fw_pages -= npages;
432-
if (func_id)
433-
dev->priv.vfs_pages -= npages;
434-
else if (mlx5_core_is_ecpf(dev) && !ec_function)
435-
dev->priv.host_pf_pages -= npages;
436442

437443
mlx5_core_dbg(dev, "npages %d, ec_function %d, func_id 0x%x\n",
438444
npages, ec_function, func_id);
@@ -498,6 +504,7 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
498504
int outlen = MLX5_ST_SZ_BYTES(manage_pages_out);
499505
u32 in[MLX5_ST_SZ_DW(manage_pages_in)] = {};
500506
int num_claimed;
507+
u16 func_type;
501508
u32 *out;
502509
int err;
503510
int i;
@@ -549,11 +556,9 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u16 func_id, int npages,
549556
if (nclaimed)
550557
*nclaimed = num_claimed;
551558

559+
func_type = func_id_to_type(dev, func_id, ec_function);
560+
dev->priv.page_counters[func_type] -= num_claimed;
552561
dev->priv.fw_pages -= num_claimed;
553-
if (func_id)
554-
dev->priv.vfs_pages -= num_claimed;
555-
else if (mlx5_core_is_ecpf(dev) && !ec_function)
556-
dev->priv.host_pf_pages -= num_claimed;
557562

558563
out_free:
559564
kvfree(out);
@@ -706,12 +711,12 @@ int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev)
706711
WARN(dev->priv.fw_pages,
707712
"FW pages counter is %d after reclaiming all pages\n",
708713
dev->priv.fw_pages);
709-
WARN(dev->priv.vfs_pages,
714+
WARN(dev->priv.page_counters[MLX5_VF],
710715
"VFs FW pages counter is %d after reclaiming all pages\n",
711-
dev->priv.vfs_pages);
712-
WARN(dev->priv.host_pf_pages,
716+
dev->priv.page_counters[MLX5_VF]);
717+
WARN(dev->priv.page_counters[MLX5_HOST_PF],
713718
"External host PF FW pages counter is %d after reclaiming all pages\n",
714-
dev->priv.host_pf_pages);
719+
dev->priv.page_counters[MLX5_HOST_PF]);
715720

716721
return 0;
717722
}

drivers/net/ethernet/mellanox/mlx5/core/sriov.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mlx5_device_disable_sriov(struct mlx5_core_dev *dev, int num_vfs, bool clear_vf)
147147

148148
mlx5_eswitch_disable_sriov(dev->priv.eswitch, clear_vf);
149149

150-
if (mlx5_wait_for_pages(dev, &dev->priv.vfs_pages))
150+
if (mlx5_wait_for_pages(dev, &dev->priv.page_counters[MLX5_VF]))
151151
mlx5_core_warn(dev, "timeout reclaiming VFs pages\n");
152152
}
153153

include/linux/mlx5/driver.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ struct mlx5_debugfs_entries {
573573
struct dentry *lag_debugfs;
574574
};
575575

576+
enum mlx5_func_type {
577+
MLX5_PF,
578+
MLX5_VF,
579+
MLX5_HOST_PF,
580+
MLX5_FUNC_TYPE_NUM,
581+
};
582+
576583
struct mlx5_ft_pool;
577584
struct mlx5_priv {
578585
/* IRQ table valid only for real pci devices PF or VF */
@@ -583,11 +590,10 @@ struct mlx5_priv {
583590
struct mlx5_nb pg_nb;
584591
struct workqueue_struct *pg_wq;
585592
struct xarray page_root_xa;
586-
u32 fw_pages;
587593
atomic_t reg_pages;
588594
struct list_head free_list;
589-
u32 vfs_pages;
590-
u32 host_pf_pages;
595+
u32 fw_pages;
596+
u32 page_counters[MLX5_FUNC_TYPE_NUM];
591597
u32 fw_pages_alloc_failed;
592598
u32 give_pages_dropped;
593599
u32 reclaim_pages_discard;

0 commit comments

Comments
 (0)