qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 1/7] util: add cacheinfo


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH v4 1/7] util: add cacheinfo
Date: Thu, 8 Jun 2017 09:42:42 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

On 06/07/2017 03:11 PM, Emilio G. Cota wrote:
On Wed, Jun 07, 2017 at 08:55:30 -0700, Richard Henderson wrote:
(snip)
+#elif defined(__APPLE__) \
+      || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# 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(void)
+{
+    /* There's only a single sysctl for both I/D cache line sizes.  */
+    size_t len = sizeof(qemu_icache_linesize);
+    if (!sysctlbyname(SYSCTL_CACHELINE_NAME, &qemu_icache_linesize,
+                      &len, NULL, 0)) {
+        qemu_dcache_linesize = qemu_icache_linesize;
+    }
+}

This doesn't work on the MacOS (Darwin 16.6.0) I have access to.

If we do
        long size; // <-- type here matters!
        size_t len = sizeof(size);
        sysctlbyname(..., &size, &len, ...);
then size == 64.

However, if instead of 'long size' we have 'int size' (as in the patch),
then  'size == 1' yet sysctlbyname still returns 0. (!)
This is why I was using an intermediate long in my previous patch,
although obviously a comment there would have been appropriate.

FWIW, if we query what length sysctlbyname expects for this param (by
calling sysctlbyname(NAME, NULL, &size, NULL, 0), we get len == 8;
I presume on both 32 and 64-bit systems passing a long will work
OK here.

Thanks, missed that. I also have to fix up the _WIN32 case, for which I missed a default: while rearranging things.

r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]