Skip to content

Commit 5c7e8bb

Browse files
Eyal DavidovichSaeed Mahameed
authored andcommitted
net/mlx5e: Use monitor counters for update stats
- Adding new notifier block (struct mlx5_nb) monitor_counters_nb for handeling MONITOR_COUNTER new event type. - Adding work queue element: monitor_counters_work for re-arm and update stats. - We re-queue the update stat work, only when working over firmware that doesn't support the monitored counters. Signed-off-by: Eyal Davidovich <[email protected]> Reviewed-by: Saeed Mahameed <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 2f8bc49 commit 5c7e8bb

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ struct mlx5e_priv {
685685
struct work_struct set_rx_mode_work;
686686
struct work_struct tx_timeout_work;
687687
struct work_struct update_stats_work;
688+
struct work_struct monitor_counters_work;
689+
struct mlx5_nb monitor_counters_nb;
688690

689691
struct mlx5_core_dev *mdev;
690692
struct net_device *netdev;
@@ -940,6 +942,7 @@ int mlx5e_create_tises(struct mlx5e_priv *priv);
940942
void mlx5e_cleanup_nic_tx(struct mlx5e_priv *priv);
941943
int mlx5e_close(struct net_device *netdev);
942944
int mlx5e_open(struct net_device *netdev);
945+
void mlx5e_update_ndo_stats(struct mlx5e_priv *priv);
943946

944947
void mlx5e_queue_update_stats(struct mlx5e_priv *priv);
945948
int mlx5e_bits_invert(unsigned long a, int size);

drivers/net/ethernet/mellanox/mlx5/core/en/monitor_stats.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "en.h"
55
#include "monitor_stats.h"
6+
#include "lib/eq.h"
67

78
/* Driver will set the following watch counters list:
89
* Ppcnt.802_3:
@@ -45,6 +46,39 @@ void mlx5e_monitor_counter_arm(struct mlx5e_priv *priv)
4546
mlx5_cmd_exec(priv->mdev, in, sizeof(in), out, sizeof(out));
4647
}
4748

49+
static void mlx5e_monitor_counters_work(struct work_struct *work)
50+
{
51+
struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
52+
monitor_counters_work);
53+
54+
mutex_lock(&priv->state_lock);
55+
mlx5e_update_ndo_stats(priv);
56+
mutex_unlock(&priv->state_lock);
57+
mlx5e_monitor_counter_arm(priv);
58+
}
59+
60+
static int mlx5e_monitor_event_handler(struct notifier_block *nb,
61+
unsigned long event, void *eqe)
62+
{
63+
struct mlx5e_priv *priv = mlx5_nb_cof(nb, struct mlx5e_priv,
64+
monitor_counters_nb);
65+
queue_work(priv->wq, &priv->monitor_counters_work);
66+
return NOTIFY_OK;
67+
}
68+
69+
void mlx5e_monitor_counter_start(struct mlx5e_priv *priv)
70+
{
71+
MLX5_NB_INIT(&priv->monitor_counters_nb, mlx5e_monitor_event_handler,
72+
MONITOR_COUNTER);
73+
mlx5_eq_notifier_register(priv->mdev, &priv->monitor_counters_nb);
74+
}
75+
76+
static void mlx5e_monitor_counter_stop(struct mlx5e_priv *priv)
77+
{
78+
mlx5_eq_notifier_unregister(priv->mdev, &priv->monitor_counters_nb);
79+
cancel_work_sync(&priv->monitor_counters_work);
80+
}
81+
4882
static int fill_monitor_counter_ppcnt_set1(int cnt, u32 *in)
4983
{
5084
enum mlx5_monitor_counter_ppcnt ppcnt_cnt;
@@ -108,12 +142,14 @@ static void mlx5e_set_monitor_counter(struct mlx5e_priv *priv)
108142
/* check if mlx5e_monitor_counter_supported before calling this function*/
109143
void mlx5e_monitor_counter_init(struct mlx5e_priv *priv)
110144
{
145+
INIT_WORK(&priv->monitor_counters_work, mlx5e_monitor_counters_work);
146+
mlx5e_monitor_counter_start(priv);
111147
mlx5e_set_monitor_counter(priv);
112148
mlx5e_monitor_counter_arm(priv);
149+
queue_work(priv->wq, &priv->update_stats_work);
113150
}
114151

115-
/* check if mlx5e_monitor_counter_supported before calling this function*/
116-
void mlx5e_monitor_counter_cleanup(struct mlx5e_priv *priv)
152+
static void mlx5e_monitor_counter_disable(struct mlx5e_priv *priv)
117153
{
118154
u32 in[MLX5_ST_SZ_DW(set_monitor_counter_in)] = {};
119155
u32 out[MLX5_ST_SZ_DW(set_monitor_counter_out)] = {};
@@ -124,3 +160,10 @@ void mlx5e_monitor_counter_cleanup(struct mlx5e_priv *priv)
124160

125161
mlx5_cmd_exec(priv->mdev, in, sizeof(in), out, sizeof(out));
126162
}
163+
164+
/* check if mlx5e_monitor_counter_supported before calling this function*/
165+
void mlx5e_monitor_counter_cleanup(struct mlx5e_priv *priv)
166+
{
167+
mlx5e_monitor_counter_disable(priv);
168+
mlx5e_monitor_counter_stop(priv);
169+
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "en/port.h"
5151
#include "en/xdp.h"
5252
#include "lib/eq.h"
53+
#include "en/monitor_stats.h"
5354

5455
struct mlx5e_rq_param {
5556
u32 rqc[MLX5_ST_SZ_DW(rqc)];
@@ -263,7 +264,7 @@ void mlx5e_update_stats(struct mlx5e_priv *priv)
263264
mlx5e_stats_grps[i].update_stats(priv);
264265
}
265266

266-
static void mlx5e_update_ndo_stats(struct mlx5e_priv *priv)
267+
void mlx5e_update_ndo_stats(struct mlx5e_priv *priv)
267268
{
268269
int i;
269270

@@ -3459,8 +3460,10 @@ mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats)
34593460
struct mlx5e_vport_stats *vstats = &priv->stats.vport;
34603461
struct mlx5e_pport_stats *pstats = &priv->stats.pport;
34613462

3462-
/* update HW stats in background for next time */
3463-
mlx5e_queue_update_stats(priv);
3463+
if (!mlx5e_monitor_counter_supported(priv)) {
3464+
/* update HW stats in background for next time */
3465+
mlx5e_queue_update_stats(priv);
3466+
}
34643467

34653468
if (mlx5e_is_uplink_rep(priv)) {
34663469
stats->rx_packets = PPORT_802_3_GET(pstats, a_frames_received_ok);
@@ -4901,6 +4904,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
49014904
mlx5_lag_add(mdev, netdev);
49024905

49034906
mlx5e_enable_async_events(priv);
4907+
if (mlx5e_monitor_counter_supported(priv))
4908+
mlx5e_monitor_counter_init(priv);
49044909

49054910
if (MLX5_ESWITCH_MANAGER(priv->mdev))
49064911
mlx5e_register_vport_reps(priv);
@@ -4940,6 +4945,9 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
49404945
if (MLX5_ESWITCH_MANAGER(priv->mdev))
49414946
mlx5e_unregister_vport_reps(priv);
49424947

4948+
if (mlx5e_monitor_counter_supported(priv))
4949+
mlx5e_monitor_counter_cleanup(priv);
4950+
49434951
mlx5e_disable_async_events(priv);
49444952
mlx5_lag_remove(mdev);
49454953
}

0 commit comments

Comments
 (0)