Commit cdeef2b1 authored by Saeed Mahameed's avatar Saeed Mahameed

net/mlx5e: Use non-delayed work for update stats

Convert mlx5e update stats work to a normal work structure, since it is
never used delayed.

Add a helper function to queue update stats work on demand which checks
for some conditions and reduce code duplication to have a better
abstraction.

Fixes: ed56c519 ("net/mlx5e: Update NIC HW stats on demand only")
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 519a0bf5
...@@ -673,7 +673,7 @@ struct mlx5e_priv { ...@@ -673,7 +673,7 @@ struct mlx5e_priv {
struct work_struct update_carrier_work; struct work_struct update_carrier_work;
struct work_struct set_rx_mode_work; struct work_struct set_rx_mode_work;
struct work_struct tx_timeout_work; struct work_struct tx_timeout_work;
struct delayed_work update_stats_work; struct work_struct update_stats_work;
struct mlx5_core_dev *mdev; struct mlx5_core_dev *mdev;
struct net_device *netdev; struct net_device *netdev;
...@@ -927,6 +927,7 @@ void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv); ...@@ -927,6 +927,7 @@ void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
int mlx5e_close(struct net_device *netdev); int mlx5e_close(struct net_device *netdev);
int mlx5e_open(struct net_device *netdev); int mlx5e_open(struct net_device *netdev);
void mlx5e_queue_update_stats(struct mlx5e_priv *priv);
int mlx5e_bits_invert(unsigned long a, int size); int mlx5e_bits_invert(unsigned long a, int size);
typedef int (*change_hw_mtu_cb)(struct mlx5e_priv *priv); typedef int (*change_hw_mtu_cb)(struct mlx5e_priv *priv);
......
...@@ -274,8 +274,7 @@ static void mlx5e_update_ndo_stats(struct mlx5e_priv *priv) ...@@ -274,8 +274,7 @@ static void mlx5e_update_ndo_stats(struct mlx5e_priv *priv)
static void mlx5e_update_stats_work(struct work_struct *work) static void mlx5e_update_stats_work(struct work_struct *work)
{ {
struct delayed_work *dwork = to_delayed_work(work); struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
struct mlx5e_priv *priv = container_of(dwork, struct mlx5e_priv,
update_stats_work); update_stats_work);
mutex_lock(&priv->state_lock); mutex_lock(&priv->state_lock);
...@@ -283,6 +282,17 @@ static void mlx5e_update_stats_work(struct work_struct *work) ...@@ -283,6 +282,17 @@ static void mlx5e_update_stats_work(struct work_struct *work)
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
} }
void mlx5e_queue_update_stats(struct mlx5e_priv *priv)
{
if (!priv->profile->update_stats)
return;
if (unlikely(test_bit(MLX5E_STATE_DESTROYING, &priv->state)))
return;
queue_work(priv->wq, &priv->update_stats_work);
}
static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv, static void mlx5e_async_event(struct mlx5_core_dev *mdev, void *vpriv,
enum mlx5_dev_event event, unsigned long param) enum mlx5_dev_event event, unsigned long param)
{ {
...@@ -2957,9 +2967,7 @@ int mlx5e_open_locked(struct net_device *netdev) ...@@ -2957,9 +2967,7 @@ int mlx5e_open_locked(struct net_device *netdev)
if (priv->profile->update_carrier) if (priv->profile->update_carrier)
priv->profile->update_carrier(priv); priv->profile->update_carrier(priv);
if (priv->profile->update_stats) mlx5e_queue_update_stats(priv);
queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
return 0; return 0;
err_clear_state_opened_flag: err_clear_state_opened_flag:
...@@ -3441,7 +3449,7 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) ...@@ -3441,7 +3449,7 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
struct mlx5e_pport_stats *pstats = &priv->stats.pport; struct mlx5e_pport_stats *pstats = &priv->stats.pport;
/* update HW stats in background for next time */ /* update HW stats in background for next time */
queue_delayed_work(priv->wq, &priv->update_stats_work, 0); mlx5e_queue_update_stats(priv);
if (mlx5e_is_uplink_rep(priv)) { if (mlx5e_is_uplink_rep(priv)) {
stats->rx_packets = PPORT_802_3_GET(pstats, a_frames_received_ok); stats->rx_packets = PPORT_802_3_GET(pstats, a_frames_received_ok);
...@@ -4946,7 +4954,7 @@ int mlx5e_netdev_init(struct net_device *netdev, ...@@ -4946,7 +4954,7 @@ int mlx5e_netdev_init(struct net_device *netdev,
INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work); INIT_WORK(&priv->update_carrier_work, mlx5e_update_carrier_work);
INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work); INIT_WORK(&priv->set_rx_mode_work, mlx5e_set_rx_mode_work);
INIT_WORK(&priv->tx_timeout_work, mlx5e_tx_timeout_work); INIT_WORK(&priv->tx_timeout_work, mlx5e_tx_timeout_work);
INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work); INIT_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
priv->wq = create_singlethread_workqueue("mlx5e"); priv->wq = create_singlethread_workqueue("mlx5e");
if (!priv->wq) if (!priv->wq)
...@@ -5037,7 +5045,7 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv) ...@@ -5037,7 +5045,7 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)
profile->cleanup_rx(priv); profile->cleanup_rx(priv);
profile->cleanup_tx(priv); profile->cleanup_tx(priv);
cancel_delayed_work_sync(&priv->update_stats_work); cancel_work_sync(&priv->update_stats_work);
} }
void mlx5e_destroy_netdev(struct mlx5e_priv *priv) void mlx5e_destroy_netdev(struct mlx5e_priv *priv)
......
...@@ -992,8 +992,7 @@ mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) ...@@ -992,8 +992,7 @@ mlx5e_rep_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
struct mlx5e_priv *priv = netdev_priv(dev); struct mlx5e_priv *priv = netdev_priv(dev);
/* update HW stats in background for next time */ /* update HW stats in background for next time */
queue_delayed_work(priv->wq, &priv->update_stats_work, 0); mlx5e_queue_update_stats(priv);
memcpy(stats, &priv->stats.vf_vport, sizeof(*stats)); memcpy(stats, &priv->stats.vf_vport, sizeof(*stats));
} }
......
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