From e6f5a90b5fd51812c31da49fe2f4950fb2ac0e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Paolacci?= Date: Mon, 12 Dec 2011 16:33:13 -0500 Subject: [PATCH] runtime: madvise and SysUnused for Linux SysUnused being a direct call to madvise MADV_DONTNEED. R=golang-dev, dave CC=golang-dev https://golang.org/cl/5477057 --- src/pkg/runtime/linux/386/defs.h | 2 ++ src/pkg/runtime/linux/386/sys.s | 11 +++++++++++ src/pkg/runtime/linux/amd64/defs.h | 6 ++++-- src/pkg/runtime/linux/amd64/sys.s | 11 +++++++++++ src/pkg/runtime/linux/arm/defs.h | 1 + src/pkg/runtime/linux/arm/sys.s | 9 +++++++++ src/pkg/runtime/linux/defs.go | 2 ++ src/pkg/runtime/linux/defs2.go | 3 +++ src/pkg/runtime/linux/defs_arm.go | 2 ++ src/pkg/runtime/linux/mem.c | 4 +--- 10 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/pkg/runtime/linux/386/defs.h b/src/pkg/runtime/linux/386/defs.h index 19d6d9eec50..02760f987bc 100644 --- a/src/pkg/runtime/linux/386/defs.h +++ b/src/pkg/runtime/linux/386/defs.h @@ -12,6 +12,8 @@ enum { MAP_PRIVATE = 0x2, MAP_FIXED = 0x10, + MADV_DONTNEED = 0x4, + SA_RESTART = 0x10000000, SA_ONSTACK = 0x8000000, SA_RESTORER = 0x4000000, diff --git a/src/pkg/runtime/linux/386/sys.s b/src/pkg/runtime/linux/386/sys.s index 7baeb34bce6..d96c022d36e 100644 --- a/src/pkg/runtime/linux/386/sys.s +++ b/src/pkg/runtime/linux/386/sys.s @@ -212,6 +212,17 @@ TEXT runtime·munmap(SB),7,$0 INT $3 RET +TEXT runtime·madvise(SB),7,$0 + MOVL $219, AX // madvise + MOVL 4(SP), BX + MOVL 8(SP), CX + MOVL 12(SP), DX + CALL *runtime·_vdso(SB) + CMPL AX, $0xfffff001 + JLS 2(PC) + INT $3 + RET + // int32 futex(int32 *uaddr, int32 op, int32 val, // struct timespec *timeout, int32 *uaddr2, int32 val2); TEXT runtime·futex(SB),7,$0 diff --git a/src/pkg/runtime/linux/amd64/defs.h b/src/pkg/runtime/linux/amd64/defs.h index 5b44a78530e..bf5f79b0e4d 100644 --- a/src/pkg/runtime/linux/amd64/defs.h +++ b/src/pkg/runtime/linux/amd64/defs.h @@ -12,6 +12,8 @@ enum { MAP_PRIVATE = 0x2, MAP_FIXED = 0x10, + MADV_DONTNEED = 0x4, + SA_RESTART = 0x10000000, SA_ONSTACK = 0x8000000, SA_RESTORER = 0x4000000, @@ -95,7 +97,7 @@ struct Siginfo { int32 si_signo; int32 si_errno; int32 si_code; - byte Pad_godefs_0[4]; + byte Pad_cgo_0[4]; byte _sifields[112]; }; struct Itimerval { @@ -181,7 +183,7 @@ struct Fpreg1 { struct Sigaltstack { byte *ss_sp; int32 ss_flags; - byte Pad_godefs_0[4]; + byte Pad_cgo_0[4]; uint64 ss_size; }; struct Mcontext { diff --git a/src/pkg/runtime/linux/amd64/sys.s b/src/pkg/runtime/linux/amd64/sys.s index ff72a753408..76bb48c75a9 100644 --- a/src/pkg/runtime/linux/amd64/sys.s +++ b/src/pkg/runtime/linux/amd64/sys.s @@ -192,6 +192,17 @@ TEXT runtime·munmap(SB),7,$0 CALL runtime·notok(SB) RET +TEXT runtime·madvise(SB),7,$0 + MOVQ 8(SP), DI + MOVQ 16(SP), SI + MOVQ 24(SP), DX + MOVQ $28, AX // madvise + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 2(PC) + CALL runtime·notok(SB) + RET + TEXT runtime·notok(SB),7,$0 MOVQ $0xf1, BP MOVQ BP, (BP) diff --git a/src/pkg/runtime/linux/arm/defs.h b/src/pkg/runtime/linux/arm/defs.h index 09b558ed0f8..da97a843395 100644 --- a/src/pkg/runtime/linux/arm/defs.h +++ b/src/pkg/runtime/linux/arm/defs.h @@ -11,6 +11,7 @@ enum { MAP_ANON = 0x20, MAP_PRIVATE = 0x2, MAP_FIXED = 0x10, + MADV_DONTNEED = 0x4, SA_RESTART = 0x10000000, SA_ONSTACK = 0x8000000, SA_RESTORER = 0x4000000, diff --git a/src/pkg/runtime/linux/arm/sys.s b/src/pkg/runtime/linux/arm/sys.s index 80f956fb083..14ea337d02e 100644 --- a/src/pkg/runtime/linux/arm/sys.s +++ b/src/pkg/runtime/linux/arm/sys.s @@ -28,6 +28,7 @@ #define SYS_futex (SYS_BASE + 240) #define SYS_exit_group (SYS_BASE + 248) #define SYS_munmap (SYS_BASE + 91) +#define SYS_madvise (SYS_BASE + 220) #define SYS_setitimer (SYS_BASE + 104) #define SYS_mincore (SYS_BASE + 219) #define SYS_gettid (SYS_BASE + 224) @@ -111,6 +112,14 @@ TEXT runtime·munmap(SB),7,$0 SWI $0 RET +TEXT runtime·madvise(SB),7,$0 + MOVW 0(FP), R0 + MOVW 4(FP), R1 + MOVW 8(FP), R2 + MOVW $SYS_madvise, R7 + SWI $0 + RET + TEXT runtime·setitimer(SB),7,$0 MOVW 0(FP), R0 MOVW 4(FP), R1 diff --git a/src/pkg/runtime/linux/defs.go b/src/pkg/runtime/linux/defs.go index 85f99db1748..bbaab2d33e7 100644 --- a/src/pkg/runtime/linux/defs.go +++ b/src/pkg/runtime/linux/defs.go @@ -36,6 +36,8 @@ const ( MAP_PRIVATE = C.MAP_PRIVATE MAP_FIXED = C.MAP_FIXED + MADV_DONTNEED = C.MADV_DONTNEED + SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK SA_RESTORER = C.SA_RESTORER diff --git a/src/pkg/runtime/linux/defs2.go b/src/pkg/runtime/linux/defs2.go index 56da642ed3e..1fafb7bfc1c 100644 --- a/src/pkg/runtime/linux/defs2.go +++ b/src/pkg/runtime/linux/defs2.go @@ -17,6 +17,7 @@ package runtime /* #cgo CFLAGS: -I/home/rsc/pub/linux-2.6/arch/x86/include -I/home/rsc/pub/linux-2.6/include -D_LOOSE_KERNEL_NAMES -D__ARCH_SI_UID_T=__kernel_uid32_t +#define size_t __kernel_size_t #include #include #include @@ -47,6 +48,8 @@ const ( MAP_PRIVATE = C.MAP_PRIVATE MAP_FIXED = C.MAP_FIXED + MADV_DONTNEED = C.MADV_DONTNEED + SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK SA_RESTORER = C.SA_RESTORER diff --git a/src/pkg/runtime/linux/defs_arm.go b/src/pkg/runtime/linux/defs_arm.go index 3312d36e54d..35f74e8dbac 100644 --- a/src/pkg/runtime/linux/defs_arm.go +++ b/src/pkg/runtime/linux/defs_arm.go @@ -53,6 +53,8 @@ const ( MAP_PRIVATE = C.MAP_PRIVATE MAP_FIXED = C.MAP_FIXED + MADV_DONTNEED = C.MADV_DONTNEED + SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK SA_RESTORER = C.SA_RESTORER diff --git a/src/pkg/runtime/linux/mem.c b/src/pkg/runtime/linux/mem.c index fe18e144831..62e4eda2c25 100644 --- a/src/pkg/runtime/linux/mem.c +++ b/src/pkg/runtime/linux/mem.c @@ -56,9 +56,7 @@ runtime·SysAlloc(uintptr n) void runtime·SysUnused(void *v, uintptr n) { - USED(v); - USED(n); - // TODO(rsc): call madvise MADV_DONTNEED + runtime·madvise(v, n, MADV_DONTNEED); } void