From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerin Jacob Subject: Re: [PATCH] eal: roundup tsc frequency when estimating it Date: Thu, 29 Nov 2018 09:08:58 +0000 Message-ID: <20181129090835.GA2591@jerin> References: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "Jacob, Jerin" , "dev@dpdk.org" To: "Bhagavatula, Pavan" Return-path: Received: from NAM05-CO1-obe.outbound.protection.outlook.com (mail-eopbgr720077.outbound.protection.outlook.com [40.107.72.77]) by dpdk.org (Postfix) with ESMTP id 64C971B45A for ; Thu, 29 Nov 2018 10:09:01 +0100 (CET) In-Reply-To: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Content-Language: en-US Content-ID: <2A851CC5F7AA114F8CAFE134EB434938@namprd07.prod.outlook.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" -----Original Message----- > Date: Thu, 29 Nov 2018 14:02:03 +0530 > From: "Bhagavatula, Pavan" > To: "Jacob, Jerin" > CC: "dev@dpdk.org" , "Bhagavatula, Pavan" > > Subject: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it >=20 > When estimating tsc frequency using sleep/gettime round it up to the > nearest multiple of 10Mhz for more accuracy. >=20 > Signed-off-by: Pavan Nikhilesh > --- > 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(-) >=20 > diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/co= mmon/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 =3D rte_rdtsc(); > sleep(1); > - return rte_rdtsc() - start; > + return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, 1E7); > } > =20 > void > @@ -83,7 +83,7 @@ set_tsc_freq(void) > if (!freq) > freq =3D estimate_tsc_freq(); > =20 > - 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 =3D freq; > } > =20 > 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)) > =20 > +/** > + * Macro to align a value to the nearest multiple of given value. > + */ > +#define RTE_ALIGN_MUL_NEAR(v, mul) \ > + ({ \ > + typeof(v) ceil =3D RTE_ALIGN_MUL_CEIL(v, mul); \ > + typeof(v) floor =3D 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/lin= uxapp/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) > =20 > double secs =3D (double)ns/NS_PER_SEC; > tsc_hz =3D (uint64_t)((end - start)/secs); > - return tsc_hz; > + return RTE_ALIGN_MUL_NEAR(tsc_hz, 1E7); > } > #endif > return 0; > --=20 > 2.19.2 >=20