From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 98310440E3;
	Mon, 27 May 2024 13:22:04 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 20329402CF;
	Mon, 27 May 2024 13:22:04 +0200 (CEST)
Received: from EUR05-AM6-obe.outbound.protection.outlook.com
 (mail-am6eur05on2066.outbound.protection.outlook.com [40.107.22.66])
 by mails.dpdk.org (Postfix) with ESMTP id DDD89402BD
 for <dev@dpdk.org>; Mon, 27 May 2024 13:22:02 +0200 (CEST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=DAoruLuCmN08OhhtLNbZIS6AeimD8soexC16Zzh9PXA1c0BDgVmBtquiquIaiEIqRSryLAM34vp1ycpzKrmsI9ZNxkLxfZiPKcFhoNAttiK1F3IhKv7gkXxTUwETl5A0E3lcwHXqyANPc/QTLpUwTsDZeveQp2H72D1+9O5tc8LFkDaqdndOOPkeVztoJvIEkkbsvlaUF7J0FuGRn5AXsbGLjwQBdAlfoah/PxTpjpzCtZo/KoNtSxUN97owtFK9+GPCXCArSre5BAV9Q54tKbFTk/FtNo9osQdiiRcDEL7qkeEAHQgAuojpUI6I76L0CRVORnS10pgzgLF3U7fJow==
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=gfsAamLQxPkfmjDnRIAqSkke8KVGALZBNkq/xgv2VwE=;
 b=AFarZyxQI+bslC4Q3toG9Nl0r/GeDx4ODwygWLFvBCefucwNaUfNIp8fdDkVX3hbiVzfe1EhfyLGbzRVEWR6nMlwaEioacwNHwS104UUh1ZE5JGPOrjGYnpn/wHUINnks4/6aggSRp9fK+nk0WHDXLynoaOH//8l6a/zNbfKL9uErDMj4cf7PQ6X18308Lsz8zpj4uFKSWsjRf3Pzb5USo+cvrdWyMxfdupEi1qKICWuptQHxuXLmKx8Xa8/Ubvnd4uIBodc001KiizR/QMF1ZzRtKg2aCAz5Vw8cdzitRktyT9JoHreFe+2Ouj9DQtMMNCJLNP+KFHCCcYDRh3Bzg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 192.176.1.74) smtp.rcpttodomain=dpdk.org 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 (0)
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=gfsAamLQxPkfmjDnRIAqSkke8KVGALZBNkq/xgv2VwE=;
 b=tmH9nfrsfIMpcBzAOBRfbh4qPYeryTcFgukKZIYR8cpqh31K5DOAMaf6iXHEbdol/Tp2Fq12osOuhtmqfSGq8rTXzjyRVQ6/EQ/3HHFPsPkRWxcig82n0FA+02SR28ZDYJ709RFDsk52I8FYHAZHYp7WUO7onUUuN1JhptlKbhSwUGGtdUwH5RDno6dB6Jf0e5R3Cvg8ph8eDiMM1D5NN3PEF66gWJzHiuoGaZGtGnSTzlrTF363lQBRamJ2R0oGzBi1qdEjYVoEiKcNaaczXBZDCTaNpqw4nNjYm7ZK7MthN/BhUr48oPB0oqS6YfxWcHB2OtJ2TUpPC1WmF8PzJQ==
Received: from AM6P194CA0041.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:84::18)
 by VI1PR07MB6672.eurprd07.prod.outlook.com (2603:10a6:800:18f::24) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May
 2024 11:22:00 +0000
Received: from AM4PEPF00025F9A.EURPRD83.prod.outlook.com
 (2603:10a6:209:84:cafe::73) by AM6P194CA0041.outlook.office365.com
 (2603:10a6:209:84::18) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29 via Frontend
 Transport; Mon, 27 May 2024 11:22:00 +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
 AM4PEPF00025F9A.mail.protection.outlook.com (10.167.16.9) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.7656.0 via Frontend Transport; Mon, 27 May 2024 11:22:00 +0000
Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by
 smtp-central.internal.ericsson.com (100.87.178.68) with Microsoft SMTP Server
 id 15.2.1544.11; Mon, 27 May 2024 13:21:59 +0200
Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100])
 by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id
 783FE1C006A; Mon, 27 May 2024 13:21:59 +0200 (CEST)
From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>
To: <dev@dpdk.org>
CC: <hofors@lysator.liu.se>, =?UTF-8?q?Morten=20Br=C3=B8rup?=
 <mb@smartsharesystems.com>, Stephen Hemminger <stephen@networkplumber.org>,
 =?UTF-8?q?Mattias=20R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>
Subject: [RFC] eal: provide option to use compiler memcpy instead of RTE
Date: Mon, 27 May 2024 13:11:51 +0200
Message-ID: <20240527111151.188607-1-mattias.ronnblom@ericsson.com>
X-Mailer: git-send-email 2.34.1
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: AM4PEPF00025F9A:EE_|VI1PR07MB6672:EE_
X-MS-Office365-Filtering-Correlation-Id: 2bed2dba-06a8-417a-279e-08dc7e3f3a4e
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
 ARA:13230031|82310400017|376005|36860700004|1800799015; 
X-Microsoft-Antispam-Message-Info: =?utf-8?B?aEE4KzZpNnBIdFJEVE0xZXpsYldvU0NOUnVxNVllQTZ1YWt0QTZ0MlF4SVpz?=
 =?utf-8?B?Q3p3S1c0NUExSjV0WURxdzcvY1RsVnYyUDZKTmx4bW1YSHd1cEQ3Z2NSM3Vv?=
 =?utf-8?B?ODhrSWZQUWlvYUdIZXAzWkxPRnQrZ2pvYjhhclp2eVVDa3JMYURXMEFrMGZX?=
 =?utf-8?B?S2MrRzZ2MHhzYzFyM3VJRndiQ21GNWRIMGU1d1V5dG4zWThENnFocmE1Y2Z6?=
 =?utf-8?B?c1JiMll2SFVSclhUV2NkMVAyWGRnN3phM0FKWGI1RnVKMjFYREloZmJtU3VZ?=
 =?utf-8?B?RHBoN29sMmlIV08zYUNTakhFMUxpTHFPY0h2S1NjU3dTdGUvSkcyTVBBQXph?=
 =?utf-8?B?N3UwVkcxVm05bU5uNGp5R1JueVRRRjFrUXJ3N0Y5OXI4UFZkMjJlUXh2bk80?=
 =?utf-8?B?cjdyRTBoRXlDaWNld2J2dE5RK29EanduaHE0MzJRako3U09FK3VqN1pvMnRl?=
 =?utf-8?B?R2xQblJuTk5zL3VnY2FtNnp0d1c2cllZUU5WV2sr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WGlN?=
 =?utf-8?B?a0JkSGpEM2pSc0NSZ01WODJFWjlmSU03NExrUktBcGNuSkpWVDJYTjlqdEdy?=
 =?utf-8?B?YVE1eTdRdkNhdXh4YlVPeVRxUEsrVEJZSDRZYldnZVVRa0RwaFh4S2tGaVJK?=
 =?utf-8?B?YTVxY21hR2VGTlpSMXV6SGgwODV6eDRtZlBuY0ZXL1dCbFdNUzkwRnpCQTJt?=
 =?utf-8?B?K2wzWGZoc2JRUzRXT09aNmJ4MGxzcTFPQ0loYWJlMjJRSElQT2tiNmJYS2tS?=
 =?utf-8?B?SHVlVk52cWczSHRUSFY5YkExdVEwZ1NzMzllSm1RNTVTUFRuL1BmOWNJc2wr?=
 =?utf-8?B?WnlrVUUxQjRsL1ZhMGdndklJSDFUWGVocHYySW1kaEdDem5iSWtYVkdPR3I3?=
 =?utf-8?B?M3RPTGFMZmZNSEhWS3hMODd1OG1NNVozRzRLL21zUEREM1JlZXNKM0g2SW5U?=
 =?utf-8?B?SVd0R1doQjcxcFZSZnd4ZG4yM2xwWWRrbDRNa2U4Mlh0eHZJLzJvQUpyakli?=
 =?utf-8?Q?9bfVH/AUhsJO2?=
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:(13230031)(82310400017)(376005)(36860700004)(1800799015);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: ericsson.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 11:22:00.5382 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 2bed2dba-06a8-417a-279e-08dc7e3f3a4e
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: AM4PEPF00025F9A.EURPRD83.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6672
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Provide build option to have functions in <rte_memcpy.h> delegate to
the standard compiler/libc memcpy(), instead of using the various
traditional, handcrafted, per-architecture rte_memcpy()
implementations.

A new meson build option 'use_cc_memcpy' is added. The default is
true. It's not obvious what should be the default, but compiler
memcpy() is enabled by default in this RFC so any tests run with this
patch use the new approach.

One purpose of this RFC is to make it easy to evaluate the costs and
benefits of a switch.

Only ARM and x86 is implemented.

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 config/meson.build                   |  1 +
 lib/eal/arm/include/rte_memcpy.h     | 10 +++++
 lib/eal/include/generic/rte_memcpy.h | 62 ++++++++++++++++++++++++----
 lib/eal/x86/include/meson.build      |  6 ++-
 lib/eal/x86/include/rte_memcpy.h     | 11 ++++-
 meson_options.txt                    |  2 +
 6 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/config/meson.build b/config/meson.build
index 8c8b019c25..456056628e 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -353,6 +353,7 @@ endforeach
 # set other values pulled from the build options
 dpdk_conf.set('RTE_MAX_ETHPORTS', get_option('max_ethports'))
 dpdk_conf.set('RTE_LIBEAL_USE_HPET', get_option('use_hpet'))
+dpdk_conf.set('RTE_USE_CC_MEMCPY', get_option('use_cc_memcpy'))
 dpdk_conf.set('RTE_ENABLE_STDATOMIC', get_option('enable_stdatomic'))
 dpdk_conf.set('RTE_ENABLE_TRACE_FP', get_option('enable_trace_fp'))
 dpdk_conf.set('RTE_PKTMBUF_HEADROOM', get_option('pkt_mbuf_headroom'))
diff --git a/lib/eal/arm/include/rte_memcpy.h b/lib/eal/arm/include/rte_memcpy.h
index 47dea9a8cc..e8aff722df 100644
--- a/lib/eal/arm/include/rte_memcpy.h
+++ b/lib/eal/arm/include/rte_memcpy.h
@@ -5,10 +5,20 @@
 #ifndef _RTE_MEMCPY_ARM_H_
 #define _RTE_MEMCPY_ARM_H_
 
+#include <rte_config.h>
+
+#ifdef RTE_USE_CC_MEMCPY
+
+#include <generic/rte_memcpy.h>
+
+#else
+
 #ifdef RTE_ARCH_64
 #include <rte_memcpy_64.h>
 #else
 #include <rte_memcpy_32.h>
 #endif
 
+#endif /* RTE_USE_CC_MEMCPY */
+
 #endif /* _RTE_MEMCPY_ARM_H_ */
diff --git a/lib/eal/include/generic/rte_memcpy.h b/lib/eal/include/generic/rte_memcpy.h
index e7f0f8eaa9..f2f66f372d 100644
--- a/lib/eal/include/generic/rte_memcpy.h
+++ b/lib/eal/include/generic/rte_memcpy.h
@@ -5,12 +5,20 @@
 #ifndef _RTE_MEMCPY_H_
 #define _RTE_MEMCPY_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /**
  * @file
  *
  * Functions for vectorised implementation of memcpy().
  */
 
+#include <stdint.h>
+#include <string.h>
+#include <rte_vect.h>
+
 /**
  * Copy 16 bytes from one location to another using optimised
  * instructions. The locations should not overlap.
@@ -35,8 +43,6 @@ rte_mov16(uint8_t *dst, const uint8_t *src);
 static inline void
 rte_mov32(uint8_t *dst, const uint8_t *src);
 
-#ifdef __DOXYGEN__
-
 /**
  * Copy 48 bytes from one location to another using optimised
  * instructions. The locations should not overlap.
@@ -49,8 +55,6 @@ rte_mov32(uint8_t *dst, const uint8_t *src);
 static inline void
 rte_mov48(uint8_t *dst, const uint8_t *src);
 
-#endif /* __DOXYGEN__ */
-
 /**
  * Copy 64 bytes from one location to another using optimised
  * instructions. The locations should not overlap.
@@ -87,8 +91,6 @@ rte_mov128(uint8_t *dst, const uint8_t *src);
 static inline void
 rte_mov256(uint8_t *dst, const uint8_t *src);
 
-#ifdef __DOXYGEN__
-
 /**
  * Copy bytes from one location to another. The locations must not overlap.
  *
@@ -111,6 +113,52 @@ rte_mov256(uint8_t *dst, const uint8_t *src);
 static void *
 rte_memcpy(void *dst, const void *src, size_t n);
 
-#endif /* __DOXYGEN__ */
+#ifdef RTE_USE_CC_MEMCPY
+static inline void
+rte_mov16(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 16);
+}
+
+static inline void
+rte_mov32(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 32);
+}
+
+static inline void
+rte_mov48(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 48);
+}
+
+static inline void
+rte_mov64(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 64);
+}
+
+static inline void
+rte_mov128(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 128);
+}
+
+static inline void
+rte_mov256(uint8_t *dst, const uint8_t *src)
+{
+	memcpy(dst, src, 256);
+}
+
+static inline void *
+rte_memcpy(void *dst, const void *src, size_t n)
+{
+	return memcpy(dst, src, n);
+}
+#endif /* RTE_USE_CC_MEMCPY */
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _RTE_MEMCPY_H_ */
diff --git a/lib/eal/x86/include/meson.build b/lib/eal/x86/include/meson.build
index 52d2f8e969..cf851df60d 100644
--- a/lib/eal/x86/include/meson.build
+++ b/lib/eal/x86/include/meson.build
@@ -7,7 +7,6 @@ arch_headers = files(
         'rte_cpuflags.h',
         'rte_cycles.h',
         'rte_io.h',
-        'rte_memcpy.h',
         'rte_pause.h',
         'rte_power_intrinsics.h',
         'rte_prefetch.h',
@@ -16,6 +15,11 @@ arch_headers = files(
         'rte_spinlock.h',
         'rte_vect.h',
 )
+
+if not get_option('use_cc_memcpy')
+        arch_headers += 'rte_memcpy.h'
+endif
+
 arch_indirect_headers = files(
         'rte_atomic_32.h',
         'rte_atomic_64.h',
diff --git a/lib/eal/x86/include/rte_memcpy.h b/lib/eal/x86/include/rte_memcpy.h
index 72a92290e0..c5ba74d2ed 100644
--- a/lib/eal/x86/include/rte_memcpy.h
+++ b/lib/eal/x86/include/rte_memcpy.h
@@ -11,12 +11,19 @@
  * Functions for SSE/AVX/AVX2/AVX512 implementation of memcpy().
  */
 
+#include <rte_config.h>
+
+#ifdef RTE_USE_CC_MEMCPY
+
+#include <generic/rte_memcpy.h>
+
+#else
+
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
 #include <rte_vect.h>
 #include <rte_common.h>
-#include <rte_config.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -878,4 +885,6 @@ rte_memcpy(void *dst, const void *src, size_t n)
 }
 #endif
 
+#endif /* RTE_USE_CC_MEMCPY */
+
 #endif /* _RTE_MEMCPY_X86_64_H_ */
diff --git a/meson_options.txt b/meson_options.txt
index e49b2fc089..263b0e7882 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -60,3 +60,5 @@ option('tests', type: 'boolean', value: true, description:
        'build unit tests')
 option('use_hpet', type: 'boolean', value: false, description:
        'use HPET timer in EAL')
+option('use_cc_memcpy', type: 'boolean', value: true, description:
+       'Have rte_memcpy() delegate to compiler/libc memcpy() instead of using custom implementation.')
-- 
2.34.1