Skip to content

Commit c6d5f19

Browse files
shifty91kuba-moo
authored andcommitted
net: stmmac: Calculate CDC error only once
The clock domain crossing error (CDC) is calculated at every fetch of Tx or Rx timestamps. It includes a division. Especially on arm32 based systems it is expensive. It also requires two conditionals in the hotpath. Add a compensation value cache to struct plat_stmmacenet_data and subtract it unconditionally in the RX/TX functions which spares the conditionals. The value is initialized to 0 and if supported calculated in the PTP initialization code. Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Kurt Kanzenbach <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2106efd commit c6d5f19

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,6 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
511511
return true;
512512
}
513513

514-
static inline u32 stmmac_cdc_adjust(struct stmmac_priv *priv)
515-
{
516-
/* Correct the clk domain crossing(CDC) error */
517-
if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate)
518-
return (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;
519-
return 0;
520-
}
521-
522514
/* stmmac_get_tx_hwtstamp - get HW TX timestamps
523515
* @priv: driver private structure
524516
* @p : descriptor pointer
@@ -550,7 +542,7 @@ static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv,
550542
}
551543

552544
if (found) {
553-
ns -= stmmac_cdc_adjust(priv);
545+
ns -= priv->plat->cdc_error_adj;
554546

555547
memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
556548
shhwtstamp.hwtstamp = ns_to_ktime(ns);
@@ -587,7 +579,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
587579
if (stmmac_get_rx_timestamp_status(priv, p, np, priv->adv_ts)) {
588580
stmmac_get_timestamp(priv, desc, priv->adv_ts, &ns);
589581

590-
ns -= stmmac_cdc_adjust(priv);
582+
ns -= priv->plat->cdc_error_adj;
591583

592584
netdev_dbg(priv->dev, "get valid RX hw timestamp %llu\n", ns);
593585
shhwtstamp = skb_hwtstamps(skb);

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ void stmmac_ptp_register(struct stmmac_priv *priv)
309309
if (priv->plat->ptp_max_adj)
310310
stmmac_ptp_clock_ops.max_adj = priv->plat->ptp_max_adj;
311311

312+
/* Calculate the clock domain crossing (CDC) error if necessary */
313+
priv->plat->cdc_error_adj = 0;
314+
if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate)
315+
priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate;
316+
312317
stmmac_ptp_clock_ops.n_per_out = priv->dma_cap.pps_out_num;
313318
stmmac_ptp_clock_ops.n_ext_ts = priv->dma_cap.aux_snapshot_n;
314319

include/linux/stmmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ struct plat_stmmacenet_data {
241241
unsigned int clk_ref_rate;
242242
unsigned int mult_fact_100ns;
243243
s32 ptp_max_adj;
244+
u32 cdc_error_adj;
244245
struct reset_control *stmmac_rst;
245246
struct reset_control *stmmac_ahb_rst;
246247
struct stmmac_axi *axi;

0 commit comments

Comments
 (0)