diff mbox series

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

Message ID 20220816115500.353-3-harini.katakam@amd.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Macb PTP enhancements | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 85 this patch: 85
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 85 this patch: 85
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Katakam, Harini Aug. 16, 2022, 11:55 a.m. UTC
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(-)

Comments

Claudiu Beznea Aug. 19, 2022, 8:19 a.m. UTC | #1
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
>
diff mbox series

Patch

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;
 }