Patchwork [1/3] Add FreeBSD/ppc host ppc_init_cacheline_sizes() implementation.

login
register
mail settings
Submitter Juergen Lock
Date Feb. 15, 2010, 10:45 p.m.
Message ID <20100215224506.GB29604@triton8.kn-bremen.de>
Download mbox | patch
Permalink /patch/45444/
State New
Headers show

Comments

Juergen Lock - Feb. 15, 2010, 10:45 p.m.
On Mon, Feb 15, 2010 at 06:15:41AM +0300, malc wrote:
> On Sun, 14 Feb 2010, Juergen Lock wrote:
> 
> > Submitted by: Andreas Tobler <andreast@fgznet.ch>
> > 
> > Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>
> > 
> > --- a/cache-utils.c
> > +++ b/cache-utils.c
> > @@ -57,6 +57,23 @@
> >  }
> >  #endif
> >  
> > +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
> > +#include <stdio.h>
> > +#include <sys/types.h>
> > +#include <sys/sysctl.h>
> > +
> > +static void ppc_init_cacheline_sizes(void)
> > +{
> > +    size_t len = 4;
> > +    unsigned cacheline;
> > +
> > +    sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0);
> 
> Error handling missing.

Mmh I suspect thats a sysctl that simply can't fail but of course checking
still doesn't hurt:

Submitted by: Andreas Tobler <andreast@fgznet.ch>

Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>

Patch

--- a/cache-utils.c
+++ b/cache-utils.c
@@ -57,6 +57,27 @@  static void ppc_init_cacheline_sizes(voi
 }
 #endif
 
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+    size_t len = 4;
+    unsigned cacheline;
+
+    if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
+        fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
+                strerror(errno));
+        exit(1);
+    }
+
+    qemu_cache_conf.dcache_bsize = cacheline;
+    qemu_cache_conf.icache_bsize = cacheline;
+}
+#endif    
+
 #ifdef __linux__
 void qemu_cache_utils_init(char **envp)
 {