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 DB7ED459DD; Fri, 20 Sep 2024 09:14:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81D6043395; Fri, 20 Sep 2024 09:14:38 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2138.outbound.protection.outlook.com [40.107.20.138]) by mails.dpdk.org (Postfix) with ESMTP id 93E6740669 for ; Fri, 20 Sep 2024 09:14:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rNKXXmq4t0M2m/eVnEZwFRvTuyfSdD5Bj0u+l/BGKlIK+75MbtevcFHzgCY2zYjymy9dqGjN99YmPvk4YQOF6Lm8JwR/SKlK6+dTxW3WSjyODsZSs39GHwy9gyUImNaMcX8qMOJGG7eCCAxVvFtb9N5F2Kv1jPdrImlbvU0/3BHjPzZx/R9TpbZa4TlDn23YQ6aAJFvh91nk3X+zAXVW+5anWuz1A00BQgTL2b1iFBp51qTWTl4HZ/6TpQ9Fhgc3eYs2U2Ct8QpPs4iY5hHFPHSqXsN01wZbiC92Caf5UT/oDKZ3I8j/Xldh72r2N79B1pqnWgM9A2/+3ju+eWS32g== 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=mrPIjVaFs9FCIsFgHIXFBriWEg9JvffvHmnL28zjhP8=; b=oTDQ5xWOoM0WjYb6jyqECTMSSraT/vEWzempiEUozklHAu54NKjNsHgIwU9YFWZasBaIiOSY07EGEKTHdGfPzZhfZBuzCGP0P5SQTavis3lOADtbo5t+Vw30EprDSLAPVQdLJ4BrO/QUK6plsNbF4pf5de3DwbHn3K9ViCR26c9r6SjawzomirS6rf0j+JxnsPCBaIu7W8nYhJLXjf7z+2qzaSI42Hfkof7nVa+TUaEPT0LUzVWlgSH9981S/WgmTbl0HXpgyrNC4tfNy4GWwWdXJYks7eIM7Sx84XFKvT19OAiBTZVDCx5ev45pvncteUM3yBeXeIjwHxmWHm5iwg== 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=mrPIjVaFs9FCIsFgHIXFBriWEg9JvffvHmnL28zjhP8=; b=RVyQk0BEdtgf3Mdy/Ved6T+lFQZPQjC7pUM2wy+VXieoOrZgX5OBBW2YzZ3ZNknud2oPcvoQOg/DP9TNOICXnLBUGloIJnQWiSbSBLTlJrV+p8yVTLaIn1ql9ogpoG2uMN/Wz52F4tyQw9vcpCXhQGblOJ+dVKb7JxJhOHVMKMU= Received: from DB8PR04CA0021.eurprd04.prod.outlook.com (2603:10a6:10:110::31) by AS8PR03MB7080.eurprd03.prod.outlook.com (2603:10a6:20b:293::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Fri, 20 Sep 2024 07:14:33 +0000 Received: from DU2PEPF00028D03.eurprd03.prod.outlook.com (2603:10a6:10:110:cafe::2a) by DB8PR04CA0021.outlook.office365.com (2603:10a6:10:110::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.25 via Frontend Transport; Fri, 20 Sep 2024 07:14:33 +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 DU2PEPF00028D03.mail.protection.outlook.com (10.167.242.187) 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 07:14:33 +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 09:14:30 +0200 From: Stefan Laesser To: CC: Stefan Laesser , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v3] net/af_packet: add timestamp offloading support Date: Fri, 20 Sep 2024 09:14:11 +0200 Message-ID: <20240920071411.477421-1-stefan.laesser@omicronenergy.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240920064408.64651-1-stefan.laesser@omicronenergy.com> References: <20240920064408.64651-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: DU2PEPF00028D03:EE_|AS8PR03MB7080:EE_ X-MS-Office365-Filtering-Correlation-Id: 62c39011-9304-4e99-7eb4-08dcd943e0c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?bHBlbGhOMFZZS0I4cmUyMDhqWStyY01udEZkbWRzRllZMXNvTWh2WW1zZnZs?= =?utf-8?B?bXc4RVhQWW5ra0l1bVdDZWZwejBWbktUSk1PUEp2SzgrZXVlYndXMkIybGVS?= =?utf-8?B?eW9aSUlpNGpmdUxseUcxSDdkbVB5ZmN1QVYxdllvVHJrdjd3aTBJczNoQ1NL?= =?utf-8?B?WjVvZnQ1ZzNjMGZVL3lzNkdCcXFydVYrVVRQZDNXaHFnU0ZxajZwUzJyNHhs?= =?utf-8?B?T3hpdGJuZEMrSzVCZ0Nab3pHa3BCV3BQYnZZR3QrbFpYMWJUdzRaRzBHUUJy?= =?utf-8?B?OTF6NFAzaTdZYlVTRm9VSFl0L2JaK2JTdnlpWWlpSFFRTnZKRmtNdVNNa0RJ?= =?utf-8?B?aysrS01XTXluc2pEUHBFUWVLNzlwaFQ4MUdQVlJKM0tzZ0Z3TW80K2dCTGVZ?= =?utf-8?B?R2M3cHp3b0M5Y3hEYmdiVGJqbjhmVm1KcWFuSkVPbEJQZnVaUVNwKzdQNUlC?= =?utf-8?B?Ylc1Wk50ZGw2U2V4aENmZndibzlqK0tNa3FOaTBPL2hnYWxBNlBqY0N1RkZT?= =?utf-8?B?Njl4SjNWSTZuYVJhMmdHT1JPU05GZVduRHdRd1pVb2NsMzBNNDc4NUI1MkJi?= =?utf-8?B?WE1IL1laYmFKTGlhRWhSVzhSQlpHTGhpdTV5dERrTHY0dlVKU0dvTjJjem1V?= =?utf-8?B?b29KazNpNXhZOXNzYklTOWVhLy9GcUNSWGlLRVhaVVRsK2w3RUgzSGI2Q2Vy?= =?utf-8?B?TEJYTGUxRStqKzczdjlJSW94NURiZlFDSTRvWE5KSmlqZ1lUUC9oS2E2RzFh?= =?utf-8?B?Nll1SUZoem0rSUlpbThwcjl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VLK0RvUzgyZkI5S2hhclUrMU92ekNtQ0orOTl3TWxaZUlSelJGdjFn?= =?utf-8?B?dU0yZDhvN0k3Y0Z5Mm1wMzNqSG1PWU1jeHppaDhTM3E1N1gyeW9meW1PZitS?= =?utf-8?B?TnphdmFFNHE0NGRpMlZKeHN3Y1kyUEVWc04xcm5GTkYwcjZ4MjlpR0xOZkNi?= =?utf-8?B?bU5JNzRWQVZNVkttK1Y5MXA4SlYxMnFFYnZ6K2pBNEJZSDhMbmRTTVozTU1Q?= =?utf-8?Q?QjvotgKaW5wS3c/xvnyhHSUZ0VJNtMpv?= 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)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1102; X-OriginatorOrg: omicronenergy.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 07:14:33.5321 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62c39011-9304-4e99-7eb4-08dcd943e0c8 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: DU2PEPF00028D03.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7080 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 --- v3: * fixed compilation errors 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..d532105745 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, timestamp_dynfield_offset, + rte_mbuf_timestamp_t *) = + (uint64_t)ppd->tp_sec * 1000000000 + ppd->tp_nsec; + + mbuf->ol_flags |= 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(×tamp_dynfield_offset, + ×tamp_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