Skip to content

Commit 571faef

Browse files
committed
Merge branch 'ethtool-hw-timestamping-statistics'
Rahul Rameshbabu says: ==================== ethtool HW timestamping statistics The goal of this patch series is to introduce a common set of ethtool statistics for hardware timestamping that a driver implementer can hook into. The statistics counters added are based on what I believe are common patterns/behaviors found across various hardware timestamping implementations seen in the kernel tree today. The mlx5 family of devices is used as the PoC for this patch series. Other vendors are more than welcome to chime in on this series. Link: https://lore.kernel.org/netdev/[email protected]/ Link: https://lore.kernel.org/netdev/[email protected]/ Link: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Rahul Rameshbabu <[email protected]> ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4196aee + 2e0e148 commit 571faef

File tree

12 files changed

+209
-12
lines changed

12 files changed

+209
-12
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ definitions:
1818
entries: []
1919
-
2020
name: header-flags
21-
enum-name:
2221
type: flags
2322
entries: [ compact-bitsets, omit-reply, stats ]
2423

@@ -565,6 +564,18 @@ attribute-sets:
565564
-
566565
name: tx-lpi-timer
567566
type: u32
567+
-
568+
name: ts-stat
569+
attributes:
570+
-
571+
name: tx-pkts
572+
type: uint
573+
-
574+
name: tx-lost
575+
type: uint
576+
-
577+
name: tx-err
578+
type: uint
568579
-
569580
name: tsinfo
570581
attributes:
@@ -587,6 +598,10 @@ attribute-sets:
587598
-
588599
name: phc-index
589600
type: u32
601+
-
602+
name: stats
603+
type: nest
604+
nested-attributes: ts-stat
590605
-
591606
name: cable-result
592607
attributes:
@@ -1394,6 +1409,7 @@ operations:
13941409
- tx-types
13951410
- rx-filters
13961411
- phc-index
1412+
- stats
13971413
dump: *tsinfo-get-op
13981414
-
13991415
name: cable-test-act

Documentation/networking/device_drivers/ethernet/mellanox/mlx5/counters.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ the software port.
300300
in the beginning of the queue. This is a normal condition.
301301
- Informative
302302

303+
* - `tx[i]_timestamps`
304+
- Transmitted packets that were hardware timestamped at the device's DMA
305+
layer.
306+
- Informative
307+
303308
* - `tx[i]_added_vlan_packets`
304309
- The number of packets sent where vlan tag insertion was offloaded to the
305310
hardware.
@@ -702,6 +707,12 @@ the software port.
702707
the device typically ensures not posting the CQE.
703708
- Error
704709

710+
* - `ptp_cq[i]_lost_cqe`
711+
- Number of times a CQE is expected to not be delivered on the PTP
712+
timestamping CQE by the device due to a time delta elapsing. If such a
713+
CQE is somehow delivered, `ptp_cq[i]_late_cqe` is incremented.
714+
- Error
715+
705716
.. [#ring_global] The corresponding ring and global counters do not share the
706717
same name (i.e. do not follow the common naming scheme).
707718

Documentation/networking/ethtool-netlink.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,12 +1237,21 @@ Kernel response contents:
12371237
``ETHTOOL_A_TSINFO_TX_TYPES`` bitset supported Tx types
12381238
``ETHTOOL_A_TSINFO_RX_FILTERS`` bitset supported Rx filters
12391239
``ETHTOOL_A_TSINFO_PHC_INDEX`` u32 PTP hw clock index
1240+
``ETHTOOL_A_TSINFO_STATS`` nested HW timestamping statistics
12401241
===================================== ====== ==========================
12411242

12421243
``ETHTOOL_A_TSINFO_PHC_INDEX`` is absent if there is no associated PHC (there
12431244
is no special value for this case). The bitset attributes are omitted if they
12441245
would be empty (no bit set).
12451246

1247+
Additional hardware timestamping statistics response contents:
1248+
1249+
===================================== ====== ===================================
1250+
``ETHTOOL_A_TS_STAT_TX_PKTS`` u64 Packets with Tx HW timestamps
1251+
``ETHTOOL_A_TS_STAT_TX_LOST`` u64 Tx HW timestamp not arrived count
1252+
``ETHTOOL_A_TS_STAT_TX_ERR`` u64 HW error request Tx timestamp count
1253+
===================================== ====== ===================================
1254+
12461255
CABLE_TEST
12471256
==========
12481257

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static void mlx5e_ptpsq_mark_ts_cqes_undelivered(struct mlx5e_ptpsq *ptpsq,
169169
WARN_ON_ONCE(!pos->inuse);
170170
pos->inuse = false;
171171
list_del(&pos->entry);
172+
ptpsq->cq_stats->lost_cqe++;
172173
}
173174
spin_unlock_bh(&cqe_list->tracker_list_lock);
174175
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,14 @@ static void mlx5e_get_rmon_stats(struct net_device *netdev,
23872387
mlx5e_stats_rmon_get(priv, rmon_stats, ranges);
23882388
}
23892389

2390+
static void mlx5e_get_ts_stats(struct net_device *netdev,
2391+
struct ethtool_ts_stats *ts_stats)
2392+
{
2393+
struct mlx5e_priv *priv = netdev_priv(netdev);
2394+
2395+
mlx5e_stats_ts_get(priv, ts_stats);
2396+
}
2397+
23902398
const struct ethtool_ops mlx5e_ethtool_ops = {
23912399
.cap_rss_ctx_supported = true,
23922400
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
@@ -2436,5 +2444,6 @@ const struct ethtool_ops mlx5e_ethtool_ops = {
24362444
.get_eth_mac_stats = mlx5e_get_eth_mac_stats,
24372445
.get_eth_ctrl_stats = mlx5e_get_eth_ctrl_stats,
24382446
.get_rmon_stats = mlx5e_get_rmon_stats,
2447+
.get_ts_stats = mlx5e_get_ts_stats,
24392448
.get_link_ext_stats = mlx5e_get_link_ext_stats
24402449
};

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,51 @@ void mlx5e_stats_rmon_get(struct mlx5e_priv *priv,
11721172
*ranges = mlx5e_rmon_ranges;
11731173
}
11741174

1175+
void mlx5e_stats_ts_get(struct mlx5e_priv *priv,
1176+
struct ethtool_ts_stats *ts_stats)
1177+
{
1178+
int i, j;
1179+
1180+
mutex_lock(&priv->state_lock);
1181+
1182+
if (priv->tx_ptp_opened) {
1183+
struct mlx5e_ptp *ptp = priv->channels.ptp;
1184+
1185+
ts_stats->pkts = 0;
1186+
ts_stats->err = 0;
1187+
ts_stats->lost = 0;
1188+
1189+
/* Aggregate stats across all TCs */
1190+
for (i = 0; i < ptp->num_tc; i++) {
1191+
struct mlx5e_ptp_cq_stats *stats =
1192+
ptp->ptpsq[i].cq_stats;
1193+
1194+
ts_stats->pkts += stats->cqe;
1195+
ts_stats->err += stats->abort + stats->err_cqe +
1196+
stats->late_cqe;
1197+
ts_stats->lost += stats->lost_cqe;
1198+
}
1199+
} else {
1200+
/* DMA layer will always successfully timestamp packets. Other
1201+
* counters do not make sense for this layer.
1202+
*/
1203+
ts_stats->pkts = 0;
1204+
1205+
/* Aggregate stats across all SQs */
1206+
for (j = 0; j < priv->channels.num; j++) {
1207+
struct mlx5e_channel *c = priv->channels.c[j];
1208+
1209+
for (i = 0; i < c->num_tc; i++) {
1210+
struct mlx5e_sq_stats *stats = c->sq[i].stats;
1211+
1212+
ts_stats->pkts += stats->timestamps;
1213+
}
1214+
}
1215+
}
1216+
1217+
mutex_unlock(&priv->state_lock);
1218+
}
1219+
11751220
#define PPORT_PHY_STATISTICAL_OFF(c) \
11761221
MLX5_BYTE_OFF(ppcnt_reg, \
11771222
counter_set.phys_layer_statistical_cntrs.c##_high)
@@ -2066,6 +2111,7 @@ static const struct counter_desc sq_stats_desc[] = {
20662111
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial_inner) },
20672112
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, added_vlan_packets) },
20682113
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, nop) },
2114+
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, timestamps) },
20692115
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, mpwqe_blks) },
20702116
{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, mpwqe_pkts) },
20712117
#ifdef CONFIG_MLX5_EN_TLS
@@ -2178,6 +2224,7 @@ static const struct counter_desc ptp_cq_stats_desc[] = {
21782224
{ MLX5E_DECLARE_PTP_CQ_STAT(struct mlx5e_ptp_cq_stats, abort) },
21792225
{ MLX5E_DECLARE_PTP_CQ_STAT(struct mlx5e_ptp_cq_stats, abort_abs_diff_ns) },
21802226
{ MLX5E_DECLARE_PTP_CQ_STAT(struct mlx5e_ptp_cq_stats, late_cqe) },
2227+
{ MLX5E_DECLARE_PTP_CQ_STAT(struct mlx5e_ptp_cq_stats, lost_cqe) },
21812228
};
21822229

21832230
static const struct counter_desc ptp_rq_stats_desc[] = {
@@ -2217,6 +2264,7 @@ static const struct counter_desc qos_sq_stats_desc[] = {
22172264
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, csum_partial_inner) },
22182265
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, added_vlan_packets) },
22192266
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, nop) },
2267+
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, timestamps) },
22202268
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, mpwqe_blks) },
22212269
{ MLX5E_DECLARE_QOS_TX_STAT(struct mlx5e_sq_stats, mpwqe_pkts) },
22222270
#ifdef CONFIG_MLX5_EN_TLS

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ void mlx5e_stats_eth_ctrl_get(struct mlx5e_priv *priv,
128128
void mlx5e_stats_rmon_get(struct mlx5e_priv *priv,
129129
struct ethtool_rmon_stats *rmon,
130130
const struct ethtool_rmon_hist_range **ranges);
131+
void mlx5e_stats_ts_get(struct mlx5e_priv *priv,
132+
struct ethtool_ts_stats *ts_stats);
131133
void mlx5e_get_link_ext_stats(struct net_device *dev,
132134
struct ethtool_link_ext_stats *stats);
133135

@@ -431,6 +433,7 @@ struct mlx5e_sq_stats {
431433
u64 stopped;
432434
u64 dropped;
433435
u64 recover;
436+
u64 timestamps;
434437
/* dirtied @completion */
435438
u64 cqes ____cacheline_aligned_in_smp;
436439
u64 wake;
@@ -463,6 +466,7 @@ struct mlx5e_ptp_cq_stats {
463466
u64 abort;
464467
u64 abort_abs_diff_ns;
465468
u64 late_cqe;
469+
u64 lost_cqe;
466470
};
467471

468472
struct mlx5e_rep_stats {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,13 @@ static void mlx5e_consume_skb(struct mlx5e_txqsq *sq, struct sk_buff *skb,
750750
u64 ts = get_cqe_ts(cqe);
751751

752752
hwts.hwtstamp = mlx5e_cqe_ts_to_ns(sq->ptp_cyc2time, sq->clock, ts);
753-
if (sq->ptpsq)
753+
if (sq->ptpsq) {
754754
mlx5e_skb_cb_hwtstamp_handler(skb, MLX5E_SKB_CB_CQE_HWTSTAMP,
755755
hwts.hwtstamp, sq->ptpsq->cq_stats);
756-
else
756+
} else {
757757
skb_tstamp_tx(skb, &hwts);
758+
sq->stats->timestamps++;
759+
}
758760
}
759761

760762
napi_consume_skb(skb, napi_budget);

include/linux/ethtool.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,26 @@ struct ethtool_rmon_stats {
480480
);
481481
};
482482

483+
/**
484+
* struct ethtool_ts_stats - HW timestamping statistics
485+
* @pkts: Number of packets successfully timestamped by the hardware.
486+
* @lost: Number of hardware timestamping requests where the timestamping
487+
* information from the hardware never arrived for submission with
488+
* the skb.
489+
* @err: Number of arbitrary timestamp generation error events that the
490+
* hardware encountered, exclusive of @lost statistics. Cases such
491+
* as resource exhaustion, unavailability, firmware errors, and
492+
* detected illogical timestamp values not submitted with the skb
493+
* are inclusive to this counter.
494+
*/
495+
struct ethtool_ts_stats {
496+
struct_group(tx_stats,
497+
u64 pkts;
498+
u64 lost;
499+
u64 err;
500+
);
501+
};
502+
483503
#define ETH_MODULE_EEPROM_PAGE_LEN 128
484504
#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f
485505

@@ -755,7 +775,10 @@ struct ethtool_rxfh_param {
755775
* @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
756776
* It may be called with RCU, or rtnl or reference on the device.
757777
* Drivers supporting transmit time stamps in software should set this to
758-
* ethtool_op_get_ts_info().
778+
* ethtool_op_get_ts_info(). Drivers must not zero statistics which they
779+
* don't report. The stats structure is initialized to ETHTOOL_STAT_NOT_SET
780+
* indicating driver does not report statistics.
781+
* @get_ts_stats: Query the device hardware timestamping statistics.
759782
* @get_module_info: Get the size and type of the eeprom contained within
760783
* a plug-in module.
761784
* @get_module_eeprom: Get the eeprom information from the plug-in module
@@ -898,6 +921,8 @@ struct ethtool_ops {
898921
struct ethtool_dump *, void *);
899922
int (*set_dump)(struct net_device *, struct ethtool_dump *);
900923
int (*get_ts_info)(struct net_device *, struct ethtool_ts_info *);
924+
void (*get_ts_stats)(struct net_device *dev,
925+
struct ethtool_ts_stats *ts_stats);
901926
int (*get_module_info)(struct net_device *,
902927
struct ethtool_modinfo *);
903928
int (*get_module_eeprom)(struct net_device *,

include/uapi/linux/ethtool_netlink.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ enum {
117117

118118
/* request header */
119119

120-
/* use compact bitsets in reply */
121-
#define ETHTOOL_FLAG_COMPACT_BITSETS (1 << 0)
122-
/* provide optional reply for SET or ACT requests */
123-
#define ETHTOOL_FLAG_OMIT_REPLY (1 << 1)
124-
/* request statistics, if supported by the driver */
125-
#define ETHTOOL_FLAG_STATS (1 << 2)
120+
enum ethtool_header_flags {
121+
ETHTOOL_FLAG_COMPACT_BITSETS = 1 << 0, /* use compact bitsets in reply */
122+
ETHTOOL_FLAG_OMIT_REPLY = 1 << 1, /* provide optional reply for SET or ACT requests */
123+
ETHTOOL_FLAG_STATS = 1 << 2, /* request statistics, if supported by the driver */
124+
};
126125

127126
#define ETHTOOL_FLAG_ALL (ETHTOOL_FLAG_COMPACT_BITSETS | \
128127
ETHTOOL_FLAG_OMIT_REPLY | \
@@ -478,12 +477,26 @@ enum {
478477
ETHTOOL_A_TSINFO_TX_TYPES, /* bitset */
479478
ETHTOOL_A_TSINFO_RX_FILTERS, /* bitset */
480479
ETHTOOL_A_TSINFO_PHC_INDEX, /* u32 */
480+
ETHTOOL_A_TSINFO_STATS, /* nest - _A_TSINFO_STAT */
481481

482482
/* add new constants above here */
483483
__ETHTOOL_A_TSINFO_CNT,
484484
ETHTOOL_A_TSINFO_MAX = (__ETHTOOL_A_TSINFO_CNT - 1)
485485
};
486486

487+
enum {
488+
ETHTOOL_A_TS_STAT_UNSPEC,
489+
490+
ETHTOOL_A_TS_STAT_TX_PKTS, /* u64 */
491+
ETHTOOL_A_TS_STAT_TX_LOST, /* u64 */
492+
ETHTOOL_A_TS_STAT_TX_ERR, /* u64 */
493+
494+
/* add new constants above here */
495+
__ETHTOOL_A_TS_STAT_CNT,
496+
ETHTOOL_A_TS_STAT_MAX = (__ETHTOOL_A_TS_STAT_CNT - 1)
497+
498+
};
499+
487500
/* PHC VCLOCKS */
488501

489502
enum {

0 commit comments

Comments
 (0)