DPDK patches and discussions
 help / color / mirror / Atom feed
From: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
To: dev@dpdk.org
Cc: konstantin.ananyev@intel.com, bruce.richardson@intel.com
Subject: [dpdk-dev] [PATCH 1/2] eal/x86: use cpuid builtin
Date: Wed, 23 Aug 2017 13:42:40 +0100	[thread overview]
Message-ID: <20170823124241.17552-1-sergio.gonzalez.monroy@intel.com> (raw)

Signed-off-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
---
 lib/librte_eal/common/arch/x86/rte_cpuflags.c | 41 +++++----------------------
 1 file changed, 7 insertions(+), 34 deletions(-)

diff --git a/lib/librte_eal/common/arch/x86/rte_cpuflags.c b/lib/librte_eal/common/arch/x86/rte_cpuflags.c
index 0138257..6760e33 100644
--- a/lib/librte_eal/common/arch/x86/rte_cpuflags.c
+++ b/lib/librte_eal/common/arch/x86/rte_cpuflags.c
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdint.h>
+#include <cpuid.h>
 
 enum cpu_register_t {
 	RTE_REG_EAX = 0,
@@ -156,38 +157,12 @@ const struct feature_entry rte_cpu_feature_table[] = {
 	FEAT_DEF(INVTSC, 0x80000007, 0, RTE_REG_EDX,  8)
 };
 
-/*
- * Execute CPUID instruction and get contents of a specific register
- *
- * This function, when compiled with GCC, will generate architecture-neutral
- * code, as per GCC manual.
- */
-static void
-rte_cpu_get_features(uint32_t leaf, uint32_t subleaf, cpuid_registers_t out)
-{
-#if defined(__i386__) && defined(__PIC__)
-	/* %ebx is a forbidden register if we compile with -fPIC or -fPIE */
-	asm volatile("movl %%ebx,%0 ; cpuid ; xchgl %%ebx,%0"
-		 : "=r" (out[RTE_REG_EBX]),
-		   "=a" (out[RTE_REG_EAX]),
-		   "=c" (out[RTE_REG_ECX]),
-		   "=d" (out[RTE_REG_EDX])
-		 : "a" (leaf), "c" (subleaf));
-#else
-	asm volatile("cpuid"
-		 : "=a" (out[RTE_REG_EAX]),
-		   "=b" (out[RTE_REG_EBX]),
-		   "=c" (out[RTE_REG_ECX]),
-		   "=d" (out[RTE_REG_EDX])
-		 : "a" (leaf), "c" (subleaf));
-#endif
-}
-
 int
 rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature)
 {
 	const struct feature_entry *feat;
 	cpuid_registers_t regs;
+	int ret;
 
 	if (feature >= RTE_CPUFLAG_NUMFLAGS)
 		/* Flag does not match anything in the feature tables */
@@ -199,13 +174,11 @@ rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature)
 		/* This entry in the table wasn't filled out! */
 		return -EFAULT;
 
-	rte_cpu_get_features(feat->leaf & 0xffff0000, 0, regs);
-	if (((regs[RTE_REG_EAX] ^ feat->leaf) & 0xffff0000) ||
-	      regs[RTE_REG_EAX] < feat->leaf)
-		return 0;
-
-	/* get the cpuid leaf containing the desired feature */
-	rte_cpu_get_features(feat->leaf, feat->subleaf, regs);
+	ret = __get_cpuid_count(feat->leaf, feat->subleaf,
+			&regs[RTE_REG_EAX], &regs[RTE_REG_EBX],
+			&regs[RTE_REG_ECX], &regs[RTE_REG_EDX]);
+	if (!ret)
+		return ret;
 
 	/* check if the feature is enabled */
 	return (regs[feat->reg] >> feat->bit) & 1;
-- 
2.9.5

             reply	other threads:[~2017-08-23 12:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 12:42 Sergio Gonzalez Monroy [this message]
2017-08-23 12:42 ` [dpdk-dev] [PATCH 2/2] eal/x86: implement x86 specific tsc hz Sergio Gonzalez Monroy
2017-08-23 13:17   ` Bruce Richardson
2017-08-23 13:57     ` Sergio Gonzalez Monroy
2017-08-23 14:03       ` Bruce Richardson
2017-08-23 20:49 ` [dpdk-dev] [PATCH 1/2] eal/x86: use cpuid builtin Thomas Monjalon
2017-08-24  8:21   ` Sergio Gonzalez Monroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170823124241.17552-1-sergio.gonzalez.monroy@intel.com \
    --to=sergio.gonzalez.monroy@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).