From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20061.outbound.protection.outlook.com [40.107.2.61]) by dpdk.org (Postfix) with ESMTP id 7D62F1B3B9 for ; Thu, 20 Dec 2018 07:42:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=COBQA5waYfZ2HnizKYHndqZk9DRR2Wy2OJ3VLPDnspY=; b=ThwJYg5zNKrlOAx2Q7pO5sGRsxDIjvklPUB286/yLqm9X/dixuwZ8V5r5Af7P7+lgQ0BDaL6ubrGX1MtXZnn/XjQS1EBnCODIGTIE3K9DcAnRh562GPrikdl73U07i44T0FN7waGaBF/zh56ZltkZ4wfFAFEt+rgPsCq8tCDT9M= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB5690.eurprd05.prod.outlook.com (20.178.104.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.17; Thu, 20 Dec 2018 06:42:47 +0000 Received: from DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::b0a0:72a4:7547:1c3c]) by DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::b0a0:72a4:7547:1c3c%3]) with mapi id 15.20.1446.020; Thu, 20 Dec 2018 06:42:47 +0000 From: Shahaf Shuler To: Tom Barbette , "dev@dpdk.org" CC: "bruce.richardson@intel.com" , "john.mcnamara@intel.com" , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Yongseok Koh Thread-Topic: [PATCH 1/3] rte_ethdev: Add API function to read dev clock Thread-Index: AQHUl6HAYSkK3yIpq0CwS3Z7mobRpKWHLi1w Date: Thu, 20 Dec 2018 06:42:47 +0000 Message-ID: References: <20181219134934.24693-1-barbette@kth.se> <20181219134934.24693-2-barbette@kth.se> In-Reply-To: <20181219134934.24693-2-barbette@kth.se> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR05MB5690; 6:inc5+FKQM4Xlc0oB8EeIQgLc42NIb3pseVmoa9BtqmPDUDb2n5qWRuFsORKWYusWxRDlvngIHxRH3swO85p06Jt1hMuOZ2+9xcsrmbLjHa5j3JBsCDNzl4AYHyqnPvcsBskTApet6jolt99eqW+YCquMCAxh5WjlL3Twbs1wI2X/7VLmbgZCCFIbauOuYtP0gGzRqv0HFEEMUDjDE0rIrArBYO0GJ5qjxTWlMg4qLpt/0w4O7hGNPohAon0CqQLjGmKtPzExA4feADO7n2ZusryaS5Ee/jlL+umFHjpSVBuia2RRmazV0uZFPUEP44qApPiTZ5D1IUh1rRIQmPWuq0HV6v9+xvpR/TnRRKVHMlhtCU0pxzveD6I+nWlDVsEH2Wsmzxi0MfgbcUNrk5KSiG6o2X+mwGk5tVFnS+/U0a/qwKRkQeKXCf58Bhp744tZpSUHINwI3EhqjV3txVRqbw==; 5:X+X2fO+vU3Lsf6YomrnbyrxG95Bs857VqxTQX1jNEM65CnixF044kB96MKIWEKEzwbJdoM2qfMxgGzJSg+GenZfk/bQwB3hzmrbQa308FDdujgGVBFgeaHMbty8sEXfq//bVdG6HVS4s+A6+7jqm9xY2Av4K6IkGfYOI+Mb0YHU=; 7:n7AJq8VNgFv0W90HpTdXdgV1wRCxM3hLAnNj+m75CkBkNXSfIsmzdQH5iqXlfa23vuBUyaIbmNmHJb6ZSWqhaCGqTa61ucCF0qb36cun7OUzjtIscAIi3RK8N9qIfIdi2w88IySTsbSVgEA6Vhlf8Q== x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 955d474a-9b02-487b-9a0a-08d666465aaf x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB5690; x-ms-traffictypediagnostic: DB7PR05MB5690: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(5005026)(6040522)(2401047)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(149066)(150057)(6041310)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:DB7PR05MB5690; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB5690; x-forefront-prvs: 0892FA9A88 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(376002)(366004)(136003)(396003)(189003)(199004)(66066001)(186003)(486006)(11346002)(316002)(6506007)(102836004)(2501003)(76176011)(446003)(7736002)(6346003)(476003)(6116002)(3846002)(6436002)(26005)(71190400001)(68736007)(105586002)(106356001)(229853002)(305945005)(86362001)(97736004)(74316002)(2906002)(71200400001)(4326008)(8676002)(110136005)(54906003)(55016002)(14454004)(107886003)(8936002)(9686003)(25786009)(256004)(14444005)(7696005)(99286004)(53936002)(81166006)(81156014)(5660300001)(478600001)(6246003)(33656002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB5690; H:DB7PR05MB4426.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=shahafs@mellanox.com; x-microsoft-antispam-message-info: WNCu3xoQr8YIpq7tg0QKsGVUKw6vo/LtqbxGmZGZTqfH+a2T//LMdc23t/aKVRJBzygiHfO5oDFxPDXVKP7NemJroBbChxTMAyjhZZzhToy1V0WpqB9XCFW6EmaNDE5XG64CWGj29vxtfOuXhrZ8Vr7Y3p4nWP74z/ryBN+Uqbm6WrUwsyxNBPVNHDLnBvL2acBMircXOv0cJtwag0tSiE10UHheSJ2sjPcMwIwzW3tUAhuypK6G8jRCKCiFNThjHTxrOVxvSoXwPLgy/PUpiZa79llYDKbyEssTmowZXEaGSiLDayWJL8Ivge68LvvP spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 955d474a-9b02-487b-9a0a-08d666465aaf X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Dec 2018 06:42:47.3924 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB5690 Subject: Re: [dpdk-dev] [PATCH 1/3] rte_ethdev: Add API function to read dev clock 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, 20 Dec 2018 06:42:52 -0000 Wednesday, December 19, 2018 3:50 PM, Tom Barbette: > Subject: [PATCH 1/3] rte_ethdev: Add API function to read dev clock >=20 > Add rte_eth_read_clock to read the raw clock of a devide. >=20 > The main use is to get the device clock conversion co-efficients to be ab= le to > translate the raw clock of the timestamp field of the pkt mbuf to a local= synced > time value. >=20 > This function was missing to allow users to convert the RX timestamp fiel= d to > real time without the complexity of the rte_timesync* facility. One can > derivate the clock frequency by calling twice read_clock and then keep a > common time base. >=20 > Signed-off-by: Tom Barbette Acked-by: Shahaf Shuler > --- > doc/guides/nics/features.rst | 1 + > lib/librte_ethdev/rte_ethdev.c | 13 +++++++ > lib/librte_ethdev/rte_ethdev.h | 44 ++++++++++++++++++++++++ > lib/librte_ethdev/rte_ethdev_core.h | 6 ++++ > lib/librte_ethdev/rte_ethdev_version.map | 1 + > lib/librte_mbuf/rte_mbuf.h | 2 ++ > 6 files changed, 67 insertions(+) >=20 > diff --git a/doc/guides/nics/features.rst b/doc/guides/nics/features.rst = index > d3f904839..45484a30f 100644 > --- a/doc/guides/nics/features.rst > +++ b/doc/guides/nics/features.rst > @@ -602,6 +602,7 @@ Supports Timestamp. > * **[provides] mbuf**: ``mbuf.ol_flags:PKT_RX_TIMESTAMP``. > * **[provides] mbuf**: ``mbuf.timestamp``. > * **[provides] rte_eth_dev_info**: ``rx_offload_capa,rx_queue_offload_ca= pa: > DEV_RX_OFFLOAD_TIMESTAMP``. > +* **[implements] eth_dev_ops**: ``read_clock``. >=20 > .. _nic_features_macsec_offload: >=20 > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethde= v.c > index 9d5107dce..97f92d11a 100644 > --- a/lib/librte_ethdev/rte_ethdev.c > +++ b/lib/librte_ethdev/rte_ethdev.c > @@ -4124,6 +4124,19 @@ rte_eth_timesync_write_time(uint16_t port_id, > const struct timespec *timestamp) > timestamp)); > } >=20 > +int > +rte_eth_read_clock(uint16_t port_id, uint64_t *timestamp) { > + struct rte_eth_dev *dev; > + > + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); > + dev =3D &rte_eth_devices[port_id]; > + > + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, - > ENOTSUP); > + return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, > + timestamp)); > +} > + > int > rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info= ) { > diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethde= v.h > index 1960f3a2d..5a831db29 100644 > --- a/lib/librte_ethdev/rte_ethdev.h > +++ b/lib/librte_ethdev/rte_ethdev.h > @@ -3642,6 +3642,50 @@ int rte_eth_timesync_read_time(uint16_t port_id, > struct timespec *time); > */ > int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec > *time); >=20 > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * Read the current clock counter of an Ethernet device > + * > + * This returns the current raw clock value of an Ethernet device. > + * The value returned here is from the same clock than the one > + * filling timestamp field of RX packets. Therefore it can be used > + * to compute a precise conversion of the device clock to the real time. > + * > + * E.g, a simple heuristic to derivate the frequency would be: > + * uint64_t start, end; > + * rte_eth_read_clock(port, start); > + * rte_delay_ms(100); > + * rte_eth_read_clock(port, end); > + * double freq =3D (end - start) * 10; > + * > + * Compute a common reference with: > + * uint64_t base_time_sec =3D current_time(); > + * uint64_t base_clock; > + * rte_eth_read_clock(port, base_clock); > + * > + * Then, convert the raw mbuf timestamp with: > + * base_time_sec + (double)(mbuf->timestamp - base_clock) / freq; > + * > + * This simple example will not provide a very good accuracy. One must > + * at least measure multiple times the frequency and do a regression. > + * To avoid deviation from the system time, the common reference can > + * be repeated from time to time. The integer division can also be > + * converted by a multiplication and a shift for better performance. > + * > + * @param port_id > + * The port identifier of the Ethernet device. > + * @param time > + * Pointer to the uint64_t that holds the raw clock value. > + * > + * @return > + * - 0: Success. > + * - -ENODEV: The port ID is invalid. > + * - -ENOTSUP: The function is not supported by the Ethernet driver. > + */ > +int __rte_experimental rte_eth_read_clock(uint16_t port_id, uint64_t > +*time); > + > /** > * Config l2 tunnel ether type of an Ethernet device for filtering speci= fic > * tunnel packets by ether type. > diff --git a/lib/librte_ethdev/rte_ethdev_core.h > b/lib/librte_ethdev/rte_ethdev_core.h > index 8f03f83f6..86806b3eb 100644 > --- a/lib/librte_ethdev/rte_ethdev_core.h > +++ b/lib/librte_ethdev/rte_ethdev_core.h > @@ -322,6 +322,10 @@ typedef int (*eth_timesync_write_time)(struct > rte_eth_dev *dev, > const struct timespec *timestamp); /**< > @internal Function used to get time from the device clock */ >=20 > +typedef int (*eth_read_clock)(struct rte_eth_dev *dev, > + uint64_t *timestamp); > +/**< @internal Function used to get the current value of the device > +clock. */ > + > typedef int (*eth_get_reg_t)(struct rte_eth_dev *dev, > struct rte_dev_reg_info *info); > /**< @internal Retrieve registers */ > @@ -496,6 +500,8 @@ struct eth_dev_ops { > eth_timesync_read_time timesync_read_time; /** Get the device > clock time. */ > eth_timesync_write_time timesync_write_time; /** Set the device > clock time. */ >=20 > + eth_read_clock read_clock; > + > eth_xstats_get_by_id_t xstats_get_by_id; > /**< Get extended device statistic values by ID. */ > eth_xstats_get_names_by_id_t xstats_get_names_by_id; diff --git > a/lib/librte_ethdev/rte_ethdev_version.map > b/lib/librte_ethdev/rte_ethdev_version.map > index 92ac3de25..12d6c3c1d 100644 > --- a/lib/librte_ethdev/rte_ethdev_version.map > +++ b/lib/librte_ethdev/rte_ethdev_version.map > @@ -249,6 +249,7 @@ EXPERIMENTAL { > rte_eth_switch_domain_free; > rte_flow_conv; > rte_flow_expand_rss; > + rte_eth_read_clock; > rte_mtr_capabilities_get; > rte_mtr_create; > rte_mtr_destroy; > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h inde= x > 3dbc6695e..4ceefa913 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -605,6 +605,8 @@ struct rte_mbuf { >=20 > /** Valid if PKT_RX_TIMESTAMP is set. The unit and time reference > * are not normalized but are always the same for a given port. > + * Some devices allow to query rte_eth_read_clock that will return the > + * current device timestamp. > */ > uint64_t timestamp; >=20 > -- > 2.17.1