Module Name:    src
Committed By:   reinoud
Date:           Tue Jan 10 12:04:56 UTC 2012

Modified Files:
        src/sys/arch/usermode/include: thunk.h
        src/sys/arch/usermode/usermode: thunk.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/usermode/include/thunk.h
cvs rdiff -u -r1.75 -r1.76 src/sys/arch/usermode/usermode/thunk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/usermode/include/thunk.h
diff -u src/sys/arch/usermode/include/thunk.h:1.57 src/sys/arch/usermode/include/thunk.h:1.58
--- src/sys/arch/usermode/include/thunk.h:1.57	Fri Jan  6 14:11:55 2012
+++ src/sys/arch/usermode/include/thunk.h	Tue Jan 10 12:04:56 2012
@@ -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 <jmcne...@invisible.ca>
@@ -67,6 +67,14 @@ struct thunk_termios {
 #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_sbrk(intptr_t len);
 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);

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.75 src/sys/arch/usermode/usermode/thunk.c:1.76
--- src/sys/arch/usermode/usermode/thunk.c:1.75	Fri Jan  6 14:11:55 2012
+++ src/sys/arch/usermode/usermode/thunk.c	Tue Jan 10 12:04:56 2012
@@ -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 <jmcne...@invisible.ca>
@@ -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 @@ thunk_to_native_mapflags(int flags)
 	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 @@ thunk_mprotect(void *addr, size_t len, i
 }
 
 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);

Reply via email to