Skip to content

Commit

Permalink
eth: fbnic: add ethtool timestamping statistics
Browse files Browse the repository at this point in the history
Add counters of packets with HW timestamps requests and lost timestamps
with no associated skbs. Use ethtool interface to report these counters.

Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Vadim Fedorenko authored and Paolo Abeni committed Oct 10, 2024
1 parent ad3d9f8 commit 96f358f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,33 @@ fbnic_get_eth_mac_stats(struct net_device *netdev,
&mac_stats->eth_mac.FrameTooLongErrors);
}

static void fbnic_get_ts_stats(struct net_device *netdev,
struct ethtool_ts_stats *ts_stats)
{
struct fbnic_net *fbn = netdev_priv(netdev);
u64 ts_packets, ts_lost;
struct fbnic_ring *ring;
unsigned int start;
int i;

ts_stats->pkts = fbn->tx_stats.ts_packets;
ts_stats->lost = fbn->tx_stats.ts_lost;
for (i = 0; i < fbn->num_tx_queues; i++) {
ring = fbn->tx[i];
do {
start = u64_stats_fetch_begin(&ring->stats.syncp);
ts_packets = ring->stats.ts_packets;
ts_lost = ring->stats.ts_lost;
} while (u64_stats_fetch_retry(&ring->stats.syncp, start));
ts_stats->pkts += ts_packets;
ts_stats->lost += ts_lost;
}
}

static const struct ethtool_ops fbnic_ethtool_ops = {
.get_drvinfo = fbnic_get_drvinfo,
.get_ts_info = fbnic_get_ts_info,
.get_ts_stats = fbnic_get_ts_stats,
.get_eth_mac_stats = fbnic_get_eth_mac_stats,
};

Expand Down
9 changes: 8 additions & 1 deletion drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget,
struct fbnic_ring *ring, bool discard,
unsigned int hw_head)
{
u64 total_bytes = 0, total_packets = 0;
u64 total_bytes = 0, total_packets = 0, ts_lost = 0;
unsigned int head = ring->head;
struct netdev_queue *txq;
unsigned int clean_desc;
Expand All @@ -404,6 +404,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget,
FBNIC_XMIT_CB(skb)->hw_head = hw_head;
if (likely(!discard))
break;
ts_lost++;
}

ring->tx_buf[head] = NULL;
Expand Down Expand Up @@ -443,6 +444,7 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector *nv, int napi_budget,
if (unlikely(discard)) {
u64_stats_update_begin(&ring->stats.syncp);
ring->stats.dropped += total_packets;
ring->stats.ts_lost += ts_lost;
u64_stats_update_end(&ring->stats.syncp);

netdev_tx_completed_queue(txq, total_packets, total_bytes);
Expand Down Expand Up @@ -504,6 +506,9 @@ static void fbnic_clean_tsq(struct fbnic_napi_vector *nv,
}

skb_tstamp_tx(skb, &hwtstamp);
u64_stats_update_begin(&ring->stats.syncp);
ring->stats.ts_packets++;
u64_stats_update_end(&ring->stats.syncp);
}

static void fbnic_page_pool_init(struct fbnic_ring *ring, unsigned int idx,
Expand Down Expand Up @@ -1060,6 +1065,8 @@ static void fbnic_aggregate_ring_tx_counters(struct fbnic_net *fbn,
fbn->tx_stats.bytes += stats->bytes;
fbn->tx_stats.packets += stats->packets;
fbn->tx_stats.dropped += stats->dropped;
fbn->tx_stats.ts_lost += stats->ts_lost;
fbn->tx_stats.ts_packets += stats->ts_packets;
}

static void fbnic_remove_tx_ring(struct fbnic_net *fbn,
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/ethernet/meta/fbnic/fbnic_txrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ struct fbnic_queue_stats {
u64 packets;
u64 bytes;
u64 dropped;
u64 ts_packets;
u64 ts_lost;
struct u64_stats_sync syncp;
};

Expand Down

0 comments on commit 96f358f

Please sign in to comment.