From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E0251459DD; Fri, 20 Sep 2024 08:45:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C6FC9433E3; Fri, 20 Sep 2024 08:45:07 +0200 (CEST) Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11022120.outbound.protection.outlook.com [52.101.66.120]) by mails.dpdk.org (Postfix) with ESMTP id 5F7DA40669 for ; Fri, 20 Sep 2024 08:45:06 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QYGDcrd1CMb2FAeGOQrATiUYypPcP/3qQjWpjYWkmyhwy8lpTuaD1QZhXPay+gXR7MgRTS7uK2lLz9cdluOrMx8BeE107L3TEa6ZBgMQphwU3KBRNddnIZ5gmvjQbAVdNJapmghdJg20NcZ4JVW/ZBAf4JUKJurrf2EjJpsG04oSwkF39AszuWmvjUKeV04+UH6/HlkLAwYeITG8m2sChDHyHBXnsvvA2wdIBr7ETnYOrJsPff6JV7zpVCDCBl9FX8EznWTbezBRZ2x2qsyPnBHDhVxi4H6fQPKmnppmQbBiBdECKD9iaV8P3xqHpgZvp3hNUQI3BcFCUFlm2+cJ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xdxO3dVxgvpJlkNMMZZ9FHjLzL8IyBii8uA5yxcO3DM=; b=hP1kEMFemi23YE6lhYcjb9z8LFyUT1Srdw4GOzNhZHboE6DR+uW6qp6HIxENfoNOkKSqmRNmzVpATqiZAEeVmsNuwafbliE0MSTTKvR2+wh2ImJfgZviCxr90FwIUXzJ2S91zpfHVr4ZJfoqFmeEPQ4xsEe/5F2gOxcEEh/OPHZzT4ZzlHCnyFhJcWK/nkvytco8f1VkjhK0RFfcKCs22XiiFjnRQlSkes132wA+zmSqW/OOuV8pD7GQzArxD+1s6hc+uZE4JQafhZYf9g/I0Dh81RWlc8bAlssNup9iGQsYA4g7tbBS95ZsPYBUBIHuwNp2GFwiymLaFQI7zZaoyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 212.183.10.29) smtp.rcpttodomain=dpdk.org smtp.mailfrom=omicronenergy.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject header.from=omicronenergy.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omicronenergy.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xdxO3dVxgvpJlkNMMZZ9FHjLzL8IyBii8uA5yxcO3DM=; b=NtrBsEyygs2yFw9C+u4bxucow9qgQbpEC7rsy5OJA98aKwvrq7hSYiyQulf7zSjBfwNGAmk8bxW31MGCg7JxiSQy1b2wpGcJavY6sSJcDw0S1LAr+TZATRqZd5NrNiGG92U34+YxNEq7PhHyC4WbeXXaL+hdDjHIjo/r+tU8HMo= Received: from AS9PR06CA0058.eurprd06.prod.outlook.com (2603:10a6:20b:463::32) by DB3PR0302MB9258.eurprd03.prod.outlook.com (2603:10a6:10:431::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Fri, 20 Sep 2024 06:45:03 +0000 Received: from AMS0EPF000001A5.eurprd05.prod.outlook.com (2603:10a6:20b:463:cafe::d5) by AS9PR06CA0058.outlook.office365.com (2603:10a6:20b:463::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.29 via Frontend Transport; Fri, 20 Sep 2024 06:45:03 +0000 X-MS-Exchange-Authentication-Results: spf=fail (sender IP is 212.183.10.29) smtp.mailfrom=omicronenergy.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=omicronenergy.com; Received-SPF: Fail (protection.outlook.com: domain of omicronenergy.com does not designate 212.183.10.29 as permitted sender) receiver=protection.outlook.com; client-ip=212.183.10.29; helo=outlook.omicron.at; Received: from outlook.omicron.at (212.183.10.29) by AMS0EPF000001A5.mail.protection.outlook.com (10.167.16.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Fri, 20 Sep 2024 06:45:02 +0000 Received: from stelas00wl01.omicron.at (172.22.41.139) by EXC03-ATKLA.omicron.at (172.22.100.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 20 Sep 2024 08:45:01 +0200 From: Stefan Laesser To: CC: Stefan Laesser , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v2] net/af_packet: add timestamp offloading support Date: Fri, 20 Sep 2024 08:44:08 +0200 Message-ID: <20240920064408.64651-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903114306.2336633-1-stefan.laesser@omicronenergy.com> References: <20240903114306.2336633-1-stefan.laesser@omicronenergy.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [172.22.41.139] X-ClientProxiedBy: EXC03-ATKLA.omicron.at (172.22.100.188) To EXC03-ATKLA.omicron.at (172.22.100.188) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001A5:EE_|DB3PR0302MB9258:EE_ X-MS-Office365-Filtering-Correlation-Id: d0c53f03-8c39-4ff2-d87b-08dcd93fc149 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZzVOdTNDQzYwb1l0ZEJwVUR4T1RPZEFCYll3S2ZhOEc2dW5LT1ZsL1A2SG1H?= =?utf-8?B?STBYSkVHMzRyNnRkb1k0TjcvNll6bXVDQUIwczJ0VmdDekU2N01mTGlpOFlt?= =?utf-8?B?SFUxVlQ3YmJnUzdJVzFGNHA4TFBZendmMzFSaXV5dEdXNHZheHljYkhWdmI3?= =?utf-8?B?VkRkUWthQ25kWk1WSXhEWmRadDNNN29xK2lVRmhDb2xuNm5zalF5ekowbnlj?= =?utf-8?B?c2ZRbVh3OHRueUhvbkhidm1GTnNGdXVva1J1VzhCOTVEbGlRRjV2SCtEdW9k?= =?utf-8?B?NTY5cjdEbmpvYmFWS3lhUUxhcUFWZVJ5dlhQcTVvMXpvaWlsR2k3TmYvRDZW?= =?utf-8?B?ZU9NNHVyU2JIMzJ6NHJyRXk5UC8rVFQ4TWdBOUg4WnFLMXFQMG1hT3N3ZGt2?= =?utf-8?B?azE4VFA5aDArV0ZkMmdlQVp1L0pxb2VJQmxRRy9QTEJUWG9sZlkvelU0T1Qr?= =?utf-8?B?S1ZYdGw2QU5ocWFGdnhLQ1BpTWtDRXdNT3BWc1FZK2t0SkRITHp4RW5mVjgv?= =?utf-8?B?ME5ocDNlZm51NU1HMEQzQnk5djEvMi8wNko3N1lTUDBFVGRwaWVFZWZJVE9E?= =?utf-8?B?SzRjbHdnVnRFc3J4dGwxenZDUWVxcnhoNGRZdWwrQ3FqMWo0cWpIS3lKbVEw?= =?utf-8?B?WTMyVFZ3RTJVKzUyNmlxZ0twbmZvSE5LT04yRHJNV1ROWVozVSt0aGxZWVhh?= =?utf-8?B?UTFtZXhIVlU2QjQrdUpRS05FK1dCQTFTTUY1ZlpsRXE1MzRmeTVpaG5ocktO?= =?utf-8?B?Z29EZzdRW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cr?= =?utf-8?B?UjU3WFNSQ0VhWXVMamxUMEZJMmFjKzMzY3VFazNIdlFrTHZOTy9NSU54anY5?= =?utf-8?B?OWFiNEp1Z3lSOERwb2JIZk5sRHc0WUtTYllhK0o4aENIT0lGakJLS2FlaHpN?= =?utf-8?B?b3pSaDBzSk9GWHlKQUdkRHYzU1g2MG50OUk2VVhSN1NPaUtabVlXcWQxNXVn?= =?utf-8?B?RFRSWTNWcTVVOE9ZclpPVlJaa1oxRng3MjVMZkwzcHgvRy9qQThMTG5kanpp?= =?utf-8?Q?dKNs1XXNBttTOsdhHn4Fey+2q5HcO6V2?= X-Forefront-Antispam-Report: CIP:212.183.10.29; CTRY:AT; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:outlook.omicron.at; PTR:212-183-10-29.omicron.at; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 06:45:02.7995 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0c53f03-8c39-4ff2-d87b-08dcd93fc149 X-MS-Exchange-CrossTenant-Id: 1357ca9e-a1a5-404b-bb16-554d5d05c5c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1357ca9e-a1a5-404b-bb16-554d5d05c5c9; Ip=[212.183.10.29]; Helo=[outlook.omicron.at] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001A5.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0302MB9258 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add the packet timestamp from TPACKET_V2 to the mbuf dynamic rx timestamp register if offload RTE_ETH_RX_OFFLOAD_TIMESTAMP is enabled. TPACKET_V2 provides the timestamp with nanosecond resolution and UNIX origo, i.e. time since 1-JAN-1970 UTC. Signed-off-by: Stefan Laesser Acked-by: Morten Brørup --- v2: * mentioned that timestamp is since 1-JAN-1970 UTC * made the two timestamp_dynflag variables private and removed prefix * undo moving of counter variable in eth_dev_start() to reduce code changes .mailmap | 1 + doc/guides/nics/af_packet.rst | 8 +++--- drivers/net/af_packet/rte_eth_af_packet.c | 30 ++++++++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/.mailmap b/.mailmap index 4a508bafad..69314e34a0 100644 --- a/.mailmap +++ b/.mailmap @@ -1414,6 +1414,7 @@ Steeven Lee Steeven Li Stefan Baranoff Stefan Hajnoczi +Stefan Laesser Stefan Puiu Stefan Wegrzyn Stepan Sojka diff --git a/doc/guides/nics/af_packet.rst b/doc/guides/nics/af_packet.rst index 66b977e1a2..a343d3a961 100644 --- a/doc/guides/nics/af_packet.rst +++ b/doc/guides/nics/af_packet.rst @@ -69,6 +69,8 @@ framecnt=512): Features and Limitations ------------------------ -The PMD will re-insert the VLAN tag transparently to the packet if the kernel -strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the -application. +* The PMD will re-insert the VLAN tag transparently to the packet if the kernel + strips it, as long as the ``RTE_ETH_RX_OFFLOAD_VLAN_STRIP`` is not enabled by the + application. +* The PMD will add the kernel packet timestamp with nanoseconds resolution and + UNIX origo, i.e. time since 1-JAN-1970 UTC, if ``RTE_ETH_RX_OFFLOAD_TIMESTAMP`` is enabled. diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 6b7b16f348..380ce15ca3 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -40,6 +40,9 @@ #define DFLT_FRAME_SIZE (1 << 11) #define DFLT_FRAME_COUNT (1 << 9) +static uint64_t timestamp_dynflag; +static int timestamp_dynfield_offset = -1; + struct __rte_cache_aligned pkt_rx_queue { int sockfd; @@ -51,6 +54,7 @@ struct __rte_cache_aligned pkt_rx_queue { struct rte_mempool *mb_pool; uint16_t in_port; uint8_t vlan_strip; + uint8_t timestamp_offloading; volatile unsigned long rx_pkts; volatile unsigned long rx_bytes; @@ -82,6 +86,7 @@ struct pmd_internals { struct pkt_rx_queue *rx_queue; struct pkt_tx_queue *tx_queue; uint8_t vlan_strip; + uint8_t timestamp_offloading; }; static const char *valid_arguments[] = { @@ -157,6 +162,16 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) PMD_LOG(ERR, "Failed to reinsert VLAN tag"); } + /* add kernel provided timestamp when offloading is enabled */ + if (pkt_q->timestamp_offloading) { + /* since TPACKET_V2 timestamps are provided in nanoseconds resolution */ + *RTE_MBUF_DYNFIELD(mbuf, af_packet_timestamp_dynfield_offset, + rte_mbuf_timestamp_t *) = + (uint64_t)ppd->tp_sec * 1000000000 + ppd->tp_nsec; + + mbuf->ol_flags |= af_packet_timestamp_dynflag; + } + /* release incoming frame and advance ring buffer */ ppd->tp_status = TP_STATUS_KERNEL; if (++framenum >= framecount) @@ -317,6 +332,16 @@ eth_dev_start(struct rte_eth_dev *dev) struct pmd_internals *internals = dev->data->dev_private; uint16_t i; + if (internals->timestamp_offloading) { + /* Register mbuf field and flag for Rx timestamp */ + int rc = rte_mbuf_dyn_rx_timestamp_register(&af_packet_timestamp_dynfield_offset, + &af_packet_timestamp_dynflag); + if (rc) { + PMD_LOG(ERR, "Cannot register mbuf field/flag for timestamp"); + return rc; + } + } + dev->data->dev_link.link_status = RTE_ETH_LINK_UP; for (i = 0; i < internals->nb_queues; i++) { dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; @@ -365,6 +390,7 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused) struct pmd_internals *internals = dev->data->dev_private; internals->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP); + internals->timestamp_offloading = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP); return 0; } @@ -381,7 +407,8 @@ eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) dev_info->min_rx_bufsize = 0; dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS | RTE_ETH_TX_OFFLOAD_VLAN_INSERT; - dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP; + dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP | + RTE_ETH_RX_OFFLOAD_TIMESTAMP; return 0; } @@ -508,6 +535,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, dev->data->rx_queues[rx_queue_id] = pkt_q; pkt_q->in_port = dev->data->port_id; pkt_q->vlan_strip = internals->vlan_strip; + pkt_q->timestamp_offloading = internals->timestamp_offloading; return 0; } -- 2.34.1