From patchwork Sat Jul 27 20:27:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harman Kalra X-Patchwork-Id: 57204 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 199271BFBB; Sat, 27 Jul 2019 22:27:21 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 8F4B31BFBA for ; Sat, 27 Jul 2019 22:27:19 +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 x6RKR6w1012233 for ; Sat, 27 Jul 2019 13:27:18 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=vkgdez1xYm4xj679Ucu03iAN8Z6a2zRvtc4Aq66RoHM=; b=GCQvkopimq6r0btMsOffcb26nMIF0pmLFlRZxvrpx43BJo+JycXIlbr5+8pEUIAc1KEv FODaiAV3FxjnZXJzyMvnBTp7C+HsqfNpS0YjOUKUr6pzEhHMjey/LFnUUXh6iQC+2fzd vR7zDZhIDNDn9m0uHj4iGSt+ssuhMkbhq2dA9tqJ+QuybqROSpj9nKYnezIFRb5A2lvF Tv3VgtwM5ufNIK3JXxqYGHSnp0dYd/CQ8l3dZqNeVY4Y1AB9McU6tkxMp0Qg8xo3FgDT hJg4w/3g48ZaIwP//NgdfuFMe+NL8fgGDtHj3Ip6uzh2HS1exn8ufjPvooKjEqFjRYka 1g== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2u0p4ks8jb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 27 Jul 2019 13:27:18 -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; Sat, 27 Jul 2019 13:27:16 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (104.47.32.54) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 27 Jul 2019 13:27:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AnSw/dJ8AFG9JTJdpIFJ0cfgDoReYivNosHd/MLtHdA5mmXsgGlgqLvB6Z99uG43jZZbBmiSpEWrvdJgPst7JluTYNfbKuYMwgMympvWAOYhinghljJY68Dy6muqb/bKKhfi6zapetsMSjUaMtSSZ08HsOBfS8BFsVyWLo1crlHT/LcFv11mpIsNC3EZhqomfmDAY1L1qcb2U3/8nL58hVTDUN5DMBWXOwuEyhBZ7fVfg2LpTiMFU+k7ErYdbmjTr6iBqDtas38y+0FpLq7OQl0nWqK2775S3kpR2Sh27s5nMTs3/UL39Liz9V7pwoxVmMhBWGgj/aW2Jabm33L2hQ== 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=vkgdez1xYm4xj679Ucu03iAN8Z6a2zRvtc4Aq66RoHM=; b=YXx9JFkYVIn0nPAONT1pTj1+CS4OZTLUw5cTSBQRh0yioBDjFKdRX8+gs/noJZba9Gb99yu59eLab7aHVItMoP7zwXxzDUYB4LgCwNYnk/NXd3g9fIPmYyzkwVM2UirF/ViZmCJLsmqNGHwtaV1oWGjO/EC40qwpLy3Wt3fkBbhlf2L4Dmgq1lZaFoOqu9WXMLXcktpud3pU7cqPRaHJ6AlGrUgpqT0K/CEuqtTBFsUbMZruA6PS+6/Uq7oUGUxymfHJOHiq2jfFteU2066fdoKBc2uJWNcAIwOPCpfRK5TGGOkShcsE1HEiyyfq1JxLGy/i87yBMff+oUE7fX74UQ== 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=vkgdez1xYm4xj679Ucu03iAN8Z6a2zRvtc4Aq66RoHM=; b=eIrSzy1NEdZpmDEJ+afiycoHFIUlZXQ+nMm2bY/ZaJ3QJTWooecVhi8awmjdhHJGW/NhUnzigbJxuJhhBdEIfNdvHZBUFwAcO+AgJduJ58OryrWqNDlSsW3K7Djl5qqKRybr23HuJx4wjPXs9reDEnrmFp+tFOxSpdY71DGUrLU= Received: from MN2PR18MB2848.namprd18.prod.outlook.com (20.179.21.149) by MN2PR18MB2880.namprd18.prod.outlook.com (20.179.22.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Sat, 27 Jul 2019 20:27:15 +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; Sat, 27 Jul 2019 20:27:14 +0000 From: Harman Kalra To: Pavan Nikhilesh Bhagavatula , "Jerin Jacob Kollanukkaran" , Nithin Kumar Dabilpuram , Kiran Kumar Kokkilagadda CC: "dev@dpdk.org" , Harman Kalra Thread-Topic: [PATCH v2 1/2] net/octeontx2: fix ptp performance issue Thread-Index: AQHVRLmt66GCBNxF7kCf8ZUo2KVshw== Date: Sat, 27 Jul 2019 20:27:14 +0000 Message-ID: <1564259217-26738-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: BMXPR01CA0029.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::15) 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: 2e09b278-6a9b-457c-436b-08d712d0cf88 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:MN2PR18MB2880; x-ms-traffictypediagnostic: MN2PR18MB2880: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 01110342A5 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(376002)(136003)(346002)(39850400004)(366004)(199004)(189003)(36756003)(66946007)(186003)(66446008)(64756008)(66556008)(66476007)(2616005)(6116002)(68736007)(99286004)(52116002)(55236004)(71190400001)(4326008)(476003)(305945005)(26005)(14454004)(386003)(6506007)(54906003)(110136005)(7736002)(5660300002)(3846002)(316002)(107886003)(86362001)(25786009)(66066001)(478600001)(2906002)(14444005)(256004)(53936002)(6512007)(8936002)(8676002)(81156014)(81166006)(102836004)(6486002)(71200400001)(486006)(6436002)(50226002)(6636002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2880; 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: SaQe5DgSUTbouApPF14zkXjR9ye504BCQLgvz+7cMXW3a0r3onCNo7doMHdFGLBZb7TsINmfvSnmFOJl5fZjFLpGnu/VWLLpj8iAoSMv7IeDiYlGhClxJZOZ51sHIZw0NLfVjEKRUFFe4VowWvpztDG9ZtHkwCyn6PbwqfSH3MwZL1L4D/xB0tQXKQi6tmvD8cKJT+RgJvv+7f8JLSfiBBovhghiE04/4izs+jJhbTgB+5Dj/4SN2Nn4U7ZcmKTscgOqdxOy3VdHnFD8+0bv6g424vEtdGm0OzF8PB4ERmlKiCPhSo2SJlgCw7NRU1734z7C49lmI1hWdXYqKzOCNQbh6Ql4s7YMmDsCulDLETEsNE4Z2ZNautwSRGJQ5I5KvYIST9v0cf31oNFdrkBvhsjj2Lb9pYB6BPEpD0GQ38k= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 2e09b278-6a9b-457c-436b-08d712d0cf88 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jul 2019 20:27:14.6432 (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: MN2PR18MB2880 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-07-27_15:2019-07-26,2019-07-27 signatures=0 Subject: [dpdk-dev] [PATCH v2 1/2] net/octeontx2: fix ptp performance issue 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" A huge drop in per core MPPS value was observed when PTP stack is enabled. The reason behind the bottleneck is HW serialises the transfer of all SQEs, which seeks timestamp capture, on the same send DMA path. Hence only those packets which requires timestamp capture should set SETTSTAMP in send mem alg. With this patch timestamping would be done only for those packets with PKT_TX_IEEE1588_TMST set. Fixes: fb3ae0951abd ("net/octeontx2: support Tx") Fixes: 8980a153006b ("event/octeontx2: support PTP for SSO") Signed-off-by: Harman Kalra --- drivers/event/octeontx2/otx2_evdev.h | 7 ++++++- drivers/event/octeontx2/otx2_worker.h | 10 +++++++-- drivers/event/octeontx2/otx2_worker_dual.h | 14 +++++++++++-- drivers/net/octeontx2/otx2_ethdev.c | 2 -- drivers/net/octeontx2/otx2_rx.c | 3 ++- drivers/net/octeontx2/otx2_rx.h | 24 +++++++++++++--------- drivers/net/octeontx2/otx2_tx.h | 19 +++++++++++++---- 7 files changed, 57 insertions(+), 22 deletions(-) diff --git a/drivers/event/octeontx2/otx2_evdev.h b/drivers/event/octeontx2/otx2_evdev.h index 9c9718f6f..5cd80e3b2 100644 --- a/drivers/event/octeontx2/otx2_evdev.h +++ b/drivers/event/octeontx2/otx2_evdev.h @@ -25,6 +25,7 @@ #define OTX2_SSO_SQB_LIMIT (0x180) #define OTX2_SSO_XAQ_SLACK (8) #define OTX2_SSO_XAQ_CACHE_CNT (0x7) +#define OTX2_SSO_WQE_SG_PTR (9) /* SSO LF register offsets (BAR2) */ #define SSO_LF_GGRP_OP_ADD_WORK0 (0x0ull) @@ -222,10 +223,14 @@ otx2_wqe_to_mbuf(uint64_t get_work1, const uint64_t mbuf, uint8_t port_id, const void * const lookup_mem) { struct nix_wqe_hdr_s *wqe = (struct nix_wqe_hdr_s *)get_work1; + uint64_t val = mbuf_init.value | (uint64_t)port_id << 48; + + if (flags & NIX_RX_OFFLOAD_TSTAMP_F) + val |= NIX_TIMESYNC_RX_OFFSET; otx2_nix_cqe_to_mbuf((struct nix_cqe_hdr_s *)wqe, tag, (struct rte_mbuf *)mbuf, lookup_mem, - mbuf_init.value | (uint64_t)port_id << 48, flags); + val, flags); } diff --git a/drivers/event/octeontx2/otx2_worker.h b/drivers/event/octeontx2/otx2_worker.h index 3c847d223..76f91bb59 100644 --- a/drivers/event/octeontx2/otx2_worker.h +++ b/drivers/event/octeontx2/otx2_worker.h @@ -18,6 +18,7 @@ otx2_ssogws_get_work(struct otx2_ssogws *ws, struct rte_event *ev, const uint32_t flags, const void * const lookup_mem) { union otx2_sso_event event; + uint64_t tstamp_ptr; uint64_t get_work1; uint64_t mbuf; @@ -69,8 +70,10 @@ otx2_ssogws_get_work(struct otx2_ssogws *ws, struct rte_event *ev, otx2_wqe_to_mbuf(get_work1, mbuf, event.sub_event_type, (uint32_t) event.get_work0, flags, lookup_mem); /* Extracting tstamp, if PTP enabled*/ + tstamp_ptr = *(uint64_t *)(((struct nix_wqe_hdr_s *)get_work1) + + OTX2_SSO_WQE_SG_PTR); otx2_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, ws->tstamp, - flags); + flags, (uint64_t *)tstamp_ptr); get_work1 = mbuf; } @@ -86,6 +89,7 @@ otx2_ssogws_get_work_empty(struct otx2_ssogws *ws, struct rte_event *ev, const uint32_t flags) { union otx2_sso_event event; + uint64_t tstamp_ptr; uint64_t get_work1; uint64_t mbuf; @@ -131,8 +135,10 @@ otx2_ssogws_get_work_empty(struct otx2_ssogws *ws, struct rte_event *ev, otx2_wqe_to_mbuf(get_work1, mbuf, event.sub_event_type, (uint32_t) event.get_work0, flags, NULL); /* Extracting tstamp, if PTP enabled*/ + tstamp_ptr = *(uint64_t *)(((struct nix_wqe_hdr_s *)get_work1) + + OTX2_SSO_WQE_SG_PTR); otx2_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, ws->tstamp, - flags); + flags, (uint64_t *)tstamp_ptr); get_work1 = mbuf; } diff --git a/drivers/event/octeontx2/otx2_worker_dual.h b/drivers/event/octeontx2/otx2_worker_dual.h index 4a72f424d..5134e3d52 100644 --- a/drivers/event/octeontx2/otx2_worker_dual.h +++ b/drivers/event/octeontx2/otx2_worker_dual.h @@ -21,6 +21,7 @@ otx2_ssogws_dual_get_work(struct otx2_ssogws_state *ws, { const uint64_t set_gw = BIT_ULL(16) | 1; union otx2_sso_event event; + uint64_t tstamp_ptr; uint64_t get_work1; uint64_t mbuf; @@ -70,8 +71,17 @@ otx2_ssogws_dual_get_work(struct otx2_ssogws_state *ws, event.event_type == RTE_EVENT_TYPE_ETHDEV) { otx2_wqe_to_mbuf(get_work1, mbuf, event.sub_event_type, (uint32_t) event.get_work0, flags, lookup_mem); - /* Extracting tstamp, if PTP enabled*/ - otx2_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, tstamp, flags); + /* Extracting tstamp, if PTP enabled. CGX will prepend the + * timestamp at starting of packet data and it can be derieved + * from WQE 9 dword which corresponds to SG iova. + * rte_pktmbuf_mtod_offset can be used for this purpose but it + * brings down the performance as it reads mbuf->buf_addr which + * is not part of cache in general fast path. + */ + tstamp_ptr = *(uint64_t *)(((struct nix_wqe_hdr_s *)get_work1) + + OTX2_SSO_WQE_SG_PTR); + otx2_nix_mbuf_to_tstamp((struct rte_mbuf *)mbuf, tstamp, flags, + (uint64_t *)tstamp_ptr); get_work1 = mbuf; } diff --git a/drivers/net/octeontx2/otx2_ethdev.c b/drivers/net/octeontx2/otx2_ethdev.c index b018b25b7..595c8003a 100644 --- a/drivers/net/octeontx2/otx2_ethdev.c +++ b/drivers/net/octeontx2/otx2_ethdev.c @@ -874,8 +874,6 @@ otx2_nix_form_default_desc(struct otx2_eth_txq *txq) send_mem = (struct nix_send_mem_s *)(txq->cmd + (send_hdr->w0.sizem1 << 1)); send_mem->subdc = NIX_SUBDC_MEM; - send_mem->dsz = 0x0; - send_mem->wmem = 0x1; send_mem->alg = NIX_SENDMEMALG_SETTSTMP; send_mem->addr = txq->dev->tstamp.tx_tstamp_iova; } diff --git a/drivers/net/octeontx2/otx2_rx.c b/drivers/net/octeontx2/otx2_rx.c index deefe9588..701efc858 100644 --- a/drivers/net/octeontx2/otx2_rx.c +++ b/drivers/net/octeontx2/otx2_rx.c @@ -68,7 +68,8 @@ nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, otx2_nix_cqe_to_mbuf(cq, cq->tag, mbuf, lookup_mem, mbuf_init, flags); - otx2_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, flags); + otx2_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, flags, + (uint64_t *)((uint8_t *)mbuf + data_off)); rx_pkts[packets++] = mbuf; otx2_prefetch_store_keep(mbuf); head++; diff --git a/drivers/net/octeontx2/otx2_rx.h b/drivers/net/octeontx2/otx2_rx.h index e150f38d7..d12e8b809 100644 --- a/drivers/net/octeontx2/otx2_rx.h +++ b/drivers/net/octeontx2/otx2_rx.h @@ -50,22 +50,26 @@ union mbuf_initializer { static __rte_always_inline void otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf, - struct otx2_timesync_info *tstamp, const uint16_t flag) + struct otx2_timesync_info *tstamp, const uint16_t flag, + uint64_t *tstamp_ptr) { if ((flag & NIX_RX_OFFLOAD_TSTAMP_F) && - mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC && (mbuf->data_off == RTE_PKTMBUF_HEADROOM + NIX_TIMESYNC_RX_OFFSET)) { - uint64_t *tstamp_ptr; - /* Deal with rx timestamp */ - tstamp_ptr = rte_pktmbuf_mtod_offset(mbuf, uint64_t *, - -NIX_TIMESYNC_RX_OFFSET); + /* Reading the rx timestamp inserted by CGX, viz at + * starting of the packet data. + */ mbuf->timestamp = rte_be_to_cpu_64(*tstamp_ptr); - tstamp->rx_tstamp = mbuf->timestamp; - tstamp->rx_ready = 1; - mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | PKT_RX_IEEE1588_TMST - | PKT_RX_TIMESTAMP; + /* PKT_RX_IEEE1588_TMST flag needs to be set only in case + * PTP packets are received. + */ + if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) { + tstamp->rx_tstamp = mbuf->timestamp; + tstamp->rx_ready = 1; + mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | + PKT_RX_IEEE1588_TMST | PKT_RX_TIMESTAMP; + } } } diff --git a/drivers/net/octeontx2/otx2_tx.h b/drivers/net/octeontx2/otx2_tx.h index b75a220ea..494ba3884 100644 --- a/drivers/net/octeontx2/otx2_tx.h +++ b/drivers/net/octeontx2/otx2_tx.h @@ -43,18 +43,29 @@ otx2_nix_xmit_prepare_tstamp(uint64_t *cmd, const uint64_t *send_mem_desc, if (flags & NIX_TX_OFFLOAD_TSTAMP_F) { struct nix_send_mem_s *send_mem; uint16_t off = (no_segdw - 1) << 1; + const uint8_t is_ol_tstamp = !(ol_flags & PKT_TX_IEEE1588_TMST); send_mem = (struct nix_send_mem_s *)(cmd + off); - if (flags & NIX_TX_MULTI_SEG_F) + if (flags & NIX_TX_MULTI_SEG_F) { /* Retrieving the default desc values */ cmd[off] = send_mem_desc[6]; + /* Using compiler barier to avoid voilation of C + * aliasing rules. + */ + rte_compiler_barrier(); + } + /* Packets for which PKT_TX_IEEE1588_TMST is not set, tx tstamp - * should not be updated at tx tstamp registered address, rather - * a dummy address which is eight bytes ahead would be updated + * should not be recorded, hence changing the alg type to + * NIX_SENDMEMALG_SET and also changing send mem addr field to + * next 8 bytes as it corrpt the actual tx tstamp registered + * address. */ + send_mem->alg = NIX_SENDMEMALG_SETTSTMP - (is_ol_tstamp); + send_mem->addr = (rte_iova_t)((uint64_t *)send_mem_desc[7] + - !(ol_flags & PKT_TX_IEEE1588_TMST)); + (is_ol_tstamp)); } } From patchwork Sat Jul 27 20:27:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harman Kalra X-Patchwork-Id: 57205 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06E561C0AD; Sat, 27 Jul 2019 22:27:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 659701BFBA for ; Sat, 27 Jul 2019 22:27:25 +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 x6RKROKp012667 for ; Sat, 27 Jul 2019 13:27:24 -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=k7bbJgddnpmKmDB1KSRSGEFfJ6RwGtjswC55uXIibGo=; b=M4yhO5uCRDEjOvw0+eoiKt9kc6Zkui9Vc110P1a900pgevDI7YV+P6FNBEYYGUU5jU7m jGFfppAY/Qma8hR7Q/JRZcmHgvKqxlvjqQezpvF6yEOFMgjMBiBRl2iRPNkdiQGvroEt JRnFOKryoHS5uI8v8kfOunUZgTJYb9mtmKeusXR2/PVPSfls2xh1BV/sDECel00Y9nJG MdgfOKx7ngDno8X5+zxi3n8LRQtvy6gDnuhu3jzw2Tp9fP4xNYUQBAyUGT8KC9+SsOZQ NL7lqOfeSCiGP3972E3ewtKC/0DXV4dMagaFKriDl5qiwGjcwRsY1L3WQsGOCqKZG5XV cw== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2u0p4ks8jg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 27 Jul 2019 13:27:24 -0700 Received: from SC-EXCH02.marvell.com (10.93.176.82) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 27 Jul 2019 13:27:22 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (104.47.32.52) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 27 Jul 2019 13:27:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GpY/BbUy6jBUdYsIvOHHyTThQZ7Texpb+G1JvKoQwJmGBoTpErNCPKZ65c+AbRBiJunoW7UVJBr+KxIa+/yyqdzhcG/AUZO1IN5qo6+NzqNo8tJYaimxpf8HZBsnnIfb2YuXIkdUQYwiGLQYdng3HmIsajOZvSu4gkV3Zo75/uuUIj8GcXmKT3h7ZOj6+wZBte+MxAitKcS+MpiYbfUdtSRSawfFoLbq22HciDkuDo8R4lgbHtAtt9EYLp1AspP/ft/bPzKXuu+SrGbu1SRxryQgW+/TFsI2FZj8g0MT8MmA8XNkqY8s/3qkmceUfCmZTi08xkHNTix+9rmTSbAc2g== 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=k7bbJgddnpmKmDB1KSRSGEFfJ6RwGtjswC55uXIibGo=; b=c8I/0o4lcz3ikIGRcjOH3bBu/Otkn+57rQF8By/vCtWhkhSkhqTby+B/Y9Q8K/Q58gei3GwaRKqKjCH3KG/LX8C9VpQmrXDsCVg+E0Fh5D5TYqS85wE9tZMBWoQBW2msk0dT0QGTPhpYykT/bBLTXA7Y+PRVxD1vEQvPy6ULZxO5qS4CwD9828s6nBZ+B56qQXiAYRipZYe2grJ7BP83iOZMq3y9hkusTPF7khaaASwVYF9NvMLfKJNHn+UUmtUui5L6o3CqwkZXODehss1ZiseKanvunF1YX/qhNggkQlwIS9B6Uby7WfP1SbL6EFLgSOobUWAOukEmsGe6Uzq9uQ== 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=k7bbJgddnpmKmDB1KSRSGEFfJ6RwGtjswC55uXIibGo=; b=j3KHpSCV8F+9J1xmfS4xDJGdJ3WvBz7/rBHFMXoxuMb0VH2ZjU+MKsuJ6xAV4IvJQG0MduJhhmg/lHSrVgNSRqgKA+zw1uBv/2hJTW6qRG8caRqgILE8vfEyqN6MwcgDqDCPPh9ekitPMx8TYc8hJJ7mjgHrCSZVOAvzGa33zH0= Received: from MN2PR18MB2848.namprd18.prod.outlook.com (20.179.21.149) by MN2PR18MB2880.namprd18.prod.outlook.com (20.179.22.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2115.10; Sat, 27 Jul 2019 20:27:21 +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; Sat, 27 Jul 2019 20:27:21 +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 v2 2/2] net/octeontx2: support read clock API Thread-Index: AQHVRLmxf3ZBRPjbhkyIQ6M7EKuPWg== Date: Sat, 27 Jul 2019 20:27:21 +0000 Message-ID: <1564259217-26738-2-git-send-email-hkalra@marvell.com> References: <1564259217-26738-1-git-send-email-hkalra@marvell.com> In-Reply-To: <1564259217-26738-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: BMXPR01CA0029.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::15) 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: af54a4fc-0463-46a7-ae11-08d712d0d392 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:MN2PR18MB2880; x-ms-traffictypediagnostic: MN2PR18MB2880: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1443; x-forefront-prvs: 01110342A5 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(376002)(136003)(346002)(39850400004)(366004)(199004)(189003)(36756003)(66946007)(446003)(186003)(66446008)(64756008)(66556008)(66476007)(2616005)(11346002)(6116002)(68736007)(99286004)(52116002)(55236004)(71190400001)(4326008)(476003)(305945005)(26005)(14454004)(386003)(6506007)(54906003)(110136005)(7736002)(5660300002)(3846002)(316002)(107886003)(86362001)(25786009)(66066001)(478600001)(2906002)(14444005)(256004)(53936002)(6512007)(8936002)(8676002)(81156014)(81166006)(102836004)(76176011)(6486002)(71200400001)(486006)(6436002)(50226002)(6636002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2880; 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: S9WAeh3EQqrz+yGaw60h5MxaYdDLKBMAdUCdh5WeU/YNjrlHPTw9R31BnmYdjtbSCxdbbW5Iwvu+71ZGoVjOHzagfqmYVXpJcqS3ht4Wq181+0/rcRiiDZQ1ymESEgIdGEmRFrJZzXk/mkn4fpoye4Iuxl9Jp4bcluFLj655G9l9mSpaf0YbUp+HQyVyXB5dZdTYN6N1UKzeZObQsN5iG5ixUYRpkIae+dyFf7s1dkVrIXue7WFiIeM8fTX8szmHSvXEBk35WF504xULG28vtQff/2Srcnocscn3GPayGIRCT5jxcnk2F3FbDjSy9K7jKLcigHOtMmIdC9FyjMTxWCXnaD9MoDF8VvOVswwjpiVAVTRslrq7mbtgwOqf+zUSYU5Mhvjpjeyyg42HDYCDv7yxGgw35xqbk9rpKV+Ja4w= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: af54a4fc-0463-46a7-ae11-08d712d0d392 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jul 2019 20:27:21.1925 (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: MN2PR18MB2880 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:5.22.84,1.0.8 definitions=2019-07-27_15:2019-07-26,2019-07-27 signatures=0 Subject: [dpdk-dev] [PATCH v2 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 --- 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 | 89 ++++++++++++++++++++++++++++ drivers/net/octeontx2/otx2_ethdev.h | 4 ++ drivers/net/octeontx2/otx2_ptp.c | 30 ++++++++++ 4 files changed, 125 insertions(+) diff --git a/drivers/common/octeontx2/otx2_mbox.h b/drivers/common/octeontx2/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; }; struct ptp_rsp { struct mbox_msghdr hdr; uint64_t __otx2_io clk; + uint64_t __otx2_io tsc; }; struct get_hw_cap_rsp { diff --git a/drivers/net/octeontx2/otx2_ethdev.c b/drivers/net/octeontx2/otx2_ethdev.c index 595c8003a..ddbce945d 100644 --- a/drivers/net/octeontx2/otx2_ethdev.c +++ b/drivers/net/octeontx2/otx2_ethdev.c @@ -521,6 +521,19 @@ otx2_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t rq, eth_dev->data->rx_queues[rq] = rxq; eth_dev->data->rx_queue_state[rq] = RTE_ETH_QUEUE_STATE_STOPPED; + + /* Calculating delta and freq mult between PTP HI clock and tsc. + * These are needed for deriving PTP HI clock value from tsc counter. + */ + if ((dev->rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) || + otx2_ethdev_is_ptp_en(dev)) { + rc = otx2_nix_raw_clock_tsc_conv(dev); + if (rc) { + otx2_err("Failed to calculate delta and freq mult"); + goto fail; + } + } + return 0; free_rxq: @@ -1186,6 +1199,81 @@ nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev) rte_mb(); } +static int +nix_read_raw_clock(struct otx2_eth_dev *dev, uint64_t *clock, uint64_t *tsc, + uint8_t is_pmu) +{ + struct otx2_mbox *mbox = dev->mbox; + struct ptp_req *req; + struct ptp_rsp *rsp; + int rc; + + req = otx2_mbox_alloc_msg_ptp_op(mbox); + req->op = PTP_OP_GET_CLOCK; + req->is_pmu = is_pmu; + rc = otx2_mbox_process_msg(mbox, (void *)&rsp); + if (rc) + goto fail; + + if (clock) + *clock = rsp->clk; + if (tsc) + *tsc = 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 = 0, ticks = 0, tsc = 0, t_freq; + int rc, val; + + /* Calculating the frequency at which PTP HI clock is running */ + rc = 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 = 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 = (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 = + (double)pow(10, floor(log10(t_freq))) / rte_get_timer_hz(); + + val = false; +#ifdef RTE_ARM_EAL_RDTSC_USE_PMU + val = true; +#endif + rc = 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 = ((uint64_t)(ticks / dev->clk_freq_mult) - tsc); + +fail: + return rc; +} + static int otx2_nix_configure(struct rte_eth_dev *eth_dev) { @@ -1649,6 +1737,7 @@ static const struct eth_dev_ops otx2_eth_dev_ops = { .vlan_pvid_set = otx2_nix_vlan_pvid_set, .rx_queue_intr_enable = otx2_nix_rx_queue_intr_enable, .rx_queue_intr_disable = otx2_nix_rx_queue_intr_disable, + .read_clock = otx2_nix_read_clock, }; static inline int diff --git a/drivers/net/octeontx2/otx2_ethdev.h b/drivers/net/octeontx2/otx2_ethdev.h index 863d4877f..ef2ff762d 100644 --- a/drivers/net/octeontx2/otx2_ethdev.h +++ b/drivers/net/octeontx2/otx2_ethdev.h @@ -300,6 +300,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; struct otx2_eth_txq { @@ -527,5 +529,7 @@ int otx2_nix_timesync_write_time(struct rte_eth_dev *eth_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); #endif /* __OTX2_ETHDEV_H__ */ diff --git a/drivers/net/octeontx2/otx2_ptp.c b/drivers/net/octeontx2/otx2_ptp.c index 0186c629a..7b24c6644 100644 --- a/drivers/net/octeontx2/otx2_ptp.c +++ b/drivers/net/octeontx2/otx2_ptp.c @@ -224,6 +224,13 @@ otx2_nix_timesync_adjust_time(struct rte_eth_dev *eth_dev, int64_t delta) rc = 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 = otx2_nix_raw_clock_tsc_conv(dev); + if (rc) + otx2_err("Failed to calculate delta and freq mult"); } dev->systime_tc.nsec += delta; dev->rx_tstamp_tc.nsec += delta; @@ -271,3 +278,26 @@ otx2_nix_timesync_read_time(struct rte_eth_dev *eth_dev, struct timespec *ts) return 0; } + + +int +otx2_nix_read_clock(struct rte_eth_dev *eth_dev, uint64_t *clock) +{ + struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev); + + if (!otx2_ethdev_is_ptp_en(dev)) { + otx2_err("PTP should be enabled."); + return -EINVAL; + } + + /* 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 = (rte_get_tsc_cycles() + dev->clk_delta) * dev->clk_freq_mult; + + return 0; +}