DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
To: "Bhagavatula, Pavan" <Pavan.Bhagavatula@cavium.com>
Cc: "Jacob,  Jerin" <Jerin.JacobKollanukkaran@cavium.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it
Date: Thu, 29 Nov 2018 09:08:58 +0000	[thread overview]
Message-ID: <20181129090835.GA2591@jerin> (raw)
In-Reply-To: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com>

-----Original Message-----
> Date: Thu, 29 Nov 2018 14:02:03 +0530
> From: "Bhagavatula, Pavan" <Pavan.Bhagavatula@cavium.com>
> To: "Jacob,  Jerin" <Jerin.JacobKollanukkaran@cavium.com>
> CC: "dev@dpdk.org" <dev@dpdk.org>, "Bhagavatula, Pavan"
>  <Pavan.Bhagavatula@cavium.com>
> Subject: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it
> 
> When estimating tsc frequency using sleep/gettime round it up to the
> nearest multiple of 10Mhz for more accuracy.
> 
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
> ---
>  lib/librte_eal/common/eal_common_timer.c   |  4 ++--
>  lib/librte_eal/common/include/rte_common.h | 10 ++++++++++
>  lib/librte_eal/linuxapp/eal/eal_timer.c    |  2 +-
>  3 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/common/eal_common_timer.c
> index dcf26bfea..1358bbed0 100644
> --- a/lib/librte_eal/common/eal_common_timer.c
> +++ b/lib/librte_eal/common/eal_common_timer.c
> @@ -69,7 +69,7 @@ estimate_tsc_freq(void)
>  	/* assume that the sleep(1) will sleep for 1 second */
>  	uint64_t start = rte_rdtsc();
>  	sleep(1);
> -	return rte_rdtsc() - start;
> +	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, 1E7);
>  }
>  
>  void
> @@ -83,7 +83,7 @@ set_tsc_freq(void)
>  	if (!freq)
>  		freq = estimate_tsc_freq();
>  
> -	RTE_LOG(DEBUG, EAL, "TSC frequency is ~%" PRIu64 " KHz\n", freq / 1000);
> +	RTE_LOG(INFO, EAL, "TSC frequency is ~%" PRIu64 " Hz\n", freq);
>  	eal_tsc_resolution_hz = freq;
>  }
>  
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index 66cdf60b2..e374b16b1 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -248,6 +248,16 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
>  #define RTE_ALIGN_MUL_FLOOR(v, mul) \
>  	((v / ((typeof(v))(mul))) * (typeof(v))(mul))
>  
> +/**
> + * Macro to align a value to the nearest multiple of given value.
> + */
> +#define RTE_ALIGN_MUL_NEAR(v, mul)				\
> +	({							\
> +		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
> +		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
> +		(ceil - v) > (v - floor) ? floor: ceil;		\
> +	})
> +

Probably it is better to have two patches.
First patch to add new API along with unit testcase.
Second patch to roundup tsc frequency when estimating it.


>  /**
>   * Checks if a pointer is aligned to a given power-of-two value
>   *
> diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c
> index bc8f05199..864d6ef29 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_timer.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
> @@ -248,7 +248,7 @@ get_tsc_freq(void)
>  
>  		double secs = (double)ns/NS_PER_SEC;
>  		tsc_hz = (uint64_t)((end - start)/secs);
> -		return tsc_hz;
> +		return RTE_ALIGN_MUL_NEAR(tsc_hz, 1E7);
>  	}
>  #endif
>  	return 0;
> -- 
> 2.19.2
> 

  reply	other threads:[~2018-11-29  9:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29  8:32 Pavan Nikhilesh
2018-11-29  9:08 ` Jerin Jacob [this message]
2018-11-29 21:21 ` Stephen Hemminger
2018-11-30  7:17   ` Pavan Nikhilesh
2019-03-16  7:03 ` [dpdk-dev] [PATCH v2 1/2] eal: add macro to align value to the nearest multiple Pavan Nikhilesh Bhagavatula
2019-03-16  7:03   ` Pavan Nikhilesh Bhagavatula
2019-03-16  7:03   ` [dpdk-dev] [PATCH v2 2/2] eal: roundup tsc frequency when estimating it Pavan Nikhilesh Bhagavatula
2019-03-16  7:03     ` Pavan Nikhilesh Bhagavatula
2019-03-16 14:42     ` Wiles, Keith
2019-03-16 14:42       ` Wiles, Keith
2019-03-16 15:06       ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula
2019-03-16 15:06         ` Pavan Nikhilesh Bhagavatula
2019-03-16 17:18         ` Wiles, Keith
2019-03-16 17:18           ` Wiles, Keith
2019-03-16 17:56           ` Pavan Nikhilesh Bhagavatula
2019-03-16 17:56             ` Pavan Nikhilesh Bhagavatula
2019-03-16 18:22             ` Wiles, Keith
2019-03-16 18:22               ` Wiles, Keith
2019-03-16 18:27               ` Pavan Nikhilesh Bhagavatula
2019-03-16 18:27                 ` Pavan Nikhilesh Bhagavatula
2019-03-16 19:01 ` [dpdk-dev] [PATCH v3 1/2] eal: add macro to align value to the nearest multiple Pavan Nikhilesh Bhagavatula
2019-03-16 19:01   ` Pavan Nikhilesh Bhagavatula
2019-03-16 19:01   ` [dpdk-dev] [PATCH v3 2/2] eal: roundup tsc frequency when estimating Pavan Nikhilesh Bhagavatula
2019-03-16 19:01     ` Pavan Nikhilesh Bhagavatula
2019-03-27 22:43     ` Thomas Monjalon
2019-03-27 22:43       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181129090835.GA2591@jerin \
    --to=jerin.jacob@caviumnetworks.com \
    --cc=Jerin.JacobKollanukkaran@cavium.com \
    --cc=Pavan.Bhagavatula@cavium.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).