From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700048.outbound.protection.outlook.com [40.107.70.48]) by dpdk.org (Postfix) with ESMTP id E3C3A1B160 for ; Thu, 29 Nov 2018 09:32:04 +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=OcXhSI1h51FRYSf39iuCNyNxy98G2BvPhHMQ93+WvqU=; b=fABRxpzDT2ZFtlnoRGdAIJmrB3uJpR8goaOKYCrydDPXEy5LQohkBuES55fdCNof4HEirNAMbzqSWAx4/oinRXcOJSy0AbijoJrg/q0V5lP5QvUSTwj/Xexy//SVQUm90WvrxUIaCsBn+iV646FVNpH6uluNoPq8P9MXAyObJbs= Received: from BYAPR07MB4966.namprd07.prod.outlook.com (52.135.238.207) by BYAPR07MB4568.namprd07.prod.outlook.com (52.135.226.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.16; Thu, 29 Nov 2018 08:32:03 +0000 Received: from BYAPR07MB4966.namprd07.prod.outlook.com ([fe80::8173:6c30:9144:add]) by BYAPR07MB4966.namprd07.prod.outlook.com ([fe80::8173:6c30:9144:add%2]) with mapi id 15.20.1361.019; Thu, 29 Nov 2018 08:32:03 +0000 From: Pavan Nikhilesh To: "Jacob, Jerin" CC: "dev@dpdk.org" , "Bhagavatula, Pavan" Thread-Topic: [dpdk-dev] [PATCH] eal: roundup tsc frequency when estimating it Thread-Index: AQHUh74AK75Q+Ix5YkeDSDp5MxeJjw== Date: Thu, 29 Nov 2018 08:32:03 +0000 Message-ID: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: PN1PR0101CA0016.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::26) To BYAPR07MB4966.namprd07.prod.outlook.com (2603:10b6:a03:5b::15) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [115.113.156.3] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BYAPR07MB4568; 6:UE8sDc3cEoSJkE4Tp5H3Np8OUMuwL+bRPpLwJz4Rs0oPyABSWE6Qk3cb72/uDJQHY+ujnqR/lzz+/zNm0j5pg7yPFnj/G+rKEBWqKnYBKutTcAO5hh9gnihxA8TTAlhpayKKx52MIKnE7RrnGsge3RwFDmuMnyKA3f1ZeL6YfFVyoiieCjaPAyhp2Uti2lOZ16naPgvOlIt7xjVvsgAyv/gGjucRXQ+/qO6Y8ttuVMaA/V1zXa9BV5nSRQy5B9sQTKR3gbUVHoBvpI4WcwEXIgjGhOsYUAyltjj8LqOMp5nqXPyl8SB1s7VCngRGqhN17Lo4GLXtqDdQNPd1pMb8SaYHQ8awnJZ9aLQPRUlVgSJLyBureDHiS+ZhXqn0QdR8kwwAmkH5xDfsh10XnKB+u012ApPBIt5/Iz94z53LGzjiWYOh5P0/AKY3wM5wJkyLoORX4lrzM5H7Ymj4hXgfkw==; 5:kcyXeknlEOHqVJhuGqjJKl9bMiRRH6B1Fw/Dr8aFlYyrLkMQH0ECzCjHQgeQHKvsHWmsVKFtCaQ9EtszafURjexySKz67ohJfAu7+9+JPeUrdSx3E4uqBoKHlg+JmKIVLJ4mtbMf4iq30ZKdeW2OcG9sxmxQC9QNenYQYcbT4ZQ=; 7:PhQAhN1Xpyaw7tL3WZtbXDBdYAyCR6ARfkWwxfqb6bczb6tY4X58o4wyWOYDZ+XHdmYYHzgilVcu3EIAdrrcUeFnlFWB4jl5f7OdhEpG0PhrnKAaUtxkOrvNp5hwB4Zplbuot2NmkpWlV0Lxv7wKVA== x-ms-office365-filtering-correlation-id: d1cd76ea-81b9-4ca2-015c-08d655d5233d x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB4568; x-ms-traffictypediagnostic: BYAPR07MB4568: x-microsoft-antispam-prvs: 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)(3002001)(10201501046)(148016)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:BYAPR07MB4568; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB4568; x-forefront-prvs: 0871917CDA x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39850400004)(136003)(366004)(376002)(396003)(346002)(199004)(189003)(6116002)(3846002)(2906002)(81166006)(81156014)(256004)(68736007)(305945005)(36756003)(8936002)(8676002)(1076002)(25786009)(478600001)(105586002)(72206003)(26005)(71190400001)(71200400001)(106356001)(14454004)(6436002)(186003)(5660300001)(6486002)(99286004)(486006)(54906003)(476003)(2616005)(6512007)(4326008)(6862004)(66066001)(6506007)(55236004)(386003)(102836004)(42882007)(7736002)(52116002)(97736004)(316002)(107886003)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB4568; H:BYAPR07MB4966.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: Bcc7Myqqsx2O67LNf388l2/bvfELXOLe2wH/qVAU1HvshpH7eP80vsmYOSo1Dh75rCsCvzrQZNxR6ghfR3iuUSNQCjEBFcGeTPuNqlYr3cYy83oyGRDpllVqjOKtsdbLiPUjpNyKOlLy3VV55SGG3zm0nZ0pq9xYP9YvloDfNkUTfboG6XZZ9lcW22iubA8wx5S2bFLjf8L3DA8aEfH7+1pTrTNNcyEpZe/+eQ94hY0v9xcA6Li8EvYT7NGH+W+NKWz8d2ncgsXTBRrVncneduNVFLSN1+q8bt3+m7+mXrF1XAwvkPdkeJwQjuayjYXh0t1IZxd5hJT/ZnTg5F6RHctTpFO6pzTZJwCT0tpoQeg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1cd76ea-81b9-4ca2-015c-08d655d5233d X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2018 08:32:03.0982 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB4568 Subject: [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 08:32:05 -0000 When estimating tsc frequency using sleep/gettime round it up to the nearest multiple of 10Mhz for more accuracy. 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(-) diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/comm= on/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/co= mmon/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; \ + }) + /** * 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/linux= app/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