Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode Add thunk_madvise() for memory access hint...



details:   https://anonhg.NetBSD.org/src/rev/91ce3d54ef4b
branches:  trunk
changeset: 772641:91ce3d54ef4b
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Tue Jan 10 12:04:56 2012 +0000

description:
Add thunk_madvise() for memory access hints to the host kernel.

diffstat:

 sys/arch/usermode/include/thunk.h  |  11 ++++++++++-
 sys/arch/usermode/usermode/thunk.c |  35 +++++++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 3 deletions(-)

diffs (95 lines):

diff -r ae9c338f42af -r 91ce3d54ef4b sys/arch/usermode/include/thunk.h
--- a/sys/arch/usermode/include/thunk.h Tue Jan 10 11:32:25 2012 +0000
+++ b/sys/arch/usermode/include/thunk.h Tue Jan 10 12:04:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.h,v 1.57 2012/01/06 14:11:55 jmcneill Exp $ */
+/* $NetBSD: thunk.h,v 1.58 2012/01/10 12:04:56 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -67,6 +67,14 @@
 #define THUNK_PROT_WRITE       0x02
 #define THUNK_PROT_EXEC                0x04
 
+#define THUNK_MADV_NORMAL      0x01
+#define THUNK_MADV_RANDOM      0x02
+#define THUNK_MADV_SEQUENTIAL  0x04
+#define THUNK_MADV_WILLNEED    0x08
+#define THUNK_MADV_DONTNEED    0x10
+#define THUNK_MADV_FREE                0x20
+
+
 struct aiocb;
 
 void   thunk_printf_debug(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
@@ -138,6 +146,7 @@
 void * thunk_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
 int    thunk_munmap(void *addr, size_t len);
 int    thunk_mprotect(void *addr, size_t len, int prot);
+int    thunk_madvise(void *addr, size_t len, int behav);
 int    thunk_posix_memalign(void **, size_t, size_t);
 
 int    thunk_idle(void);
diff -r ae9c338f42af -r 91ce3d54ef4b sys/arch/usermode/usermode/thunk.c
--- a/sys/arch/usermode/usermode/thunk.c        Tue Jan 10 11:32:25 2012 +0000
+++ b/sys/arch/usermode/usermode/thunk.c        Tue Jan 10 12:04:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.75 2012/01/06 14:11:55 jmcneill Exp $ */
+/* $NetBSD: thunk.c,v 1.76 2012/01/10 12:04:56 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.75 2012/01/06 14:11:55 jmcneill Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.76 2012/01/10 12:04:56 reinoud Exp $");
 #endif
 
 #include <sys/types.h>
@@ -213,6 +213,27 @@
        return nflags;
 }
 
+static int
+thunk_to_native_madviseflags(int flags)
+{
+       int nflags = 0;
+
+       if (flags & THUNK_MADV_NORMAL)
+               nflags |= MADV_NORMAL;
+       if (flags & THUNK_MADV_RANDOM)
+               nflags |= MADV_RANDOM;
+       if (flags & THUNK_MADV_SEQUENTIAL)
+               nflags |= MADV_SEQUENTIAL;
+       if (flags & THUNK_MADV_WILLNEED)
+               nflags |= MADV_WILLNEED;
+       if (flags & THUNK_MADV_DONTNEED)
+               nflags |= MADV_DONTNEED;
+       if (flags & THUNK_MADV_FREE)
+               nflags |= MADV_FREE;
+
+       return nflags;
+}
+
 int
 thunk_setitimer(int which, const struct thunk_itimerval *value,
     struct thunk_itimerval *ovalue)
@@ -673,6 +694,16 @@
 }
 
 int
+thunk_madvise(void *addr, size_t len, int behav)
+{
+       int nbehav;
+
+       nbehav = thunk_to_native_madviseflags(behav);
+
+       return madvise(addr, len, nbehav);
+}
+
+int
 thunk_posix_memalign(void **ptr, size_t alignment, size_t size)
 {
        return posix_memalign(ptr, alignment, size);



Home | Main Index | Thread Index | Old Index