]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mlxsw: spectrum_qdisc: Extract a per-TC stat function
authorPetr Machata <petrm@mellanox.com>
Fri, 24 Jan 2020 13:23:07 +0000 (15:23 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 25 Jan 2020 09:56:31 +0000 (10:56 +0100)
Extract from mlxsw_sp_qdisc_get_prio_stats() two new functions:
mlxsw_sp_qdisc_collect_tc_stats() to accumulate stats for that one TC only,
and mlxsw_sp_qdisc_update_stats() that makes the stats relative to base
values stored earlier. Use them from mlxsw_sp_qdisc_get_red_stats().

Signed-off-by: Petr Machata <petrm@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_qdisc.c

index d57c9b15f45e44bd50abd1fb0b874c6ee9edfd4c..ef63b8cbbc9468d8838f92bd32c65557f52d5e28 100644 (file)
@@ -227,6 +227,52 @@ mlxsw_sp_qdisc_bstats_per_priority_get(struct mlxsw_sp_port_xstats *xstats,
        }
 }
 
+static void
+mlxsw_sp_qdisc_collect_tc_stats(struct mlxsw_sp_port *mlxsw_sp_port,
+                               struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
+                               u64 *p_tx_bytes, u64 *p_tx_packets,
+                               u64 *p_drops, u64 *p_backlog)
+{
+       u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
+       struct mlxsw_sp_port_xstats *xstats;
+       u64 tx_bytes, tx_packets;
+
+       xstats = &mlxsw_sp_port->periodic_hw_stats.xstats;
+       mlxsw_sp_qdisc_bstats_per_priority_get(xstats,
+                                              mlxsw_sp_qdisc->prio_bitmap,
+                                              &tx_packets, &tx_bytes);
+
+       *p_tx_packets += tx_packets;
+       *p_tx_bytes += tx_bytes;
+       *p_drops += xstats->wred_drop[tclass_num] +
+                   mlxsw_sp_xstats_tail_drop(xstats, tclass_num);
+       *p_backlog += mlxsw_sp_xstats_backlog(xstats, tclass_num);
+}
+
+static void
+mlxsw_sp_qdisc_update_stats(struct mlxsw_sp *mlxsw_sp,
+                           struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
+                           u64 tx_bytes, u64 tx_packets,
+                           u64 drops, u64 backlog,
+                           struct tc_qopt_offload_stats *stats_ptr)
+{
+       struct mlxsw_sp_qdisc_stats *stats_base = &mlxsw_sp_qdisc->stats_base;
+
+       tx_bytes -= stats_base->tx_bytes;
+       tx_packets -= stats_base->tx_packets;
+       drops -= stats_base->drops;
+       backlog -= stats_base->backlog;
+
+       _bstats_update(stats_ptr->bstats, tx_bytes, tx_packets);
+       stats_ptr->qstats->drops += drops;
+       stats_ptr->qstats->backlog += mlxsw_sp_cells_bytes(mlxsw_sp, backlog);
+
+       stats_base->backlog += backlog;
+       stats_base->drops += drops;
+       stats_base->tx_bytes += tx_bytes;
+       stats_base->tx_packets += tx_packets;
+}
+
 static int
 mlxsw_sp_tclass_congestion_enable(struct mlxsw_sp_port *mlxsw_sp_port,
                                  int tclass_num, u32 min, u32 max,
@@ -403,41 +449,30 @@ mlxsw_sp_qdisc_get_red_stats(struct mlxsw_sp_port *mlxsw_sp_port,
                             struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
                             struct tc_qopt_offload_stats *stats_ptr)
 {
-       u64 tx_bytes, tx_packets, overlimits, drops, backlog;
        u8 tclass_num = mlxsw_sp_qdisc->tclass_num;
        struct mlxsw_sp_qdisc_stats *stats_base;
        struct mlxsw_sp_port_xstats *xstats;
+       u64 tx_packets = 0;
+       u64 tx_bytes = 0;
+       u64 backlog = 0;
+       u64 overlimits;
+       u64 drops = 0;
 
        xstats = &mlxsw_sp_port->periodic_hw_stats.xstats;
        stats_base = &mlxsw_sp_qdisc->stats_base;
 
-       mlxsw_sp_qdisc_bstats_per_priority_get(xstats,
-                                              mlxsw_sp_qdisc->prio_bitmap,
-                                              &tx_packets, &tx_bytes);
-       tx_bytes = tx_bytes - stats_base->tx_bytes;
-       tx_packets = tx_packets - stats_base->tx_packets;
-
+       mlxsw_sp_qdisc_collect_tc_stats(mlxsw_sp_port, mlxsw_sp_qdisc,
+                                       &tx_bytes, &tx_packets,
+                                       &drops, &backlog);
        overlimits = xstats->wred_drop[tclass_num] + xstats->ecn -
                     stats_base->overlimits;
-       drops = xstats->wred_drop[tclass_num] +
-               mlxsw_sp_xstats_tail_drop(xstats, tclass_num) -
-               stats_base->drops;
-       backlog = mlxsw_sp_xstats_backlog(xstats, tclass_num);
 
-       _bstats_update(stats_ptr->bstats, tx_bytes, tx_packets);
+       mlxsw_sp_qdisc_update_stats(mlxsw_sp_port->mlxsw_sp, mlxsw_sp_qdisc,
+                                   tx_bytes, tx_packets, drops, backlog,
+                                   stats_ptr);
        stats_ptr->qstats->overlimits += overlimits;
-       stats_ptr->qstats->drops += drops;
-       stats_ptr->qstats->backlog +=
-                               mlxsw_sp_cells_bytes(mlxsw_sp_port->mlxsw_sp,
-                                                    backlog) -
-                               mlxsw_sp_cells_bytes(mlxsw_sp_port->mlxsw_sp,
-                                                    stats_base->backlog);
-
-       stats_base->backlog = backlog;
-       stats_base->drops +=  drops;
        stats_base->overlimits += overlimits;
-       stats_base->tx_bytes += tx_bytes;
-       stats_base->tx_packets += tx_packets;
+
        return 0;
 }
 
@@ -628,37 +663,23 @@ mlxsw_sp_qdisc_get_prio_stats(struct mlxsw_sp_port *mlxsw_sp_port,
                              struct mlxsw_sp_qdisc *mlxsw_sp_qdisc,
                              struct tc_qopt_offload_stats *stats_ptr)
 {
-       u64 tx_bytes, tx_packets, drops = 0, backlog = 0;
-       struct mlxsw_sp_qdisc_stats *stats_base;
-       struct mlxsw_sp_port_xstats *xstats;
-       struct rtnl_link_stats64 *stats;
+       struct mlxsw_sp_qdisc *tc_qdisc;
+       u64 tx_packets = 0;
+       u64 tx_bytes = 0;
+       u64 backlog = 0;
+       u64 drops = 0;
        int i;
 
-       xstats = &mlxsw_sp_port->periodic_hw_stats.xstats;
-       stats = &mlxsw_sp_port->periodic_hw_stats.stats;
-       stats_base = &mlxsw_sp_qdisc->stats_base;
-
-       tx_bytes = stats->tx_bytes - stats_base->tx_bytes;
-       tx_packets = stats->tx_packets - stats_base->tx_packets;
-
        for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
-               drops += mlxsw_sp_xstats_tail_drop(xstats, i);
-               drops += xstats->wred_drop[i];
-               backlog += mlxsw_sp_xstats_backlog(xstats, i);
+               tc_qdisc = &mlxsw_sp_port->tclass_qdiscs[i];
+               mlxsw_sp_qdisc_collect_tc_stats(mlxsw_sp_port, tc_qdisc,
+                                               &tx_bytes, &tx_packets,
+                                               &drops, &backlog);
        }
-       drops = drops - stats_base->drops;
 
-       _bstats_update(stats_ptr->bstats, tx_bytes, tx_packets);
-       stats_ptr->qstats->drops += drops;
-       stats_ptr->qstats->backlog +=
-                               mlxsw_sp_cells_bytes(mlxsw_sp_port->mlxsw_sp,
-                                                    backlog) -
-                               mlxsw_sp_cells_bytes(mlxsw_sp_port->mlxsw_sp,
-                                                    stats_base->backlog);
-       stats_base->backlog = backlog;
-       stats_base->drops += drops;
-       stats_base->tx_bytes += tx_bytes;
-       stats_base->tx_packets += tx_packets;
+       mlxsw_sp_qdisc_update_stats(mlxsw_sp_port->mlxsw_sp, mlxsw_sp_qdisc,
+                                   tx_bytes, tx_packets, drops, backlog,
+                                   stats_ptr);
        return 0;
 }