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 F23A0430C3; Mon, 21 Aug 2023 17:42:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CB527427E9; Mon, 21 Aug 2023 17:42:56 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 56CEA40DF5 for ; Mon, 21 Aug 2023 17:42:55 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id AAFCC211FA3D; Mon, 21 Aug 2023 08:42:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AAFCC211FA3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1692632574; bh=S395bbBHKbyrh6Cd3RG/AQs3qfXsZlb2sTShRAmNxP0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ku817ZBvJ7gVwK7A9aF7gQfAroBIqZkAO1C6VPS1UIGnRV5wsf29VN/Cl2LwvWEf1 aimfiOIhjZ/FXePoSgFLSyCwKufLuKI0hD/pJm41T/rzgNG4hWTMemjkCztRM2ZRQU QIQuPbsCdjcz6/FbNxiyOtgN34sySF8r6AZ7fTFc= Date: Mon, 21 Aug 2023 08:42:54 -0700 From: Tyler Retzlaff To: Bruce Richardson Cc: Ferruh Yigit , Konstantin Ananyev , "Tummala, Sivaprasad" , "david.hunt@intel.com" , "anatoly.burakov@intel.com" , "david.marchand@redhat.com" , "thomas@monjalon.net" , "dev@dpdk.org" Subject: Re: [PATCH v5 3/3] power: amd power monitor support Message-ID: <20230821154254.GA20964@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20230418082529.544777-2-sivaprasad.tummala@amd.com> <20230816185959.1331336-1-sivaprasad.tummala@amd.com> <20230816185959.1331336-3-sivaprasad.tummala@amd.com> <20230816192758.GA12453@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <92e7bd2e-b799-9658-c90e-f50638c6fdbd@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 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, Aug 18, 2023 at 02:48:42PM +0100, Bruce Richardson wrote: > On Fri, Aug 18, 2023 at 02:25:14PM +0100, Ferruh Yigit wrote: > > On 8/17/2023 3:18 PM, Konstantin Ananyev wrote: > > > > > >>> Caution: This message originated from an External Source. Use proper caution > > >>> when opening attachments, clicking links, or responding. > > >>> > > >>> > > >>> On Wed, Aug 16, 2023 at 11:59:59AM -0700, Sivaprasad Tummala wrote: > > >>>> mwaitx allows EPYC processors to enter a implementation dependent > > >>>> power/performance optimized state (C1 state) for a specific period or > > >>>> until a store to the monitored address range. > > >>>> > > >>>> Signed-off-by: Sivaprasad Tummala > > >>>> Acked-by: Anatoly Burakov > > >>>> --- > > >>>> lib/eal/x86/rte_power_intrinsics.c | 77 > > >>>> +++++++++++++++++++++++++----- > > >>>> 1 file changed, 66 insertions(+), 11 deletions(-) > > >>>> > > >>>> diff --git a/lib/eal/x86/rte_power_intrinsics.c > > >>>> b/lib/eal/x86/rte_power_intrinsics.c > > >>>> index 6eb9e50807..b4754e17da 100644 > > >>>> --- a/lib/eal/x86/rte_power_intrinsics.c > > >>>> +++ b/lib/eal/x86/rte_power_intrinsics.c > > >>>> @@ -17,6 +17,60 @@ static struct power_wait_status { > > >>>> volatile void *monitor_addr; /**< NULL if not currently sleeping > > >>>> */ } __rte_cache_aligned wait_status[RTE_MAX_LCORE]; > > >>>> > > >>>> +/** > > >>>> + * These functions uses UMONITOR/UMWAIT instructions and will enter C0.2 > > >>> state. > > >>>> + * For more information about usage of these instructions, please > > >>>> +refer to > > >>>> + * Intel(R) 64 and IA-32 Architectures Software Developer's Manual. > > >>>> + */ > > >>>> +static void intel_umonitor(volatile void *addr) { > > >>>> + /* UMONITOR */ > > >>>> + asm volatile(".byte 0xf3, 0x0f, 0xae, 0xf7;" > > >>>> + : > > >>>> + : "D"(addr)); > > >>>> +} > > >>>> + > > >>>> +static void intel_umwait(const uint64_t timeout) { > > >>>> + const uint32_t tsc_l = (uint32_t)timeout; > > >>>> + const uint32_t tsc_h = (uint32_t)(timeout >> 32); > > >>>> + /* UMWAIT */ > > >>>> + asm volatile(".byte 0xf2, 0x0f, 0xae, 0xf7;" > > >>>> + : /* ignore rflags */ > > >>>> + : "D"(0), /* enter C0.2 */ > > >>>> + "a"(tsc_l), "d"(tsc_h)); } > > >>> > > >>> question and perhaps Anatoly Burakov can chime in with expertise. > > >>> > > >>> gcc/clang have built-in intrinsics for umonitor and umwait i believe as per our other > > >>> thread of discussion is there a benefit to also providing inline assembly over just > > >>> using the intrinsics? I understand that the intrinsics may not exist for the monitorx > > >>> and mwaitx below so it is probably necessary for amd. > > >>> > > >>> so the suggestion here is when they are available just use the intrinsics. > > >>> > > >>> thanks > > >>> > > >> The gcc built-in functions __builtin_ia32_monitorx()/__builtin_ia32_mwaitx are available only when -mmwaitx > > >> is used specific for AMD platforms. On generic builds, these built-ins are not available and hence inline > > >> assembly is required here. > > > > > > Ok... but we can probably put them into a separate .c file that will be compiled with that specific flag? > > > Same thing can be probably done for Intel specific instructions. > > > In general, I think it is much more preferable to use built-ins vs inline assembly > > > (if possible off-course). > > > > > > > We don't compile different set of files for AMD and Intel, but there are > > runtime checks, so putting into separate file is not much different. > > > > It may be an option to always enable compiler flag (-mmwaitx), I think > > it won't hurt other platforms but I am not sure about implications of > > this to other platforms (what was the motivation for the compiler guys > > to enable these build-ins with specific flag?). > > > > Also this requires detecting compiler that supports 'mmwaitx' or not, etc.. > > > This is the biggest reason why we have in the past added support for these > instructions via asm bytes rather than intrinsics. It takes a long time for > end-user compilers, especially those in LTS releases, to get the necessary > intrinsics. Consider a user running e.g. RHEL 8, who wants to take > advantages of the latest DPDK features; they should not be required to > upgrade their compiler - and possibly binutils/assembler - to do so. yes, this is understood. just for clarity i'm only asking that the intrinsics be used for intel since they are available. for amd we'll have to use the inline asm if the older compilers don't have intrinsics. ty > > /Bruce