diff mbox series

[1/1] Fix cacheline detection on FreeBSD/powerpc.

Message ID 20190821082546.5252-2-laurent@vivier.eu (mailing list archive)
State New, archived
Headers show
Series Fix cacheline detection on FreeBSD/powerpc | expand

Commit Message

Laurent Vivier Aug. 21, 2019, 8:25 a.m. UTC
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>
---
 util/cacheinfo.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Laurent Vivier Sept. 19, 2019, 10:19 a.m. UTC | #1
Le 21/08/2019 à 10:25, Laurent Vivier a écrit :
> 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>
> ---
>  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 */
>  
> 

Applied to my trivial-patches branch.

Thanks,
Laurent
diff mbox series

Patch

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 */