From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6DAF3A0487 for ; Sun, 28 Jul 2019 11:09:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 78D541BF82; Sun, 28 Jul 2019 11:09:51 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 57C6D1BF1C for ; Sun, 28 Jul 2019 11:09:49 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x6S96gUh009691 for ; Sun, 28 Jul 2019 02:09:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=AGrLmnc9tCjPTsU/rtv6lrhkm6BF/pVrhpLj/akWQ3E=; b=CkqRKDne50s+ZGISHo0vQ0atgfACsIysU0Ma44CCpCluufsq3sK952zxW5MKdfxslaTR 8g7nxrd0bDE+R1501U0XKaEhs+fLf1MpSKLdGfrKug4DLJ8fz0nxt8wedUr9Ly1lKgXs jBhn1wsnbYKFjAxdd5GkJdXb5URf0APE42784ReUcAwnr639At/ydaltdp6ReS2VXPq1 zlOWBda9pfa/3MTUR5orLmWeW917f0XvnJPV6gHsxfOOlDNlbOH+fHs7eSB+punQSNDa 5Y3v2EY0cYRszavH4ExTaLRO9WilblLyRp6Nc7bwFSG8KR3r970sFP0cQsISAmCe9LQo +g== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2u0p4ku3br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 28 Jul 2019 02:09:48 -0700 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 28 Jul 2019 02:09:46 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (104.47.41.50) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sun, 28 Jul 2019 02:09:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AGib7ZOVDxlKm5DcUzczhn8oSpfLnt8NQSz2fio2VCllYIrj2Llv4rACeJmeJCL8/HkzjG31gp//22qf8Z/u+e2jWxhpkn3jTWXqLDCbFVs2Ipe1SbotgJ+ww96A80JrIMPlPEvYBsLQhIXQXBV7VzuY6/NYejGB4GiSl5utNH5JcW2jfeppIlgzXBRDyXWK4RgYyZZ+cTw7PueAXEcV2r1PrFgLntD8GiS8VksUzqlALESCAaSURT93Wp4UiG9viMhCjH2IxuZgjYHnGT8wTi+ESfL2Mo58T8OHGAE5BH4+DUDtejukZSC4/dtbrb0nR+pFNqGeXxDKz6klG5YhaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AGrLmnc9tCjPTsU/rtv6lrhkm6BF/pVrhpLj/akWQ3E=; b=CqQ5v0o8LqHtcrSxh31ktO4QzeGzPyYmXRorMzMwBxhr8rJ9c2Lhnam2HH0D6ktjL7RlBEa/SY13wOPvBETvMDDRwHBIK961a0mrD/zKV0MhPBVknk57KPunC8K8uA1PS4Au5AocpWp01+fFR1NBgKqs/wwlqlsPmHqZk+2XwTQM+Z9I8bHUJHNRVAhOtGzFxdtSLnKLLTmRrJofDbDRssyiPqFAV3JOqOsaAv90GUtVPyCeHEtsGJc9lfpE2qXI57BTaSCuhTixf/x8PD+KlEgXS4ou3eMlt1sz/J88D6sGIuWhDJIKCYy9bmJbBJP6Efwm8L/tksnS28p97eq2bQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=marvell.com;dmarc=pass action=none header.from=marvell.com;dkim=pass header.d=marvell.com;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector2-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AGrLmnc9tCjPTsU/rtv6lrhkm6BF/pVrhpLj/akWQ3E=; b=nQ+xZD7+x8uqyFt04nkRXbst48vqow67IUv9EMoeve6vXli4X7SqO+JYERn1Cv3u4C+qW2bYBBTXoxkfOdgy6nkYDuru06WQt4lu7nCz6rksAHoaEaiiQwCNnnW779rJM2mhQYstAfSQHPFes/YBggGw8Np9EplCgUmVkhB8GMY= Received: from MN2PR18MB2848.namprd18.prod.outlook.com (20.179.21.149) by MN2PR18MB2576.namprd18.prod.outlook.com (20.179.83.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Sun, 28 Jul 2019 09:09:45 +0000 Received: from MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::4447:9459:5386:2e18]) by MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::4447:9459:5386:2e18%7]) with mapi id 15.20.2115.005; Sun, 28 Jul 2019 09:09:45 +0000 From: Harman Kalra To: Jerin Jacob Kollanukkaran , Nithin Kumar Dabilpuram , Vamsi Krishna Attunuru , Kiran Kumar Kokkilagadda CC: "dev@dpdk.org" , Harman Kalra Thread-Topic: [PATCH v3 2/2] net/octeontx2: support read clock API Thread-Index: AQHVRSQyJmkYgIvRMUeEm/No9YGAaw== Date: Sun, 28 Jul 2019 09:09:45 +0000 Message-ID: <1564304876-13274-2-git-send-email-hkalra@marvell.com> References: <1564304876-13274-1-git-send-email-hkalra@marvell.com> In-Reply-To: <1564304876-13274-1-git-send-email-hkalra@marvell.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BM1PR0101CA0038.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::24) To MN2PR18MB2848.namprd18.prod.outlook.com (2603:10b6:208:3e::21) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [115.113.156.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 59a24c42-b0c8-4438-cde6-08d7133b553a x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR18MB2576; x-ms-traffictypediagnostic: MN2PR18MB2576: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1443; x-forefront-prvs: 01128BA907 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(39850400004)(366004)(136003)(376002)(346002)(199004)(189003)(14454004)(305945005)(486006)(478600001)(52116002)(6636002)(54906003)(66446008)(64756008)(66556008)(66476007)(66946007)(102836004)(55236004)(66066001)(26005)(386003)(6506007)(446003)(99286004)(11346002)(2616005)(476003)(7736002)(6436002)(186003)(76176011)(8936002)(71190400001)(71200400001)(5660300002)(6512007)(50226002)(25786009)(68736007)(86362001)(81166006)(81156014)(4326008)(2906002)(8676002)(36756003)(110136005)(6116002)(3846002)(6486002)(316002)(107886003)(256004)(14444005)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2576; H:MN2PR18MB2848.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: bAvfub7ayhQUE4B+AfjVogngqRZOQb5TKYMsRZIQu5pThnLm61Ptg/Y2d7FDxxP02lfV1kgMPp4Q65ggdRKZCNfaVd21GS7DG1C9jb6a33hlK47xxjOeSPBTKSHxjfXSPQ3Xzad6swRuJeTnzlEeXJ/OwmjS+3nDjd+vw6ZgqMsC4JG+mYRSb39ipMspepiZOH2qSF8hFw9uSyodoL1BvaxazInRTlliRLdjS3h4vki/sviOxKRtHpvlM/0I2b+N2ZkHtVCWdF5Nngpmq+5dqqZ/iO0RayKdbTv4wc5wiu40GrFYwy0ZQM0ezWnAt6abpWJmkwK2gwU1MZGTyj9YlFCZEbdm3MGgaucUhpclOGqWHze8085vY6He1+W3oulT2cL39Q6iyluDRInDLxbzPy4fdk8Pd8BR+ekTt2bFHq8= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 59a24c42-b0c8-4438-cde6-08d7133b553a X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jul 2019 09:09:45.2068 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: hkalra@marvell.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB2576 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-07-28_04:2019-07-26,2019-07-28 signatures=0 Subject: [dpdk-dev] [PATCH v3 2/2] net/octeontx2: support read clock API 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" This patch implements read clock api whose purpose is to return raw clock ticks. Using this API real time ticks spent in processing a packet can be known: - mbuf->timestamp Calling mbox for reading raw clock ticks in fastpath is very expensive so its value is derived from time stamp counter(tsc) using freq multipler (ratio of raw clock ticks and tsc) and clock delta (by how much tsc is lagging from raw clock value). Signed-off-by: Harman Kalra --- V3: * Moved most implementation in otx2_ptp.c keeping otx2_ethdev.c cleaner. * Removed ptp enable check in read_clock op fastpath. V2: * More detailed commit message * changed rdtsc to tsc (timestamp counter) * Initialized a variable to zero only when needed * changed done label to fail drivers/common/octeontx2/otx2_mbox.h | 2 + drivers/net/octeontx2/otx2_ethdev.c | 16 ++++- drivers/net/octeontx2/otx2_ethdev.h | 5 ++ drivers/net/octeontx2/otx2_ptp.c | 100 +++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) diff --git a/drivers/common/octeontx2/otx2_mbox.h b/drivers/common/octeontx= 2/otx2_mbox.h index c0bb676b2..b2c59c86e 100644 --- a/drivers/common/octeontx2/otx2_mbox.h +++ b/drivers/common/octeontx2/otx2_mbox.h @@ -1354,11 +1354,13 @@ struct ptp_req { struct mbox_msghdr hdr; uint8_t __otx2_io op; int64_t __otx2_io scaled_ppm; + uint8_t __otx2_io is_pmu; }; =20 struct ptp_rsp { struct mbox_msghdr hdr; uint64_t __otx2_io clk; + uint64_t __otx2_io tsc; }; =20 struct get_hw_cap_rsp { diff --git a/drivers/net/octeontx2/otx2_ethdev.c b/drivers/net/octeontx2/ot= x2_ethdev.c index 595c8003a..3fb7bd93f 100644 --- a/drivers/net/octeontx2/otx2_ethdev.c +++ b/drivers/net/octeontx2/otx2_ethdev.c @@ -3,7 +3,6 @@ */ =20 #include -#include =20 #include #include @@ -521,6 +520,20 @@ otx2_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, u= int16_t rq, =20 eth_dev->data->rx_queues[rq] =3D rxq; eth_dev->data->rx_queue_state[rq] =3D RTE_ETH_QUEUE_STATE_STOPPED; + + /* Calculating delta and freq mult between PTP HI clock and tsc. + * These are needed in deriving raw clock value from tsc counter. + * read_clock eth op returns raw clock value. + */ + if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) || + otx2_ethdev_is_ptp_en(dev)) { + rc =3D otx2_nix_raw_clock_tsc_conv(dev); + if (rc) { + otx2_err("Failed to calculate delta and freq mult"); + goto fail; + } + } + return 0; =20 free_rxq: @@ -1649,6 +1662,7 @@ static const struct eth_dev_ops otx2_eth_dev_ops =3D = { .vlan_pvid_set =3D otx2_nix_vlan_pvid_set, .rx_queue_intr_enable =3D otx2_nix_rx_queue_intr_enable, .rx_queue_intr_disable =3D otx2_nix_rx_queue_intr_disable, + .read_clock =3D otx2_nix_read_clock, }; =20 static inline int diff --git a/drivers/net/octeontx2/otx2_ethdev.h b/drivers/net/octeontx2/ot= x2_ethdev.h index 863d4877f..720386fd1 100644 --- a/drivers/net/octeontx2/otx2_ethdev.h +++ b/drivers/net/octeontx2/otx2_ethdev.h @@ -5,6 +5,7 @@ #ifndef __OTX2_ETHDEV_H__ #define __OTX2_ETHDEV_H__ =20 +#include #include =20 #include @@ -300,6 +301,8 @@ struct otx2_eth_dev { struct rte_timecounter systime_tc; struct rte_timecounter rx_tstamp_tc; struct rte_timecounter tx_tstamp_tc; + double clk_freq_mult; + uint64_t clk_delta; } __rte_cache_aligned; =20 struct otx2_eth_txq { @@ -527,5 +530,7 @@ int otx2_nix_timesync_write_time(struct rte_eth_dev *et= h_dev, int otx2_nix_timesync_read_time(struct rte_eth_dev *eth_dev, struct timespec *ts); int otx2_eth_dev_ptp_info_update(struct otx2_dev *dev, bool ptp_en); +int otx2_nix_read_clock(struct rte_eth_dev *eth_dev, uint64_t *time); +int otx2_nix_raw_clock_tsc_conv(struct otx2_eth_dev *dev); =20 #endif /* __OTX2_ETHDEV_H__ */ diff --git a/drivers/net/octeontx2/otx2_ptp.c b/drivers/net/octeontx2/otx2_= ptp.c index 0186c629a..52e5456b5 100644 --- a/drivers/net/octeontx2/otx2_ptp.c +++ b/drivers/net/octeontx2/otx2_ptp.c @@ -8,6 +8,81 @@ =20 #define PTP_FREQ_ADJUST (1 << 9) =20 +static int +nix_read_raw_clock(struct otx2_eth_dev *dev, uint64_t *clock, uint64_t *ts= c, + uint8_t is_pmu) +{ + struct otx2_mbox *mbox =3D dev->mbox; + struct ptp_req *req; + struct ptp_rsp *rsp; + int rc; + + req =3D otx2_mbox_alloc_msg_ptp_op(mbox); + req->op =3D PTP_OP_GET_CLOCK; + req->is_pmu =3D is_pmu; + rc =3D otx2_mbox_process_msg(mbox, (void *)&rsp); + if (rc) + goto fail; + + if (clock) + *clock =3D rsp->clk; + if (tsc) + *tsc =3D rsp->tsc; + +fail: + return rc; +} + +/* This function calculates two parameters "clk_freq_mult" and + * "clk_delta" which is useful in deriving PTP HI clock from + * timestamp counter (tsc) value. + */ +int +otx2_nix_raw_clock_tsc_conv(struct otx2_eth_dev *dev) +{ + uint64_t ticks_base =3D 0, ticks =3D 0, tsc =3D 0, t_freq; + int rc, val; + + /* Calculating the frequency at which PTP HI clock is running */ + rc =3D nix_read_raw_clock(dev, &ticks_base, &tsc, false); + if (rc) { + otx2_err("Failed to read the raw clock value: %d", rc); + goto fail; + } + + rte_delay_ms(100); + + rc =3D nix_read_raw_clock(dev, &ticks, &tsc, false); + if (rc) { + otx2_err("Failed to read the raw clock value: %d", rc); + goto fail; + } + + t_freq =3D (ticks - ticks_base) * 10; + + /* Calculating the freq multiplier viz the ratio between the + * frequency at which PTP HI clock works and tsc clock runs + */ + dev->clk_freq_mult =3D + (double)pow(10, floor(log10(t_freq))) / rte_get_timer_hz(); + + val =3D false; +#ifdef RTE_ARM_EAL_RDTSC_USE_PMU + val =3D true; +#endif + rc =3D nix_read_raw_clock(dev, &ticks, &tsc, val); + if (rc) { + otx2_err("Failed to read the raw clock value: %d", rc); + goto fail; + } + + /* Calculating delta between PTP HI clock and tsc */ + dev->clk_delta =3D ((uint64_t)(ticks / dev->clk_freq_mult) - tsc); + +fail: + return rc; +} + static void nix_start_timecounters(struct rte_eth_dev *eth_dev) { @@ -224,6 +299,13 @@ otx2_nix_timesync_adjust_time(struct rte_eth_dev *eth_= dev, int64_t delta) rc =3D otx2_mbox_process_msg(mbox, (void *)&rsp); if (rc) return rc; + /* Since the frequency of PTP comp register is tuned, delta and + * freq mult calculation for deriving PTP_HI from timestamp + * counter should be done again. + */ + rc =3D otx2_nix_raw_clock_tsc_conv(dev); + if (rc) + otx2_err("Failed to calculate delta and freq mult"); } dev->systime_tc.nsec +=3D delta; dev->rx_tstamp_tc.nsec +=3D delta; @@ -271,3 +353,21 @@ otx2_nix_timesync_read_time(struct rte_eth_dev *eth_de= v, struct timespec *ts) =20 return 0; } + + +int +otx2_nix_read_clock(struct rte_eth_dev *eth_dev, uint64_t *clock) +{ + struct otx2_eth_dev *dev =3D otx2_eth_pmd_priv(eth_dev); + + /* This API returns the raw PTP HI clock value. Since LFs doesn't + * have direct access to PTP registers and it requires mbox msg + * to AF for this value. In fastpath reading this value for every + * packet (which involes mbox call) becomes very expensive, hence + * we should be able to derive PTP HI clock value from tsc by + * using freq_mult and clk_delta calculated during configure stage. + */ + *clock =3D (rte_get_tsc_cycles() + dev->clk_delta) * dev->clk_freq_mult; + + return 0; +} --=20 2.18.0