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 2A136425E9; Mon, 25 Sep 2023 11:43:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A4915402CC; Mon, 25 Sep 2023 11:43:15 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id A3CF8402B7 for ; Mon, 25 Sep 2023 11:43:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695634993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kTU/0Hq6lnG/bNhXmSaKxRxrcGUDDCDSm5sOMbYUK8A=; b=PjqDqaBaSy5p8QVWLiIO1bwYMjyRPE/vFLtvVrOj/zNgJtmPSttACz+OwczlV5KDqCcQ3Z 5B0bG+jI+N2AaH6JkDpkVDAbnW/LBSrqI1/x3xO8AwqZf+b8+LB8zK5/4TlEEzhuvcTvTj AIIIWJqSEx7E98NST6rTh6T1H0yUDww= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-GB98E--wPJalnkycQwtpSg-1; Mon, 25 Sep 2023 05:43:11 -0400 X-MC-Unique: GB98E--wPJalnkycQwtpSg-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2c01ce3c29fso88137351fa.3 for ; Mon, 25 Sep 2023 02:43:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695634990; x=1696239790; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTU/0Hq6lnG/bNhXmSaKxRxrcGUDDCDSm5sOMbYUK8A=; b=iUTMiFVfgC38dkwHVFkMwByCQrRQel9m+JsVNDn0rELVxOAerED7LFqxQCHV0fGMoQ oZiNAQJangkrgDBJIh3K6WLzQiynvGhgrhov1+YSum37N0WS2YatpmzBVVPV6fmWmT35 vkJw63LYm1UuwfMsZx74Ko+Pb50Y6vbM31iLU48qOzfZLwxPtUHnoDV/F1WQ/pG4LtuP IfouyjC3jt4g4WjEjgGQS/CcMysUdUfoohRyzsn0H+bCjKact4t0v38mUHcUVE02QpUe XsaJRJyeH15eZmzd6vxT3lOPLJJpgnHIO59PKRTLJRvCCQY6jYLFZ1bCimwKivVDnanX NVLw== X-Gm-Message-State: AOJu0YxHW+tDOdHyLW08bfAaQWgyNU+rDhuKq2e4tUFf1L6ebqAU4ltM OKUooZKhkfYW6PjvE33RMqNxj+pmQWrChFneFQoWO3X+LggYToKKbCPoxLxYDBuakf0vVNPlnSd vuyYa/dmKmre1gj+pupw= X-Received: by 2002:a2e:92d5:0:b0:2bf:af49:daf7 with SMTP id k21-20020a2e92d5000000b002bfaf49daf7mr5357674ljh.42.1695634990348; Mon, 25 Sep 2023 02:43:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoEIY6vxbFjo3eoA9v8YFilz1cqINbskgfdAmQ+xGnc0LUGXYE7qOpthIcWkOcXdQ12038yYW0k6Z57t0Ug0U= X-Received: by 2002:a2e:92d5:0:b0:2bf:af49:daf7 with SMTP id k21-20020a2e92d5000000b002bfaf49daf7mr5357661ljh.42.1695634990044; Mon, 25 Sep 2023 02:43:10 -0700 (PDT) MIME-Version: 1.0 References: <20230922093722.2057688-1-david.marchand@redhat.com> <20230922093722.2057688-2-david.marchand@redhat.com> In-Reply-To: From: David Marchand Date: Mon, 25 Sep 2023 11:42:58 +0200 Message-ID: Subject: Re: [PATCH 1/2] eal: introduce x86 processor identification To: Bruce Richardson Cc: dev@dpdk.org, ferruh.yigit@amd.com, thomas@monjalon.net, konstantin.v.ananyev@yandex.ru, ruifeng.wang@arm.com, zhoumin@loongson.cn, drc@linux.vnet.ibm.com, kda@semihalf.com, roretzla@linux.microsoft.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Fri, Sep 22, 2023 at 11:47=E2=80=AFAM Bruce Richardson wrote: > > On Fri, Sep 22, 2023 at 11:37:20AM +0200, David Marchand wrote: > > In some really specific cases, it may be needed to get a detailed > > information on the processor running a DPDK application for drivers to > > achieve better performance, or for matters that concern only them. > > > > Those information are highly arch-specific and require a specific API. > > > > Introduce a set of functions to get brand, family and model of a x86 > > processor. > > Those functions do not make sense on other arches and a > > driver must first check rte_cpu_is_x86() before anything else. > > > > Signed-off-by: David Marchand > > --- > > MAINTAINERS | 1 + > > app/test/meson.build | 1 + > > app/test/test_cpu.c | 37 +++++++++ > > lib/eal/common/eal_common_cpu.c | 141 ++++++++++++++++++++++++++++++++ > > lib/eal/common/eal_cpu.h | 77 +++++++++++++++++ > > lib/eal/common/meson.build | 1 + > > lib/eal/version.map | 6 ++ > > 7 files changed, 264 insertions(+) > > create mode 100644 app/test/test_cpu.c > > create mode 100644 lib/eal/common/eal_common_cpu.c > > create mode 100644 lib/eal/common/eal_cpu.h > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index 698608cdb2..b87d47a1e4 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -158,6 +158,7 @@ F: app/test/test_barrier.c > > F: app/test/test_bitcount.c > > F: app/test/test_byteorder.c > > F: app/test/test_common.c > > +F: app/test/test_cpu.c > > F: app/test/test_cpuflags.c > > F: app/test/test_cycles.c > > F: app/test/test_debug.c > > diff --git a/app/test/meson.build b/app/test/meson.build > > index 05bae9216d..4b37ad02fa 100644 > > --- a/app/test/meson.build > > +++ b/app/test/meson.build > > @@ -44,6 +44,7 @@ source_file_deps =3D { > > 'test_cmdline_string.c': [], > > 'test_common.c': [], > > 'test_compressdev.c': ['compressdev'], > > + 'test_cpu.c': [], > > 'test_cpuflags.c': [], > > 'test_crc.c': ['net'], > > 'test_cryptodev.c': test_cryptodev_deps, > > diff --git a/app/test/test_cpu.c b/app/test/test_cpu.c > > new file mode 100644 > > index 0000000000..40d8bd94eb > > --- /dev/null > > +++ b/app/test/test_cpu.c > > @@ -0,0 +1,37 @@ > > +/* SPDX-License-Identifier: BSD-3-Clause > > + * Copyright(c) 2023 Red Hat, Inc. > > + */ > > + > > +#include > > +#include > > + > > +#include "eal_cpu.h" > > + > > +#include "test.h" > > + > > +static int > > +test_cpu(void) > > +{ > > +#ifndef RTE_ARCH_X86 > > + RTE_TEST_ASSERT(!rte_cpu_is_x86(), "rte_cpu_is_x86() returned tru= e on " RTE_STR(RTE_ARCH)); > > +#else > > + const char *vendor; > > + > > + RTE_TEST_ASSERT(rte_cpu_is_x86(), "rte_cpu_is_x86() returned fals= e"); > > + > > + if (rte_cpu_x86_is_amd()) > > + vendor =3D "AMD"; > > + else if (rte_cpu_x86_is_intel()) > > + vendor =3D "Intel"; > > + else > > + vendor =3D "unknown"; > > + > > + printf("The processor running this program is a x86 %s processor,= brand=3D0x%" > > + PRIx8", family=3D0x%"PRIx8", model=3D0x%"PRIx8"\n", vendo= r, rte_cpu_x86_brand(), > > + rte_cpu_x86_family(), rte_cpu_x86_model()); > > +#endif > > + > > + return TEST_SUCCESS; > > +} > > + > > +REGISTER_FAST_TEST(cpu_autotest, true, true, test_cpu); > > diff --git a/lib/eal/common/eal_common_cpu.c b/lib/eal/common/eal_commo= n_cpu.c > > new file mode 100644 > > index 0000000000..18cdb27f75 > > --- /dev/null > > +++ b/lib/eal/common/eal_common_cpu.c > > @@ -0,0 +1,141 @@ > > +/* SPDX-License-Identifier: BSD-3-Clause > > + * Copyright(c) 2023 Red Hat, Inc. > > + */ > > + > > +#include > > + > > +#include "eal_cpu.h" > > + > > +#ifdef RTE_ARCH_X86 > > +#ifndef RTE_TOOLCHAIN_MSVC > > +#include > > +#endif > > + > > +static void > > +x86_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *eb= x, > > + uint32_t *ecx, uint32_t *edx) > > +{ > > + uint32_t regs[4] =3D { 0 }; > > + > > +#ifdef RTE_TOOLCHAIN_MSVC > > + __cpuidex(regs, leaf, subleaf); > > +#else > > + __cpuid_count(leaf, subleaf, regs[0], regs[1], regs[2], regs[3]); > > +#endif > > + > > + *eax =3D regs[0]; > > + *ebx =3D regs[1]; > > + *ecx =3D regs[2]; > > + *edx =3D regs[3]; > > +} > > +#endif /* RTE_ARCH_X86 */ > > From a readability perspective, I think it would be better to expand the > scope of this ifdef and have two copies of each function in the file, > rather than a single copy of each with #ifdefs. WDYT? I can have a try later, but if you want to take over the series, I don't mind :-). --=20 David Marchand