DPDK patches and discussions
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: dev@dpdk.org
Cc: "H. Peter Anvin" <hpa@zytor.com>
Subject: [dpdk-dev] [PATCH v3] eal: Fix up assembly for x86_64 in rte_cpu_get_features
Date: Thu, 20 Mar 2014 07:42:13 -0400	[thread overview]
Message-ID: <1395315733-8108-1-git-send-email-nhorman@tuxdriver.com> (raw)
In-Reply-To: <1395175414-25232-1-git-send-email-nhorman@tuxdriver.com>

x86_64 doesn't need to save off and restore ebx when issuing cpuid, since x86_64
uses RIP relative addressing.  Doing the save actually clobbers the lower half
of rbx, which could be used and not saved off independently, leading to
undefined behavior.  Fix up the defines so that for x86_64 we just issue the
cpuid instruction, which is safe.  Also, while we're at it, lets clean up the
input and output constraints on the inline asm, so that we don't load registers
that the cpuid instruction isn't sensitive to.

Note that this patch does alter the API, in that specifcations to ebx and edx
are ignored.  I chose to go ahead and do that because there is only a single
caller of this function and neither register is ever written currently.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: "H. Peter Anvin" <hpa@zytor.com>
---
 lib/librte_eal/common/eal_common_cpuflags.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c
index 1ebf78c..0a18d53 100644
--- a/lib/librte_eal/common/eal_common_cpuflags.c
+++ b/lib/librte_eal/common/eal_common_cpuflags.c
@@ -192,7 +192,7 @@ rte_cpu_get_features(struct cpuid_parameters_t params)
 {
 	int eax, ebx, ecx, edx;            /* registers */
 
-#ifndef __PIC__
+#if !defined(__PIC__) || !defined(__i386__)
    asm volatile ("cpuid"
                  /* output */
                  : "=a" (eax),
@@ -201,23 +201,19 @@ rte_cpu_get_features(struct cpuid_parameters_t params)
                    "=d" (edx)
                  /* input */
                  : "a" (params.eax),
-                   "b" (params.ebx),
-                   "c" (params.ecx),
-                   "d" (params.edx));
+                   "c" (params.ecx));
 #else
 	asm volatile ( 
-            "mov %%ebx, %%edi\n"
+            "mov %%ebx, %0\n"
             "cpuid\n"
-            "xchgl %%ebx, %%edi;\n"
-            : "=a" (eax),
-              "=D" (ebx),
+            "xchgl %%ebx, %0\n"
+            : "=r" (ebx),
+	      "=a" (eax),
               "=c" (ecx),
               "=d" (edx)
             /* input */
             : "a" (params.eax),
-              "D" (params.ebx),
-              "c" (params.ecx),
-              "d" (params.edx));
+              "c" (params.ecx));
 #endif
 
 	switch (params.return_register) {
-- 
1.8.3.1

      parent reply	other threads:[~2014-03-20 11:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18 20:43 [dpdk-dev] [PATCH] eal: fix up bad asm " Neil Horman
2014-03-19 14:48 ` [dpdk-dev] [PATCH v2] " Neil Horman
2014-03-19 15:44   ` H. Peter Anvin
2014-03-20  0:40     ` Neil Horman
2014-03-20  4:22       ` H. Peter Anvin
2014-03-20 11:03         ` Neil Horman
2014-03-20 11:27           ` Neil Horman
2014-03-20 15:20             ` H. Peter Anvin
2014-03-20 11:42 ` Neil Horman [this message]

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=1395315733-8108-1-git-send-email-nhorman@tuxdriver.com \
    --to=nhorman@tuxdriver.com \
    --cc=dev@dpdk.org \
    --cc=hpa@zytor.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).