From mboxrd@z Thu Jan 1 00:00:00 1970 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N8a1LuUZEUrXSE92G+Fdeq3rIRfY8056JYE26pfGzzw=; b=Iao1WmTaRu95I/DKL4piVu7PDYfLdIJG6H84nxRKKboOQXSCQkAzVmhXh7vn1cz/WAY6HJGjqmP+SVwisT3B67yRf8zx2s3Hl80oh8Jqma0K9z8K4t8rmtfjF9IJJt+ltmaGxbfEh9RksN1fkqQkxavzeouOR9o8qo0IEqln5hw= Received: from BYAPR07MB4997.namprd07.prod.outlook.com (52.135.238.214) by BYAPR07MB4824.namprd07.prod.outlook.com (52.135.203.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.27; Thu, 29 Nov 2018 09:08:59 +0000 Received: from BYAPR07MB4997.namprd07.prod.outlook.com ([fe80::2d56:eab:242f:fdfc]) by BYAPR07MB4997.namprd07.prod.outlook.com ([fe80::2d56:eab:242f:fdfc%3]) with mapi id 15.20.1339.032; Thu, 29 Nov 2018 09:08:59 +0000 From: Jerin Jacob To: "Bhagavatula, Pavan" CC: "Jacob, Jerin" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it Thread-Index: AQHUh74AK75Q+Ix5YkeDSDp5MxeJj6Vmdr2A Date: Thu, 29 Nov 2018 09:08:58 +0000 Message-ID: <20181129090835.GA2591@jerin> References: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> In-Reply-To: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [122.178.219.219] x-clientproxiedby: SG2PR03CA0121.apcprd03.prod.outlook.com (2603:1096:4:91::25) To BYAPR07MB4997.namprd07.prod.outlook.com (2603:10b6:a03:5b::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerin.JacobKollanukkaran@cavium.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BYAPR07MB4824; 6:Swruuvi8gU7A5UFrE2xKWhVT8rj/8LTZWlukW1FhKoFzhzdUehld8w0cdn7bpJQHSc6zWntVxv/En/Ajjv6TCiMrWvaLYWmWZdNWTZ2wf4rTr/vpAodYpkShdLX5OtcVS7xa/dhFYjbnPRDOk9GiMDWjyawbppj2We+8h7TMzQgtrYr14cqjrf74DmUltYdV1riUIQY5emFI36uJY0w3JH9UaiFuOU2tbtrNkTKY/JejSVCMVqJ5pomFTqUr7M9KHYyXTwChkV7+imyUSlgb3NT9qNj2L+TB3n/LnPLoIZ2aPD2Uqo5PWIzwxMbjj3Ny+CnQsPb6Ry7aPbgju0/k0Yl7rd+33mbngiz9eui2T9UCKRXEtvhiZoAY4djuDoQDUt5ENo5kFMxQPUnlfLo+4WSE9tU7LgSuJojuGcO9SWWkZg6ogJWQNY7K8h0eX58LiPCr2fzmTjbeFaFvXZW2UA==; 5:YWF6JJNt7j5VdplaT7q0uzsibfSPKyntHtFfbYC906FFFGzzU4FicFB2ciI5DVOg8QDDIvaXq5BK+c/cFLyqAAJ04g6nDc/D0auRN2+PvL2rzqi2ad8Z6rGs+zOOeKrdR1auLq278MdBKEVfWmhiobtgniQTm0lPSy80TNE7Ias=; 7:L3vXKqqoF1quAl4MTjlLwCmU7/YWJDL21x7SMjePYSc7/y7Cl5bEOqbKEh88l6bJBfiTZV5OqngsvTwXpexKNrGvBPX800f4MPqoI/YrLvcXc/uSYfmpfXXLHseUxN45htZhI8wd7gZQCTCWw8kOpg== x-ms-office365-filtering-correlation-id: e181aa44-b4c3-40f1-a480-08d655da4bf4 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB4824; x-ms-traffictypediagnostic: BYAPR07MB4824: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(3231453)(999002)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:BYAPR07MB4824; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB4824; x-forefront-prvs: 0871917CDA x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(7916004)(366004)(346002)(136003)(376002)(396003)(39860400002)(13464003)(199004)(189003)(486006)(33896004)(53936002)(8676002)(6246003)(305945005)(476003)(81156014)(81166006)(26005)(6486002)(446003)(6436002)(9686003)(6512007)(72206003)(52116002)(11346002)(33656002)(76176011)(66066001)(71190400001)(71200400001)(6506007)(386003)(97736004)(7736002)(256004)(102836004)(6116002)(3846002)(478600001)(1076002)(5660300001)(6862004)(2906002)(4326008)(25786009)(105586002)(106356001)(99286004)(42882007)(54906003)(33716001)(316002)(229853002)(68736007)(14454004)(186003)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB4824; H:BYAPR07MB4997.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: +e7YC3jv/Ejrp/Ywt6FjOwihLktcvGJUimPHQOAdckh6elph7XCI5Y+HrMggfsmjJvb4dV6ZDlMS+SIEp0InMJXfbI8NBkWr1pXi4wVHP4I/ugStqgacWQgzJ1D9QEYdXCccjghAh/aEreVObgsJ54jOeVzDRnkk3KLrQXDWecM5JjPd+NM1Dqp2PsEnAw2YpK0TiKMaJRglk0kbBiNJy3dPqDDGR+r+rnoLbQeB7WrkpbIv2JwETlk3SNGVn1+vzcX5AuTRNZT0+Niqoux3X5CfNtrbtuCohHYxfKnGqtN7yYUE+HjdUjl0kUJWcgOwsWczrRPOdENgvWpUt3j9sfpXFZZex/ToNHILNqBGii8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <2A851CC5F7AA114F8CAFE134EB434938@namprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: e181aa44-b4c3-40f1-a480-08d655da4bf4 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2018 09:08:58.9922 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB4824 Subject: Re: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Nov 2018 09:09:01 -0000 -----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