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 67368458F5; Tue, 3 Sep 2024 13:43:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BD8C4042C; Tue, 3 Sep 2024 13:43:57 +0200 (CEST) Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11022107.outbound.protection.outlook.com [52.101.66.107]) by mails.dpdk.org (Postfix) with ESMTP id 21ECF402D0 for ; Tue, 3 Sep 2024 13:43:56 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Bz4FF+iHN8HUUP0ahijInkE4RyB2zsaI8xD3QZ4VfnXp6nZVtStdntALavQo+XrJJQ2i6ZOydNcR0CAjG639WlC3vA3+rH+lJNGE8gvWNHEcSysnEcaQhatFaGpCIOdTITlHRE2zCMaBEvaMS0uj6onoEIz6KzJ9AZ4D5SQDO/1gYC87BncsOtlbQ2BtBG1bI98W3D0vX3wwBQ8bM4gsPpY/DAfBq/alP3+SHIGeYlxPyD76cY9UeyILLNnmt80Y6cRHuh3XPW7T+NZG1RMyuMDrvsB+HX8EgsJ4uzlwbgExoZ0ZpGFeSbedyjIhy7MYaTu4RxAxg91/xvaiQzz26A== 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=eax/4pkGk2f4AqXQvdtZ1+McGoyaavRhYN4Y8jpeXlQ=; b=CMgROk9MqpoZt/KHElGsQxHShG7AKl2xxzI4NCmmVTcutH0VHmEPd7ZnKBGDzGO0pPGHf03nhx3pXXGy11usjv3LbfBfaJMbnl9qLgvPxAQTpalHmeSICHZ5WmArFvfpJOvp8p43VuLAuTH53KUgJY7IPcY1xa8KSj1XgGB1hLJP4jR2j96wwwOmOnC8uHKt/tIRf4OPEEUeI+0wVd9XpiB/V9IPPt3MLo1/ZwRhabC9tcd+zwe070jJvD+Xhdxe3G/Ql4m2Pk7BHJhL6wGqvEQQH1llL9nrVDuyHJTmjHy8OX3WX6ViqIMWNBwZVRblh1k4JUoIUv1eQPNZpmfJQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 212.183.10.29) smtp.rcpttodomain=monjalon.net 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=eax/4pkGk2f4AqXQvdtZ1+McGoyaavRhYN4Y8jpeXlQ=; b=A1fnUlh/k0AjBDkQa/lZYzcg9ddJf5T6a+3iKFVEt+gjLDYnp4zhbRG7A8QTRbiZ5kKf4/50Kf1nWJDSmqbHJCQsiGEkYhuW+rM2ZtgYFdc4DaVwpvQH0uy8Kk2C0wUe76XtBYhHrnwQmabGOAM7y8Ia+Z19Yfq+NK+bCgSHVCQ= Received: from AS9PR06CA0774.eurprd06.prod.outlook.com (2603:10a6:20b:484::29) by PAWPR03MB9948.eurprd03.prod.outlook.com (2603:10a6:102:365::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.26; Tue, 3 Sep 2024 11:43:42 +0000 Received: from AMS0EPF0000019B.eurprd05.prod.outlook.com (2603:10a6:20b:484:cafe::5f) by AS9PR06CA0774.outlook.office365.com (2603:10a6:20b:484::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Tue, 3 Sep 2024 11:43:42 +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 AMS0EPF0000019B.mail.protection.outlook.com (10.167.16.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Tue, 3 Sep 2024 11:43:42 +0000 Received: from stelas00wl01.omicron.at (172.22.41.138) 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.32; Tue, 3 Sep 2024 13:43:41 +0200 From: Stefan Laesser To: Thomas Monjalon , "John W. Linville" CC: , Stefan Laesser Subject: [PATCH] net/af_packet: add timestamp offloading support Date: Tue, 3 Sep 2024 13:43:06 +0200 Message-ID: <20240903114306.2336633-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.22.41.138] 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: AMS0EPF0000019B:EE_|PAWPR03MB9948:EE_ X-MS-Office365-Filtering-Correlation-Id: b6bfd7be-96f3-48d4-8356-08dccc0da948 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?GiJRwNGT+HAW1ERJ+ehtcMpEUNcZB3HfhhEPtY2YdfZL5WnNMSINvqQBH6hu?= =?us-ascii?Q?ZTE0kxHOGZqxAFfIEQIdfuXV46oMYcRsbtsQ8sHemLg8BQNF3dkTnE9mEiz+?= =?us-ascii?Q?kj59Qv9M5Oj+k6gYN9zGfRXSHnldeNyGEBSA4pDAPp6MGUcasHvsGeUwUYUF?= =?us-ascii?Q?evwve0Qaf3+oX6AJxXaixKoH24kTafqlvsKudBEtR3YaXs2E58rOhpO64vs6?= =?us-ascii?Q?hbpOOPZhUPPLwZh94L3MczwaGSOPYKNx5//JR73qkfVfCD6C4cMuwI6WwO2R?= =?us-ascii?Q?/fgiqsCh4bb7z9iomvXDwod1FXXBljGdQLUNx8I4svFQ38Ns93BBtZ6Y+Isc?= =?us-ascii?Q?Z+UydLkRMMHys38R06qoU0jyeRN7CP3Z3YBEoL6BscDGcuvSodBHAj3e08eD?= =?us-ascii?Q?77KATclZ8MelofZQyu/RXP79vVWO/8XJuRIkdkvtxeSf4n3lXbZPfFe4Vsx+?= =?us-ascii?Q?oPL3JLqtI4gOrq3q//NBlfNcHV4mHK3ow0YS9h1mCf5xod9CDsOc+YYwDjzP?= =?us-ascii?Q?xVCg746Ax1wdHRQitjoKEFnxs71L4VtMvQ0u055rokymHOTipe8g/ERxN4j8?= =?us-ascii?Q?PKvg6BmYSrdUZuz8MryB1cFbcdg7TlWJk71WQDs6AYxvOYLOoJ3CSm2Fd4jn?= =?us-ascii?Q?Uie2oJLilAVSd2HBNLZerSzvvBlTig1B8xq01etgsG0E2Q10/4xV6LZI8JT1?= =?us-ascii?Q?JXVdlFaivulNm1am6d3m/5QfbIjfW8OZzTGAvUoQuUMoj5bWcgS6KEt6E2gL?= =?us-ascii?Q?R1EWG2B/MYZrb6MLXj9T+aOYVpPgBeN2HAIBTFsiKYmVFGejRNjnY3kAO6y8?= =?us-ascii?Q?/z8bk+m4UbD4oIus0GkZrhpRkg2+hXEqodIsyQoK6rN84wirdcQyp+C4OJNv?= =?us-ascii?Q?KQyN8z/xP+zoUrT7j9g81Fo83XGQ+6jsaewt9TqAEr8DTLGOIrXPsIP9HJNV?= =?us-ascii?Q?ZqqWqdMpxm2v3YNQoBK6t11fxXoY6AtgMbk0WmcV6/cteNjifxi5nE5l5Tcr?= =?us-ascii?Q?kShZiBrusW16M+53ov1oogb9vsbKgx8sHHpjIKYQ8ENXhtZrjONyk/Jp65f9?= =?us-ascii?Q?y/gZG1e5CK2qdUymmNzkobRLqWJZsExo0hVfzrXFoIYsHUpcuBZiazipBx1S?= =?us-ascii?Q?09bN2jCrUgHtCbJy4Pio4HljNFaKBmZa3a+a8P53ckmYhjxwhfAQ6q9gv8Ff?= =?us-ascii?Q?xQ2Ng6kXR+NiXrTqEN+gSrCQ6hwtzrRrOetqKEooTgmxauPcvHcAk/lQh3pc?= =?us-ascii?Q?IC4ZhFYpOR7koDZ2b0pIZboaKz90C+43l2j9D6Cg1xQrQ1AFKD4lOR0HvjZ/?= =?us-ascii?Q?dG2tpin4OgFDUBZGI1t/uWHl+RooXW6HXDufWR5oKVOijDB8UaSEL9pJ4/zv?= =?us-ascii?Q?5lBtlWfa+oMN53WEJSIny4dyZ8W9OasSv5KOg7zyCBaE7PsblukZyvJL8mlK?= =?us-ascii?Q?5dNnVPIZ+3tBdkBEEoyzOwziTRWXnv4I?= 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)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2024 11:43:42.5729 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6bfd7be-96f3-48d4-8356-08dccc0da948 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: AMS0EPF0000019B.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR03MB9948 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. Signed-off-by: Stefan Laesser --- .mailmap | 1 + doc/guides/nics/af_packet.rst | 8 ++++-- drivers/net/af_packet/rte_eth_af_packet.c | 34 +++++++++++++++++++++-- 3 files changed, 38 insertions(+), 5 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..e5da625e09 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 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..6a7d5d0ffb 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) +uint64_t af_packet_timestamp_dynflag; +int af_packet_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) @@ -315,13 +330,25 @@ static int 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; + + uint16_t i; for (i = 0; i < internals->nb_queues; i++) { dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; } + return 0; } @@ -365,6 +392,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 +409,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 +537,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