From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 1B008A05D3 for ; Thu, 25 Apr 2019 19:08:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1F7281B5CD; Thu, 25 Apr 2019 19:08:34 +0200 (CEST) Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id AF6AA1B5C8 for ; Thu, 25 Apr 2019 19:08:32 +0200 (CEST) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (uk.solarflare.com [193.34.186.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id F0D35780078; Thu, 25 Apr 2019 17:08:30 +0000 (UTC) Received: from [192.168.38.17] (91.220.146.112) by ukex01.SolarFlarecom.com (10.17.10.4) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 25 Apr 2019 18:08:10 +0100 To: Tom Barbette , CC: , , Thomas Monjalon , Ferruh Yigit , Shahaf Shuler , Yongseok Koh , References: <20190424173424.34628-1-barbette@kth.se> <20190424173424.34628-2-barbette@kth.se> From: Andrew Rybchenko Message-ID: <735cce4a-7fe7-73fb-c4f3-1fd0daa2ef7c@solarflare.com> Date: Thu, 25 Apr 2019 20:08:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190424173424.34628-2-barbette@kth.se> Content-Language: en-GB X-Originating-IP: [91.220.146.112] X-ClientProxiedBy: ocex03.SolarFlarecom.com (10.20.40.36) To ukex01.SolarFlarecom.com (10.17.10.4) X-TM-AS-Product-Ver: SMEX-12.5.0.1300-8.5.1010-24572.003 X-TM-AS-Result: No-12.582000-8.000000-10 X-TMASE-MatchedRID: PL66URbwWA8OwH4pD14DsPHkpkyUphL9MZm0+sEE9mvKY//WmIj/oQrU aOXZFU93cXv5gCs2lPghqyX6bKayTV/yzOBJu22CjoyKzEmtrEdKgIbix5+XxAXjqIVJnzaPgju zl/ha282siimY4WPDatoYR5Q1QShUGNZpatR+Wd7hG1IOMb7PsO+aBTJJYa54JtZH9tzUWm5vkO NK/M1of5+CIvdU2yti9DF0CcY8j9KlTHNxJDwdpC97pb4g5HCt+f3gajT2cGz1gF7PCEF9bnmd+ 25VkQszZba7TbjqApHIrN0uSVF9A06XywckxmYRj56aIafJ4NEhpWQUitAWG/t592eq2xoTz7ZU Y0BF1aBux6gKtWqXz8iJ/rHBIDSKGhA/jdSevJbBtFDYGmaWKpkShYcLpGH9H06W6rwtvNXN2Wj bpqXgofa8+G6VxpdYgWg8WzvAdS0FrDF4OCzISZ06nVOMOuVpnTcLR8+TzEp4jy7i2qNcvd0pRI Fbsjfbb7mJ6HbhlhGRk6XtYogiau9c69BWUTGwVnRXm1iHN1ZsZUSYh+N/e0FGYYKZ2uPNy6Puw Rm2UH1GIdeKZRMxVVfOUbqfqWptRyeasQTx2skW0a0ZqN5ZnWTWnVUdztXLtLP8GnZqo8A87BD9 ter1NA== X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--12.582000-8.000000 X-TMASE-Version: SMEX-12.5.0.1300-8.5.1010-24572.003 X-MDID: 1556212112-L_gWE0xw041I Content-Type: text/plain; charset="UTF-8"; format="flowed" Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH v3 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190425170807.MpU-aeSTOZS4W20kp8_cVhPH9W3-_cc1yASUK5aDwDY@z> On 4/24/19 8:34 PM, Tom Barbette wrote: > Add rte_eth_read_clock to read the raw clock of a devide. Typo above "devide" > The main use is to get the device clock conversion co-efficients to be > able to translate the raw clock of the timestamp field of the pkt mbuf > to a local synced time value. > > This function was missing to allow users to convert the RX timestamp field RX -> Rx > 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. > > Signed-off-by: Tom Barbette [snip] > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c > index d7cfa3d53..22e35d839 100644 > --- a/lib/librte_ethdev/rte_ethdev.c > +++ b/lib/librte_ethdev/rte_ethdev.c > @@ -4170,6 +4170,19 @@ rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp) > timestamp)); > } > > +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 = &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)); Why timestamp on the next line? > +} > + > 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_ethdev.h > index b8d19c69f..dfaf16a56 100644 > --- a/lib/librte_ethdev/rte_ethdev.h > +++ b/lib/librte_ethdev/rte_ethdev.h > @@ -3793,6 +3793,51 @@ 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); > > +/** > + * @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 RX -> Rx > + * 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 = (end - start) * 10; > + * > + * Compute a common reference with: > + * uint64_t base_time_sec = 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 *timestamp); > + > /** > * Config l2 tunnel ether type of an Ethernet device for filtering specific > * tunnel packets by ether type. [snip] > 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 afcd25599..670e4fad5 100644 > --- a/lib/librte_ethdev/rte_ethdev_version.map > +++ b/lib/librte_ethdev/rte_ethdev_version.map > @@ -253,10 +253,12 @@ EXPERIMENTAL { > rte_eth_dev_rx_intr_ctl_q_get_fd; > rte_eth_find_next_of; > rte_eth_find_next_sibling; > + rte_eth_read_clock; > rte_eth_switch_domain_alloc; > rte_eth_switch_domain_free; > rte_flow_conv; > rte_flow_expand_rss; > + rte_eth_read_clock; Dup [snip]