Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/131829/?format=api
http://patchwork.dpdk.org/api/patches/131829/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20230922093722.2057688-2-david.marchand@redhat.com/", "project": { "id": 1, "url": "http://patchwork.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20230922093722.2057688-2-david.marchand@redhat.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20230922093722.2057688-2-david.marchand@redhat.com", "date": "2023-09-22T09:37:20", "name": "[1/2] eal: introduce x86 processor identification", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "ac5de3684feeb28df6a98629fa9737f99f8df5a8", "submitter": { "id": 1173, "url": "http://patchwork.dpdk.org/api/people/1173/?format=api", "name": "David Marchand", "email": "david.marchand@redhat.com" }, "delegate": { "id": 1, "url": "http://patchwork.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20230922093722.2057688-2-david.marchand@redhat.com/mbox/", "series": [ { "id": 29605, "url": "http://patchwork.dpdk.org/api/series/29605/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=29605", "date": "2023-09-22T09:37:19", "name": "Introduce x86 specific identification API", "version": 1, "mbox": "http://patchwork.dpdk.org/series/29605/mbox/" } ], "comments": "http://patchwork.dpdk.org/api/patches/131829/comments/", "check": "warning", "checks": "http://patchwork.dpdk.org/api/patches/131829/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id E152E42616;\n\tFri, 22 Sep 2023 11:37:44 +0200 (CEST)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id EC6C24068A;\n\tFri, 22 Sep 2023 11:37:43 +0200 (CEST)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by mails.dpdk.org (Postfix) with ESMTP id B8B1040685\n for <dev@dpdk.org>; Fri, 22 Sep 2023 11:37:42 +0200 (CEST)", "from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-599-fGRyghn9PRiHfr-rXfI1zw-1; Fri, 22 Sep 2023 05:37:38 -0400", "from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com\n [10.11.54.1])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4523D101A529;\n Fri, 22 Sep 2023 09:37:38 +0000 (UTC)", "from dmarchan.redhat.com (unknown [10.45.224.128])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 88FDD40C2064;\n Fri, 22 Sep 2023 09:37:36 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1695375462;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=IRpfa9LTLMcERvWDvpQKsrh+yRqpHDFZyrFp1JRInqw=;\n b=FW1y4GuXcpab3XY1jFkHhlKoIBMGJNETYpDAgHCkHKGk2qGK8qgeRbCrhpdBfg1d+zRnaE\n WZGZTmjk7uyDVdmLWBk+D9UQ5vlRFekB9tjtsMvgacLo/mnhaywaGAj9HdhIU8oI+u5YzS\n LQMyjicsQc9PCd42KHgCz2jbdCO5zhI=", "X-MC-Unique": "fGRyghn9PRiHfr-rXfI1zw-1", "From": "David Marchand <david.marchand@redhat.com>", "To": "dev@dpdk.org", "Cc": "ferruh.yigit@amd.com, thomas@monjalon.net, bruce.richardson@intel.com,\n konstantin.v.ananyev@yandex.ru, ruifeng.wang@arm.com, zhoumin@loongson.cn,\n drc@linux.vnet.ibm.com, kda@semihalf.com, roretzla@linux.microsoft.com", "Subject": "[PATCH 1/2] eal: introduce x86 processor identification", "Date": "Fri, 22 Sep 2023 11:37:20 +0200", "Message-ID": "<20230922093722.2057688-2-david.marchand@redhat.com>", "In-Reply-To": "<20230922093722.2057688-1-david.marchand@redhat.com>", "References": "<20230922093722.2057688-1-david.marchand@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.1 on 10.11.54.1", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true", "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>,\n <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>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "In some really specific cases, it may be needed to get a detailed\ninformation on the processor running a DPDK application for drivers to\nachieve better performance, or for matters that concern only them.\n\nThose information are highly arch-specific and require a specific API.\n\nIntroduce a set of functions to get brand, family and model of a x86\nprocessor.\nThose functions do not make sense on other arches and a\ndriver must first check rte_cpu_is_x86() before anything else.\n\nSigned-off-by: David Marchand <david.marchand@redhat.com>\n---\n MAINTAINERS | 1 +\n app/test/meson.build | 1 +\n app/test/test_cpu.c | 37 +++++++++\n lib/eal/common/eal_common_cpu.c | 141 ++++++++++++++++++++++++++++++++\n lib/eal/common/eal_cpu.h | 77 +++++++++++++++++\n lib/eal/common/meson.build | 1 +\n lib/eal/version.map | 6 ++\n 7 files changed, 264 insertions(+)\n create mode 100644 app/test/test_cpu.c\n create mode 100644 lib/eal/common/eal_common_cpu.c\n create mode 100644 lib/eal/common/eal_cpu.h", "diff": "diff --git a/MAINTAINERS b/MAINTAINERS\nindex 698608cdb2..b87d47a1e4 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -158,6 +158,7 @@ F: app/test/test_barrier.c\n F: app/test/test_bitcount.c\n F: app/test/test_byteorder.c\n F: app/test/test_common.c\n+F: app/test/test_cpu.c\n F: app/test/test_cpuflags.c\n F: app/test/test_cycles.c\n F: app/test/test_debug.c\ndiff --git a/app/test/meson.build b/app/test/meson.build\nindex 05bae9216d..4b37ad02fa 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -44,6 +44,7 @@ source_file_deps = {\n 'test_cmdline_string.c': [],\n 'test_common.c': [],\n 'test_compressdev.c': ['compressdev'],\n+ 'test_cpu.c': [],\n 'test_cpuflags.c': [],\n 'test_crc.c': ['net'],\n 'test_cryptodev.c': test_cryptodev_deps,\ndiff --git a/app/test/test_cpu.c b/app/test/test_cpu.c\nnew file mode 100644\nindex 0000000000..40d8bd94eb\n--- /dev/null\n+++ b/app/test/test_cpu.c\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2023 Red Hat, Inc.\n+ */\n+\n+#include <stdio.h>\n+#include <inttypes.h>\n+\n+#include \"eal_cpu.h\"\n+\n+#include \"test.h\"\n+\n+static int\n+test_cpu(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\tRTE_TEST_ASSERT(!rte_cpu_is_x86(), \"rte_cpu_is_x86() returned true on \" RTE_STR(RTE_ARCH));\n+#else\n+\tconst char *vendor;\n+\n+\tRTE_TEST_ASSERT(rte_cpu_is_x86(), \"rte_cpu_is_x86() returned false\");\n+\n+\tif (rte_cpu_x86_is_amd())\n+\t\tvendor = \"AMD\";\n+\telse if (rte_cpu_x86_is_intel())\n+\t\tvendor = \"Intel\";\n+\telse\n+\t\tvendor = \"unknown\";\n+\n+\tprintf(\"The processor running this program is a x86 %s processor, brand=0x%\"\n+\t\tPRIx8\", family=0x%\"PRIx8\", model=0x%\"PRIx8\"\\n\", vendor, rte_cpu_x86_brand(),\n+\t\trte_cpu_x86_family(), rte_cpu_x86_model());\n+#endif\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+REGISTER_FAST_TEST(cpu_autotest, true, true, test_cpu);\ndiff --git a/lib/eal/common/eal_common_cpu.c b/lib/eal/common/eal_common_cpu.c\nnew file mode 100644\nindex 0000000000..18cdb27f75\n--- /dev/null\n+++ b/lib/eal/common/eal_common_cpu.c\n@@ -0,0 +1,141 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2023 Red Hat, Inc.\n+ */\n+\n+#include <rte_debug.h>\n+\n+#include \"eal_cpu.h\"\n+\n+#ifdef RTE_ARCH_X86\n+#ifndef RTE_TOOLCHAIN_MSVC\n+#include <cpuid.h>\n+#endif\n+\n+static void\n+x86_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx,\n+\tuint32_t *ecx, uint32_t *edx)\n+{\n+\tuint32_t regs[4] = { 0 };\n+\n+#ifdef RTE_TOOLCHAIN_MSVC\n+\t__cpuidex(regs, leaf, subleaf);\n+#else\n+\t__cpuid_count(leaf, subleaf, regs[0], regs[1], regs[2], regs[3]);\n+#endif\n+\n+\t*eax = regs[0];\n+\t*ebx = regs[1];\n+\t*ecx = regs[2];\n+\t*edx = regs[3];\n+}\n+#endif /* RTE_ARCH_X86 */\n+\n+bool\n+rte_cpu_is_x86(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\treturn false;\n+#else\n+\treturn true;\n+#endif\n+}\n+\n+bool\n+rte_cpu_x86_is_amd(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\trte_panic(\"Calling %s does not make sense on %s architecture.\\n\",\n+\t\t__func__, RTE_STR(RTE_ARCH));\n+#else\n+\tuint32_t eax, ebx, ecx, edx;\n+\n+\tx86_cpuid(0x0, 0x0, &eax, &ebx, &ecx, &edx);\n+\t/* ascii_to_little_endian(\"Auth enti cAMD\") */\n+\treturn ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65;\n+#endif\n+}\n+\n+bool\n+rte_cpu_x86_is_intel(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\trte_panic(\"Calling %s does not make sense on %s architecture.\\n\",\n+\t\t__func__, RTE_STR(RTE_ARCH));\n+#else\n+\tuint32_t eax, ebx, ecx, edx;\n+\n+\tx86_cpuid(0x0, 0x0, &eax, &ebx, &ecx, &edx);\n+\t/* ascii_to_little_endian(\"Genu ineI ntel\") */\n+\treturn ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69;\n+#endif\n+}\n+\n+uint8_t\n+rte_cpu_x86_brand(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\trte_panic(\"Calling %s does not make sense on %s architecture.\\n\",\n+\t\t__func__, RTE_STR(RTE_ARCH));\n+#else\n+\tuint32_t eax, ebx, ecx, edx;\n+\tuint8_t brand = 0;\n+\n+\tx86_cpuid(0x0, 0x0, &eax, &ebx, &ecx, &edx);\n+\tif (eax >= 1) {\n+\t\tx86_cpuid(0x1, 0x0, &eax, &ebx, &ecx, &edx);\n+\t\tbrand = ebx & 0xff;\n+\t}\n+\n+\treturn brand;\n+#endif\n+}\n+\n+uint8_t\n+rte_cpu_x86_family(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\trte_panic(\"Calling %s does not make sense on %s architecture.\\n\",\n+\t\t__func__, RTE_STR(RTE_ARCH));\n+#else\n+\tuint32_t eax, ebx, ecx, edx;\n+\tuint8_t family = 0;\n+\n+\tx86_cpuid(0x0, 0x0, &eax, &ebx, &ecx, &edx);\n+\tif (eax >= 1) {\n+\t\tuint8_t family_id;\n+\n+\t\tx86_cpuid(0x1, 0x0, &eax, &ebx, &ecx, &edx);\n+\t\tfamily_id = (eax >> 8) & 0x0f;\n+\t\tfamily = family_id;\n+\t\tif (family_id == 0xf)\n+\t\t\tfamily += (eax >> 20) & 0xff;\n+\t}\n+\n+\treturn family;\n+#endif\n+}\n+\n+uint8_t\n+rte_cpu_x86_model(void)\n+{\n+#ifndef RTE_ARCH_X86\n+\trte_panic(\"Calling %s does not make sense on %s architecture.\\n\",\n+\t\t__func__, RTE_STR(RTE_ARCH));\n+#else\n+\tuint32_t eax, ebx, ecx, edx;\n+\tuint8_t model = 0;\n+\n+\tx86_cpuid(0x0, 0x0, &eax, &ebx, &ecx, &edx);\n+\tif (eax >= 1) {\n+\t\tuint8_t family_id;\n+\n+\t\tx86_cpuid(0x1, 0x0, &eax, &ebx, &ecx, &edx);\n+\t\tfamily_id = (eax >> 8) & 0x0f;\n+\t\tmodel = (eax >> 4) & 0x0f;\n+\t\tif (family_id == 0x6 || family_id == 0xf)\n+\t\t\tmodel += (eax >> 12) & 0xf0;\n+\t}\n+\n+\treturn model;\n+#endif\n+}\ndiff --git a/lib/eal/common/eal_cpu.h b/lib/eal/common/eal_cpu.h\nnew file mode 100644\nindex 0000000000..26d8e06bf0\n--- /dev/null\n+++ b/lib/eal/common/eal_cpu.h\n@@ -0,0 +1,77 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2023 Red Hat, Inc.\n+ */\n+\n+#ifndef EAL_CPU_H\n+#define EAL_CPU_H\n+\n+#include <stdbool.h>\n+#include <stdint.h>\n+\n+#include <rte_compat.h>\n+\n+/**\n+ * Returns whether the processor running this program is a x86 one.\n+ *\n+ * @return\n+ * true or false\n+ */\n+__rte_internal\n+bool rte_cpu_is_x86(void);\n+\n+/**\n+ * Returns whether the processor running this program is a AMD x86 one.\n+ *\n+ * Note: calling this function only makes sense if rte_cpu_is_x86() == true.\n+ *\n+ * @return\n+ * true or false\n+ */\n+__rte_internal\n+bool rte_cpu_x86_is_amd(void);\n+\n+/**\n+ * Returns whether the processor running this program is a Intel x86 one.\n+ *\n+ * Note: calling this function only makes sense if rte_cpu_is_x86() == true.\n+ *\n+ * @return\n+ * true or false\n+ */\n+__rte_internal\n+bool rte_cpu_x86_is_intel(void);\n+\n+/**\n+ * Returns the processor brand (as returned by CPUID).\n+ *\n+ * Note: calling this function only makes sense if rte_cpu_is_x86() == true.\n+ *\n+ * @return\n+ * x86 processor brand\n+ */\n+__rte_internal\n+uint8_t rte_cpu_x86_brand(void);\n+\n+/**\n+ * Returns the processor family (as returned by CPUID).\n+ *\n+ * Note: calling this function only makes sense if rte_cpu_is_x86() == true.\n+ *\n+ * @return\n+ * x86 processor family\n+ */\n+__rte_internal\n+uint8_t rte_cpu_x86_family(void);\n+\n+/**\n+ * Returns the processor model (as returned by CPUID).\n+ *\n+ * Note: calling this function only makes sense if rte_cpu_is_x86() == true.\n+ *\n+ * @return\n+ * x86 processor model\n+ */\n+__rte_internal\n+uint8_t rte_cpu_x86_model(void);\n+\n+#endif /* EAL_CPU_H */\ndiff --git a/lib/eal/common/meson.build b/lib/eal/common/meson.build\nindex 22a626ba6f..bef5b2575b 100644\n--- a/lib/eal/common/meson.build\n+++ b/lib/eal/common/meson.build\n@@ -9,6 +9,7 @@ sources += files(\n 'eal_common_bus.c',\n 'eal_common_class.c',\n 'eal_common_config.c',\n+ 'eal_common_cpu.c',\n 'eal_common_debug.c',\n 'eal_common_dev.c',\n 'eal_common_devargs.c',\ndiff --git a/lib/eal/version.map b/lib/eal/version.map\nindex 7940431e5a..62632202c5 100644\n--- a/lib/eal/version.map\n+++ b/lib/eal/version.map\n@@ -424,6 +424,12 @@ INTERNAL {\n \n \trte_bus_register;\n \trte_bus_unregister;\n+\trte_cpu_is_x86;\n+\trte_cpu_x86_brand;\n+\trte_cpu_x86_family;\n+\trte_cpu_x86_is_amd;\n+\trte_cpu_x86_is_intel;\n+\trte_cpu_x86_model;\n \trte_eal_get_baseaddr;\n \trte_eal_parse_coremask;\n \trte_firmware_read;\n", "prefixes": [ "1/2" ] }{ "id": 131829, "url": "