1
0
mirror of https://github.com/golang/go synced 2024-11-25 19:57:56 -07:00

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
This commit is contained in:
Sébastien Paolacci 2011-12-12 16:33:13 -05:00 committed by Russ Cox
parent 0f4f3c6769
commit e6f5a90b5f
10 changed files with 46 additions and 5 deletions

View File

@ -12,6 +12,8 @@ enum {
MAP_PRIVATE = 0x2, MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10, MAP_FIXED = 0x10,
MADV_DONTNEED = 0x4,
SA_RESTART = 0x10000000, SA_RESTART = 0x10000000,
SA_ONSTACK = 0x8000000, SA_ONSTACK = 0x8000000,
SA_RESTORER = 0x4000000, SA_RESTORER = 0x4000000,

View File

@ -212,6 +212,17 @@ TEXT runtime·munmap(SB),7,$0
INT $3 INT $3
RET 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, // int32 futex(int32 *uaddr, int32 op, int32 val,
// struct timespec *timeout, int32 *uaddr2, int32 val2); // struct timespec *timeout, int32 *uaddr2, int32 val2);
TEXT runtime·futex(SB),7,$0 TEXT runtime·futex(SB),7,$0

View File

@ -12,6 +12,8 @@ enum {
MAP_PRIVATE = 0x2, MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10, MAP_FIXED = 0x10,
MADV_DONTNEED = 0x4,
SA_RESTART = 0x10000000, SA_RESTART = 0x10000000,
SA_ONSTACK = 0x8000000, SA_ONSTACK = 0x8000000,
SA_RESTORER = 0x4000000, SA_RESTORER = 0x4000000,
@ -95,7 +97,7 @@ struct Siginfo {
int32 si_signo; int32 si_signo;
int32 si_errno; int32 si_errno;
int32 si_code; int32 si_code;
byte Pad_godefs_0[4]; byte Pad_cgo_0[4];
byte _sifields[112]; byte _sifields[112];
}; };
struct Itimerval { struct Itimerval {
@ -181,7 +183,7 @@ struct Fpreg1 {
struct Sigaltstack { struct Sigaltstack {
byte *ss_sp; byte *ss_sp;
int32 ss_flags; int32 ss_flags;
byte Pad_godefs_0[4]; byte Pad_cgo_0[4];
uint64 ss_size; uint64 ss_size;
}; };
struct Mcontext { struct Mcontext {

View File

@ -192,6 +192,17 @@ TEXT runtime·munmap(SB),7,$0
CALL runtime·notok(SB) CALL runtime·notok(SB)
RET 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 TEXT runtime·notok(SB),7,$0
MOVQ $0xf1, BP MOVQ $0xf1, BP
MOVQ BP, (BP) MOVQ BP, (BP)

View File

@ -11,6 +11,7 @@ enum {
MAP_ANON = 0x20, MAP_ANON = 0x20,
MAP_PRIVATE = 0x2, MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10, MAP_FIXED = 0x10,
MADV_DONTNEED = 0x4,
SA_RESTART = 0x10000000, SA_RESTART = 0x10000000,
SA_ONSTACK = 0x8000000, SA_ONSTACK = 0x8000000,
SA_RESTORER = 0x4000000, SA_RESTORER = 0x4000000,

View File

@ -28,6 +28,7 @@
#define SYS_futex (SYS_BASE + 240) #define SYS_futex (SYS_BASE + 240)
#define SYS_exit_group (SYS_BASE + 248) #define SYS_exit_group (SYS_BASE + 248)
#define SYS_munmap (SYS_BASE + 91) #define SYS_munmap (SYS_BASE + 91)
#define SYS_madvise (SYS_BASE + 220)
#define SYS_setitimer (SYS_BASE + 104) #define SYS_setitimer (SYS_BASE + 104)
#define SYS_mincore (SYS_BASE + 219) #define SYS_mincore (SYS_BASE + 219)
#define SYS_gettid (SYS_BASE + 224) #define SYS_gettid (SYS_BASE + 224)
@ -111,6 +112,14 @@ TEXT runtime·munmap(SB),7,$0
SWI $0 SWI $0
RET 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 TEXT runtime·setitimer(SB),7,$0
MOVW 0(FP), R0 MOVW 0(FP), R0
MOVW 4(FP), R1 MOVW 4(FP), R1

View File

@ -36,6 +36,8 @@ const (
MAP_PRIVATE = C.MAP_PRIVATE MAP_PRIVATE = C.MAP_PRIVATE
MAP_FIXED = C.MAP_FIXED MAP_FIXED = C.MAP_FIXED
MADV_DONTNEED = C.MADV_DONTNEED
SA_RESTART = C.SA_RESTART SA_RESTART = C.SA_RESTART
SA_ONSTACK = C.SA_ONSTACK SA_ONSTACK = C.SA_ONSTACK
SA_RESTORER = C.SA_RESTORER SA_RESTORER = C.SA_RESTORER

View File

@ -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 #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 <asm/signal.h> #include <asm/signal.h>
#include <asm/mman.h> #include <asm/mman.h>
#include <asm/sigcontext.h> #include <asm/sigcontext.h>
@ -47,6 +48,8 @@ const (
MAP_PRIVATE = C.MAP_PRIVATE MAP_PRIVATE = C.MAP_PRIVATE
MAP_FIXED = C.MAP_FIXED MAP_FIXED = C.MAP_FIXED
MADV_DONTNEED = C.MADV_DONTNEED
SA_RESTART = C.SA_RESTART SA_RESTART = C.SA_RESTART
SA_ONSTACK = C.SA_ONSTACK SA_ONSTACK = C.SA_ONSTACK
SA_RESTORER = C.SA_RESTORER SA_RESTORER = C.SA_RESTORER

View File

@ -53,6 +53,8 @@ const (
MAP_PRIVATE = C.MAP_PRIVATE MAP_PRIVATE = C.MAP_PRIVATE
MAP_FIXED = C.MAP_FIXED MAP_FIXED = C.MAP_FIXED
MADV_DONTNEED = C.MADV_DONTNEED
SA_RESTART = C.SA_RESTART SA_RESTART = C.SA_RESTART
SA_ONSTACK = C.SA_ONSTACK SA_ONSTACK = C.SA_ONSTACK
SA_RESTORER = C.SA_RESTORER SA_RESTORER = C.SA_RESTORER

View File

@ -56,9 +56,7 @@ runtime·SysAlloc(uintptr n)
void void
runtime·SysUnused(void *v, uintptr n) runtime·SysUnused(void *v, uintptr n)
{ {
USED(v); runtime·madvise(v, n, MADV_DONTNEED);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
} }
void void