[RESEND PATCH 2/2] net: macb: Optimize reading HW timestamp

Harini Katakam posted 2 patches 3 years, 7 months ago
[RESEND PATCH 2/2] net: macb: Optimize reading HW timestamp
Posted by Harini Katakam 3 years, 7 months ago
From: Harini Katakam <harini.katakam@xilinx.com>

The seconds input from BD (6 bits) just needs to be ORed with the
upper bits from timer in this function. Avoid +/- operations every
single time. Check for seconds rollover at BIT 5 and subtract the
overhead only in that case.

Signed-off-by: Harini Katakam <harini.katakam@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
Acked-by: Richard Cochran <richardcochran@gmail.com>
---
 drivers/net/ethernet/cadence/macb_ptp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
index e6cb20aaa76a..674002661366 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -247,6 +247,7 @@ static int gem_hw_timestamp(struct macb *bp, u32 dma_desc_ts_1,
 			    u32 dma_desc_ts_2, struct timespec64 *ts)
 {
 	struct timespec64 tsu;
+	bool sec_rollover = false;
 
 	ts->tv_sec = (GEM_BFEXT(DMA_SECH, dma_desc_ts_2) << GEM_DMA_SECL_SIZE) |
 			GEM_BFEXT(DMA_SECL, dma_desc_ts_1);
@@ -264,9 +265,12 @@ static int gem_hw_timestamp(struct macb *bp, u32 dma_desc_ts_1,
 	 */
 	if ((ts->tv_sec & (GEM_DMA_SEC_TOP >> 1)) &&
 	    !(tsu.tv_sec & (GEM_DMA_SEC_TOP >> 1)))
-		ts->tv_sec -= GEM_DMA_SEC_TOP;
+		sec_rollover = true;
+
+	ts->tv_sec |= ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);
 
-	ts->tv_sec += ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);
+	if (sec_rollover)
+		ts->tv_sec -= GEM_DMA_SEC_TOP;
 
 	return 0;
 }
-- 
2.17.1
Re: [RESEND PATCH 2/2] net: macb: Optimize reading HW timestamp
Posted by Claudiu.Beznea@microchip.com 3 years, 7 months ago
On 16.08.2022 14:55, Harini Katakam wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> From: Harini Katakam <harini.katakam@xilinx.com>
> 
> The seconds input from BD (6 bits) just needs to be ORed with the
> upper bits from timer in this function. Avoid +/- operations every
> single time. Check for seconds rollover at BIT 5 and subtract the
> overhead only in that case.
> 
> Signed-off-by: Harini Katakam <harini.katakam@xilinx.com>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
> Acked-by: Richard Cochran <richardcochran@gmail.com>
> ---
>  drivers/net/ethernet/cadence/macb_ptp.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet/cadence/macb_ptp.c
> index e6cb20aaa76a..674002661366 100644
> --- a/drivers/net/ethernet/cadence/macb_ptp.c
> +++ b/drivers/net/ethernet/cadence/macb_ptp.c
> @@ -247,6 +247,7 @@ static int gem_hw_timestamp(struct macb *bp, u32 dma_desc_ts_1,
>                             u32 dma_desc_ts_2, struct timespec64 *ts)
>  {
>         struct timespec64 tsu;
> +       bool sec_rollover = false;
> 
>         ts->tv_sec = (GEM_BFEXT(DMA_SECH, dma_desc_ts_2) << GEM_DMA_SECL_SIZE) |
>                         GEM_BFEXT(DMA_SECL, dma_desc_ts_1);
> @@ -264,9 +265,12 @@ static int gem_hw_timestamp(struct macb *bp, u32 dma_desc_ts_1,
>          */
>         if ((ts->tv_sec & (GEM_DMA_SEC_TOP >> 1)) &&
>             !(tsu.tv_sec & (GEM_DMA_SEC_TOP >> 1)))
> -               ts->tv_sec -= GEM_DMA_SEC_TOP;
> +               sec_rollover = true;
> +
> +       ts->tv_sec |= ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);

It looks to me that this instruction could be moved before

>         if ((ts->tv_sec & (GEM_DMA_SEC_TOP >> 1)) &&
>             !(tsu.tv_sec & (GEM_DMA_SEC_TOP >> 1)))

and get rid of sec_rolover extra variable thus, in the end, the diff could
look like this:

diff --git a/drivers/net/ethernet/cadence/macb_ptp.c
b/drivers/net/ethernet/cadence/macb_ptp.c
index e6cb20aaa76a..f9db4501b995 100644
--- a/drivers/net/ethernet/cadence/macb_ptp.c
+++ b/drivers/net/ethernet/cadence/macb_ptp.c
@@ -258,6 +258,8 @@ static int gem_hw_timestamp(struct macb *bp, u32
dma_desc_ts_1,
         */
        gem_tsu_get_time(&bp->ptp_clock_info, &tsu, NULL);

+       ts->tv_sec |= ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);
+
        /* If the top bit is set in the timestamp,
         * but not in 1588 timer, it has rolled over,
         * so subtract max size
@@ -266,8 +268,6 @@ static int gem_hw_timestamp(struct macb *bp, u32
dma_desc_ts_1,
            !(tsu.tv_sec & (GEM_DMA_SEC_TOP >> 1)))
                ts->tv_sec -= GEM_DMA_SEC_TOP;

-       ts->tv_sec += ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);
-
        return 0;
 }

> 
> -       ts->tv_sec += ((~GEM_DMA_SEC_MASK) & tsu.tv_sec);
> +       if (sec_rollover)
> +               ts->tv_sec -= GEM_DMA_SEC_TOP;
> 
>         return 0;
>  }
> --
> 2.17.1
>