qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Michael Tokarev <mjt@tls.msk.ru>,
	Laurent Vivier <laurent@vivier.eu>,
	Justin Hibbits <chmeeedalf@gmail.com>
Subject: [Qemu-devel] [PULL 6/8] Fix cacheline detection on FreeBSD/powerpc.
Date: Thu, 19 Sep 2019 15:54:41 +0200	[thread overview]
Message-ID: <20190919135443.15164-7-laurent@vivier.eu> (raw)
In-Reply-To: <20190919135443.15164-1-laurent@vivier.eu>

From: Justin Hibbits <chmeeedalf@gmail.com>

machdep.cacheline_size is an integer, not a long.  Since PowerPC is
big-endian this causes sysctlbyname() to fill in the upper bits of the
argument, rather than the correct 'lower bits' of the word.  Specify the
correct type to fix this.

Fixes: b255b2c8a548 ("util: add cacheinfo")
Signed-off-by: Justin Hibbits <chmeeedalf@gmail.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Tested-by: Justin Hibbits <chmeeedalf@gmail.com>
Message-Id: <20190821082546.5252-2-laurent@vivier.eu>
---
 util/cacheinfo.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index eebe1ce9c5d2..ea6f3e99bf4a 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -65,25 +65,28 @@ static void sys_cache_info(int *isize, int *dsize)
     g_free(buf);
 }
 
-#elif defined(__APPLE__) \
-      || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__APPLE__)
 # include <sys/sysctl.h>
-# if defined(__APPLE__)
-#  define SYSCTL_CACHELINE_NAME "hw.cachelinesize"
-# else
-#  define SYSCTL_CACHELINE_NAME "machdep.cacheline_size"
-# endif
-
 static void sys_cache_info(int *isize, int *dsize)
 {
     /* There's only a single sysctl for both I/D cache line sizes.  */
     long size;
     size_t len = sizeof(size);
-    if (!sysctlbyname(SYSCTL_CACHELINE_NAME, &size, &len, NULL, 0)) {
+    if (!sysctlbyname("hw.cachelinesize", &size, &len, NULL, 0)) {
+        *isize = *dsize = size;
+    }
+}
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# include <sys/sysctl.h>
+static void sys_cache_info(int *isize, int *dsize)
+{
+    /* There's only a single sysctl for both I/D cache line sizes.  */
+    int size;
+    size_t len = sizeof(size);
+    if (!sysctlbyname("machdep.cacheline_size", &size, &len, NULL, 0)) {
         *isize = *dsize = size;
     }
 }
-
 #else
 /* POSIX */
 
-- 
2.21.0



  parent reply	other threads:[~2019-09-19 14:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 13:54 [Qemu-devel] [PULL 0/8] Trivial branch patches Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 1/8] vfio: fix a typo Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 2/8] cutils: Move size_to_str() from "qemu-common.h" to "qemu/cutils.h" Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 3/8] Replace '-machine accel=xyz' with '-accel xyz' Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 4/8] target/m68k/fpu_helper.c: rename the access arguments Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 5/8] build: Don't ignore qapi-visit-core.c Laurent Vivier
2019-09-19 13:54 ` Laurent Vivier [this message]
2019-09-19 13:54 ` [Qemu-devel] [PULL 7/8] kvm: Fix typo in header of kvm_device_access() Laurent Vivier
2019-09-19 13:54 ` [Qemu-devel] [PULL 8/8] configure: Add xkbcommon configure options Laurent Vivier
2019-09-20 16:28 ` [Qemu-devel] [PULL 0/8] Trivial branch patches Peter Maydell

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=20190919135443.15164-7-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=chmeeedalf@gmail.com \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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).