Skip to content

Commit 5995ef8

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: realloc VSI stats arrays
Previously only case when queues amount is lower was covered. Implement realloc for case when queues amount is higher than previous one. Use krealloc() function and zero new allocated elements. It has to be done before ice_vsi_def_cfg(), because stats element for ring is set there. Reviewed-by: Wojciech Drewek <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 86197ad commit 5995ef8

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,42 +3076,63 @@ ice_vsi_rebuild_set_coalesce(struct ice_vsi *vsi,
30763076
}
30773077

30783078
/**
3079-
* ice_vsi_realloc_stat_arrays - Frees unused stat structures
3079+
* ice_vsi_realloc_stat_arrays - Frees unused stat structures or alloc new ones
30803080
* @vsi: VSI pointer
3081-
* @prev_txq: Number of Tx rings before ring reallocation
3082-
* @prev_rxq: Number of Rx rings before ring reallocation
30833081
*/
3084-
static void
3085-
ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
3082+
static int
3083+
ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi)
30863084
{
3085+
u16 req_txq = vsi->req_txq ? vsi->req_txq : vsi->alloc_txq;
3086+
u16 req_rxq = vsi->req_rxq ? vsi->req_rxq : vsi->alloc_rxq;
3087+
struct ice_ring_stats **tx_ring_stats;
3088+
struct ice_ring_stats **rx_ring_stats;
30873089
struct ice_vsi_stats *vsi_stat;
30883090
struct ice_pf *pf = vsi->back;
3091+
u16 prev_txq = vsi->alloc_txq;
3092+
u16 prev_rxq = vsi->alloc_rxq;
30893093
int i;
30903094

3091-
if (!prev_txq || !prev_rxq)
3092-
return;
3093-
if (vsi->type == ICE_VSI_CHNL)
3094-
return;
3095-
30963095
vsi_stat = pf->vsi_stats[vsi->idx];
30973096

3098-
if (vsi->num_txq < prev_txq) {
3099-
for (i = vsi->num_txq; i < prev_txq; i++) {
3097+
if (req_txq < prev_txq) {
3098+
for (i = req_txq; i < prev_txq; i++) {
31003099
if (vsi_stat->tx_ring_stats[i]) {
31013100
kfree_rcu(vsi_stat->tx_ring_stats[i], rcu);
31023101
WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL);
31033102
}
31043103
}
31053104
}
31063105

3107-
if (vsi->num_rxq < prev_rxq) {
3108-
for (i = vsi->num_rxq; i < prev_rxq; i++) {
3106+
tx_ring_stats = vsi_stat->rx_ring_stats;
3107+
vsi_stat->tx_ring_stats =
3108+
krealloc_array(vsi_stat->tx_ring_stats, req_txq,
3109+
sizeof(*vsi_stat->tx_ring_stats),
3110+
GFP_KERNEL | __GFP_ZERO);
3111+
if (!vsi_stat->tx_ring_stats) {
3112+
vsi_stat->tx_ring_stats = tx_ring_stats;
3113+
return -ENOMEM;
3114+
}
3115+
3116+
if (req_rxq < prev_rxq) {
3117+
for (i = req_rxq; i < prev_rxq; i++) {
31093118
if (vsi_stat->rx_ring_stats[i]) {
31103119
kfree_rcu(vsi_stat->rx_ring_stats[i], rcu);
31113120
WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL);
31123121
}
31133122
}
31143123
}
3124+
3125+
rx_ring_stats = vsi_stat->rx_ring_stats;
3126+
vsi_stat->rx_ring_stats =
3127+
krealloc_array(vsi_stat->rx_ring_stats, req_rxq,
3128+
sizeof(*vsi_stat->rx_ring_stats),
3129+
GFP_KERNEL | __GFP_ZERO);
3130+
if (!vsi_stat->rx_ring_stats) {
3131+
vsi_stat->rx_ring_stats = rx_ring_stats;
3132+
return -ENOMEM;
3133+
}
3134+
3135+
return 0;
31153136
}
31163137

31173138
/**
@@ -3128,9 +3149,9 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
31283149
{
31293150
struct ice_vsi_cfg_params params = {};
31303151
struct ice_coalesce_stored *coalesce;
3131-
int ret, prev_txq, prev_rxq;
31323152
int prev_num_q_vectors = 0;
31333153
struct ice_pf *pf;
3154+
int ret;
31343155

31353156
if (!vsi)
31363157
return -EINVAL;
@@ -3149,8 +3170,9 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
31493170

31503171
prev_num_q_vectors = ice_vsi_rebuild_get_coalesce(vsi, coalesce);
31513172

3152-
prev_txq = vsi->num_txq;
3153-
prev_rxq = vsi->num_rxq;
3173+
ret = ice_vsi_realloc_stat_arrays(vsi);
3174+
if (ret)
3175+
goto err_vsi_cfg;
31543176

31553177
ice_vsi_decfg(vsi);
31563178
ret = ice_vsi_cfg_def(vsi, &params);
@@ -3168,8 +3190,6 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
31683190
return ice_schedule_reset(pf, ICE_RESET_PFR);
31693191
}
31703192

3171-
ice_vsi_realloc_stat_arrays(vsi, prev_txq, prev_rxq);
3172-
31733193
ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors);
31743194
kfree(coalesce);
31753195

0 commit comments

Comments
 (0)