From patchwork Fri Jul 8 12:56:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 113833 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 62A33A00C5; Fri, 8 Jul 2022 14:58:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 561A04280D; Fri, 8 Jul 2022 14:58:54 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70081.outbound.protection.outlook.com [40.107.7.81]) by mails.dpdk.org (Postfix) with ESMTP id 19BCE40A7F; Fri, 8 Jul 2022 14:58:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IFAK/922eAkfohRZx1YoXTBPPm91/RBn+UxNYSrCyOQGnC8LtxG9XWtfN/Qd0MuRSQBCI+zysnvYLOLTAV198JanmR2x8Czjht+Ii3ZipZfr4UwQm/6YCq/jnfv4jRgmRFVV1Sp0EieDqsR+tM9FJujQ0OefCaP2SzU6b9cqhg5btFE0EliXQXInMRfjN1HySiFsEf+URFu8sQ0b3f/kle0GLB2vuHo9CHtg/CZ14QnzkLHp/1mPUK9WyibMtWJlmBEiYBnw4DSUnGKocdGexIq1rynzm0gyeviRWWzfsVHJ1AnKEVuXS+c2HwsimzeiwcdfOLCeGY0G9gXWNRLiEw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hANFhmr+wOCNJNl5cHyUC6uBEo7+EvEBGQzwU/kCRLQ=; b=cOrNsZWRxcifImFI08NJ3fKOjFjgV2ehA2+uI7hCX0oHAzb9UcYYq4xqEqnvE1WehZvhtWourRHW0pw/xsXwae2+N0s1OY2PGvkcbOp0d4rViosd8/FvpyBxeHEMrpnIr9x9ACHayxaNM3vJvDXNaiR5dMs4dmv5eXmapX3jW/ZkNY3KRYnWXEgq/HvTFaUlixexEE3C7pnJR1XrGG1hjWLUzppqJZVIYe3CL75qFZLCqOzyktoLeEbKfNbfdj3r0jiJ0tbkwkJxDtthhEzraWJ0VPvSP92ByvhSEjjtfzfTXJNpHa/hRSkjFIy5WoQfqTlY8lgt0duKhuI0yBhE4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=6wind.com smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hANFhmr+wOCNJNl5cHyUC6uBEo7+EvEBGQzwU/kCRLQ=; b=HenPM5C8KiXAyQgFYWX2siU6+BX39CKvB3ukR6acCx46bi6e6igpK4pOVQKeYP6IIdS3Gm9oa354Dng0LaEo0wy0GbCLldyH+37byS+og0SV2oFS5xbcR4Lix2NuA7EaXj9DN+KS09NEVfpj5CzxJ63ZByWUuN9B3p9YPiPv5Js= Received: from AS9PR06CA0137.eurprd06.prod.outlook.com (2603:10a6:20b:467::29) by PA4PR07MB8599.eurprd07.prod.outlook.com (2603:10a6:102:270::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.8; Fri, 8 Jul 2022 12:58:51 +0000 Received: from AM5EUR02FT024.eop-EUR02.prod.protection.outlook.com (2603:10a6:20b:467:cafe::f3) by AS9PR06CA0137.outlook.office365.com (2603:10a6:20b:467::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20 via Frontend Transport; Fri, 8 Jul 2022 12:58:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AM5EUR02FT024.mail.protection.outlook.com (10.152.8.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.5417.16 via Frontend Transport; Fri, 8 Jul 2022 12:58:50 +0000 Received: from ESESBMB505.ericsson.se (153.88.183.172) by ESESSMR501.ericsson.se (153.88.183.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.28; Fri, 8 Jul 2022 14:58:50 +0200 Received: from ESESBMB501.ericsson.se (153.88.183.168) by ESESBMB505.ericsson.se (153.88.183.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.28; Fri, 8 Jul 2022 14:58:49 +0200 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.184) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Fri, 8 Jul 2022 14:58:49 +0200 Received: from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id E9858380061; Fri, 8 Jul 2022 14:58:49 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: Emil Berg , , , , , , , =?utf-8?q?Morten_Br=C3=B8rup?= , =?utf-8?q?Mattia?= =?utf-8?q?s_R=C3=B6nnblom?= Subject: [PATCH v2 1/2] app/test: add cksum performance test Date: Fri, 8 Jul 2022 14:56:07 +0200 Message-ID: <20220708125608.24532-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <6839721a-8050-0e11-0c66-0f735ec8c56d@ericsson.com> References: <6839721a-8050-0e11-0c66-0f735ec8c56d@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 99e63972-b552-4436-5833-08da60e19ae2 X-MS-TrafficTypeDiagnostic: PA4PR07MB8599:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HvwEiCFkE3rEiFNq2T/lppGuOi4pVSAowFhhtHRNcVrgbjXwV6RaFoGj1mVqk76BLJyUYCNut3pRHVUenl/TuwpI7YGaAVoWP7Zcz1BNZf3ReQiO52S6ljKGQdB226AcOkLNRqytWwlZuGPpPwD0G6eMeQ8ILSC0Cf4e3qzDE2SCBwG4tcibBvmxiahKOajRIaXGGaeJR/WWvnWKOeHF44xCuIXjyeWKiCgN6QW5VcJUonpzVSvymmJ+IjVzeVtPrWDQbXn4m344RImLPVzDUSjvqa6WLbMb3wh93uupt8bIyR9LRuZtpyKGRNNaZEgpGhEZvah7f6QOI67t6m31xM0KQj9yFtCv5UPwQy8buOb2d+Q6AOE6Udu3gqMc6lBySxZmEAVGX1A0Qz3sKTJKMSbTy0ohPYR4199pg1P9DPRvoxvXanWvksjrr0AbaNPSNVlsmR7z4fY/zEtZFgsCQdMCSeU3GNXCqnmZiX/lImGGuzFCaPZ980hysAg3lK1jtRP2j99EK8oY6o8U+cooB+Q911ol++ZxUhv25vq4z6H2WqONAbY/sYJTtRKumCWGP/KyB4wKXNMi+W2ul9n2uiA0M26dQvlW/P/Z3CcIvqxEdPZiTqv2gj0E0UaOP7KQDzyp42euUKWGSpNwj0KxGk08BE8v29fEqXuD/Bs42t+Jh5oHyp/1W3wfX6LOGvfTawBpcEmwCi0vFuOY7KOJI97N6gR1asNbDEPjl77c+4qVQh/3037RyXKbxhvxa4VAw8HX4FO8e1CwlqekfylgSxqKikX61YKvmX2PHOfGRTtd+l/Gvmo8vP0eE0nLJ5Jk X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(396003)(39860400002)(346002)(40470700004)(46966006)(36840700001)(82960400001)(6266002)(8936002)(82740400003)(26005)(5660300002)(54906003)(1076003)(356005)(41300700001)(40460700003)(478600001)(316002)(186003)(2616005)(8676002)(7636003)(107886003)(336012)(36756003)(70206006)(66574015)(86362001)(36860700001)(83380400001)(6916009)(82310400005)(6666004)(70586007)(2906002)(4326008)(40140700001)(40480700001)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2022 12:58:50.8310 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 99e63972-b552-4436-5833-08da60e19ae2 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR02FT024.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR07MB8599 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 performance test for the rte_raw_cksum() function, which delegates the actual work to __rte_raw_cksum(), which in turn is used by other functions in need of Internet checksum calculation. Signed-off-by: Mattias Rönnblom --- v2: * Added __rte_unused to unused volatile variable, to keep the Intel compiler happy. --- MAINTAINERS | 1 + app/test/meson.build | 1 + app/test/test_cksum_perf.c | 118 +++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 app/test/test_cksum_perf.c diff --git a/MAINTAINERS b/MAINTAINERS index c923712946..2a4c99e05a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1414,6 +1414,7 @@ Network headers M: Olivier Matz F: lib/net/ F: app/test/test_cksum.c +F: app/test/test_cksum_perf.c Packet CRC M: Jasvinder Singh diff --git a/app/test/meson.build b/app/test/meson.build index 431c5bd318..191db03d1d 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -18,6 +18,7 @@ test_sources = files( 'test_bpf.c', 'test_byteorder.c', 'test_cksum.c', + 'test_cksum_perf.c', 'test_cmdline.c', 'test_cmdline_cirbuf.c', 'test_cmdline_etheraddr.c', diff --git a/app/test/test_cksum_perf.c b/app/test/test_cksum_perf.c new file mode 100644 index 0000000000..bff73cb3bb --- /dev/null +++ b/app/test/test_cksum_perf.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Ericsson AB + */ + +#include + +#include +#include +#include +#include +#include + +#include "test.h" + +#define NUM_BLOCKS (10) +#define ITERATIONS (1000000) + +static const size_t data_sizes[] = { 20, 21, 100, 101, 1500, 1501 }; + +static __rte_noinline uint16_t +do_rte_raw_cksum(const void *buf, size_t len) +{ + return rte_raw_cksum(buf, len); +} + +static void +init_block(void *buf, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) + ((char *)buf)[i] = (uint8_t)rte_rand(); +} + +static int +test_cksum_perf_size_alignment(size_t block_size, bool aligned) +{ + char *data[NUM_BLOCKS]; + char *blocks[NUM_BLOCKS]; + unsigned int i; + uint64_t start; + uint64_t end; + /* Floating point to handle low (pseudo-)TSC frequencies */ + double block_latency; + double byte_latency; + volatile __rte_unused uint64_t sum = 0; + + for (i = 0; i < NUM_BLOCKS; i++) { + data[i] = rte_malloc(NULL, block_size + 1, 0); + + if (data[i] == NULL) { + printf("Failed to allocate memory for block\n"); + return TEST_FAILED; + } + + init_block(data[i], block_size + 1); + + blocks[i] = aligned ? data[i] : data[i] + 1; + } + + start = rte_rdtsc(); + + for (i = 0; i < ITERATIONS; i++) { + unsigned int j; + for (j = 0; j < NUM_BLOCKS; j++) + sum += do_rte_raw_cksum(blocks[j], block_size); + } + + end = rte_rdtsc(); + + block_latency = (end - start) / (double)(ITERATIONS * NUM_BLOCKS); + byte_latency = block_latency / block_size; + + printf("%-9s %10zd %19.1f %16.2f\n", aligned ? "Aligned" : "Unaligned", + block_size, block_latency, byte_latency); + + for (i = 0; i < NUM_BLOCKS; i++) + rte_free(data[i]); + + return TEST_SUCCESS; +} + +static int +test_cksum_perf_size(size_t block_size) +{ + int rc; + + rc = test_cksum_perf_size_alignment(block_size, true); + if (rc != TEST_SUCCESS) + return rc; + + rc = test_cksum_perf_size_alignment(block_size, false); + + return rc; +} + +static int +test_cksum_perf(void) +{ + uint16_t i; + + printf("### rte_raw_cksum() performance ###\n"); + printf("Alignment Block size TSC cycles/block TSC cycles/byte\n"); + + for (i = 0; i < RTE_DIM(data_sizes); i++) { + int rc; + + rc = test_cksum_perf_size(data_sizes[i]); + if (rc != TEST_SUCCESS) + return rc; + } + + return TEST_SUCCESS; +} + + +REGISTER_TEST_COMMAND(cksum_perf_autotest, test_cksum_perf); + From patchwork Fri Jul 8 12:56:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 113832 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 21959A00C5; Fri, 8 Jul 2022 14:58:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 092D940A7B; Fri, 8 Jul 2022 14:58:53 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2082.outbound.protection.outlook.com [40.107.20.82]) by mails.dpdk.org (Postfix) with ESMTP id 44A884021E; Fri, 8 Jul 2022 14:58:52 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LPDmbGyRyLjuv+ck0INPmvmD06lfhQrr1rfqwqhtW4ymW1kKesAstcZRzPqG5CYLESpc8lH0cFh7JVv07vdhZ3zd6xWMpK85ul8KjV85aOjNPKZNRODHsgZGfkDBMQE1cqCmGqp+gqZJqObGpM5WwFu41RqBkpGAKlPl4kWNCSw1tg+Q8IconuGDfuhhxPiQY6jK2go4qYJJZOQ6mrKNMpoZXCfTO4rzyqLTClX9WRx6JJLU3Nc00rryVxqb6hWT8P6WcrP6AzB1tPgTK5TA2kQ5e+wadQQOmP8U8mpNCYuSJEjWsndPMUa5UDo0o+OqhbfGQNmvAjl5or0q1lM3vw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2mL4GPclqKE/CYJjgy9KTHGuRzLBVZKVHkusoc0cj/0=; b=nJh7oE5M5rnuz3+N4CLj4Qe/Kq1ndAYK7sgpI7ZNz6Nxd6N+jpo2+nJfJ4RI2T1qQbA/s4iPeJlUTJ7eg5exLbr/SqIb+zfpdCid+TFLsvZ5SYKDPINtALhFL4kMnzZZzdKLs4u+pxzI5+lVJQx9CjrTlnsY3vyiGUwj4eVWCBxOOpTWlSIO2vo/vyszeKZRwADM7DzgPrIoR1qDiCms20I4rJrla778LjkJgAkvEdCb9sKlISCKQVje5XHYyTC0hX+1SuRu3qIz7HIoRfg/biEVMZZ6lg3d/Y5fmQwHko+09jm5bVjnfBOUsHAfQX498e3XtvOjbIwopzFypBBhjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=6wind.com smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2mL4GPclqKE/CYJjgy9KTHGuRzLBVZKVHkusoc0cj/0=; b=I1bak7UOZH7axK7fItQquRTTjIygKQKPFphta8YHWZGY4VhFrqlGXCzHeja4RXXDyeT5nocxaVwBa35A4oE+NgEKOt4A+FD4QyrTKMEZYdlmxO9LfOykyP90D7mZGsxp/kyFTSRaV+yFYLe6kXKdEeC5n/Vjf0Q1/75Qih5X974= Received: from AS8PR05CA0014.eurprd05.prod.outlook.com (2603:10a6:20b:311::19) by AS1PR07MB8407.eurprd07.prod.outlook.com (2603:10a6:20b:4c5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.15; Fri, 8 Jul 2022 12:58:51 +0000 Received: from AM5EUR02FT022.eop-EUR02.prod.protection.outlook.com (2603:10a6:20b:311:cafe::8c) by AS8PR05CA0014.outlook.office365.com (2603:10a6:20b:311::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20 via Frontend Transport; Fri, 8 Jul 2022 12:58:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AM5EUR02FT022.mail.protection.outlook.com (10.152.8.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.5417.16 via Frontend Transport; Fri, 8 Jul 2022 12:58:51 +0000 Received: from ESESSMB503.ericsson.se (153.88.183.164) by ESESBMR502.ericsson.se (153.88.183.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.28; Fri, 8 Jul 2022 14:58:50 +0200 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.191) with Microsoft SMTP Server id 15.1.2375.28 via Frontend Transport; Fri, 8 Jul 2022 14:58:50 +0200 Received: from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id A22E4380061; Fri, 8 Jul 2022 14:58:50 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: Emil Berg , , , , , , , =?utf-8?q?Morten_Br=C3=B8rup?= , =?utf-8?q?Mattia?= =?utf-8?q?s_R=C3=B6nnblom?= Subject: [PATCH v2 2/2] net: have checksum routines accept unaligned data Date: Fri, 8 Jul 2022 14:56:08 +0200 Message-ID: <20220708125608.24532-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220708125608.24532-1-mattias.ronnblom@ericsson.com> References: <6839721a-8050-0e11-0c66-0f735ec8c56d@ericsson.com> <20220708125608.24532-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3436133a-395a-434d-4490-08da60e19b1f X-MS-TrafficTypeDiagnostic: AS1PR07MB8407:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2mDCqJ986PDV6NXJ1Ls/LR5uEx/7P8U+98/q14RZd5R/67EvKhCcoJtTOx/yiOl2CSdmkX6erbDDkEZ5QojHbD9PMX/IUzZzncBgdQArmXKcndEmHLm+wzBOAv9kOFr7Fc9dWhk/rmCEie+/B3H15EhsmIlGvBXhRMBVJvZrC1FfCx5kIKHOSaRRlSJVaTUD2B4BJHdvoOCSc0vmuefpdw+BxoT0xZA13PcdloAw8K2dDA7KfefFLISgYRQrtMluw5fublCJa/7zVaNfk7kRu7Qakkm56UXSTdFsIPaHQm/oxsUdICgVDTW1NqZOzRh74b/44/iU1BsTQp5gHvTMD40qAuF+pc4kC/73mOjnok2HxzAmf2qyzfUy5qGI5QzRmiGun+vfw3TDsw2aKasTghOpYPdZlPtUlMRnehXcmIXm9P938qayY6VflQalivK1f2X4Y4JM7Xx8zbJS2LUfY6N+Stkr6pZmtR0gpItbgv/L1CsrrTjBIaigCAxC3yzorSjnYexxzaVho0uy0b83tnHZ7+Kl66wDREeblCFxB1olOnOqWunB4A0mFrMJzS0m59KmdU3eqpvA4DJCsJVyvaslnUId3ZvovKCmNttikrtMYEt4L96tBfnRwnp6KAgSNzAbQdwiLOppZLeiBj3+/xlAaKdD+N+pbuVjd3JZic9j3fonJ2ztWKzHTVaSr6hMeitJHkxKSR/mG9vbQAoAuZdKCszpmv/1+JGuWl6YDjjCWNHQ9cNTxlc/7qTyAh6hSGljPn8MURWgzyrc48rpgw1/P0nxdws0xM/7Zi/3b9YkRtSDlL3N2zPC1wu0oia1 X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230016)(4636009)(346002)(396003)(376002)(39860400002)(136003)(40470700004)(46966006)(36840700001)(36756003)(83380400001)(478600001)(40460700003)(316002)(6266002)(54906003)(47076005)(6916009)(2616005)(26005)(8676002)(70586007)(40480700001)(82310400005)(2906002)(70206006)(4326008)(86362001)(5660300002)(336012)(41300700001)(1076003)(8936002)(82740400003)(82960400001)(6666004)(36860700001)(7636003)(186003)(66574015)(356005)(107886003); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2022 12:58:51.2128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3436133a-395a-434d-4490-08da60e19b1f X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR02FT022.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8407 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 __rte_raw_cksum() (used by rte_raw_cksum() among others) accessed its data through an uint16_t pointer, which allowed the compiler to assume the data was 16-bit aligned. This in turn would, with certain architectures and compiler flag combinations, result in code with SIMD load or store instructions with restrictions on data alignment. This patch keeps the old algorithm, but data is read using memcpy() instead of direct pointer access, forcing the compiler to always generate code that handles unaligned input. The __may_alias__ GCC attribute is no longer needed. The data on which the Internet checksum functions operates are almost always 16-bit aligned, but there are exceptions. In particular, the PDCP protocol header may (literally) have an odd size. Performance impact seems to range from none to a very slight regression. Bugzilla ID: 1035 Cc: stable@dpdk.org --- v2: * Simplified the odd-length conditional (Morten Brørup). Reviewed-by: Morten Brørup Signed-off-by: Mattias Rönnblom --- lib/net/rte_ip.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h index b502481670..a0334d931e 100644 --- a/lib/net/rte_ip.h +++ b/lib/net/rte_ip.h @@ -160,18 +160,21 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr) static inline uint32_t __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) { - /* extend strict-aliasing rules */ - typedef uint16_t __attribute__((__may_alias__)) u16_p; - const u16_p *u16_buf = (const u16_p *)buf; - const u16_p *end = u16_buf + len / sizeof(*u16_buf); + const void *end; - for (; u16_buf != end; ++u16_buf) - sum += *u16_buf; + for (end = RTE_PTR_ADD(buf, (len/sizeof(uint16_t)) * sizeof(uint16_t)); + buf != end; buf = RTE_PTR_ADD(buf, sizeof(uint16_t))) { + uint16_t v; + + memcpy(&v, buf, sizeof(uint16_t)); + sum += v; + } /* if length is odd, keeping it byte order independent */ if (unlikely(len % 2)) { uint16_t left = 0; - *(unsigned char *)&left = *(const unsigned char *)end; + + memcpy(&left, end, 1); sum += left; }